First import from throwbot
motors.cpp@1:201d986498c7, 2014-10-05 (annotated)
- Committer:
- Throwbot
- Date:
- Sun Oct 05 12:20:47 2014 +0000
- Revision:
- 1:201d986498c7
- Parent:
- 0:5b2bf6e79b07
Motors code
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Throwbot | 0:5b2bf6e79b07 | 1 | #include "motors.h" |
Throwbot | 0:5b2bf6e79b07 | 2 | |
Throwbot | 0:5b2bf6e79b07 | 3 | Motors::Motors(TB6612 * L, TB6612 * R, PinName STBY): |
Throwbot | 0:5b2bf6e79b07 | 4 | Left(L), Right(R), enable(STBY) |
Throwbot | 0:5b2bf6e79b07 | 5 | { |
Throwbot | 0:5b2bf6e79b07 | 6 | enable = 1; |
Throwbot | 0:5b2bf6e79b07 | 7 | } |
Throwbot | 0:5b2bf6e79b07 | 8 | |
Throwbot | 0:5b2bf6e79b07 | 9 | void Motors::flip() |
Throwbot | 0:5b2bf6e79b07 | 10 | { |
Throwbot | 0:5b2bf6e79b07 | 11 | TB6612 * temp = Left; |
Throwbot | 0:5b2bf6e79b07 | 12 | Left = Right; |
Throwbot | 0:5b2bf6e79b07 | 13 | Right = temp; |
Throwbot | 0:5b2bf6e79b07 | 14 | |
Throwbot | 0:5b2bf6e79b07 | 15 | Left->scale *= -1; |
Throwbot | 0:5b2bf6e79b07 | 16 | Right->scale *= -1; |
Throwbot | 1:201d986498c7 | 17 | } |
Throwbot | 1:201d986498c7 | 18 | void Motors::reverse(bool m) |
Throwbot | 1:201d986498c7 | 19 | { |
Throwbot | 1:201d986498c7 | 20 | if(m) |
Throwbot | 1:201d986498c7 | 21 | Right->scale *= -1; //reverse right motor |
Throwbot | 1:201d986498c7 | 22 | else |
Throwbot | 1:201d986498c7 | 23 | Left->scale *= -1; //reverse left motor |
Throwbot | 1:201d986498c7 | 24 | } |
Throwbot | 1:201d986498c7 | 25 | |
Throwbot | 1:201d986498c7 | 26 | //TODO: write in a function that automatically sets the motors to be oriented properly. Use the |
Throwbot | 1:201d986498c7 | 27 | //gyroscopes and accelerometer to do this. |