Library for rolling motor
Revision 0:e492422d50a7, committed 2020-03-17
- Comitter:
- Sigma884
- Date:
- Tue Mar 17 12:30:18 2020 +0000
- Commit message:
- commit for publish stability_seed2019_v1
Changed in this revision
Motor_lib.cpp | Show annotated file Show diff for this revision Revisions of this file |
Motor_lib.h | Show annotated file Show diff for this revision Revisions of this file |
diff -r 000000000000 -r e492422d50a7 Motor_lib.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Motor_lib.cpp Tue Mar 17 12:30:18 2020 +0000 @@ -0,0 +1,53 @@ +#include "Motor_lib.h" +#include "mbed.h" + +Motor_lib :: Motor_lib(PinName pin1, PinName pin2) : out1(pin1),out2(pin2){ + mlib = this; + out1 = 0; + out2 = 0; + status = 0; +} + +void Motor_lib :: turn_a(){ + out1 = 1; + out2 = 0; + status = 1; +} + +void Motor_lib :: turn_a(float power){ + out1 = power; + out2 = 0; + status = power; +} + +void Motor_lib :: turn_b(){ + out1 = 0; + out2 = 1; + status = -1; +} + +void Motor_lib :: turn_b(float power){ + out1 = 0; + out2 = power; + status = power * -1; +} + +void Motor_lib :: stop(){ + out1 = 0; + out2 = 0; + status = 0; +} + +void Motor_lib :: break_stop(float time){ + out1 = 1; + out2 = 1; + status = 0; + stopTime.attach(mlib, &Motor_lib::stop, time); +} + +void Motor_lib :: break_stop(){ + out1 = 1; + out2 = 1; + status = 0; + stopTime.attach(mlib, &Motor_lib::stop, 0.1f); +} \ No newline at end of file
diff -r 000000000000 -r e492422d50a7 Motor_lib.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Motor_lib.h Tue Mar 17 12:30:18 2020 +0000 @@ -0,0 +1,27 @@ +#ifndef MOTOR_LIB_H +#define MOTOR_LIB_H + +#include "mbed.h" + +class Motor_lib{ + + public: + Motor_lib(PinName pin1, PinName pin2); + float status; + private: + PwmOut out1; + PwmOut out2; + Motor_lib *mlib; + Timeout stopTime; + + public: + void turn_a(); + void turn_a(float power); + void turn_b(); + void turn_b(float power); + void stop(); + void break_stop(float time); + void break_stop(); +}; + +#endif \ No newline at end of file