Init
Dependents: JetflyerMotorController
Revision 1:39b173360768, committed 2017-07-13
- Comitter:
- skrickl
- Date:
- Thu Jul 13 13:42:32 2017 +0000
- Parent:
- 0:5eb2bad9ea40
- Commit message:
- bla
Changed in this revision
Motor.cpp | Show annotated file Show diff for this revision Revisions of this file |
Motor.h | Show annotated file Show diff for this revision Revisions of this file |
diff -r 5eb2bad9ea40 -r 39b173360768 Motor.cpp --- a/Motor.cpp Mon Jun 12 19:58:20 2017 +0000 +++ b/Motor.cpp Thu Jul 13 13:42:32 2017 +0000 @@ -0,0 +1,44 @@ +#include "Motor.h" + + +Motor::Motor() : forward(pin_forward),backward(pin_backward),throttle(pin_pwm_motor) +{ + +direction_old = 1; +} + +Motor::~Motor() +{ + +} + +//speed in percent + int Motor::drive(int speed, int direction) + { + // if direction change is detected both pins are set to 0 + if(direction_old != direction) + { + backward =0; + forward = 0; + } + else + { + + if(direction == 1) + { + backward =0; + forward =1; + } + if(direction == -1) + { + backward =1; + forward =0; + + } + + } + + throttle.write(((float)speed)/100.0f); + direction_old = direction; + return 0; + } \ No newline at end of file
diff -r 5eb2bad9ea40 -r 39b173360768 Motor.h --- a/Motor.h Mon Jun 12 19:58:20 2017 +0000 +++ b/Motor.h Thu Jul 13 13:42:32 2017 +0000 @@ -0,0 +1,34 @@ +#include "mbed.h" + + +#ifndef MOTOR_H +#define MOTOR_H + +#define pin_forward p29 +#define pin_backward p30 +#define pin_pwm_motor p23 + + + + +class Motor +{ + public: + Motor(); + ~Motor(); + + DigitalOut forward; + DigitalOut backward; + AnalogOut throttle; + + int drive(int speed, int direction); + + + private: + + int direction_old; + + +}; + +#endif \ No newline at end of file