basic motor controller class to be used with the TB6612 motor controller.
motor.cpp@0:322cf8e3ef05, 2021-10-31 (annotated)
- Committer:
- snapo
- Date:
- Sun Oct 31 10:44:13 2021 +0000
- Revision:
- 0:322cf8e3ef05
initial motor controller class for use in a maze solving robot
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
snapo | 0:322cf8e3ef05 | 1 | #include "motor.h" |
snapo | 0:322cf8e3ef05 | 2 | |
snapo | 0:322cf8e3ef05 | 3 | motor::motor(PinName dir1, PinName dir2, PinName motorOne): |
snapo | 0:322cf8e3ef05 | 4 | dir1_(dir1), dir2_(dir2), motorOne_(motorOne) {} |
snapo | 0:322cf8e3ef05 | 5 | |
snapo | 0:322cf8e3ef05 | 6 | void motor::setSpeed(float speed){ |
snapo | 0:322cf8e3ef05 | 7 | |
snapo | 0:322cf8e3ef05 | 8 | if (speed > 0){ |
snapo | 0:322cf8e3ef05 | 9 | dir1_ = true; |
snapo | 0:322cf8e3ef05 | 10 | dir2_ = false; |
snapo | 0:322cf8e3ef05 | 11 | motorOne_ = speed; |
snapo | 0:322cf8e3ef05 | 12 | |
snapo | 0:322cf8e3ef05 | 13 | } else { |
snapo | 0:322cf8e3ef05 | 14 | dir1_ = false; |
snapo | 0:322cf8e3ef05 | 15 | dir2_ = true; |
snapo | 0:322cf8e3ef05 | 16 | motorOne_ = speed; |
snapo | 0:322cf8e3ef05 | 17 | } |
snapo | 0:322cf8e3ef05 | 18 | } |
snapo | 0:322cf8e3ef05 | 19 | |
snapo | 0:322cf8e3ef05 | 20 | motor & motor::operator = (float speed){ |
snapo | 0:322cf8e3ef05 | 21 | setSpeed(speed); |
snapo | 0:322cf8e3ef05 | 22 | return *this; |
snapo | 0:322cf8e3ef05 | 23 | } |
snapo | 0:322cf8e3ef05 | 24 | |
snapo | 0:322cf8e3ef05 | 25 |