progress...
Fork of MotorController by
MotorController.h@2:70607c6dad36, 2016-01-10 (annotated)
- Committer:
- Sinterbaas
- Date:
- Sun Jan 10 23:46:12 2016 +0000
- Revision:
- 2:70607c6dad36
- Parent:
- 1:ed42d9035468
All of the latest changes (inc. Motor stuck detection)
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Sinterbaas | 0:ec2f323f6388 | 1 | #ifndef MOTORCONTROLLER_H |
Sinterbaas | 0:ec2f323f6388 | 2 | #define MOTORCONTROLLER_H |
Sinterbaas | 0:ec2f323f6388 | 3 | |
Sinterbaas | 0:ec2f323f6388 | 4 | #include "mbed.h" |
Sinterbaas | 0:ec2f323f6388 | 5 | #include "HBridge.h" |
Sinterbaas | 0:ec2f323f6388 | 6 | |
Sinterbaas | 0:ec2f323f6388 | 7 | class MotorController { |
Sinterbaas | 0:ec2f323f6388 | 8 | public: |
Sinterbaas | 0:ec2f323f6388 | 9 | MotorController (HBridge &motor, AnalogIn &motorInput); |
Sinterbaas | 0:ec2f323f6388 | 10 | |
Sinterbaas | 0:ec2f323f6388 | 11 | void start (); |
Sinterbaas | 0:ec2f323f6388 | 12 | void stop (); |
Sinterbaas | 0:ec2f323f6388 | 13 | |
Sinterbaas | 0:ec2f323f6388 | 14 | void turnLeft (); |
Sinterbaas | 0:ec2f323f6388 | 15 | void turnRight (); |
Sinterbaas | 0:ec2f323f6388 | 16 | void setPosition (float position); |
Sinterbaas | 0:ec2f323f6388 | 17 | |
Sinterbaas | 0:ec2f323f6388 | 18 | float getPosition (); |
Sinterbaas | 0:ec2f323f6388 | 19 | |
Sinterbaas | 2:70607c6dad36 | 20 | void setCurrentAction (char c); |
Sinterbaas | 2:70607c6dad36 | 21 | char getCurrentAction (); |
Sinterbaas | 2:70607c6dad36 | 22 | |
Sinterbaas | 2:70607c6dad36 | 23 | void setCurrentStatus (char c); |
Sinterbaas | 2:70607c6dad36 | 24 | char getCurrentStatus (); |
jurgy | 1:ed42d9035468 | 25 | |
jurgy | 1:ed42d9035468 | 26 | static const float POSITION_0 = 0.0f; |
jurgy | 1:ed42d9035468 | 27 | static const float POSITION_1 = 0.65f; |
jurgy | 1:ed42d9035468 | 28 | static const float POSITION_2 = 2.55f; |
jurgy | 1:ed42d9035468 | 29 | static const float POSITION_3 = 8.2f; |
jurgy | 1:ed42d9035468 | 30 | static const float POSITION_4 = 14.65f; |
jurgy | 1:ed42d9035468 | 31 | static const float POSITION_5 = 22.3f; |
jurgy | 1:ed42d9035468 | 32 | static const float POSITION_6 = 29.3f; |
jurgy | 1:ed42d9035468 | 33 | static const float POSITION_7 = 41.6f; |
jurgy | 1:ed42d9035468 | 34 | static const float POSITION_8 = 68.5f; |
jurgy | 1:ed42d9035468 | 35 | static const float POSITION_9 = 98.0f; |
Sinterbaas | 0:ec2f323f6388 | 36 | static const float POSITION_10 = 100.0f; |
jurgy | 1:ed42d9035468 | 37 | |
Sinterbaas | 2:70607c6dad36 | 38 | static const float MARGIN_PERCENTAGE = 0.013f; |
Sinterbaas | 2:70607c6dad36 | 39 | static const float MARGIN_FIXED = 0.13f; |
Sinterbaas | 2:70607c6dad36 | 40 | |
Sinterbaas | 2:70607c6dad36 | 41 | static const float STATUS_OK = 'o'; |
Sinterbaas | 2:70607c6dad36 | 42 | static const float STATUS_STUCK = 's'; |
Sinterbaas | 0:ec2f323f6388 | 43 | |
Sinterbaas | 0:ec2f323f6388 | 44 | private: |
Sinterbaas | 2:70607c6dad36 | 45 | static const int BUFFER_SIZE = 20; |
Sinterbaas | 0:ec2f323f6388 | 46 | HBridge &motor; |
Sinterbaas | 0:ec2f323f6388 | 47 | AnalogIn &motorInput; |
Sinterbaas | 2:70607c6dad36 | 48 | |
jurgy | 1:ed42d9035468 | 49 | char currentAction; |
Sinterbaas | 2:70607c6dad36 | 50 | char currentStatus; |
Sinterbaas | 2:70607c6dad36 | 51 | |
Sinterbaas | 2:70607c6dad36 | 52 | int bufferCount; |
Sinterbaas | 2:70607c6dad36 | 53 | int bufferIndex; |
Sinterbaas | 2:70607c6dad36 | 54 | float positionBuffer[BUFFER_SIZE]; |
Sinterbaas | 2:70607c6dad36 | 55 | |
Sinterbaas | 2:70607c6dad36 | 56 | bool isMotorStuck (); |
Sinterbaas | 2:70607c6dad36 | 57 | void addLatestPosition (float position); |
Sinterbaas | 2:70607c6dad36 | 58 | void CheckMotorStatus (); |
Sinterbaas | 0:ec2f323f6388 | 59 | }; |
Sinterbaas | 0:ec2f323f6388 | 60 | |
Sinterbaas | 0:ec2f323f6388 | 61 | #endif |