David's dead reckoning code for the LVBots competition on March 6th. Uses the mbed LPC1768, DRV8835, QTR-3RC, and two DC motors with encoders.
Dependencies: PololuEncoder Pacer mbed GeneralDebouncer
reckoner.h@27:2456f68be679, 2014-03-01 (annotated)
- Committer:
- DavidEGrayson
- Date:
- Sat Mar 01 01:46:35 2014 +0000
- Revision:
- 27:2456f68be679
- Parent:
- 21:c279c6a83671
- Child:
- 36:ccb03b734737
Fixed a major bug in the line following (reduceSpeed return value was not used). Made finalSettleIn better by adding an integral term and increasing the settleSpeed from 200 to 300.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
DavidEGrayson | 21:c279c6a83671 | 1 | #pragma once |
DavidEGrayson | 21:c279c6a83671 | 2 | |
DavidEGrayson | 12:835a4d24ae3b | 3 | class Reckoner |
DavidEGrayson | 12:835a4d24ae3b | 4 | { |
DavidEGrayson | 12:835a4d24ae3b | 5 | public: |
DavidEGrayson | 12:835a4d24ae3b | 6 | |
DavidEGrayson | 12:835a4d24ae3b | 7 | Reckoner(); |
DavidEGrayson | 12:835a4d24ae3b | 8 | |
DavidEGrayson | 12:835a4d24ae3b | 9 | // Together, cos and sin form a vector with a magnitude close to 2^30 that indicates |
DavidEGrayson | 13:bba5b3abd13f | 10 | // the current position of the robot. |
DavidEGrayson | 12:835a4d24ae3b | 11 | // cos corresponds to the x component of the orientation vector. |
DavidEGrayson | 12:835a4d24ae3b | 12 | // sin corresponds to the y component of the orientation vector. |
DavidEGrayson | 12:835a4d24ae3b | 13 | int32_t cos, sin; |
DavidEGrayson | 12:835a4d24ae3b | 14 | |
DavidEGrayson | 12:835a4d24ae3b | 15 | // Together, x and y are a vector that points from the starting point to the |
DavidEGrayson | 12:835a4d24ae3b | 16 | // robot's current position. |
DavidEGrayson | 13:bba5b3abd13f | 17 | // The untis are Df / (1<<14), where Df is the distance the robot moves forward |
DavidEGrayson | 13:bba5b3abd13f | 18 | // or backwards due to a single encoder tick. |
DavidEGrayson | 12:835a4d24ae3b | 19 | int32_t x, y; |
DavidEGrayson | 12:835a4d24ae3b | 20 | |
DavidEGrayson | 21:c279c6a83671 | 21 | void reset(); |
DavidEGrayson | 21:c279c6a83671 | 22 | |
DavidEGrayson | 12:835a4d24ae3b | 23 | void handleTickLeftForward(); |
DavidEGrayson | 12:835a4d24ae3b | 24 | void handleTickLeftBackward(); |
DavidEGrayson | 12:835a4d24ae3b | 25 | void handleTickRightForward(); |
DavidEGrayson | 12:835a4d24ae3b | 26 | void handleTickRightBackward(); |
DavidEGrayson | 12:835a4d24ae3b | 27 | void handleForward(); |
DavidEGrayson | 12:835a4d24ae3b | 28 | void handleBackward(); |
DavidEGrayson | 12:835a4d24ae3b | 29 | void handleRight(); |
DavidEGrayson | 12:835a4d24ae3b | 30 | void handleLeft(); |
DavidEGrayson | 12:835a4d24ae3b | 31 | }; |