Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed QEI biquadFilter
controller.h@18:1c9dc6caab9d, 2016-11-03 (annotated)
- Committer:
- ronvbree
- Date:
- Thu Nov 03 16:29:31 2016 +0000
- Revision:
- 18:1c9dc6caab9d
- Parent:
- 12:8295c02d740f
- Child:
- 24:5c67674a40cf
final
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| ronvbree | 7:a80cb6b06320 | 1 | #include "robot.h" |
| ronvbree | 0:494acf21d3bc | 2 | |
| ronvbree | 12:8295c02d740f | 3 | const float topY = h + 0.5 * d + 0.3 * reach; |
| ronvbree | 18:1c9dc6caab9d | 4 | const float topX = 30; |
| ronvbree | 12:8295c02d740f | 5 | |
| ronvbree | 12:8295c02d740f | 6 | const float bottomY = h + 0.5 * d - 0.3 * reach; |
| ronvbree | 18:1c9dc6caab9d | 7 | const float bottomX = 30; |
| ronvbree | 12:8295c02d740f | 8 | |
| ronvbree | 7:a80cb6b06320 | 9 | class RobotController { |
| ronvbree | 7:a80cb6b06320 | 10 | private: |
| ronvbree | 7:a80cb6b06320 | 11 | // Robot |
| ronvbree | 7:a80cb6b06320 | 12 | Robot robot; |
| ronvbree | 7:a80cb6b06320 | 13 | // Serial communication for debugging purposes |
| ronvbree | 7:a80cb6b06320 | 14 | Serial debug; |
| ronvbree | 7:a80cb6b06320 | 15 | // Ticker |
| ronvbree | 7:a80cb6b06320 | 16 | Ticker ticker; |
| ronvbree | 7:a80cb6b06320 | 17 | // Controllers |
| ronvbree | 12:8295c02d740f | 18 | // -- Controls direct movement for the upper arm |
| ronvbree | 7:a80cb6b06320 | 19 | PIDController upperArmController; |
| ronvbree | 12:8295c02d740f | 20 | // -- Controls direct movement for the lower arm |
| ronvbree | 7:a80cb6b06320 | 21 | PIDController lowerArmController; |
| ronvbree | 12:8295c02d740f | 22 | // -- Controls the velocity at which the upper arm compensates for the dx induced by the lower arm |
| ronvbree | 12:8295c02d740f | 23 | PIDController upperXController; |
| ronvbree | 12:8295c02d740f | 24 | // -- Controls the velocity at which the lower arm compensates for the dx induced by the upper arm |
| ronvbree | 12:8295c02d740f | 25 | PIDController lowerXController; |
| ronvbree | 12:8295c02d740f | 26 | |
| ronvbree | 7:a80cb6b06320 | 27 | // Reference arm lengths |
| ronvbree | 7:a80cb6b06320 | 28 | volatile float upperArmLengthReference; |
| ronvbree | 7:a80cb6b06320 | 29 | volatile float lowerArmLengthReference; |
| ronvbree | 12:8295c02d740f | 30 | // Reference coordinates for straight movement |
| ronvbree | 12:8295c02d740f | 31 | volatile float referenceX; |
| ronvbree | 12:8295c02d740f | 32 | volatile float referenceY; |
| ronvbree | 7:a80cb6b06320 | 33 | |
| ronvbree | 7:a80cb6b06320 | 34 | // Control state flags |
| ronvbree | 7:a80cb6b06320 | 35 | volatile bool MOVE_BY_REFERENCE; |
| ronvbree | 7:a80cb6b06320 | 36 | volatile bool PAINT_MOVE_UP; |
| ronvbree | 7:a80cb6b06320 | 37 | volatile bool PAINT_MOVE_DOWN; |
| ronvbree | 7:a80cb6b06320 | 38 | |
| ronvbree | 12:8295c02d740f | 39 | // Set all flags to false |
| ronvbree | 12:8295c02d740f | 40 | void clearFlags(); |
| ronvbree | 12:8295c02d740f | 41 | |
| ronvbree | 7:a80cb6b06320 | 42 | void doTick(); |
| ronvbree | 7:a80cb6b06320 | 43 | |
| ronvbree | 7:a80cb6b06320 | 44 | public: |
| ronvbree | 7:a80cb6b06320 | 45 | // Constructor |
| ronvbree | 7:a80cb6b06320 | 46 | RobotController(); |
| ronvbree | 7:a80cb6b06320 | 47 | // Move the roller to a x,y coordinate |
| ronvbree | 7:a80cb6b06320 | 48 | void moveTo(float x, float y); |
| ronvbree | 7:a80cb6b06320 | 49 | // Move the arms to the indicates arm lengths |
| ronvbree | 7:a80cb6b06320 | 50 | void setArmLengths(float upper, float lower); |
| ronvbree | 7:a80cb6b06320 | 51 | // Move to max y |
| ronvbree | 7:a80cb6b06320 | 52 | void goToTop(); |
| ronvbree | 7:a80cb6b06320 | 53 | // Move to min y |
| ronvbree | 7:a80cb6b06320 | 54 | void goToBottom(); |
| ronvbree | 7:a80cb6b06320 | 55 | // Make a straight painting movement upwards |
| ronvbree | 7:a80cb6b06320 | 56 | void paintUp(); |
| ronvbree | 7:a80cb6b06320 | 57 | // Make a straight painting movement downwards |
| ronvbree | 7:a80cb6b06320 | 58 | void paintDown(); |
| ronvbree | 7:a80cb6b06320 | 59 | |
| ronvbree | 7:a80cb6b06320 | 60 | // Robot queries |
| ronvbree | 7:a80cb6b06320 | 61 | bool isKilled(); |
| ronvbree | 7:a80cb6b06320 | 62 | float getUpperArmLength(); |
| ronvbree | 7:a80cb6b06320 | 63 | float getLowerArmLength(); |
| ronvbree | 7:a80cb6b06320 | 64 | |
| ronvbree | 12:8295c02d740f | 65 | // Get the robot instance |
| ronvbree | 7:a80cb6b06320 | 66 | Robot* getRobot(); |
| ronvbree | 7:a80cb6b06320 | 67 | |
| ronvbree | 7:a80cb6b06320 | 68 | }; |
| ronvbree | 0:494acf21d3bc | 69 | |
| ronvbree | 0:494acf21d3bc | 70 |