Basic Mid-Level control for the rebuilt MorphGI control unit, using PWM to communicate with the low level controllers.

Dependencies:   ros_lib_kinetic

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers LLComms.h Source File

LLComms.h

00001 // LLComms.h
00002 
00003 #ifndef LLCOMMS_H
00004 #define LLCOMMS_H
00005 
00006 // STANDARD IMPORTS
00007 #include "math.h"
00008 #include <algorithm>
00009 // MBED IMPORTS
00010 #include "mbed.h"
00011 #include "mbed_events.h"
00012 // CUSTOM IMPORTS
00013 #include "MLSettings.h"
00014 
00015 // ADC SPI DEFINES
00016 #define PREAMBLE 0x06
00017 #define CHAN_1 0x30
00018 #define CHAN_2 0x70
00019 #define CHAN_3 0xB0
00020 #define CHAN_4 0xF0
00021 #define DATA_MASK 0x0F
00022 
00023 class LLComms
00024 {
00025         
00026     public:
00027         
00028         EventQueue queue;
00029         Mutex mutChannel[N_CHANNELS];
00030         bool isDataReady[N_CHANNELS]; // Flag to indicate path data is ready for transmission to low level.
00031         double demandPosition_mm[N_CHANNELS];
00032         double demandSpeed_mmps[N_CHANNELS];
00033         char chrErrorFlag[N_CHANNELS]; // 3 error bits from LL
00034         unsigned int positionSensor_uint[N_CHANNELS];
00035         double positionSensor_mm[N_CHANNELS]; // The actual chamber lengths in meters given as the change in length relative to neutral (should always be >=0)
00036         unsigned int pressureSensor_uint[N_CHANNELS];
00037         double pressureSensor_bar[N_CHANNELS];  // The pressure in a given chamber in bar (1 bar  = 100,000 Pa)
00038         unsigned int formatMessage(short int type, double dblValue, double dblMaxValue);
00039         //bool CheckMessage(int msg, short int trueType);
00040         bool CheckMessage(int msg);
00041         bool PerformMasterSPI(SPI *spi, unsigned int outboundMsgs[], unsigned int inboundMsgsData[]);
00042         void SendReceiveData(int channel);
00043         int countervar;     
00044         
00045         LLComms(); // Constructor
00046         //~LLComms(); // Destructor
00047     
00048     private:
00049     
00050         // PIN DECLARATIONS     
00051         SPI spi_0; // mosi, miso, sclk
00052         //SPI spi_1; // mosi, miso, sclk
00053         DigitalOut* cs_LL[N_CHANNELS]; // Chip select for low level controller
00054         //DigitalOut* cs_ADC[N_CHANNELS]; // Chip select for ADC
00055         // These interrupt pins have to be declared AFTER SPI declaration. No Clue Why.
00056         InterruptIn pinGate0;
00057         InterruptIn pinGate1;
00058         InterruptIn pinGate2;
00059         //InterruptIn pinGate3;
00060         DigitalInOut pinReset; // Reset pin for all controllers.
00061         
00062         int ThreadID[N_CHANNELS];
00063         
00064         
00065         void common_rise_handler(int channel);
00066         void common_fall_handler(int channel);
00067         void rise0(void);
00068         void rise1(void);
00069         void rise2(void);
00070         //void rise3(void);
00071         void fall0(void);
00072         void fall1(void);
00073         void fall2(void);
00074         //void fall3(void);
00075 
00076 };
00077 
00078 #endif