Zumy code for sending struct data

Dependencies:   MPU6050IMU QEI RPCInterface mbed

Fork of zumy_mbed by David McPherson

Revision:
8:1e47a6b49537
Parent:
7:50b807559e1a
Child:
9:6bff048c3b49
--- a/main.cpp	Wed Feb 17 02:38:26 2016 +0000
+++ b/main.cpp	Wed Feb 17 03:45:51 2016 +0000
@@ -3,34 +3,17 @@
 #include "MPU6050.h"
 #include "QEI.h"
 
-typedef struct sensor_data{
-    float rpc_accel[3];
-    float rpc_gyro[3];
-    int   rpc_enc[2];
-} Sensor_data;
-
-Sensor_data sd;
+extern "C" void mbed_reset();
 
 SerialRPCInterface SerialRPC(USBTX, USBRX, 115200);
-
+//Serial pc(USBTX, USBRX); // tx, rx
 void GetSensorData(char* input, char* output);
 RPCFunction gsd(&GetSensorData, "gsd");
-
-//Serial pc(USBTX, USBRX); // tx, rx
+void Reset(char* input, char* output);
+RPCFunction rst(&Reset, "rst");
 
-// old RPCVariable code
-//float accel_x, accel_y, accel_z, gyro_x, gyro_y, gyro_z;
-//int r_enc, l_enc;
-/*
-RPCVariable<float> rpc_accel_x(&accel_x, "accel_x");
-RPCVariable<float> rpc_accel_y(&accel_y, "accel_y");
-RPCVariable<float> rpc_accel_z(&accel_z, "accel_z");
-RPCVariable<float> rpc_gryo_x(&gyro_x, "gyro_x");
-RPCVariable<float> rpc_gryo_y(&gyro_y, "gyro_y");
-RPCVariable<float> rpc_gryo_z(&gyro_z, "gyro_z");
-RPCVariable<int>   rpc_r_enc(&r_enc, "r_enc");
-RPCVariable<int>   rpc_l_enc(&l_enc, "l_enc");
-*/
+float accel_x, accel_y, accel_z, gyro_x, gyro_y, gyro_z;
+int r_enc, l_enc;
 
 QEI l_wheel (p29, p30, NC, 624);
 QEI r_wheel (p11, p12, NC, 624);
@@ -75,8 +58,8 @@
         wait_ms(10);
         
         // Handle the encoders
-        sd.rpc_enc[1] = r_wheel.getPulses();
-        sd.rpc_enc[0] = l_wheel.getPulses();
+        r_enc = r_wheel.getPulses();
+        l_enc = l_wheel.getPulses();
         //pc.printf("Pulses are: %i, %i\r\n", l_enc,r_enc);
         
         if (!(--loop_count)) {
@@ -91,22 +74,23 @@
                 mpu6050.readGyroData(gyroCount);  // Read the x/y/z adc values
 
                 // Now we'll calculate the accleration value into actual g's
-                sd.rpc_accel[0] = (float)accelCount[0]*aRes - accelBias[0];  // get actual g value, this depends on scale being set
-                sd.rpc_accel[1] = (float)accelCount[1]*aRes - accelBias[1];   
-                sd.rpc_accel[2] = (float)accelCount[2]*aRes - accelBias[2];
+                accel_x = (float)accelCount[0]*aRes - accelBias[0];  // get actual g value, this depends on scale being set
+                accel_y = (float)accelCount[1]*aRes - accelBias[1];   
+                accel_z = (float)accelCount[2]*aRes - accelBias[2];
                                
                 // Calculate the gyro value into actual degrees per second
-                sd.rpc_gyro[0] = (float)gyroCount[0]*gRes - gyroBias[0];  // get actual gyro value, this depends on scale being set
-                sd.rpc_gyro[1] = (float)gyroCount[1]*gRes - gyroBias[1];  
-                sd.rpc_gyro[2] = (float)gyroCount[2]*gRes - gyroBias[2];
+                gyro_x = (float)gyroCount[0]*gRes - gyroBias[0];  // get actual gyro value, this depends on scale being set
+                gyro_y = (float)gyroCount[1]*gRes - gyroBias[1];  
+                gyro_z = (float)gyroCount[2]*gRes - gyroBias[2];
             }
         }
     }
 }
 
 void GetSensorData(char* input, char* output){
-    sprintf(output, "%f,%f,%f,%f,%f,%f,%i,%i", 
-           sd.rpc_accel[0], sd.rpc_accel[1], sd.rpc_accel[2],
-           sd.rpc_gyro[0], sd.rpc_gyro[1], sd.rpc_gyro[2],
-           sd.rpc_enc[0], sd.rpc_enc[1]);
+    sprintf(output, "%f,%f,%f,%f,%f,%f,%i,%i", accel_x, accel_y, accel_z, gyro_x, gyro_y, gyro_z, l_enc, r_enc);
 }
+
+void Reset(char* input, char* output){
+    mbed_reset();
+}