Interface with Parallax's high speed continuous rotation servo (Activity Bot)
Dependencies: Tach
ContinuousServo.cpp@1:f1fc02b6744f, 2019-04-17 (annotated)
- Committer:
- m211002
- Date:
- Wed Apr 17 20:08:25 2019 +0000
- Revision:
- 1:f1fc02b6744f
- Parent:
- 0:d6371727ce0c
Sonar Subsystem: Stops cart 4/17/19 2.0
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
jdonnal | 0:d6371727ce0c | 1 | #include "ContinuousServo.h" |
jdonnal | 0:d6371727ce0c | 2 | |
jdonnal | 0:d6371727ce0c | 3 | //64 counts per rev |
jdonnal | 0:d6371727ce0c | 4 | |
jdonnal | 0:d6371727ce0c | 5 | ContinuousServo::ContinuousServo(PinName output): servo_(output){ |
jdonnal | 0:d6371727ce0c | 6 | servo_.period_ms(50); |
jdonnal | 0:d6371727ce0c | 7 | } |
jdonnal | 0:d6371727ce0c | 8 | |
jdonnal | 0:d6371727ce0c | 9 | void ContinuousServo::speed(float val){ |
jdonnal | 0:d6371727ce0c | 10 | //convert val from -1,1 to 1.3 to 1.7 |
jdonnal | 0:d6371727ce0c | 11 | if(val<-1.0) |
jdonnal | 0:d6371727ce0c | 12 | val = -1.0; |
jdonnal | 0:d6371727ce0c | 13 | if(val>1.0) |
jdonnal | 0:d6371727ce0c | 14 | val = 1.0; |
jdonnal | 0:d6371727ce0c | 15 | servo_.pulsewidth_us((int)(1500+200*val)); |
jdonnal | 0:d6371727ce0c | 16 | } |
jdonnal | 0:d6371727ce0c | 17 | |
jdonnal | 0:d6371727ce0c | 18 | void ContinuousServo::stop(){ |
jdonnal | 0:d6371727ce0c | 19 | servo_.pulsewidth_us(0); |
jdonnal | 0:d6371727ce0c | 20 | } |