Thank u for suggestion
My purpose is to hovering a quadcopter indoor with combine image processing information and IMU data.
Due to image processing can do only in minicomputer (in my case is NUC i3). I must exchange some kind of data between arduinoDUE and my minicomputer.
And a diagram will be placed a thousand word.
arduinoDUE ------ IMU data ---> minicomputer (NUC i3)
if(position_is_ready_to_send) {
minicomputer------position,velocity---->arduinoDUE
}
Everything work fine when i send IMU from arduinoDUE to minicomputer without send back following the graph have been shown acceleration z is still at around 9.8 m/s^2. But when the position data that ready to use, i clicked allow it to send the data to arduinoDUE that have been pack with python code below.
I got a problem that IMU are going crazy, in spite of position not affect to IMU.
(NUC send image processing data to arduinoDUE with this function)
def send_vision_data(self,datav) : #(3 float 1 uint)
dlen = 14
head = struct.pack('ccc',chr(181),chr(dlen),chr(VISION_DATA))
data = struct.pack('fffH',datav[0],datav[1],datav[2],datav[3])
summ= 181+dlen+VISION_DATA
for d in str(data):
summ+=ord(d)
chk = struct.pack('h',summ)
tatal = len(head)+len(data)+len(chk)
self.s.write( head )
self.s.write( data )
self.s.write( chk )
print 'p x:', datav[0] ,'p y:' , datav[1]
return tatal
arduinoDUE receieve the position with this function (placed top of void loop()
#define Serial_ulink SerialUSB
void loop()
{
SerialUSBEvent();
currentTime = micros();
if (currentTime - sensorPreviousTime >= 1000) {
imu_read();
}
if (frameCounter % TASK_50HZ == 0) {
....
}
.....
}
uint8_t st = 0,_lenp,_msgid,_pay[512],_idp,_c[2];
uint16_t _sum_pay,_csum;
static void SerialUSBEvent() {
while (Serial_ulink.available()) {
uint8_t dd = Serial_ulink.read();
switch (st) {
case 0:
_sum_pay=0;
if (dd == HEADER) {
_sum_pay+=dd;
st++;
}
break;
case 1 :
_lenp = dd;
_sum_pay+=dd;
st++;
break;
case 2 :
_msgid = dd;
_sum_pay+=dd;
_idp = 0;
st++;
break;
case 3 :
_pay[_idp++] = dd;
_sum_pay+=dd;
if (_idp >=_lenp) st++;
break;
case 4 :
_c[0] = dd;
st++;
break;
case 5 :
_c[1] = dd;
_csum = toUint(_c);
st = 0;
if (_sum_pay == _csum) {
if (_msgid == CMD_TAKEOFF) {
uint8_t h;
h = _pay[0];
}else if(_msgid == VISION_DATA) { //float x,float y,float z uint vision_is_good?
uint8_t vision_tracking_quality = toUint(_pay[12]);
vision_is_good= (vision_tracking_quality > 1 ? 1:0);
vision_time_stamp=millis();
vision_bx[0]=toFlt(_pay[0]);
vision_by[0]=toFlt(_pay[4]);
vision_bz[0]=toFlt(_pay[8]);
}
}
break;
}
}
}