Interface with Parallax's high speed continuous rotation servo (Activity Bot)
Dependents: ES202FinalProject ES202_FinalProject_workingExample DREAMTEAM ES202_straight1 ... more
Diff: ContinuousServo.cpp
- Revision:
- 0:d6371727ce0c
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