Remote control code for https://developer.mbed.org/users/ivo_david_michelle/code/QuadTrio/

Dependencies:   Analog_Joystick Sender mbed

Fork of ESE350-Whack-a-Mole by Eric Berdinis

Revision:
7:8714628b62e5
Parent:
6:db985df4354b
Child:
8:ff7cd3525c32
--- a/rc.cpp	Thu Mar 31 19:26:48 2016 +0000
+++ b/rc.cpp	Thu Mar 31 22:41:19 2016 +0000
@@ -1,8 +1,9 @@
+#include "mbed.h"
 #include "MRF24J40.h"
 #include "sender.h"
 #include "analog_joystick.h"
 
-#include <string>
+#include <string.h>
 
 // RF tranceiver to link with handheld.
 MRF24J40 mrf(p11, p12, p13, p14, p21);
@@ -19,18 +20,14 @@
 // Serial port for showing RX data.
 Serial pc(USBTX, USBRX);
 
-// Used for sending and receiving
-char txBuffer[128];
-char rxBuffer[128];
-int rxLen;
-LocalFileSystem local("local");
+int iterations = 100;
 
 //***************** send and receive methods *****************//
 /*
 void wait_for_ping(uint8_t length) {
     int receive = 0;
     uint8_t *rssi = 0;
-    
+
     while (receive == 0) {
         receive = rf_receive_rssi(rxBuffer, rssi, length);
     }
@@ -40,62 +37,29 @@
 
 //***************** main loop *****************//
 
-int main (void)
-{
+int main (void) {
     uint8_t channel = 3;
-    uint8_t iterations = 0;
-    uint8_t successCounter = 0;
-    uint8_t rssiBuffer[iterations];
-    
-    char *byteTransmit = "!"; // TODO: change this! 
 
     //Set the Channel. 0 is default, 15 is max
     mrf.SetChannel(channel);
 
     //Start the timer
     timer.start();
-    
+
     pc.printf("START\r\n");
-    
-    FILE *fp = fopen("/local/out.txt\r\n", "w");
-    if (fp == NULL) {
-        pc.printf("error opening file\r\n");
-        return 0;
-    }
-    
-    int count = 25;
-    while (count > 0) {
-        count--;
+
+    // send_three_way_handshake();
 
-        pc.printf("yaw: %f\r\n", read_yaw());
-        pc.printf("pitch: %f\r\n", read_pitch());
-        pc.printf("roll: %f\r\n", read_roll());
-        pc.printf("thrust: %f\r\n", read_thrust());
-        
-        wait(0.2);
-    }
+    int i;
+    char txBuffer[50];
     
-    
-    // send_three_way_handshake();
-    
-    for (int i = 0; i < iterations; i++) {
-        strcpy(txBuffer, byteTransmit);
+    for (i = 0; i < iterations; i++) {
+        sprintf(txBuffer, "%f,%f,%f,%f", read_thrust(), read_yaw(), read_pitch(), read_roll());
         rf_send(mrf, txBuffer, strlen(txBuffer) + 1);
         pc.printf("RC Sent: %s \r\n", txBuffer);
-    
-        wait(0.2);
+
+        wait(0.2);  // TODO: change this value?
     }
-    
-    // output data
-    fprintf(fp, "# received\t= %d\n", successCounter);
-    fprintf(fp, "# sent\t= %d\n", iterations);
-    fprintf(fp, "success rate\t= %f\n", (double) successCounter / (double) iterations);
-    double sum = 0;
-    for (int i = 0; i < successCounter; i++) {
-        sum += rssiBuffer[i];
-    }
-    fprintf(fp, "average rssi\t= %f\n", sum / (double) successCounter);
-    fclose(fp);
-    
+
     pc.printf("END\r\n");
 }