A library to control a CYS S8218 servo

Dependents:   Heiko

Revision:
1:c42f4b73e85c
Parent:
0:23a6381d15ff
Child:
2:695c74c6d483
--- a/CYS8218Controller.hpp	Wed Sep 07 00:15:46 2016 +0000
+++ b/CYS8218Controller.hpp	Wed Sep 07 03:07:07 2016 +0200
@@ -0,0 +1,58 @@
+#ifndef CYS8218CONTROLLER_H
+#define CYS8218CONTROLLER_H
+
+//Includes
+#include "mbed.h"
+
+/**
+ *  A CYS S8218 servo controller library
+ *
+ * @author CA Bezuidenhout
+ */
+class CYS8218Controller
+{
+public:
+  /**
+   * @param pwmPin : PWM pin of servo / orange wire
+   * @param initAngle : The angle the servo goes to when object is created
+   */
+  CYS8218Controller(PinName pwmPin, float initAngle = 0.0f);
+
+  /**
+   * Saves the current position as the zero position.
+   */
+  void SaveZero();
+
+  /**
+   * Calibrate the servo
+   * @param actualAngle : The actual angle from zero, of the current position in degrees.
+   */
+  void Calibrate(float actualAngle);
+
+  /**
+   * Sets the angular position of the servo
+   * @param angle : Desired angle from the zero position in degrees
+   */
+  void Set(float angle);
+
+  /**
+   * Moves to an relative angular position from the current position
+   * @param relAngle : The relative angle to move in degrees
+   */
+  void Move(float relAngle);
+
+
+private:
+  PwmOut _servo;
+  float _angle;
+  float _ref;
+  float PW_PER_DEG;
+  float ZEROPW;
+
+  static const float MIN_PW = 0.0005;
+  static const float MAX_PW = 0.0025f;
+
+  void SetServo();
+};
+
+#endif