A library to control a CYS S8218 servo
CYS8218Controller.hpp@2:695c74c6d483, 2016-09-23 (annotated)
- Committer:
- Kerneels Bezuidenhout
- Date:
- Fri Sep 23 03:01:18 2016 +0200
- Revision:
- 2:695c74c6d483
- Parent:
- 1:c42f4b73e85c
- Child:
- 4:c43d375a84a9
Added SetZero function
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Kerneels Bezuidenhout |
1:c42f4b73e85c | 1 | #ifndef CYS8218CONTROLLER_H |
Kerneels Bezuidenhout |
1:c42f4b73e85c | 2 | #define CYS8218CONTROLLER_H |
Kerneels Bezuidenhout |
1:c42f4b73e85c | 3 | |
Kerneels Bezuidenhout |
1:c42f4b73e85c | 4 | //Includes |
Kerneels Bezuidenhout |
1:c42f4b73e85c | 5 | #include "mbed.h" |
Kerneels Bezuidenhout |
1:c42f4b73e85c | 6 | |
Kerneels Bezuidenhout |
1:c42f4b73e85c | 7 | /** |
Kerneels Bezuidenhout |
1:c42f4b73e85c | 8 | * A CYS S8218 servo controller library |
Kerneels Bezuidenhout |
1:c42f4b73e85c | 9 | * |
Kerneels Bezuidenhout |
1:c42f4b73e85c | 10 | * @author CA Bezuidenhout |
Kerneels Bezuidenhout |
1:c42f4b73e85c | 11 | */ |
Kerneels Bezuidenhout |
1:c42f4b73e85c | 12 | class CYS8218Controller |
Kerneels Bezuidenhout |
1:c42f4b73e85c | 13 | { |
Kerneels Bezuidenhout |
1:c42f4b73e85c | 14 | public: |
Kerneels Bezuidenhout |
1:c42f4b73e85c | 15 | /** |
Kerneels Bezuidenhout |
1:c42f4b73e85c | 16 | * @param pwmPin : PWM pin of servo / orange wire |
Kerneels Bezuidenhout |
1:c42f4b73e85c | 17 | * @param initAngle : The angle the servo goes to when object is created |
Kerneels Bezuidenhout |
1:c42f4b73e85c | 18 | */ |
Kerneels Bezuidenhout |
1:c42f4b73e85c | 19 | CYS8218Controller(PinName pwmPin, float initAngle = 0.0f); |
Kerneels Bezuidenhout |
1:c42f4b73e85c | 20 | |
Kerneels Bezuidenhout |
1:c42f4b73e85c | 21 | /** |
Kerneels Bezuidenhout |
1:c42f4b73e85c | 22 | * Saves the current position as the zero position. |
Kerneels Bezuidenhout |
1:c42f4b73e85c | 23 | */ |
Kerneels Bezuidenhout |
1:c42f4b73e85c | 24 | void SaveZero(); |
Kerneels Bezuidenhout |
1:c42f4b73e85c | 25 | |
Kerneels Bezuidenhout |
1:c42f4b73e85c | 26 | /** |
Kerneels Bezuidenhout |
2:695c74c6d483 | 27 | * Sets the zero position without moving the servo |
Kerneels Bezuidenhout |
2:695c74c6d483 | 28 | * |
Kerneels Bezuidenhout |
2:695c74c6d483 | 29 | * @param angle : The angle to set as the zero position |
Kerneels Bezuidenhout |
2:695c74c6d483 | 30 | */ |
Kerneels Bezuidenhout |
2:695c74c6d483 | 31 | void SetZero(float angle); |
Kerneels Bezuidenhout |
2:695c74c6d483 | 32 | |
Kerneels Bezuidenhout |
2:695c74c6d483 | 33 | /** |
Kerneels Bezuidenhout |
1:c42f4b73e85c | 34 | * Calibrate the servo |
Kerneels Bezuidenhout |
1:c42f4b73e85c | 35 | * @param actualAngle : The actual angle from zero, of the current position in degrees. |
Kerneels Bezuidenhout |
1:c42f4b73e85c | 36 | */ |
Kerneels Bezuidenhout |
1:c42f4b73e85c | 37 | void Calibrate(float actualAngle); |
Kerneels Bezuidenhout |
1:c42f4b73e85c | 38 | |
Kerneels Bezuidenhout |
1:c42f4b73e85c | 39 | /** |
Kerneels Bezuidenhout |
1:c42f4b73e85c | 40 | * Sets the angular position of the servo |
Kerneels Bezuidenhout |
1:c42f4b73e85c | 41 | * @param angle : Desired angle from the zero position in degrees |
Kerneels Bezuidenhout |
1:c42f4b73e85c | 42 | */ |
Kerneels Bezuidenhout |
1:c42f4b73e85c | 43 | void Set(float angle); |
Kerneels Bezuidenhout |
1:c42f4b73e85c | 44 | |
Kerneels Bezuidenhout |
1:c42f4b73e85c | 45 | /** |
Kerneels Bezuidenhout |
1:c42f4b73e85c | 46 | * Moves to an relative angular position from the current position |
Kerneels Bezuidenhout |
1:c42f4b73e85c | 47 | * @param relAngle : The relative angle to move in degrees |
Kerneels Bezuidenhout |
1:c42f4b73e85c | 48 | */ |
Kerneels Bezuidenhout |
1:c42f4b73e85c | 49 | void Move(float relAngle); |
Kerneels Bezuidenhout |
1:c42f4b73e85c | 50 | |
Kerneels Bezuidenhout |
1:c42f4b73e85c | 51 | |
Kerneels Bezuidenhout |
1:c42f4b73e85c | 52 | private: |
Kerneels Bezuidenhout |
1:c42f4b73e85c | 53 | PwmOut _servo; |
Kerneels Bezuidenhout |
1:c42f4b73e85c | 54 | float _angle; |
Kerneels Bezuidenhout |
1:c42f4b73e85c | 55 | float _ref; |
Kerneels Bezuidenhout |
1:c42f4b73e85c | 56 | float PW_PER_DEG; |
Kerneels Bezuidenhout |
1:c42f4b73e85c | 57 | float ZEROPW; |
Kerneels Bezuidenhout |
1:c42f4b73e85c | 58 | |
Kerneels Bezuidenhout |
1:c42f4b73e85c | 59 | static const float MIN_PW = 0.0005; |
Kerneels Bezuidenhout |
1:c42f4b73e85c | 60 | static const float MAX_PW = 0.0025f; |
Kerneels Bezuidenhout |
1:c42f4b73e85c | 61 | |
Kerneels Bezuidenhout |
1:c42f4b73e85c | 62 | void SetServo(); |
Kerneels Bezuidenhout |
1:c42f4b73e85c | 63 | }; |
Kerneels Bezuidenhout |
1:c42f4b73e85c | 64 | |
Kerneels Bezuidenhout |
1:c42f4b73e85c | 65 | #endif |