Servomotor
Dependents: ServomotorTests NerfUSTarget
source/Servomotor.cpp
- Committer:
- dupm2216
- Date:
- 2017-02-25
- Revision:
- 1:7e200831ba73
- Parent:
- Servomotor.cpp@ 0:46b4e7d76586
- Child:
- 5:003d3d682097
File content as of revision 1:7e200831ba73:
#include "Servomotor.hpp" Servomotor::Servomotor(PwmOutInterface &pwm_out) : pwm_out(pwm_out) { } //Angle 0 degree = duty cycle 1 ms //Angle 90 degree = duty cycle 1.5 ms //Angle 180 degree = duty cycle 2 ms void Servomotor::set_angle(const float angle_degree) { const float duty_cycle_ms = angle_degree / 180.0 + 1.0; pwm_out.pulsewidth_ms(duty_cycle_ms); } void Servomotor::set_position_up() { set_angle(0); } void Servomotor::set_position_down() { set_angle(90); }