Interface with Parallax's high speed continuous rotation servo (Activity Bot)
Dependencies: Tach
ContinuousServo.cpp@0:d6371727ce0c, 2018-03-02 (annotated)
- Committer:
- jdonnal
- Date:
- Fri Mar 02 16:51:35 2018 +0000
- Revision:
- 0:d6371727ce0c
Initial Commit
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 | } |