Servomotor
Dependents: ServomotorTests NerfUSTarget
source/Servomotor.cpp@7:a5b6e6d9ad3d, 2017-04-11 (annotated)
- Committer:
- GaiSensei
- Date:
- Tue Apr 11 03:48:35 2017 +0000
- Revision:
- 7:a5b6e6d9ad3d
- Parent:
- 6:8d8268e5a561
- Child:
- 8:e42a3a06e072
Calibrate servomotors
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
dupm2216 | 0:46b4e7d76586 | 1 | #include "Servomotor.hpp" |
dupm2216 | 0:46b4e7d76586 | 2 | |
dupm2216 | 0:46b4e7d76586 | 3 | Servomotor::Servomotor(PwmOutInterface &pwm_out) : |
GaiSensei | 7:a5b6e6d9ad3d | 4 | pwm_out(pwm_out), |
GaiSensei | 7:a5b6e6d9ad3d | 5 | up_angle(90) |
dupm2216 | 0:46b4e7d76586 | 6 | { |
dupm2216 | 0:46b4e7d76586 | 7 | |
dupm2216 | 0:46b4e7d76586 | 8 | } |
dupm2216 | 0:46b4e7d76586 | 9 | |
GaiSensei | 5:003d3d682097 | 10 | //Angle 0 degree = duty cycle 500 ns |
GaiSensei | 5:003d3d682097 | 11 | //Angle 90 degree = duty cycle 1500 ns |
GaiSensei | 5:003d3d682097 | 12 | //Angle 180 degree = duty cycle 2500 ns |
dupm2216 | 0:46b4e7d76586 | 13 | void Servomotor::set_angle(const float angle_degree) |
dupm2216 | 0:46b4e7d76586 | 14 | { |
GaiSensei | 6:8d8268e5a561 | 15 | const float duty_cycle_us = (angle_degree / 180.0) * 2000 + 500; |
GaiSensei | 6:8d8268e5a561 | 16 | pwm_out.pulsewidth_us(duty_cycle_us); |
dupm2216 | 0:46b4e7d76586 | 17 | } |
dupm2216 | 0:46b4e7d76586 | 18 | |
dupm2216 | 0:46b4e7d76586 | 19 | void Servomotor::set_position_up() |
dupm2216 | 0:46b4e7d76586 | 20 | { |
GaiSensei | 7:a5b6e6d9ad3d | 21 | set_angle(up_angle); |
dupm2216 | 0:46b4e7d76586 | 22 | } |
dupm2216 | 0:46b4e7d76586 | 23 | |
dupm2216 | 0:46b4e7d76586 | 24 | void Servomotor::set_position_down() |
dupm2216 | 0:46b4e7d76586 | 25 | { |
GaiSensei | 7:a5b6e6d9ad3d | 26 | set_angle(up_angle - 75); |
GaiSensei | 7:a5b6e6d9ad3d | 27 | } |