Servomotor
Dependents: ServomotorTests NerfUSTarget
source/Servomotor.cpp
- Committer:
- GaiSensei
- Date:
- 2017-04-09
- Revision:
- 5:003d3d682097
- Parent:
- 1:7e200831ba73
- Child:
- 6:8d8268e5a561
File content as of revision 5:003d3d682097:
#include "Servomotor.hpp" Servomotor::Servomotor(PwmOutInterface &pwm_out) : pwm_out(pwm_out) { } //Angle 0 degree = duty cycle 500 ns //Angle 90 degree = duty cycle 1500 ns //Angle 180 degree = duty cycle 2500 ns void Servomotor::set_angle(const float angle_degree) { const float duty_cycle_ns = (angle_degree / 180.0) * 2000 + 500; pwm_out.pulsewidth_ns(duty_cyclduty_cycle_ns); } void Servomotor::set_position_up() { set_angle(0); } void Servomotor::set_position_down() { set_angle(90); }