From 52a777002a02f17b5520fff7c01102b0fd47e025 Mon Sep 17 00:00:00 2001 From: Alberto Nidasio <alberto.nidasio@skywarder.eu> Date: Wed, 18 May 2022 10:41:39 +0200 Subject: [PATCH] [Servo] Implemented position limitation --- src/shared/actuators/Servo/Servo.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/shared/actuators/Servo/Servo.cpp b/src/shared/actuators/Servo/Servo.cpp index ceffefd29..e08ca3cb8 100644 --- a/src/shared/actuators/Servo/Servo.cpp +++ b/src/shared/actuators/Servo/Servo.cpp @@ -61,6 +61,11 @@ void Servo::disable() {} void Servo::setPosition(float position) { + if (position < 0) + position = 0; + else if (position > 1) + position = 1; + float pulse = minPulse + (maxPulse - minPulse) * position; float dutyCycle = pulse * frequency / 1000000.0f; -- GitLab