Skip to content

Bugfixes #6

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion simulator/modules/sbot_interface/boards/servo_board.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def handle_command(self, command: str) -> str:
if args[0] == '*IDN?':
return f'Student Robotics:SBv4B:{self.asset_tag}:{self.software_version}'
elif args[0] == '*STATUS?':
return f"{self.watchdog_fail}:{self.pgood}"
return f"{self.watchdog_fail:d}:{self.pgood:d}"
elif args[0] == '*RESET':
LOGGER.info(f'Resetting servo board {self.asset_tag}')
for servo in self.servos:
Expand Down
12 changes: 7 additions & 5 deletions simulator/modules/sbot_interface/devices/servo.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@
map_to_range,
)

MAX_POSITION = 2000
MIN_POSITION = 1000
MAX_POSITION = 4000
MIN_POSITION = 300
SERVO_MAX = 1980
SERVO_MIN = 350


class BaseServo(ABC):
Expand Down Expand Up @@ -92,13 +94,13 @@ class Servo(BaseServo):
"""A servo connected to the Servo board."""

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

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

self._device.setPosition(map_to_range(
value,
(MIN_POSITION, MAX_POSITION),
(SERVO_MIN, SERVO_MAX),
(self._min_position + 0.001, self._max_position - 0.001),
))
self.position = value
Expand Down
Loading