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: Change map command #28

Merged
merged 2 commits into from
Nov 19, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
21 changes: 21 additions & 0 deletions mir_connector/inorbit_mir_connector/src/connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,27 @@ def _inorbit_command_handler(self, command_name, args, options):
elif script_name == "set_waiting_for" and script_args[0] == "--text":
self._logger.info(f"Setting 'waiting for' value to {script_args[1]}")
self.mission_tracking.waiting_for_text = script_args[1]
elif script_name == "change_map":
if (
script_args[0] == "--mir_map_id"
and script_args[2] == "--x"
and script_args[4] == "--y"
and script_args[6] == "--orientation"
):
status = {
"position": {
"x": float(script_args[3]),
"y": float(script_args[5]),
"orientation": float(script_args[7]),
},
"map_id": script_args[1],
}
self._logger.info(f"Changing map to {script_args[1]}")
self.mir_api.set_status(status)
else:
self._logger.error("Invalid arguments for 'change_map' command")
options["result_function"]("1", execution_status_details="Invalid arguments")
return
else:
# Other kind if custom commands may be handled by the edge-sdk (e.g. user_scripts)
# and not by the connector code itself
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,10 @@ def _delete(self, url: str, session: Session, **kwargs) -> Response:
self._handle_status(res, kwargs)
return res

def _put(self, url: str, session: Session, *kwargs) -> Response:
def _put(self, url: str, session: Session, **kwargs) -> Response:
"""Perform a PUT request."""
self.logger.debug(f"PUTing {url}: {kwargs}")
res = session.delete(url, **kwargs)
res = session.put(url, **kwargs)
self.logger.debug(f"Response: {res}")
self._handle_status(res, kwargs)
return res
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,8 @@ def set_status(self, data):
response = self._put(
status_api_url,
self.api_session,
data=data,
headers={"Content-Type": "application/json"},
json=data,
)
return response.json()

Expand Down
27 changes: 27 additions & 0 deletions mir_connector/inorbit_mir_connector/tests/test_connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,33 @@ def test_command_callback_inorbit_messages(connector, callback_kwargs):
assert connector.mir_api.set_state.call_args == call(code)


def test_command_callback_change_map(connector, callback_kwargs):
callback_kwargs["command_name"] = "customCommand"
# test invalid args
callback_kwargs["args"] = ["change_map", ["--map_id", "map_id"]]
connector._inorbit_command_handler(**callback_kwargs)
connector.mir_api.change_map.assert_not_called()
callback_kwargs["options"]["result_function"].assert_called_with(
"1", execution_status_details="Invalid arguments"
)
# test valid args
callback_kwargs["args"] = [
"change_map",
["--mir_map_id", "map_id", "--x", 1, "--y", "2", "--orientation", 3.14],
]
connector._inorbit_command_handler(**callback_kwargs)
connector.mir_api.set_status.assert_called_with(
{
"position": {
"x": 1.0,
"y": 2.0,
"orientation": 3.14,
},
"map_id": "map_id",
}
)


def test_connector_loop(connector, monkeypatch):
connector.mission_tracking.report_mission = Mock()

Expand Down
Loading