Files at this revision

API Documentation at this revision

Comitter:
sllez
Date:
Mon Jun 29 15:54:28 2020 +0000
Commit message:
final

Changed in this revision

hoverserial.cpp Show annotated file Show diff for this revision Revisions of this file
hoverserial.h Show annotated file Show diff for this revision Revisions of this file
diff -r 000000000000 -r ca040e149431 hoverserial.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/hoverserial.cpp	Mon Jun 29 15:54:28 2020 +0000
@@ -0,0 +1,36 @@
+// CONFIGURATION on the hoverboard side in config.h:
+// • Option 1: Serial on Left Sensor cable (long wired cable)
+//   #define CONTROL_SERIAL_USART2
+//   #define FEEDBACK_SERIAL_USART2
+//   // #define DEBUG_SERIAL_USART2
+// • Option 2: Serial on Right Sensor cable (short wired cable) - recommended, so the ADCs on the other cable are still available
+//   #define CONTROL_SERIAL_USART3
+//   #define FEEDBACK_SERIAL_USART3
+//   // #define DEBUG_SERIAL_USART3
+// *******************************************************************
+
+// ########################## INCLUDES ##########################
+
+#include "mbed.h"
+#include "hoverserial.h"
+#include "BufferedSerial.h"
+
+HoverSerial::HoverSerial(PinName tx, PinName rx) :
+hoverserial(tx, rx)
+
+{
+    hoverserial.baud(38400);
+}
+
+void HoverSerial::sendData(int16_t uSteer, int16_t uSpeed) {
+    // Create command
+    Command.start    = (uint16_t)START_FRAME;
+    Command.steer    = (int16_t)uSteer;
+    Command.speed    = (int16_t)uSpeed;
+    Command.checksum = (uint16_t)(Command.start ^ Command.steer ^ Command.speed);
+    // Write to Serial
+    hoverserial.write((uint8_t *) &Command, sizeof(Command));
+}
+
+void HoverSerial::receiveData() {
+}
\ No newline at end of file
diff -r 000000000000 -r ca040e149431 hoverserial.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/hoverserial.h	Mon Jun 29 15:54:28 2020 +0000
@@ -0,0 +1,42 @@
+#include "mbed.h"
+#include "BufferedSerial.h"
+
+#define HOVERSERIAL_BAUD    38400       // [-] Baud rate for HoverSerial (used to communicate with the hoverboard)
+#define START_FRAME         0xABCD      // [-] Start frme definition for reliable serial communication
+//#define DEBUG_RX                      // [-] Debug received data. Prints all bytes to serial (comment-out to disable)
+
+class HoverSerial {
+    public:
+        // @parm    tx  communication tx pin
+        //          rx  communocation rx pin
+        HoverSerial(PinName tx, PinName rx);
+        
+        typedef struct {                        //Structure for sending data to hoverboard
+            uint16_t  start;
+            int16_t  steer;
+            int16_t  speed;
+            uint16_t checksum;
+        } SerialCommand;
+        SerialCommand Command;
+
+        typedef struct {                       //Structure for feedback from hoverboard
+            uint16_t start;
+            int16_t   cmd1;
+            int16_t   cmd2;
+            int16_t   speedR_meas;
+            int16_t   speedL_meas;
+            int16_t   batVoltage;
+            int16_t   boardTemp;
+            uint16_t cmdLed;
+            uint16_t checksum;
+        } SerialFeedback;
+        SerialFeedback Feedback;
+        SerialFeedback NewFeedback;
+        
+        void sendData(int16_t uSteer, int16_t uSpeed);
+        
+        void receiveData();
+        
+    private:
+        BufferedSerial hoverserial;
+};
\ No newline at end of file