120 uint8_t *output_buf = sfg->pControlSubsystem->serial_out_buf;
123 static uint32_t iTimeStamp = 0;
136 uint8_t AngularVelocityPacketOn,
139 int8_t AccelCalPacketOn;
140 static uint8_t iPacketNumber = 0;
145#if (MAXPACKETRATEHZ < FUSION_HZ)
146 if (Throttle())
return;
151 quaternionPacketType = sfg->pControlSubsystem->QuaternionPacketType;
152 AngularVelocityPacketOn = sfg->pControlSubsystem->AngularVelocityPacketOn;
153 DebugPacketOn = sfg->pControlSubsystem->DebugPacketOn;
154 RPCPacketOn = sfg->pControlSubsystem->RPCPacketOn;
155 AccelCalPacketOn = sfg->pControlSubsystem->AccelCalPacketOn;
158 sfg->pControlSubsystem->bytes_to_send = 0;
183 output_buf[iIndex++] = 0x7E;
199 switch (quaternionPacketType)
207 if( sfg->Accel.iCountsPerg != 0 ) {
208 scratch32 = (sfg->Accel.iGc[
CHX] * 8192) / sfg->Accel.iCountsPerg;
209 if (scratch32 > 32767) scratch32 = 32767;
210 if (scratch32 < -32768) scratch32 = -32768;
211 scratch16 = (int16_t) (scratch32);
213 scratch32 = (sfg->Accel.iGc[
CHY] * 8192) / sfg->Accel.iCountsPerg;
214 if (scratch32 > 32767) scratch32 = 32767;
215 if (scratch32 < -32768) scratch32 = -32768;
216 scratch16 = (int16_t) (scratch32);
218 scratch32 = (sfg->Accel.iGc[
CHZ] * 8192) / sfg->Accel.iCountsPerg;
219 if (scratch32 > 32767) scratch32 = 32767;
220 if (scratch32 < -32768) scratch32 = -32768;
221 scratch16 = (int16_t) (scratch32);
235 OutputBufAppendZeros(output_buf, &iIndex, 3);
240 OutputBufAppendZeros(output_buf, &iIndex, 3);
245 switch (quaternionPacketType)
272 OutputBufAppendZeros(output_buf, &iIndex, 3);
278 OutputBufAppendZeros(output_buf, &iIndex, 3);
285 switch (quaternionPacketType)
293 if( sfg->Gyro.iCountsPerDegPerSec != 0 ) {
294 scratch16 = (int16_t) ((sfg->Gyro.iYs[
CHX] * 20) / sfg->Gyro.iCountsPerDegPerSec);
296 scratch16 = (int16_t) ((sfg->Gyro.iYs[
CHY] * 20) / sfg->Gyro.iCountsPerDegPerSec);
298 scratch16 = (int16_t) ((sfg->Gyro.iYs[
CHZ] * 20) / sfg->Gyro.iCountsPerDegPerSec);
313 OutputBufAppendZeros(output_buf, &iIndex, 3);
320 OutputBufAppendZeros(output_buf, &iIndex, 3);
325 fq.
q1 = fq.
q2 = fq.
q3 = 0.0F;
327 iOmega[
CHX] = iOmega[
CHY] = iOmega[
CHZ] = 0;
328 iPhi = iThe = iRho = iDelta = 0;
343 switch (quaternionPacketType)
350 ReadCommonParams((
SV_ptr)&sfg->SV_3DOF_G_BASIC, &fq, &iPhi, &iThe, &iRho, iOmega, &isystick);
359 ReadCommonParams((
SV_ptr)&sfg->SV_3DOF_B_BASIC, &fq, &iPhi, &iThe, &iRho, iOmega, &isystick);
368 ReadCommonParams((
SV_ptr)&sfg->SV_3DOF_Y_BASIC, &fq, &iPhi, &iThe, &iRho, iOmega, &isystick);
377 iDelta = (int16_t) (10.0F * sfg->SV_6DOF_GB_BASIC.fLPDelta);
378 ReadCommonParams((
SV_ptr)&sfg->SV_6DOF_GB_BASIC, &fq, &iPhi, &iThe, &iRho, iOmega, &isystick);
387 ReadCommonParams((
SV_ptr)&sfg->SV_6DOF_GY_KALMAN, &fq, &iPhi, &iThe, &iRho, iOmega, &isystick);
396 iDelta = (int16_t) (10.0F * sfg->SV_9DOF_GBY_KALMAN.fDeltaPl);
397 ReadCommonParams((
SV_ptr)&sfg->SV_9DOF_GBY_KALMAN, &fq, &iPhi, &iThe, &iRho, iOmega, &isystick);
407 scratch16 = (int16_t) (fq.
q0 * 30000.0F);
409 scratch16 = (int16_t) (fq.
q1 * 30000.0F);
411 scratch16 = (int16_t) (fq.
q2 * 30000.0F);
413 scratch16 = (int16_t) (fq.
q3 * 30000.0F);
417#if THISCOORDSYSTEM == ANDROID
420#elif THISCOORDSYSTEM == WIN8
429 tmpuint8_t = ((THIS_SHIELD & 0x07) << 5) | (THIS_BOARD & 0x1F);
433 output_buf[iIndex++] = 0x7E;
442 output_buf[iIndex++] = 0x7E;
460 output_buf[iIndex++] = 0x7E;
467 if (AngularVelocityPacketOn)
470 output_buf[iIndex++] = 0x7E;
489 output_buf[iIndex++] = 0x7E;
499 output_buf[iIndex++] = 0x7E;
518 output_buf[iIndex++] = 0x7E;
528 if (sfg->pControlSubsystem->AltPacketOn && sfg->Pressure.iWhoAmI)
531 output_buf[iIndex++] = 0x7E;
546 scratch32 = (int32_t) (sfg->SV_1DOF_P_BASIC.fLPH * 1000.0F);
550 scratch16 = (int16_t) (sfg->SV_1DOF_P_BASIC.fLPT * 100.0F);
554 output_buf[iIndex++] = 0x7E;
565 static int16_t MagneticPacketID = 0;
569 output_buf[iIndex++] = 0x7E;
591 scratch16 = (int16_t) (sfg->
MagCal.
fB * 10.0F);
595 k = MagneticPacketID - 10;
604 if ((MagneticPacketID >= 10) && (sfg->
MagBuffer.
index[i][j] == -1))
607 scratch16 = -MagneticPacketID;
613 scratch16 = MagneticPacketID;
620 switch (MagneticPacketID)
638 scratch16 = (int16_t) (sfg->
MagCal.
fV[
CHX] * 10.0F);
640 scratch16 = (int16_t) (sfg->
MagCal.
fV[
CHY] * 10.0F);
642 scratch16 = (int16_t) (sfg->
MagCal.
fV[
CHZ] * 10.0F);
673 OutputBufAppendZeros(output_buf, &iIndex, 3);
690 MagneticPacketID = 0;
693 output_buf[iIndex++] = 0x7E;
706 kalman = six_axis_kalman;
710 kalman = kalman | nine_axis_kalman;
712#if F_6DOF_GY_KALMAN || F_9DOF_GBY_KALMAN
715 if ((quaternionPacketType ==
Q6AG) || (quaternionPacketType ==
Q9))
718 output_buf[iIndex++] = 0x7E;
731 for (i =
CHX; i <=
CHZ; i++)
734 if (six_axis_kalman) scratch16 = (int16_t) (sfg->SV_6DOF_GY_KALMAN.fZErr[i] * 30000.0F);
737 if (nine_axis_kalman) scratch16 = (int16_t) (sfg->SV_9DOF_GBY_KALMAN.fZErr[i] * 30000.0F);
745 for (i =
CHX; i <=
CHZ; i++)
748 if (six_axis_kalman) scratch16 = (int16_t) (sfg->SV_6DOF_GY_KALMAN.fqgErrPl[i] * 30000.0F);
751 if (nine_axis_kalman) scratch16 = (int16_t) (sfg->SV_9DOF_GBY_KALMAN.fqgErrPl[i] * 30000.0F);
759 for (i =
CHX; i <=
CHZ; i++)
762 if (six_axis_kalman) scratch16 = 0;
765 if (nine_axis_kalman) scratch16 = (int16_t) (sfg->SV_9DOF_GBY_KALMAN.fZErr[i + 3] * 30000.0F);
773 for (i =
CHX; i <=
CHZ; i++)
776 if (six_axis_kalman) scratch16 = 0;
779 if (nine_axis_kalman) scratch16 = (int16_t) (sfg->SV_9DOF_GBY_KALMAN.fqmErrPl[i] * 30000.0F);
787 for (i =
CHX; i <=
CHZ; i++)
790 if (six_axis_kalman) scratch16 = (int16_t) (sfg->SV_6DOF_GY_KALMAN.fbPl[i] * 1000.0F);
793 if (nine_axis_kalman) scratch16 = (int16_t) (sfg->SV_9DOF_GBY_KALMAN.fbPl[i] * 1000.0F);
801 if (nine_axis_kalman) scratch16 = (int16_t) (sfg->SV_9DOF_GBY_KALMAN.fDeltaPl * 100.0F);
808 for (i =
CHX; i <=
CHZ; i++)
813 if (six_axis_kalman) ftmp = sfg->SV_6DOF_GY_KALMAN.fAccGl[i] * 8192.0F;
816 if (nine_axis_kalman) ftmp = sfg->SV_9DOF_GBY_KALMAN.fAccGl[i] * 8192.0F;
820 if (ftmp > 32767.0F) scratch16 = 32767;
821 else if (ftmp < -32768.0F) scratch16 = -32768;
822 else scratch16 = (int16_t) ftmp;
829 for (i =
CHX; i <=
CHZ; i++)
834 if (nine_axis_kalman) ftmp = sfg->SV_9DOF_GBY_KALMAN.fDisGl[i] * 100.0F;
838 if (ftmp > 32767.0F) scratch16 = 32767;
839 else if (ftmp < -32768.0F) scratch16 = -32768;
840 else scratch16 = (int16_t) ftmp;
845 output_buf[iIndex++] = 0x7E;
856 if (AccelCalPacketOn != -1)
859 output_buf[iIndex++] = 0x7E;
872 (uint8_t *) &(AccelCalPacketOn), 1);
875 if ((AccelCalPacketOn >= 0) &&
878 scratch16 = (int16_t) (sfg->AccelBuffer.fGsStored[AccelCalPacketOn][
CHX] * 8192.0F);
880 scratch16 = (int16_t) (sfg->AccelBuffer.fGsStored[AccelCalPacketOn][
CHY] * 8192.0F);
882 scratch16 = (int16_t) (sfg->AccelBuffer.fGsStored[AccelCalPacketOn][
CHZ] * 8192.0F);
888 OutputBufAppendZeros(output_buf, &iIndex, 3);
892 scratch16 = (int16_t) (sfg->AccelCal.fV[
CHX] * 32768.0F);
894 scratch16 = (int16_t) (sfg->AccelCal.fV[
CHY] * 32768.0F);
896 scratch16 = (int16_t) (sfg->AccelCal.fV[
CHZ] * 32768.0F);
900 scratch16 = (int16_t) ((sfg->AccelCal.finvW[
CHX][
CHX] - 1.0F) * 10000.0F);
902 scratch16 = (int16_t) ((sfg->AccelCal.finvW[
CHY][
CHY] - 1.0F) * 10000.0F);
904 scratch16 = (int16_t) ((sfg->AccelCal.finvW[
CHZ][
CHZ] - 1.0F) * 10000.0F);
908 scratch16 = (int16_t) (sfg->AccelCal.finvW[
CHX][
CHY] * 10000.0F);
910 scratch16 = (int16_t) (sfg->AccelCal.finvW[
CHX][
CHZ] * 10000.0F);
912 scratch16 = (int16_t) (sfg->AccelCal.finvW[
CHY][
CHZ] * 10000.0F);
916 scratch16 = (int16_t) (sfg->AccelCal.fR0[
CHX][
CHX] * 10000.0F);
918 scratch16 = (int16_t) (sfg->AccelCal.fR0[
CHY][
CHY] * 10000.0F);
920 scratch16 = (int16_t) (sfg->AccelCal.fR0[
CHZ][
CHZ] * 10000.0F);
924 scratch16 = (int16_t) (sfg->AccelCal.fR0[
CHX][
CHY] * 10000.0F);
926 scratch16 = (int16_t) (sfg->AccelCal.fR0[
CHX][
CHZ] * 10000.0F);
928 scratch16 = (int16_t) (sfg->AccelCal.fR0[
CHY][
CHX] * 10000.0F);
930 scratch16 = (int16_t) (sfg->AccelCal.fR0[
CHY][
CHZ] * 10000.0F);
932 scratch16 = (int16_t) (sfg->AccelCal.fR0[
CHZ][
CHX] * 10000.0F);
934 scratch16 = (int16_t) (sfg->AccelCal.fR0[
CHZ][
CHY] * 10000.0F);
938 output_buf[iIndex++] = 0x7E;
941 sfg->pControlSubsystem->AccelCalPacketOn = -1;
949 sfg->pControlSubsystem->bytes_to_send = iIndex;