PID motor controll for the biorobotics project.
Dependents: PID_example Motor_calibration Demo_mode Demo_mode ... more
Diff: motor.cpp
- Revision:
- 7:eb8787e7a5f5
- Parent:
- 6:d83c79716ea1
- Child:
- 8:bff5193c7d74
--- a/motor.cpp Wed Oct 31 08:01:35 2018 +0000 +++ b/motor.cpp Wed Oct 31 08:47:16 2018 +0000 @@ -8,6 +8,7 @@ pid = PID(); target_angle = 0; + extra_reduction_ratio = 1.0; printcount = 0; pid_period = 0; @@ -62,12 +63,16 @@ pid.set_k_values(k_p, k_i, k_d); } +void Motor::set_extra_reduction_ratio(double ratio) { + extra_reduction_ratio = ratio; +} + void Motor::set_target_angle(double angle) { - target_angle = angle; + target_angle = angle * extra_reduction_ratio; } double Motor::get_current_angle() { - return encoder_pulses_to_radians(encoder.getPulses()); + return encoder_pulses_to_radians(encoder.getPulses()) * extra_reduction_ratio; } void Motor::update() {