2014 Eurobot fork
Dependencies: mbed-rtos mbed QEI
Actuators/MainMotors/MainMotor.h@2:45da48fab346, 2013-03-29 (annotated)
- Committer:
- twighk
- Date:
- Fri Mar 29 20:09:21 2013 +0000
- Revision:
- 2:45da48fab346
- Parent:
- 1:8119211eae14
- Child:
- 5:56a5fdd373c9
Emergency Stop Button, Derive all actuator classes from the base class, and implement a virtual halt function that releases power from them
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
twighk | 0:200635fa1b08 | 1 | |
twighk | 0:200635fa1b08 | 2 | // Eurobot13 MainMotor.h |
twighk | 0:200635fa1b08 | 3 | |
twighk | 0:200635fa1b08 | 4 | #include "mbed.h" |
twighk | 2:45da48fab346 | 5 | #include "Actuators/Actuator.h" |
twighk | 0:200635fa1b08 | 6 | |
twighk | 2:45da48fab346 | 7 | class MainMotor: public Actuator{ |
twighk | 0:200635fa1b08 | 8 | private: |
twighk | 0:200635fa1b08 | 9 | PwmOut PWM1; |
twighk | 0:200635fa1b08 | 10 | PwmOut PWM2; |
twighk | 0:200635fa1b08 | 11 | |
twighk | 0:200635fa1b08 | 12 | public: |
twighk | 0:200635fa1b08 | 13 | MainMotor(PinName pin1, PinName pin2) : PWM1(pin1), PWM2(pin2){ |
twighk | 0:200635fa1b08 | 14 | } |
twighk | 0:200635fa1b08 | 15 | |
twighk | 0:200635fa1b08 | 16 | void operator()(float in){ |
twighk | 0:200635fa1b08 | 17 | power(in); |
twighk | 0:200635fa1b08 | 18 | } |
twighk | 0:200635fa1b08 | 19 | |
twighk | 0:200635fa1b08 | 20 | void power(float power){ |
twighk | 0:200635fa1b08 | 21 | if( power > 0 ){ |
twighk | 0:200635fa1b08 | 22 | PWM1 = power; |
twighk | 0:200635fa1b08 | 23 | PWM2 = 0; |
twighk | 0:200635fa1b08 | 24 | } else { |
twighk | 0:200635fa1b08 | 25 | PWM1 = 0; |
twighk | 0:200635fa1b08 | 26 | PWM2 = -power; |
twighk | 0:200635fa1b08 | 27 | } |
twighk | 0:200635fa1b08 | 28 | } |
twighk | 2:45da48fab346 | 29 | |
twighk | 2:45da48fab346 | 30 | virtual void halt (void){ |
twighk | 2:45da48fab346 | 31 | DigitalOut myled(LED2); |
twighk | 2:45da48fab346 | 32 | myled = 1; |
twighk | 2:45da48fab346 | 33 | PWM1 = 0; |
twighk | 2:45da48fab346 | 34 | PWM2 = 0; |
twighk | 2:45da48fab346 | 35 | } |
twighk | 0:200635fa1b08 | 36 | |
twighk | 0:200635fa1b08 | 37 | }; |