Library for rolling motor
Motor_lib.cpp@0:e492422d50a7, 2020-03-17 (annotated)
- Committer:
- Sigma884
- Date:
- Tue Mar 17 12:30:18 2020 +0000
- Revision:
- 0:e492422d50a7
commit for publish stability_seed2019_v1
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Sigma884 | 0:e492422d50a7 | 1 | #include "Motor_lib.h" |
Sigma884 | 0:e492422d50a7 | 2 | #include "mbed.h" |
Sigma884 | 0:e492422d50a7 | 3 | |
Sigma884 | 0:e492422d50a7 | 4 | Motor_lib :: Motor_lib(PinName pin1, PinName pin2) : out1(pin1),out2(pin2){ |
Sigma884 | 0:e492422d50a7 | 5 | mlib = this; |
Sigma884 | 0:e492422d50a7 | 6 | out1 = 0; |
Sigma884 | 0:e492422d50a7 | 7 | out2 = 0; |
Sigma884 | 0:e492422d50a7 | 8 | status = 0; |
Sigma884 | 0:e492422d50a7 | 9 | } |
Sigma884 | 0:e492422d50a7 | 10 | |
Sigma884 | 0:e492422d50a7 | 11 | void Motor_lib :: turn_a(){ |
Sigma884 | 0:e492422d50a7 | 12 | out1 = 1; |
Sigma884 | 0:e492422d50a7 | 13 | out2 = 0; |
Sigma884 | 0:e492422d50a7 | 14 | status = 1; |
Sigma884 | 0:e492422d50a7 | 15 | } |
Sigma884 | 0:e492422d50a7 | 16 | |
Sigma884 | 0:e492422d50a7 | 17 | void Motor_lib :: turn_a(float power){ |
Sigma884 | 0:e492422d50a7 | 18 | out1 = power; |
Sigma884 | 0:e492422d50a7 | 19 | out2 = 0; |
Sigma884 | 0:e492422d50a7 | 20 | status = power; |
Sigma884 | 0:e492422d50a7 | 21 | } |
Sigma884 | 0:e492422d50a7 | 22 | |
Sigma884 | 0:e492422d50a7 | 23 | void Motor_lib :: turn_b(){ |
Sigma884 | 0:e492422d50a7 | 24 | out1 = 0; |
Sigma884 | 0:e492422d50a7 | 25 | out2 = 1; |
Sigma884 | 0:e492422d50a7 | 26 | status = -1; |
Sigma884 | 0:e492422d50a7 | 27 | } |
Sigma884 | 0:e492422d50a7 | 28 | |
Sigma884 | 0:e492422d50a7 | 29 | void Motor_lib :: turn_b(float power){ |
Sigma884 | 0:e492422d50a7 | 30 | out1 = 0; |
Sigma884 | 0:e492422d50a7 | 31 | out2 = power; |
Sigma884 | 0:e492422d50a7 | 32 | status = power * -1; |
Sigma884 | 0:e492422d50a7 | 33 | } |
Sigma884 | 0:e492422d50a7 | 34 | |
Sigma884 | 0:e492422d50a7 | 35 | void Motor_lib :: stop(){ |
Sigma884 | 0:e492422d50a7 | 36 | out1 = 0; |
Sigma884 | 0:e492422d50a7 | 37 | out2 = 0; |
Sigma884 | 0:e492422d50a7 | 38 | status = 0; |
Sigma884 | 0:e492422d50a7 | 39 | } |
Sigma884 | 0:e492422d50a7 | 40 | |
Sigma884 | 0:e492422d50a7 | 41 | void Motor_lib :: break_stop(float time){ |
Sigma884 | 0:e492422d50a7 | 42 | out1 = 1; |
Sigma884 | 0:e492422d50a7 | 43 | out2 = 1; |
Sigma884 | 0:e492422d50a7 | 44 | status = 0; |
Sigma884 | 0:e492422d50a7 | 45 | stopTime.attach(mlib, &Motor_lib::stop, time); |
Sigma884 | 0:e492422d50a7 | 46 | } |
Sigma884 | 0:e492422d50a7 | 47 | |
Sigma884 | 0:e492422d50a7 | 48 | void Motor_lib :: break_stop(){ |
Sigma884 | 0:e492422d50a7 | 49 | out1 = 1; |
Sigma884 | 0:e492422d50a7 | 50 | out2 = 1; |
Sigma884 | 0:e492422d50a7 | 51 | status = 0; |
Sigma884 | 0:e492422d50a7 | 52 | stopTime.attach(mlib, &Motor_lib::stop, 0.1f); |
Sigma884 | 0:e492422d50a7 | 53 | } |