
Basic Mid-Level control for the rebuilt MorphGI control unit, using PWM to communicate with the low level controllers.
Dependencies: ros_lib_kinetic
LLComms.h
- Committer:
- dofydoink
- Date:
- 2021-06-24
- Revision:
- 42:5a5ad23a4bb1
- Parent:
- 37:37da606f4466
File content as of revision 42:5a5ad23a4bb1:
// LLComms.h #ifndef LLCOMMS_H #define LLCOMMS_H // STANDARD IMPORTS #include "math.h" #include <algorithm> // MBED IMPORTS #include "mbed.h" #include "mbed_events.h" // CUSTOM IMPORTS #include "MLSettings.h" // ADC SPI DEFINES #define PREAMBLE 0x06 #define CHAN_1 0x30 #define CHAN_2 0x70 #define CHAN_3 0xB0 #define CHAN_4 0xF0 #define DATA_MASK 0x0F class LLComms { public: EventQueue queue; Mutex mutChannel[N_CHANNELS]; bool isDataReady[N_CHANNELS]; // Flag to indicate path data is ready for transmission to low level. double demandPosition_mm[N_CHANNELS]; double demandSpeed_mmps[N_CHANNELS]; char chrErrorFlag[N_CHANNELS]; // 3 error bits from LL unsigned int positionSensor_uint[N_CHANNELS]; double positionSensor_mm[N_CHANNELS]; // The actual chamber lengths in meters given as the change in length relative to neutral (should always be >=0) unsigned int pressureSensor_uint[N_CHANNELS]; double pressureSensor_bar[N_CHANNELS]; // The pressure in a given chamber in bar (1 bar = 100,000 Pa) unsigned int formatMessage(short int type, double dblValue, double dblMaxValue); //bool CheckMessage(int msg, short int trueType); bool CheckMessage(int msg); bool PerformMasterSPI(SPI *spi, unsigned int outboundMsgs[], unsigned int inboundMsgsData[]); void SendReceiveData(int channel); int countervar; LLComms(); // Constructor //~LLComms(); // Destructor private: // PIN DECLARATIONS SPI spi_0; // mosi, miso, sclk //SPI spi_1; // mosi, miso, sclk DigitalOut* cs_LL[N_CHANNELS]; // Chip select for low level controller //DigitalOut* cs_ADC[N_CHANNELS]; // Chip select for ADC // These interrupt pins have to be declared AFTER SPI declaration. No Clue Why. InterruptIn pinGate0; InterruptIn pinGate1; InterruptIn pinGate2; //InterruptIn pinGate3; DigitalInOut pinReset; // Reset pin for all controllers. int ThreadID[N_CHANNELS]; void common_rise_handler(int channel); void common_fall_handler(int channel); void rise0(void); void rise1(void); void rise2(void); //void rise3(void); void fall0(void); void fall1(void); void fall2(void); //void fall3(void); }; #endif