A library to control a CYS S8218 servo
CYS8218Controller.hpp@1:c42f4b73e85c, 2016-09-07 (annotated)
- Committer:
- Kerneels Bezuidenhout
- Date:
- Wed Sep 07 03:07:07 2016 +0200
- Revision:
- 1:c42f4b73e85c
- Parent:
- 0:23a6381d15ff
- Child:
- 2:695c74c6d483
Initial version
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 |
1:c42f4b73e85c | 27 | * Calibrate the servo |
Kerneels Bezuidenhout |
1:c42f4b73e85c | 28 | * @param actualAngle : The actual angle from zero, of the current position in degrees. |
Kerneels Bezuidenhout |
1:c42f4b73e85c | 29 | */ |
Kerneels Bezuidenhout |
1:c42f4b73e85c | 30 | void Calibrate(float actualAngle); |
Kerneels Bezuidenhout |
1:c42f4b73e85c | 31 | |
Kerneels Bezuidenhout |
1:c42f4b73e85c | 32 | /** |
Kerneels Bezuidenhout |
1:c42f4b73e85c | 33 | * Sets the angular position of the servo |
Kerneels Bezuidenhout |
1:c42f4b73e85c | 34 | * @param angle : Desired angle from the zero position in degrees |
Kerneels Bezuidenhout |
1:c42f4b73e85c | 35 | */ |
Kerneels Bezuidenhout |
1:c42f4b73e85c | 36 | void Set(float angle); |
Kerneels Bezuidenhout |
1:c42f4b73e85c | 37 | |
Kerneels Bezuidenhout |
1:c42f4b73e85c | 38 | /** |
Kerneels Bezuidenhout |
1:c42f4b73e85c | 39 | * Moves to an relative angular position from the current position |
Kerneels Bezuidenhout |
1:c42f4b73e85c | 40 | * @param relAngle : The relative angle to move in degrees |
Kerneels Bezuidenhout |
1:c42f4b73e85c | 41 | */ |
Kerneels Bezuidenhout |
1:c42f4b73e85c | 42 | void Move(float relAngle); |
Kerneels Bezuidenhout |
1:c42f4b73e85c | 43 | |
Kerneels Bezuidenhout |
1:c42f4b73e85c | 44 | |
Kerneels Bezuidenhout |
1:c42f4b73e85c | 45 | private: |
Kerneels Bezuidenhout |
1:c42f4b73e85c | 46 | PwmOut _servo; |
Kerneels Bezuidenhout |
1:c42f4b73e85c | 47 | float _angle; |
Kerneels Bezuidenhout |
1:c42f4b73e85c | 48 | float _ref; |
Kerneels Bezuidenhout |
1:c42f4b73e85c | 49 | float PW_PER_DEG; |
Kerneels Bezuidenhout |
1:c42f4b73e85c | 50 | float ZEROPW; |
Kerneels Bezuidenhout |
1:c42f4b73e85c | 51 | |
Kerneels Bezuidenhout |
1:c42f4b73e85c | 52 | static const float MIN_PW = 0.0005; |
Kerneels Bezuidenhout |
1:c42f4b73e85c | 53 | static const float MAX_PW = 0.0025f; |
Kerneels Bezuidenhout |
1:c42f4b73e85c | 54 | |
Kerneels Bezuidenhout |
1:c42f4b73e85c | 55 | void SetServo(); |
Kerneels Bezuidenhout |
1:c42f4b73e85c | 56 | }; |
Kerneels Bezuidenhout |
1:c42f4b73e85c | 57 | |
Kerneels Bezuidenhout |
1:c42f4b73e85c | 58 | #endif |