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
arm.h@0:494acf21d3bc, 2016-10-31 (annotated)
- Committer:
- ronvbree
- Date:
- Mon Oct 31 13:05:53 2016 +0000
- Revision:
- 0:494acf21d3bc
- Child:
- 2:fc869e45e672
test
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| ronvbree | 0:494acf21d3bc | 1 | #include "mbed.h" |
| ronvbree | 0:494acf21d3bc | 2 | |
| ronvbree | 0:494acf21d3bc | 3 | /* |
| ronvbree | 0:494acf21d3bc | 4 | Constants |
| ronvbree | 0:494acf21d3bc | 5 | */ |
| ronvbree | 0:494acf21d3bc | 6 | |
| ronvbree | 0:494acf21d3bc | 7 | const bool clockwise = true; |
| ronvbree | 0:494acf21d3bc | 8 | const bool counterClockwise = false; |
| ronvbree | 0:494acf21d3bc | 9 | |
| ronvbree | 0:494acf21d3bc | 10 | const float motorGain = 8.4f; // Rad/s |
| ronvbree | 0:494acf21d3bc | 11 | const float maxVelocity = 8.4f; // Rad/s (max velocity: 80 rpm = 80*2*pi/60 = 8.4 rad/s) |
| ronvbree | 0:494acf21d3bc | 12 | const float tick = 0.1f; // In seconds |
| ronvbree | 0:494acf21d3bc | 13 | const float gearRadius = 5.2f; // In cm |
| ronvbree | 0:494acf21d3bc | 14 | |
| ronvbree | 0:494acf21d3bc | 15 | /* |
| ronvbree | 0:494acf21d3bc | 16 | Arm class |
| ronvbree | 0:494acf21d3bc | 17 | */ |
| ronvbree | 0:494acf21d3bc | 18 | |
| ronvbree | 0:494acf21d3bc | 19 | class Arm { |
| ronvbree | 0:494acf21d3bc | 20 | private: |
| ronvbree | 0:494acf21d3bc | 21 | // Instance Variables |
| ronvbree | 0:494acf21d3bc | 22 | float length; // Current length of the arm in centimeters |
| ronvbree | 0:494acf21d3bc | 23 | float velocity; // Angular velocity in rotations per second |
| ronvbree | 0:494acf21d3bc | 24 | PwmOut motorControl; |
| ronvbree | 0:494acf21d3bc | 25 | DigitalOut motorDirection; |
| ronvbree | 0:494acf21d3bc | 26 | Ticker ticker; // Keeps the arm's instance variables up to date |
| ronvbree | 0:494acf21d3bc | 27 | // Methods |
| ronvbree | 0:494acf21d3bc | 28 | void setMotor(float motorValue); |
| ronvbree | 0:494acf21d3bc | 29 | void doTick(); |
| ronvbree | 0:494acf21d3bc | 30 | public: |
| ronvbree | 0:494acf21d3bc | 31 | // Constructor |
| ronvbree | 0:494acf21d3bc | 32 | Arm(float initialLength, PinName motorPWM, PinName motorDir); |
| ronvbree | 0:494acf21d3bc | 33 | // Methods |
| ronvbree | 0:494acf21d3bc | 34 | float getLength(); |
| ronvbree | 0:494acf21d3bc | 35 | float getVelocity(); |
| ronvbree | 0:494acf21d3bc | 36 | void setVelocity(float referenceVelocity); |
| ronvbree | 0:494acf21d3bc | 37 | |
| ronvbree | 0:494acf21d3bc | 38 | }; |