David's line following code from the LVBots competition, 2015.
Dependencies: GeneralDebouncer Pacer PololuEncoder mbed
Fork of DeadReckoning by
reckoner.h@31:739b91331f31, 2014-03-04 (annotated)
- Committer:
- DavidEGrayson
- Date:
- Tue Mar 04 03:04:00 2014 +0000
- Revision:
- 31:739b91331f31
- Parent:
- 21:c279c6a83671
- Child:
- 36:ccb03b734737
testLineSensors seems to work fine with QTR-3RC.
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 | }; |