Skip to content
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

MiR: Custom command callback messages #31

Merged
merged 4 commits into from
Nov 29, 2024
Merged
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
14 changes: 10 additions & 4 deletions mir_connector/inorbit_mir_connector/src/connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,12 @@ def _inorbit_command_handler(self, command_name, args, options):
"""
if command_name == COMMAND_CUSTOM_COMMAND:
self._logger.info(f"Received '{command_name}'!. {args}")
if len(args) < 2:
self._logger.error("Invalid number of arguments: ", args)
options["result_function"](
"1", execution_status_details="Invalid number of arguments"
)
return
script_name = args[0]
script_args = args[1]
# TODO (Elvio): Needs to be re designed.
Expand All @@ -139,8 +145,9 @@ def _inorbit_command_handler(self, command_name, args, options):
if script_args[0] == "--state_id":
state_id = script_args[1]
if not state_id.isdigit() or int(state_id) not in MIR_STATE.keys():
self._logger.error(f"Invalid `state_id` ({state_id})")
options["result_function"]("1")
error = f"Invalid `state_id` '{state_id}'"
self._logger.error(error)
options["result_function"]("1", execution_status_details=error)
return
state_id = int(state_id)
self._logger.info(
Expand Down Expand Up @@ -196,9 +203,8 @@ def _inorbit_command_handler(self, command_name, args, options):
self.mir_api.set_state(4)
elif msg == "inorbit_resume":
self.mir_api.set_state(3)

else:
self._logger.info(f"Received '{command_name}'!. {args}")
self._logger.info(f"Received unknown command '{command_name}'!. {args}")

def _connect(self) -> None:
"""Connect to the robot services and to InOrbit"""
Expand Down
8 changes: 6 additions & 2 deletions mir_connector/inorbit_mir_connector/tests/test_connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,12 +189,16 @@ def test_command_callback_state(connector, callback_kwargs):

callback_kwargs["args"] = ["set_state", ["--state_id", "123"]]
connector._inorbit_command_handler(**callback_kwargs)
callback_kwargs["options"]["result_function"].assert_called_with("1")
callback_kwargs["options"]["result_function"].assert_called_with(
"1", execution_status_details="Invalid `state_id` '123'"
)
assert not connector.mir_api.set_state.called

callback_kwargs["args"] = ["set_state", ["--state_id", "abc"]]
connector._inorbit_command_handler(**callback_kwargs)
callback_kwargs["options"]["result_function"].assert_called_with("1")
callback_kwargs["options"]["result_function"].assert_called_with(
"1", execution_status_details="Invalid `state_id` 'abc'"
)
assert not connector.mir_api.set_state.called


Expand Down