Servomotor
Dependents: ServomotorTests NerfUSTarget
source/Servomotor.cpp@5:003d3d682097, 2017-04-09 (annotated)
- Committer:
- GaiSensei
- Date:
- Sun Apr 09 23:11:11 2017 +0000
- Revision:
- 5:003d3d682097
- Parent:
- 1:7e200831ba73
- Child:
- 6:8d8268e5a561
Adjusted servomotor value
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) : |
dupm2216 | 0:46b4e7d76586 | 4 | pwm_out(pwm_out) |
dupm2216 | 0:46b4e7d76586 | 5 | { |
dupm2216 | 0:46b4e7d76586 | 6 | |
dupm2216 | 0:46b4e7d76586 | 7 | } |
dupm2216 | 0:46b4e7d76586 | 8 | |
GaiSensei | 5:003d3d682097 | 9 | //Angle 0 degree = duty cycle 500 ns |
GaiSensei | 5:003d3d682097 | 10 | //Angle 90 degree = duty cycle 1500 ns |
GaiSensei | 5:003d3d682097 | 11 | //Angle 180 degree = duty cycle 2500 ns |
dupm2216 | 0:46b4e7d76586 | 12 | void Servomotor::set_angle(const float angle_degree) |
dupm2216 | 0:46b4e7d76586 | 13 | { |
GaiSensei | 5:003d3d682097 | 14 | const float duty_cycle_ns = (angle_degree / 180.0) * 2000 + 500; |
GaiSensei | 5:003d3d682097 | 15 | pwm_out.pulsewidth_ns(duty_cyclduty_cycle_ns); |
dupm2216 | 0:46b4e7d76586 | 16 | } |
dupm2216 | 0:46b4e7d76586 | 17 | |
dupm2216 | 0:46b4e7d76586 | 18 | void Servomotor::set_position_up() |
dupm2216 | 0:46b4e7d76586 | 19 | { |
dupm2216 | 0:46b4e7d76586 | 20 | set_angle(0); |
dupm2216 | 0:46b4e7d76586 | 21 | } |
dupm2216 | 0:46b4e7d76586 | 22 | |
dupm2216 | 0:46b4e7d76586 | 23 | void Servomotor::set_position_down() |
dupm2216 | 0:46b4e7d76586 | 24 | { |
dupm2216 | 0:46b4e7d76586 | 25 | set_angle(90); |
dupm2216 | 0:46b4e7d76586 | 26 | } |