Skip to content

Commit f44660e

Browse files
committed
Allow servo firmware to request pulse widths outside the servo's range
1 parent 272c2df commit f44660e

File tree

1 file changed

+7
-5
lines changed
  • simulator/modules/sbot_interface/devices

1 file changed

+7
-5
lines changed

simulator/modules/sbot_interface/devices/servo.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,10 @@
1414
map_to_range,
1515
)
1616

17-
MAX_POSITION = 2000
18-
MIN_POSITION = 1000
17+
MAX_POSITION = 4000
18+
MIN_POSITION = 300
19+
SERVO_MAX = 1980
20+
SERVO_MIN = 350
1921

2022

2123
class BaseServo(ABC):
@@ -92,13 +94,13 @@ class Servo(BaseServo):
9294
"""A servo connected to the Servo board."""
9395

9496
def __init__(self, device_name: str) -> None:
95-
self.position = (MAX_POSITION + MIN_POSITION) // 2
9697
# TODO use setAvailableForce to simulate disabled
9798
self._enabled = False
9899
g = get_globals()
99100
self._device = get_robot_device(g.robot, device_name, WebotsDevice.Motor)
100101
self._max_position = self._device.getMaxPosition()
101102
self._min_position = self._device.getMinPosition()
103+
self.position = (SERVO_MAX + SERVO_MIN) // 2
102104

103105
def disable(self) -> None:
104106
"""Disable the servo."""
@@ -112,11 +114,11 @@ def set_position(self, value: int) -> None:
112114
"""
113115
# Apply a small amount of variation to the power setting to simulate
114116
# inaccuracies in the servo
115-
value = int(add_jitter(value, (MIN_POSITION, MAX_POSITION)))
117+
value = int(add_jitter(value, (SERVO_MIN, SERVO_MAX)))
116118

117119
self._device.setPosition(map_to_range(
118120
value,
119-
(MIN_POSITION, MAX_POSITION),
121+
(SERVO_MIN, SERVO_MAX),
120122
(self._min_position + 0.001, self._max_position - 0.001),
121123
))
122124
self.position = value

0 commit comments

Comments
 (0)