![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
All tasks complete
Dependencies: mbed MCP23017 mbed-rtos WattBob_TextLCD
assignment3tasks.cpp@5:f5dda79b93cb, 2019-03-26 (annotated)
- Committer:
- aingks
- Date:
- Tue Mar 26 15:20:57 2019 +0000
- Revision:
- 5:f5dda79b93cb
- Parent:
- 4:27340b291c09
- Child:
- 6:abbd51d9b045
added frequency times (accommodating for the stage 9 case at 2 hz)
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
aingks | 0:0943f040009c | 1 | #include "header.h" |
aingks | 3:f88d667629e6 | 2 | |
aingks | 2:9d6d07c9cc9c | 3 | |
aingks | 4:27340b291c09 | 4 | //definitions of tasks |
aingks | 4:27340b291c09 | 5 | //lock and unlock variables in struct when performing calculations |
aingks | 0:0943f040009c | 6 | |
aingks | 0:0943f040009c | 7 | //pedals |
aingks | 0:0943f040009c | 8 | AnalogIn brake_pedal(pin_analog_1); |
aingks | 0:0943f040009c | 9 | AnalogIn accel_pedal(pin_analog_2); |
aingks | 0:0943f040009c | 10 | |
aingks | 0:0943f040009c | 11 | |
aingks | 0:0943f040009c | 12 | //switches |
aingks | 0:0943f040009c | 13 | DigitalIn ngene(pin_digital_1); |
aingks | 1:c4f62ef9b5b7 | 14 | DigitalIn leftsw(pin_digital_2); |
aingks | 1:c4f62ef9b5b7 | 15 | DigitalIn rightsw(pin_digital_3); |
aingks | 1:c4f62ef9b5b7 | 16 | DigitalIn sidesw(pin_digital_4); |
aingks | 0:0943f040009c | 17 | |
aingks | 0:0943f040009c | 18 | |
aingks | 0:0943f040009c | 19 | //indicators |
aingks | 0:0943f040009c | 20 | DigitalOut ngeneind(pin_LED1); |
aingks | 4:27340b291c09 | 21 | PwmOut leftind(pin_LED2); //was digitalout |
aingks | 4:27340b291c09 | 22 | PwmOut rightind(pin_LED3);//was digitalout |
aingks | 0:0943f040009c | 23 | DigitalOut sideind(pin_LED4); |
aingks | 0:0943f040009c | 24 | |
aingks | 0:0943f040009c | 25 | |
aingks | 0:0943f040009c | 26 | //RED box lights |
aingks | 0:0943f040009c | 27 | DigitalOut brakeind(pin_LED5); |
aingks | 0:0943f040009c | 28 | DigitalOut overspeedind(pin_LED6); |
aingks | 0:0943f040009c | 29 | |
aingks | 4:27340b291c09 | 30 | |
aingks | 4:27340b291c09 | 31 | |
aingks | 4:27340b291c09 | 32 | // |
aingks | 4:27340b291c09 | 33 | extern SDATA speed; |
aingks | 4:27340b291c09 | 34 | extern CARINFO info; |
aingks | 4:27340b291c09 | 35 | extern SIMU_DATA sim; |
aingks | 4:27340b291c09 | 36 | |
aingks | 4:27340b291c09 | 37 | // LCD |
aingks | 4:27340b291c09 | 38 | |
aingks | 4:27340b291c09 | 39 | extern WattBob_TextLCD *display; |
aingks | 4:27340b291c09 | 40 | |
aingks | 4:27340b291c09 | 41 | // MUTEX |
aingks | 4:27340b291c09 | 42 | |
aingks | 4:27340b291c09 | 43 | extern Mutex simuXS; |
aingks | 4:27340b291c09 | 44 | extern Mutex speedXS; |
aingks | 4:27340b291c09 | 45 | extern Mutex carstateXS; |
aingks | 4:27340b291c09 | 46 | // |
aingks | 2:9d6d07c9cc9c | 47 | |
aingks | 0:0943f040009c | 48 | |
aingks | 0:0943f040009c | 49 | void task1readbrake() |
aingks | 0:0943f040009c | 50 | { |
aingks | 4:27340b291c09 | 51 | speedXS.lock();//lock |
aingks | 1:c4f62ef9b5b7 | 52 | speed.brakevalue = brake_pedal.read(); |
aingks | 4:27340b291c09 | 53 | speedXS.unlock();//unlock |
aingks | 0:0943f040009c | 54 | } |
aingks | 0:0943f040009c | 55 | |
aingks | 0:0943f040009c | 56 | void task2readaccel() |
aingks | 0:0943f040009c | 57 | { |
aingks | 4:27340b291c09 | 58 | speedXS.lock();//lock |
aingks | 1:c4f62ef9b5b7 | 59 | speed.accelvalue = accel_pedal.read(); |
aingks | 4:27340b291c09 | 60 | speedXS.unlock();//unlock |
aingks | 0:0943f040009c | 61 | } |
aingks | 0:0943f040009c | 62 | |
aingks | 0:0943f040009c | 63 | void task3enginestate() |
aingks | 1:c4f62ef9b5b7 | 64 | { |
aingks | 1:c4f62ef9b5b7 | 65 | //lock |
aingks | 4:27340b291c09 | 66 | carstateXS.lock(); |
aingks | 1:c4f62ef9b5b7 | 67 | uint8_t engineonoff = ngene.read(); |
aingks | 2:9d6d07c9cc9c | 68 | info.ENGINESTATE = engineonoff; |
aingks | 4:27340b291c09 | 69 | carstateXS.unlock(); |
aingks | 1:c4f62ef9b5b7 | 70 | //unlock |
aingks | 1:c4f62ef9b5b7 | 71 | |
aingks | 1:c4f62ef9b5b7 | 72 | if(engineonoff == 1){ |
aingks | 1:c4f62ef9b5b7 | 73 | ngeneind = 1; |
aingks | 1:c4f62ef9b5b7 | 74 | } |
aingks | 1:c4f62ef9b5b7 | 75 | else{ |
aingks | 1:c4f62ef9b5b7 | 76 | ngeneind = 0; |
aingks | 1:c4f62ef9b5b7 | 77 | } |
aingks | 0:0943f040009c | 78 | } |
aingks | 0:0943f040009c | 79 | |
aingks | 0:0943f040009c | 80 | void task4average() |
aingks | 0:0943f040009c | 81 | { |
aingks | 5:f5dda79b93cb | 82 | //lock |
aingks | 0:0943f040009c | 83 | |
aingks | 5:f5dda79b93cb | 84 | for(int i = 0; i < SAMPLESIZE ; i++){ |
aingks | 5:f5dda79b93cb | 85 | //speed.raw = (speed.accelvalue - speed.brakevalue)*MAXSPEED; |
aingks | 5:f5dda79b93cb | 86 | speed.average += speed.array[i]; |
aingks | 5:f5dda79b93cb | 87 | speed.average = (speed.average / SAMPLESIZE); |
aingks | 5:f5dda79b93cb | 88 | |
aingks | 5:f5dda79b93cb | 89 | |
aingks | 5:f5dda79b93cb | 90 | |
aingks | 5:f5dda79b93cb | 91 | } |
aingks | 5:f5dda79b93cb | 92 | |
aingks | 5:f5dda79b93cb | 93 | //unlock |
aingks | 0:0943f040009c | 94 | } |