This is some awesome robot code
Dependencies: mbed-rtos mbed QEI
Fork of ICRSEurobot13 by
Revision 2:45da48fab346, committed 2013-03-29
- Comitter:
- twighk
- Date:
- Fri Mar 29 20:09:21 2013 +0000
- Parent:
- 1:8119211eae14
- Child:
- 3:717de74f6ebd
- Commit message:
- Emergency Stop Button, Derive all actuator classes from the base class, and implement a virtual halt function that releases power from them
Changed in this revision
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Actuators/Actuator.cpp Fri Mar 29 20:09:21 2013 +0000 @@ -0,0 +1,9 @@ + +// Eurobot13 Actuator.cpp + +#include "Actuator.h" + + +Actuator *Actuator::Head = NULL; + +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Actuators/Actuator.h Fri Mar 29 20:09:21 2013 +0000 @@ -0,0 +1,41 @@ +#ifndef __Actuator_h__ +#define __Actuator_h__ +// Eurobot13 Actuator.h + +#include "mbed.h" + +class Actuator { + private: + static Actuator *Head; + Actuator *next; + + public: + Actuator(){ + next = NULL; + if (Head == NULL){ + Head = this; + } else { + Actuator* nxt = Head; + for(;nxt->next != NULL; nxt = nxt->next); + nxt->next = this; + } + } + + virtual void halt (void) = 0; + + static void haltandCatchFire(void){ + //halt + for(Actuator* nxt = Head; nxt != NULL; nxt = nxt->next){ + nxt->halt(); + } + DigitalOut myled(LED1); + myled = 1; + + //catchFire + while(true); + } + + +}; + +#endif \ No newline at end of file
--- a/Actuators/Arms/Arm.h Fri Mar 29 16:28:56 2013 +0000 +++ b/Actuators/Arms/Arm.h Fri Mar 29 20:09:21 2013 +0000 @@ -3,8 +3,9 @@ #include "mbed.h" #include "Servo.h" +#include "Actuators/Actuator.h" -class Arm : public Servo +class Arm : public Servo, public Actuator { private: bool updirn; @@ -27,7 +28,9 @@ write(updirn?0:1); } - void relax() { // servo applies no force + virtual void halt() { // servo applies no force + DigitalOut myled(LED3); + myled = 1; _pwm = 0; } };
--- a/Actuators/MainMotors/MainMotor.h Fri Mar 29 16:28:56 2013 +0000 +++ b/Actuators/MainMotors/MainMotor.h Fri Mar 29 20:09:21 2013 +0000 @@ -2,8 +2,9 @@ // Eurobot13 MainMotor.h #include "mbed.h" +#include "Actuators/Actuator.h" -class MainMotor{ +class MainMotor: public Actuator{ private: PwmOut PWM1; PwmOut PWM2; @@ -25,5 +26,12 @@ PWM2 = -power; } } + + virtual void halt (void){ + DigitalOut myled(LED2); + myled = 1; + PWM1 = 0; + PWM2 = 0; + } }; \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Others/EmergencyStop/EmergencyStop.h Fri Mar 29 20:09:21 2013 +0000 @@ -0,0 +1,24 @@ + +// Eurobot13 EmergencyStop.h + +#include "mbed.h" +#include "Actuators/Actuator.h" + +class EmergencyStop : public InterruptIn{ + private: + public: + EmergencyStop ( PinName pin + , void (*risefunction)(void) = Actuator::haltandCatchFire + , void (*fallfunction)(void) = Actuator::haltandCatchFire + ) + : InterruptIn(pin) + { + if (risefunction != NULL){ + rise(risefunction); + } + + if (fallfunction != NULL){ + fall(fallfunction); + } + } +}; \ No newline at end of file
--- a/Sensors/Sonar/Sonar.h Fri Mar 29 16:28:56 2013 +0000 +++ b/Sensors/Sonar/Sonar.h Fri Mar 29 20:09:21 2013 +0000 @@ -0,0 +1,2 @@ + +// Eurobot13 Sonar.h \ No newline at end of file
--- a/main.cpp Fri Mar 29 16:28:56 2013 +0000 +++ b/main.cpp Fri Mar 29 20:09:21 2013 +0000 @@ -6,8 +6,9 @@ #include "Actuators/MainMotors/MainMotor.h" #include "Sensors/Encoders/Encoder.h" #include "Actuators/Arms/Arm.h" +#include "Others/EmergencyStop/EmergencyStop.h" -PwmOut Led(LED1); + void motortest(); void encodertest(); @@ -15,15 +16,21 @@ void motorencodetestline(); void motorsandservostest(); void armtest(); +void motortestline(); int main() { +/* Setup Emergency stop for actuators, + Derive all actuators from the pure virtual actuator class +*/ EmergencyStop EStop(p8); + //motortest(); //encodertest(); //motorencodetest(); //motorencodetestline(); //motorsandservostest(); armtest(); -} + //motortestline(); + } void armtest(){ Arm white(p26), black(p25, false,0.0005, 180); @@ -61,7 +68,7 @@ if (servoTimer.read() < 1){ sTop.clockwise(); } else if (servoTimer.read() < 4) { - sTop.relax(); + sTop.halt(); } else if (servoTimer.read() < 5) { sBottom.anticlockwise(); //Led=1; @@ -69,7 +76,7 @@ sBottom.clockwise(); //Led=0; } else if (servoTimer.read() < 7) { - sBottom.relax(); + sBottom.halt(); }else { sTop.anticlockwise(); } @@ -77,6 +84,13 @@ } } +void motortestline(){ + MainMotor mleft(p24,p23), mright(p21,p22); + const float speed = 0.2; + mleft(speed); mright(speed); + while(true) wait(1); +} + void motorencodetestline(){ Encoder Eleft(p27, p28), Eright(p30, p29); MainMotor mleft(p24,p23), mright(p21,p22);