Interface with Parallax's high speed continuous rotation servo (Activity Bot)

Dependents:   ES202FinalProject ES202_FinalProject_workingExample DREAMTEAM ES202_straight1 ... more

Files at this revision

API Documentation at this revision

Comitter:
jdonnal
Date:
Fri Mar 02 16:51:35 2018 +0000
Commit message:
Initial Commit

Changed in this revision

ContinuousServo.cpp Show annotated file Show diff for this revision Revisions of this file
ContinuousServo.h Show annotated file Show diff for this revision Revisions of this file
diff -r 000000000000 -r d6371727ce0c ContinuousServo.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ContinuousServo.cpp	Fri Mar 02 16:51:35 2018 +0000
@@ -0,0 +1,20 @@
+#include "ContinuousServo.h"
+ 
+ //64 counts per rev
+ 
+ContinuousServo::ContinuousServo(PinName output): servo_(output){
+    servo_.period_ms(50);
+}
+
+void ContinuousServo::speed(float val){
+    //convert val from -1,1 to 1.3 to 1.7
+    if(val<-1.0)
+        val = -1.0;
+    if(val>1.0)
+        val = 1.0;
+    servo_.pulsewidth_us((int)(1500+200*val));
+}
+
+void ContinuousServo::stop(){
+    servo_.pulsewidth_us(0);
+}
\ No newline at end of file
diff -r 000000000000 -r d6371727ce0c ContinuousServo.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ContinuousServo.h	Fri Mar 02 16:51:35 2018 +0000
@@ -0,0 +1,39 @@
+
+/* Parallax High Speed Continuous Servo
+   John Donnal 2018
+*/
+
+#ifndef CONTINUOUS_SERVO_H
+#define CONTINUOUS_SERVO_H
+
+/**
+ * Includes
+ */
+#include "mbed.h"
+
+/**
+ * Parallax High Speed Continuous Servo Interface.
+ */
+class ContinuousServo {
+
+public:
+
+    /**
+     * Constructor.
+     *
+     * Drive Parallax servo (ActivityBot)
+     * -1: full speed reverse
+     *  0: stop
+     *  1: full speed forward
+     * @param output mbed pin for output channel.
+     */
+    ContinuousServo(PinName output);
+
+    void speed(float val);
+    void stop(void);
+private:
+
+    PwmOut servo_;
+};
+
+#endif /* CONTINUOUS_SERVO_H */