Skip to content

Commit

Permalink
Update check_actuator_connection decorator and DephyActuator meth…
Browse files Browse the repository at this point in the history
…ods for offline mode

* Update `check_actuator_connection` decorator to allow offline mode without raising an exception
* Update `start` method in `DephyActuator` to check for offline mode and skip connection attempt if offline
* Update `home` method in `DephyActuator` to check for offline mode and skip update call if offline
* Add test cases for offline mode in `test_actuators_base.py` to ensure no exceptions are raised
  • Loading branch information
senthurayyappan committed Oct 30, 2024
1 parent 9ffde77 commit b68b780
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 2 deletions.
2 changes: 1 addition & 1 deletion opensourceleg/actuators/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
def check_actuator_connection(func):
@wraps(func)
def wrapper(self: ActuatorBase, *args, **kwargs):
if self.is_offline:
if not self.is_offline and not self.is_open:
raise ActuatorConnectionException(tag=self.tag)

return func(self, *args, **kwargs)
Expand Down
13 changes: 12 additions & 1 deletion opensourceleg/actuators/dephy.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,11 @@ def _CONTROL_MODE_CONFIGS(self) -> CONTROL_MODE_CONFIGS:

@check_actuator_connection
def start(self) -> None:
if self.is_offline:
self._is_open = True
self._is_streaming = True
return

try:
self.open()
self._is_open = True
Expand Down Expand Up @@ -281,7 +286,8 @@ def home(

try:
while is_homing:
self.update()
if not self.is_offline:
self.update()
time.sleep(1 / homing_frequency)

_motor_encoder_array.append(self.motor_position)
Expand Down Expand Up @@ -1044,6 +1050,11 @@ def _CONTROL_MODE_CONFIGS(self) -> CONTROL_MODE_CONFIGS:

@check_actuator_connection
def start(self) -> None:
if self.is_offline:
self._is_open = True
self._is_streaming = True
return

try:
self.open(
freq=self._frequency,
Expand Down
27 changes: 27 additions & 0 deletions tests/test_actuators/test_actuators_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -566,3 +566,30 @@ def test_motor_constants_properties(mock_actuator: MockActuator):

def test_hello_world():
assert len("Hello World") == 11


def test_offline_mode():
mock_actuator = MockActuator(
"test_actuator",
10.0,
MOTOR_CONSTANTS(
MOTOR_COUNT_PER_REV=1000,
NM_PER_AMP=0.1,
NM_PER_RAD_TO_K=1.0,
NM_S_PER_RAD_TO_B=0.1,
MAX_CASE_TEMPERATURE=100.0,
MAX_WINDING_TEMPERATURE=150.0,
),
offline=True,
)

assert mock_actuator.is_offline

# Test start method in offline mode
mock_actuator.start()
assert mock_actuator.is_open
assert mock_actuator.is_streaming

# Test home method in offline mode
mock_actuator.home()
assert mock_actuator.is_homed

0 comments on commit b68b780

Please sign in to comment.