Skip to content

Commit

Permalink
Add minimum motor power limit
Browse files Browse the repository at this point in the history
To warn competitors that low values will not work with their physical robots
  • Loading branch information
WillB97 committed Aug 17, 2024
1 parent 023d36f commit d1a386c
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions simulator/modules/sbot_interface/devices/motor.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
The motor will apply a small amount of variation to the power setting to simulate
inaccuracies in the motor.
"""
import logging
from abc import ABC, abstractmethod

from sbot_interface.devices.util import (
Expand Down Expand Up @@ -110,9 +111,15 @@ def set_power(self, value: int) -> None:
:param value: The power setting for the motor. A value between -1000 and 1000.
"""
if value != 0:
# Apply a small amount of variation to the power setting to simulate
# inaccuracies in the motor
value = int(add_jitter(value, (MIN_POWER, MAX_POWER)))
if abs(value) < 0.05:
logging.warning(
"Motor power is too low, values below 0.05 will not move the motor."
)
value = 0
else:
# Apply a small amount of variation to the power setting to simulate
# inaccuracies in the motor
value = int(add_jitter(value, (MIN_POWER, MAX_POWER)))

self._device.setVelocity(map_to_range(
value,
Expand Down

0 comments on commit d1a386c

Please sign in to comment.