All mbed code for control over dive planes, pump motor, valve motor, BCUs, UART interface, etc.
Dependencies: mbed ESC mbed MODDMA
robotic_fish_6/SerialControl/SerialController.h@0:c3a329a5b05d, 2020-01-14 (annotated)
- Committer:
- juansal12
- Date:
- Tue Jan 14 19:17:05 2020 +0000
- Revision:
- 0:c3a329a5b05d
Sofi7 mbed code;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
juansal12 | 0:c3a329a5b05d | 1 | /* |
juansal12 | 0:c3a329a5b05d | 2 | * JoystickController.h |
juansal12 | 0:c3a329a5b05d | 3 | * |
juansal12 | 0:c3a329a5b05d | 4 | * Author: Joseph DelPreto |
juansal12 | 0:c3a329a5b05d | 5 | */ |
juansal12 | 0:c3a329a5b05d | 6 | |
juansal12 | 0:c3a329a5b05d | 7 | #define serialControl |
juansal12 | 0:c3a329a5b05d | 8 | |
juansal12 | 0:c3a329a5b05d | 9 | #ifdef serialControl |
juansal12 | 0:c3a329a5b05d | 10 | |
juansal12 | 0:c3a329a5b05d | 11 | #ifndef SERIALCONTROL_SERIALCONTROLLER_H_ |
juansal12 | 0:c3a329a5b05d | 12 | #define SERIALCONTROL_SERIALCONTROLLER_H_ |
juansal12 | 0:c3a329a5b05d | 13 | |
juansal12 | 0:c3a329a5b05d | 14 | #include "FishController.h" |
juansal12 | 0:c3a329a5b05d | 15 | #include "mbed.h" |
juansal12 | 0:c3a329a5b05d | 16 | #include "string" |
juansal12 | 0:c3a329a5b05d | 17 | #include "SerialBase.h" |
juansal12 | 0:c3a329a5b05d | 18 | |
juansal12 | 0:c3a329a5b05d | 19 | #define serialDefaultBaudUSB 115200 |
juansal12 | 0:c3a329a5b05d | 20 | #define serialDefaultBaud 115200 |
juansal12 | 0:c3a329a5b05d | 21 | #define serialDefaultTX p13 |
juansal12 | 0:c3a329a5b05d | 22 | #define serialDefaultRX p14 |
juansal12 | 0:c3a329a5b05d | 23 | // note lowBatteryVoltagePin is defined in FishController |
juansal12 | 0:c3a329a5b05d | 24 | |
juansal12 | 0:c3a329a5b05d | 25 | //#define debugBCUControl // whether to print BCU control values (setDepth, curDepth, Vset, etc.) |
juansal12 | 0:c3a329a5b05d | 26 | //#define debugSensor // whether to print sensor values being read |
juansal12 | 0:c3a329a5b05d | 27 | //#define print2Pi // whether to print data to Pi serial monitor |
juansal12 | 0:c3a329a5b05d | 28 | #define printStatusSerialController // whether to print what's going on (i.e. when it gets commands, etc.) |
juansal12 | 0:c3a329a5b05d | 29 | //#define debugLEDsSerial // LED1: initialized LED2: running LED3: receiving a character LED4: done (others turn off) |
juansal12 | 0:c3a329a5b05d | 30 | //#define runTimeSerial 10000 // how long to run for (in milliseconds) if infiniteLoopSerial is undefined |
juansal12 | 0:c3a329a5b05d | 31 | #define infiniteLoopSerial // if defined, will run forever (or until stop() is called from another thread) |
juansal12 | 0:c3a329a5b05d | 32 | |
juansal12 | 0:c3a329a5b05d | 33 | #define serialControllerControlFish // whether to start fishController to control the servos and motor |
juansal12 | 0:c3a329a5b05d | 34 | #define enableAutoMode // whether to start automode (ignores commands, follows commands defined in FishController.cpp |
juansal12 | 0:c3a329a5b05d | 35 | |
juansal12 | 0:c3a329a5b05d | 36 | // Map bytes sent over serial (1-255) to ranges for each fish property |
juansal12 | 0:c3a329a5b05d | 37 | #define serialMinPitch fishMinPitch |
juansal12 | 0:c3a329a5b05d | 38 | #define serialMaxPitch fishMaxPitch |
juansal12 | 0:c3a329a5b05d | 39 | #define serialMinYaw fishMinYaw |
juansal12 | 0:c3a329a5b05d | 40 | #define serialMaxYaw fishMaxYaw |
juansal12 | 0:c3a329a5b05d | 41 | #define serialMinThrust fishMinThrust |
juansal12 | 0:c3a329a5b05d | 42 | #define serialMaxThrust fishMaxThrust |
juansal12 | 0:c3a329a5b05d | 43 | #define serialMinFrequency fishMinFrequency |
juansal12 | 0:c3a329a5b05d | 44 | #define serialMaxFrequency fishMaxFrequency |
juansal12 | 0:c3a329a5b05d | 45 | #define dataPeriod 1000 |
juansal12 | 0:c3a329a5b05d | 46 | |
juansal12 | 0:c3a329a5b05d | 47 | class SerialController |
juansal12 | 0:c3a329a5b05d | 48 | { |
juansal12 | 0:c3a329a5b05d | 49 | public: |
juansal12 | 0:c3a329a5b05d | 50 | // Initialization |
juansal12 | 0:c3a329a5b05d | 51 | SerialController(Serial* serialObject = NULL, Serial* usbSerialObject = NULL); // if objects are null, ones will be created |
juansal12 | 0:c3a329a5b05d | 52 | void init(Serial* serialObject = NULL, Serial* usbSerialObject = NULL); // if serial objects are null, ones will be created |
juansal12 | 0:c3a329a5b05d | 53 | // Execution control |
juansal12 | 0:c3a329a5b05d | 54 | void run(); |
juansal12 | 0:c3a329a5b05d | 55 | void stop(); |
juansal12 | 0:c3a329a5b05d | 56 | void lowBatteryCallback(); |
juansal12 | 0:c3a329a5b05d | 57 | float printTime; |
juansal12 | 0:c3a329a5b05d | 58 | private: |
juansal12 | 0:c3a329a5b05d | 59 | Timer programTimer; |
juansal12 | 0:c3a329a5b05d | 60 | bool terminated; |
juansal12 | 0:c3a329a5b05d | 61 | Serial* usbSerial; |
juansal12 | 0:c3a329a5b05d | 62 | Serial* serial; |
juansal12 | 0:c3a329a5b05d | 63 | |
juansal12 | 0:c3a329a5b05d | 64 | void processSerialWord(uint8_t* word); |
juansal12 | 0:c3a329a5b05d | 65 | |
juansal12 | 0:c3a329a5b05d | 66 | // Low battery monitor |
juansal12 | 0:c3a329a5b05d | 67 | DigitalIn* lowBatteryVoltageInput; |
juansal12 | 0:c3a329a5b05d | 68 | //InterruptIn* lowBatteryInterrupt; |
juansal12 | 0:c3a329a5b05d | 69 | Ticker lowBatteryTicker; |
juansal12 | 0:c3a329a5b05d | 70 | bool detectedLowBattery; |
juansal12 | 0:c3a329a5b05d | 71 | |
juansal12 | 0:c3a329a5b05d | 72 | // Debug LEDs |
juansal12 | 0:c3a329a5b05d | 73 | #ifdef debugLEDsSerial |
juansal12 | 0:c3a329a5b05d | 74 | DigitalOut* serialLEDs[4]; |
juansal12 | 0:c3a329a5b05d | 75 | #endif |
juansal12 | 0:c3a329a5b05d | 76 | }; |
juansal12 | 0:c3a329a5b05d | 77 | |
juansal12 | 0:c3a329a5b05d | 78 | // Create a static instance of SerialController to be used by anyone doing serial control |
juansal12 | 0:c3a329a5b05d | 79 | extern SerialController serialController; |
juansal12 | 0:c3a329a5b05d | 80 | |
juansal12 | 0:c3a329a5b05d | 81 | #endif /* SERIALCONTROL_SERIALCONTROLLER_H_ */ |
juansal12 | 0:c3a329a5b05d | 82 | |
juansal12 | 0:c3a329a5b05d | 83 | #endif // #ifdef serialControl |