hej
Revision 0:66a1feb3ba85, committed 2014-04-05
- Comitter:
- iLyngklip
- Date:
- Sat Apr 05 07:56:52 2014 +0000
- Commit message:
- dillerdasker
Changed in this revision
hack_motor.cpp | Show annotated file Show diff for this revision Revisions of this file |
hack_motor.h | Show annotated file Show diff for this revision Revisions of this file |
diff -r 000000000000 -r 66a1feb3ba85 hack_motor.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/hack_motor.cpp Sat Apr 05 07:56:52 2014 +0000 @@ -0,0 +1,59 @@ +#include "mbed.h" +#include "hack_motor.h" +#include "PwmOut.h" + +Wheel::Wheel() : M1A(PTC8), M1B(PTC10), M2A(PTC9), M2B(PTC11) + { + init(); + } + + +void Wheel::init() //Initialize the driver pwm to 150Hz + { + M1A.period(0.0066); + M2A.period(0.0066); + speed = 0.0; + } + +void Wheel::FW() + { + fw = 0.5+(0.5*speed); //forward lies in the upper 50% of the duty cycle + M1A.write(fw); //Set the duty cycle to the wanted percent, from speed variable + M2A.write(fw); // -//- + M1B = 0; + M2B = 0; + wait_ms(1); + } + +void Wheel::BW() + { + bw = 0.5-(0.5*speed); //Backward lies within the lower 50% of the duty cycle + M1A.write(bw); //Set the duty cycle to the wanted percent, from speed variable + M2A.write(bw); // -//- + M1B = 1; + M2B = 1; + } + +void Wheel::right() + { + M1A.write(0.75); //Left side forward 50% + M2A.write(0.25); //Right side backwards 50% + M1B = 0; + M2B = 1; + } + +void Wheel::left() + { + M1A.write(0.25); //Right side forward 50% + M2A.write(0.75); //Left side backwards 50% + M1B = 1; + M2B = 0; + } + +void Wheel::stop() + { + M1A.write(0.0); //Pin A's set low + M2A.write(0.0); + M1B = 0; + M2B = 0; //Pin B's set high + } \ No newline at end of file
diff -r 000000000000 -r 66a1feb3ba85 hack_motor.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/hack_motor.h Sat Apr 05 07:56:52 2014 +0000 @@ -0,0 +1,27 @@ +#ifndef HACK_MOTOR_H +#define HACK_MOTOR_H +#include "mbed.h" + +class Wheel { + +public: + PwmOut M1A, M2A; + + DigitalOut M1B, M2B; + + Wheel(); + void FW(); + void BW(); + void right(); + void left(); + void stop(); + void init(); + float speed; +protected: + float fw, bw; + +}; + + + +#endif \ No newline at end of file