/** * Set the servo angle. * * Assume that the servo angle is linear with respect to the PWM value (big * assumption, need to test). * * Servo angles that are out of the supported range of the servo simply * "saturate" in that direction * In other words, if the servo has a range of (X degrees to Y degrees) than * angles of less than X * result in an angle of X being set and angles of more than Y degrees result in * an angle of Y being set. * * @param degrees The angle in degrees to set the servo. */ void Servo::SetAngle(float degrees) { if (degrees < kMinServoAngle) { degrees = kMinServoAngle; } else if (degrees > kMaxServoAngle) { degrees = kMaxServoAngle; } SetPosition(((float)(degrees - kMinServoAngle)) / GetServoAngleRange()); }
/** * Get the servo angle. * * Assume that the servo angle is linear with respect to the PWM value (big assumption, need to test). * @return The angle in degrees to which the servo is set. */ float Servo::GetAngle() { return (float)GetPosition() * GetServoAngleRange() + kMinServoAngle; }