Revision 1:880e551fa457, committed 2017-10-21
- Comitter:
- Cornelius Bezuidenhout
- Date:
- Sat Oct 21 22:26:13 2017 +0200
- Parent:
- 0:624433cd59dd
- Commit message:
- Initial version
Changed in this revision
diff -r 624433cd59dd -r 880e551fa457 PanTilt.cpp
--- a/PanTilt.cpp Sat Oct 21 19:26:23 2017 +0000
+++ b/PanTilt.cpp Sat Oct 21 22:26:13 2017 +0200
@@ -0,0 +1,52 @@
+#include "PanTilt.hpp"
+
+PanTilt::PanTilt(PinName panPin, PinName tiltName) :
+ _panServo(panPin),
+ _tiltServo(tiltPin)
+{
+
+}
+
+void PanTilt::Set(float pan, float tilt) {
+ _panServo.Set(pan);
+ _tiltServo.Set(tilt);
+}
+void PanTilt::SetPan(float pan) { Set(pan, 0.0f); }
+void PanTilt::SetTilt(float tilt) { _panServo.Set(0.0f, tilt); }
+
+void PanTilt::Move(float pan, float tilt) {
+ _panServo.Move(pan);
+ _tiltServo.Move(tilt);
+}
+void PanTilt::MovePan(float pan) { Move(pan, 0.0f); }
+void PanTilt::MoveTilt(float tilt) { Move(0.0f, tilt); }
+
+float PanTilt::GetPan() { return _panServo.GetAngle(); }
+float PanTilt::GetTilt() { return _titlServo.GetAngle(); }
+
+void PanTilt:Off() {
+ _panServo.Off();
+ _tiltServo.Off();
+}
+void PanTilt::PanOff() { _panServo.Off(); }
+void PanTilt::TiltOff() { _tiltServo.Off(); }
+
+void PanTilt::SetZero(float panZero, float tiltZero) {
+ _panServo.SetZero(panZero);
+ _tiltServo.SetZero(tiltZero);
+}
+void PanTilt::SetPanZero(float panZero) { SetZero(panZero, 0.0f); }
+void PanTilt::SetTiltZero(float tiltZero) { SetZero( 0.0f, tiltZero); }
+
+void PanTilt::SetMin(float panMin, float tiltMin) {
+ _panServo.SetMin(panMin);
+ _tiltServo.SetMin(tiltMin);
+}
+void PanTilt::SetPanMin(float panMin) { SetMin(panMin, 0.0f); }
+void PanTilt::SetTiltMin(float tiltMin) { SetMin(0.0f, tiltMin); }
+
+float PanTilt::GetPanMin() { return _panServo.GetMin(); }
+float PanTilt::GetTiltMin() { return _tiltServo.GetMin(); }
+
+float PanTilt::GetPanMax() { return _panServo.GetMax(); }
+float PanTilt::GetTiltMax() { return _tiltServo.GetMax(); }
\ No newline at end of file
diff -r 624433cd59dd -r 880e551fa457 PanTilt.hpp
--- a/PanTilt.hpp Sat Oct 21 19:26:23 2017 +0000
+++ b/PanTilt.hpp Sat Oct 21 22:26:13 2017 +0200
@@ -0,0 +1,83 @@
+#ifndef _PANTILT_
+#define _PANTILT_
+
+#include "mbed.h"
+
+/**
+ * Library for a sevo controlled pan tilt
+ *
+ * @author CA Bezuidenhout
+ */
+class PanTilt {
+
+public:
+ /**
+ * @param panPin : PWM pin of pan servo
+ * @param tiltPin : PWM pin of tilt servo
+ */
+ PanTilt(PinName panPin, PinName tiltName);
+
+ /**
+ * Sets pan, tilt angles in degrees
+ * @param pan : Pan angle in degrees
+ * @param tilt : Tilt angle in degrees
+ */
+ void Set(float pan, float tilt);
+
+ /**
+ * Sets the pan angle in degrees
+ * @param pan : Pan angle in degrees
+ */
+ void SetPan(float pan);
+
+ /**
+ * Sets tilt angle in degrees
+ * @param tilt : Tilt angle in degrees
+ */
+ void SetTilt(float tilt);
+
+ /**
+ * Moves the pan, tilt with specified degrees relative to current position
+ * @param pan : Relative pan angle in degrees
+ * @param tilt : Relative tilt angle in degrees
+ */
+ void Move(float pan, float tilt);
+
+ /**
+ * Moves the pan with specified degrees relative to current position
+ * @param pan : Relative pan angle in degrees
+ */
+ void MovePan(float pan, float tilt);
+
+ /**
+ * Moves the tilt with specified degrees relative to current position
+ * @param tilt : Relative tilt angle in degrees
+ */
+ void MoveTilt(float pan, float tilt);
+
+ float GetPan();
+ float GetTilt();
+
+ void Off();
+ void PanOff();
+ void TiltOff();
+
+ void SetZero(float panZero, float tiltZero);
+ void SetPanZero(float panZero);
+ void SetTiltZero(float tiltZero);
+
+ void SetMin(float panMin, float tiltMin);
+ void SetPanMin(float panMin);
+ void SetTiltMin(float tiltMin);
+
+ float GetPanMin();
+ float GetTiltMin();
+
+ float GetPanMax();
+ float GetTiltMax();
+
+private:
+ Servo _panServo;
+ Servo _tiltServo;
+};
+#endif
\ No newline at end of file