Corrected header file include guards.
Dependencies: FiniteStateMachine HipControl Knee LinearBlend1 LocalFileSystem_Read dataComm hapticFeedback initExoVars mbed Blend_Generator Brad_poly_gait Gait_Generator MM_gait Encoders IMUdriver
Fork of Motion Control by
main.cpp@23:e0923403be2f, 2015-04-27 (annotated)
- Committer:
- mzling
- Date:
- Mon Apr 27 21:57:54 2015 +0000
- Revision:
- 23:e0923403be2f
- Parent:
- 22:357327fe25af
- Child:
- 24:2e56d3bebb24
Added float-short conversion
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
perr1940 | 0:d38d627c922f | 1 | /************************************** |
perr1940 | 0:d38d627c922f | 2 | This is the main file for the "RyanEXO" control software. |
perr1940 | 0:d38d627c922f | 3 | This sets up the main control loop that operates at a 1kHz frequency |
perr1940 | 0:d38d627c922f | 4 | and controls the flow of the rest of the software |
perr1940 | 0:d38d627c922f | 5 | |
perr1940 | 0:d38d627c922f | 6 | The configuration for the exo system that this software runs: |
perr1940 | 0:d38d627c922f | 7 | amplifiers: 2 Copley Controls 10A digital amplifiers |
perr1940 | 0:d38d627c922f | 8 | sensors: 2 Austria Microsystems 12 bit magnetic encoders, handled by encoders.h |
perr1940 | 0:d38d627c922f | 9 | motors: 2 maxon EC90 DC brushless motors, handled by HipMotorControl.h (called in FSM.h) |
perr1940 | 0:d38d627c922f | 10 | Knees: wrap spring clutch controlled by Firgelli PQ12P linear actuators, controlled in linearActuatorControl.h |
cashdollar | 3:9719ad064a2c | 11 | **************************************/ |
perr1940 | 0:d38d627c922f | 12 | |
perr1940 | 0:d38d627c922f | 13 | #include "mbed.h" |
perr1940 | 0:d38d627c922f | 14 | #include "initExoVars.h" |
perr1940 | 0:d38d627c922f | 15 | #include "FSM.h" |
perr1940 | 2:89b78367d173 | 16 | #include "dataBedComm.h" |
mzling | 13:c588cb388240 | 17 | #include "dataComm.h" |
mzling | 18:03d7c5fdc0c7 | 18 | short dataIn[7]; |
mzling | 21:715c8cf78e14 | 19 | short dataOut[]={0xFF,30,31,0, 0, 0, 0, 0, 0xFE}; |
mzling | 18:03d7c5fdc0c7 | 20 | dataComm dc = dataComm(); |
mzling | 18:03d7c5fdc0c7 | 21 | Timer dbg; |
mzling | 15:3596b7ca1c20 | 22 | |
perr1940 | 0:d38d627c922f | 23 | /////////////////////////////////////////////////////////////////////////// |
cashdollar | 3:9719ad064a2c | 24 | |
cashdollar | 3:9719ad064a2c | 25 | // periodicFcns runs at the start of every control loop cycle |
cashdollar | 3:9719ad064a2c | 26 | // It initiates communication with dataBed, checks for errors/safety, and starts the FSM |
mzling | 23:e0923403be2f | 27 | |
mzling | 23:e0923403be2f | 28 | union float_to_short { |
mzling | 23:e0923403be2f | 29 | float f; |
mzling | 23:e0923403be2f | 30 | uint32_t u; |
mzling | 23:e0923403be2f | 31 | } q; |
perr1940 | 0:d38d627c922f | 32 | void periodicFcns() |
perr1940 | 0:d38d627c922f | 33 | { |
mzling | 18:03d7c5fdc0c7 | 34 | dbg.reset(); |
mzling | 20:cf8e99d989a6 | 35 | // dataOut[1]=encoder_L.readRaw(); |
mzling | 20:cf8e99d989a6 | 36 | float f1 = encoder_L.read_angle(); |
mzling | 20:cf8e99d989a6 | 37 | float f2 = fsm.read_angle_y(); |
mzling | 23:e0923403be2f | 38 | //float f2 = -87.43423; |
mzling | 23:e0923403be2f | 39 | short s1 = (short)(f1*91); |
mzling | 23:e0923403be2f | 40 | short s2 = (short)(f2*91); |
mzling | 23:e0923403be2f | 41 | dataOut[1] = s1; |
mzling | 23:e0923403be2f | 42 | dataOut[2] = s2; |
mzling | 23:e0923403be2f | 43 | pc.printf("first is %f %d\r\n", f1, s1); |
mzling | 23:e0923403be2f | 44 | pc.printf("second is %f %d\r\n", f2, s2); |
mzling | 22:357327fe25af | 45 | //dataOut[3] = (short)f1; |
mzling | 22:357327fe25af | 46 | //dataOut[4] = (short)f2; |
mzling | 22:357327fe25af | 47 | //dataOut[5] = (short)f2; |
mzling | 20:cf8e99d989a6 | 48 | //pc.printf("%f\r\n", f1); |
mzling | 22:357327fe25af | 49 | //pc.printf("data1: %d\r\n", dataOut[1]); |
mzling | 20:cf8e99d989a6 | 50 | //pc.printf("%f\r\n", f2); |
mzling | 22:357327fe25af | 51 | //pc.printf("Size %d\r\n", sizeof dataOut[2]); |
mzling | 22:357327fe25af | 52 | //pc.printf("data2: %d\r\n", dataOut[2]); |
mzling | 20:cf8e99d989a6 | 53 | //for (int i = 2; i < 4; i++) { |
mzling | 20:cf8e99d989a6 | 54 | // pc.printf("data%d is %x\r\n", i, dataOut[i]); |
mzling | 20:cf8e99d989a6 | 55 | //} |
mzling | 18:03d7c5fdc0c7 | 56 | //dataOut[2]=fsm.error(); |
mzling | 18:03d7c5fdc0c7 | 57 | short* ptr=dataIn; |
mzling | 21:715c8cf78e14 | 58 | ptr=sendData(dataOut, 9, dataIn); |
mzling | 21:715c8cf78e14 | 59 | //for (int i = 0; i < 7; i++) { |
mzling | 21:715c8cf78e14 | 60 | if (dataIn[1] != 0) { |
mzling | 21:715c8cf78e14 | 61 | pc.printf("UI: %d\r\n", dataIn[1]); |
mzling | 18:03d7c5fdc0c7 | 62 | } |
mzling | 21:715c8cf78e14 | 63 | //} |
mzling | 21:715c8cf78e14 | 64 | //pc.printf("\r\n");*/ |
mzling | 21:715c8cf78e14 | 65 | dc.process_write(dataIn+2, 7); |
perr1940 | 7:d44555be84b7 | 66 | //pc.printf("%d, %d, %d, %d,", dataIn[0], dataIn[1], dataIn[2], dataIn[3]); |
mzling | 18:03d7c5fdc0c7 | 67 | |
cashdollar | 3:9719ad064a2c | 68 | // Run state change/analysis in FSM |
mzling | 17:b77c31807825 | 69 | int exoState=fsm.state(dataIn[1]); |
mzling | 18:03d7c5fdc0c7 | 70 | float temp=dbg.read_us(); |
mzling | 21:715c8cf78e14 | 71 | //pc.printf("%f\r\n",temp); |
mzling | 18:03d7c5fdc0c7 | 72 | |
perr1940 | 0:d38d627c922f | 73 | } |
perr1940 | 0:d38d627c922f | 74 | |
mzling | 20:cf8e99d989a6 | 75 | //Starts the Exo controlbed, and processes messages by repeatedly executing periodicFcns |
perr1940 | 0:d38d627c922f | 76 | int main() |
perr1940 | 0:d38d627c922f | 77 | { |
cashdollar | 5:498c9bfc56f0 | 78 | pc.printf("\r\nExoStart \r\n"); |
perr1940 | 0:d38d627c922f | 79 | initializeExoIOs(); |
mzling | 18:03d7c5fdc0c7 | 80 | //pc.printf("Test\r\n"); // keep for debugging compile errors |
mzling | 20:cf8e99d989a6 | 81 | mbedLED1 = 1; |
perr1940 | 0:d38d627c922f | 82 | pc.printf("Starting exo...\n\r"); |
perr1940 | 0:d38d627c922f | 83 | //If desired, a startup sound can be played. This function is defined in the DatabedCode, because it will command a sound to be played once it detects a heartbeat from ControlBed |
perr1940 | 0:d38d627c922f | 84 | wait(2); |
mzling | 18:03d7c5fdc0c7 | 85 | dbg.start(); |
perr1940 | 0:d38d627c922f | 86 | Ticker doControl; |
mzling | 14:8929f5a9837c | 87 | dataBedSPI.format(16,0); |
perr1940 | 0:d38d627c922f | 88 | doControl.attach(&periodicFcns, SAMPLE_TIME); |
perr1940 | 0:d38d627c922f | 89 | |
mzling | 18:03d7c5fdc0c7 | 90 | while (1); |
perr1940 | 0:d38d627c922f | 91 | } |