Skip to content
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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,6 @@ log/

#
*.env

# NiceGUI storage (map view settings) when the GUI is run from the repository
.nicegui/
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ ATOS comes with an installation script that automates the installation process.
./setup_atos.sh
```

> **Note:** The ATOS GUI (control panel with map view, config and object panels) requires Python 3.10 or newer, so it is **not available on Ubuntu 20.04 / ROS 2 Foxy**. ATOS is installed and runs there without the GUI. For the GUI, use Ubuntu 22.04 or newer, or the Docker image (Ubuntu 22.04 / ROS 2 Humble).

## <a name="Native build"></a> Building from source manually
You can find instructions on how to manually install ATOS and its dependencies from source [here](https://atos.readthedocs.io/en/latest/Installation/installation/).

Expand Down
22 changes: 20 additions & 2 deletions atos/launch/launch_utils/launch_base.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Don't launch this file directly, rather use the launch files one level up instead
import copy
import importlib.util
import os
from pathlib import Path

Expand Down Expand Up @@ -32,8 +33,8 @@ def get_files():
return validate_atos_dir()


def get_pythonpath_setup_action():
venv_site_packages = (
def get_venv_site_packages():
return (
Path.home()
/ ".local"
/ "share"
Expand All @@ -43,6 +44,17 @@ def get_pythonpath_setup_action():
/ (f"python{os.sys.version_info.major}.{os.sys.version_info.minor}")
/ "site-packages"
)


def gui_dependencies_available():
"""The GUI needs NiceGUI, which is only installed on Python >= 3.10 (not ROS 2 Foxy)."""
if importlib.util.find_spec("nicegui") is not None:
return True
return (get_venv_site_packages() / "nicegui").is_dir()


def get_pythonpath_setup_action():
venv_site_packages = get_venv_site_packages()
if not venv_site_packages.exists():
return None

Expand Down Expand Up @@ -167,6 +179,12 @@ def get_base_nodes(include_gui=True):
if pythonpath_setup is not None:
base_nodes.insert(2, pythonpath_setup)

if include_gui and not gui_dependencies_available():
logging.get_logger("launch").warning(
"NiceGUI is not installed (the ATOS GUI requires Python >= 3.10), skipping the GUI."
)
include_gui = False

if include_gui:
base_nodes.insert(
3 if pythonpath_setup is not None else 2,
Expand Down
24 changes: 12 additions & 12 deletions atos_gui/atos_gui/configpanel/configpanel.py
Original file line number Diff line number Diff line change
Expand Up @@ -484,67 +484,67 @@ def assign_value_and_type_to_parameter(
"""
match param_type:
case "file":
if type(param_value) != str:
if type(param_value) is not str:
ui.notify("Please select a file")
return
parameter.value.type = ParameterType.PARAMETER_STRING
parameter.value.string_value = param_value
case "bool":
if type(param_value) != bool:
if type(param_value) is not bool:
ui.notify("Please select a boolean")
return
parameter.value.type = ParameterType.PARAMETER_BOOL
parameter.value.bool_value = param_value
case "int":
if type(param_value) != int:
if type(param_value) is not int:
ui.notify("Please select an integer")
return
parameter.value.type = ParameterType.PARAMETER_INTEGER
parameter.value.integer_value = param_value
case "double":
if type(param_value) != float:
if type(param_value) is not float:
ui.notify("Please select a double")
return
parameter.value.type = ParameterType.PARAMETER_DOUBLE
parameter.value.double_value = param_value
case "string":
if type(param_value) != str:
if type(param_value) is not str:
ui.notify("Please select a string")
return
parameter.value.type = ParameterType.PARAMETER_STRING
parameter.value.string_value = param_value
case "file_array":
if type(param_value) != list or type(param_value[0]) != str:
if type(param_value) is not list or type(param_value[0]) is not str:
ui.notify("Please select one or more files")
return
parameter.value.type = ParameterType.PARAMETER_STRING_ARRAY
parameter.value.string_array_value = param_value
case "byte_array":
if type(param_value) != list or type(param_value[0]) != int:
if type(param_value) is not list or type(param_value[0]) is not int:
ui.notify("Please select one or more bytes")
return
parameter.value.type = ParameterType.PARAMETER_BYTE_ARRAY
parameter.value.byte_array_value = param_value
case "bool_array":
if type(param_value) != list or type(param_value[0]) != bool:
if type(param_value) is not list or type(param_value[0]) is not bool:
ui.notify("Please select one or more booleans")
return
parameter.value.type = ParameterType.PARAMETER_BOOL_ARRAY
parameter.value.bool_array_value = param_value
case "int_array":
if type(param_value) != list or type(param_value[0]) != int:
if type(param_value) is not list or type(param_value[0]) is not int:
ui.notify("Please select one or more integers")
return
parameter.value.type = ParameterType.PARAMETER_INTEGER_ARRAY
parameter.value.integer_array_value = param_value
case "double_array":
if type(param_value) != list or type(param_value[0]) != float:
if type(param_value) is not list or type(param_value[0]) is not float:
ui.notify("Please select one or more doubles")
return
parameter.value.type = ParameterType.PARAMETER_DOUBLE_ARRAY
parameter.value.double_array_value = param_value
case "string_array":
if type(param_value) != list or type(param_value[0]) != str:
if type(param_value) is not list or type(param_value[0]) is not str:
ui.notify("Please select one or more strings")
return
parameter.value.type = ParameterType.PARAMETER_STRING_ARRAY
Expand All @@ -570,4 +570,4 @@ def refresh(self) -> None:
threading.Thread(
target=self.fetch_parameters_list, args=(self.parameter_clients,)
).start()
ui.open("/config")
ui.navigate.to("/config")
20 changes: 10 additions & 10 deletions atos_gui/atos_gui/configpanel/local_file_picker.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
"""This Source Code Form is subject to the terms of the Mozilla Public
License, v. 2.0. If a copy of the MPL was not distributed with this
file, You can obtain one at https://mozilla.org/MPL/2.0/.
"""

"""This file is taken from the NiceGUI repository and added some dosctrings for clarifications.
Original file: https://github.com/zauberzeug/nicegui/blob/main/examples/local_file_picker/local_file_picker.py """
This file is taken from the NiceGUI repository and added some dosctrings for clarifications.
Original file: https://github.com/zauberzeug/nicegui/blob/main/examples/local_file_picker/local_file_picker.py"""

import platform
from pathlib import Path
Expand Down Expand Up @@ -48,7 +47,9 @@ def __init__(
ui.aggrid(
{
"columnDefs": [{"field": "name", "headerName": "File"}],
"rowSelection": "multiple" if multiple else "single",
"rowSelection": {
"mode": "multiRow" if multiple else "singleRow"
},
},
html_columns=[0],
)
Expand Down Expand Up @@ -83,7 +84,7 @@ def update_grid(self) -> None:
paths.sort(key=lambda p: p.name.lower())
paths.sort(key=lambda p: not p.is_dir())

self.grid.options["rowData"] = [
rows = [
{
"name": f"📁 <strong>{p.name}</strong>" if p.is_dir() else p.name,
"path": str(p),
Expand All @@ -96,14 +97,15 @@ def update_grid(self) -> None:
or self.upper_limit is not None
and self.path != self.upper_limit
):
self.grid.options["rowData"].insert(
rows.insert(
0,
{
"name": "📁 <strong>..</strong>",
"path": str(self.path.parent),
},
)
self.grid.update()
# Assigning to the element's options updates the grid (NiceGUI >= 3.0).
self.grid.options["rowData"] = rows

def handle_double_click(self, e: events.GenericEventArguments) -> None:
"""Handle a double click on a file or directory."""
Expand All @@ -115,7 +117,5 @@ def handle_double_click(self, e: events.GenericEventArguments) -> None:

async def _handle_ok(self):
"""Handle the OK button click."""
rows = await ui.run_javascript(
f"getElement({self.grid.id}).gridOptions.api.getSelectedRows()"
)
rows = await self.grid.get_selected_rows()
self.submit([r["path"] for r in rows])
15 changes: 12 additions & 3 deletions atos_gui/atos_gui/controlpanel/controlpanel.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
from rclpy.node import Node
from std_msgs.msg import Empty

from atos_interfaces.srv import *
from atos_gui.mapview.map_data import MapDataSource
from atos_gui.mapview.map_view import MapView
from atos_interfaces.srv import GetObjectControlState

QOS = rclpy.qos.QoSProfile(depth=10)

Expand Down Expand Up @@ -54,12 +56,17 @@ def __init__(self) -> None:
)

self.OBC_state = {"state": "UNDEFINED"}
self.OBC_state_number = None
self.lost_connection = True

self.map_data = MapDataSource(
self, get_control_state=lambda: self.OBC_state_number
)

@ui.page(path="/control", title="ATOS Control Panel")
def render_page():
with ui.row().bind_visibility_from(self, "lost_connection"):
ui.label("Lost connection to ATOS...").tailwind.text_color("red")
ui.label("Lost connection to ATOS...").classes("text-red")
with ui.row():
ui.button(
"Abort",
Expand Down Expand Up @@ -113,6 +120,7 @@ def render_page():
on_click=lambda: self.reloadObjectSettingsPub.publish(Empty()),
color="grey",
)
MapView(self.map_data)

def get_object_control_state_callback(self):
# Call the service
Expand All @@ -133,4 +141,5 @@ def get_object_control_state_callback_done(self, future):
except Exception as e:
self.get_logger().info("Service call failed %r" % (e,))
else:
self.OBC_state["state"] = OBC_STATES[response.state]
self.OBC_state_number = response.state
self.OBC_state["state"] = OBC_STATES.get(response.state, "UNDEFINED")
12 changes: 7 additions & 5 deletions atos_gui/atos_gui/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,9 +151,6 @@ def _on_state(self, msg: String) -> None:


def render_atosfleetmanagement_pages() -> None:
if FLEET_STATIC_DIR.exists():
app.add_static_files(FLEET_STATIC_ROUTE, str(FLEET_STATIC_DIR))

@ui.page(path="/", title="TruckObjectGUI")
def render_home() -> None:
ui.add_head_html(
Expand Down Expand Up @@ -208,7 +205,8 @@ def render_home() -> None:
)
map_id = "fleet-road-map"
ui.html(
f'<div id="{map_id}" style="height:75vh;width:100%;border-radius:8px;"></div>'
f'<div id="{map_id}" style="height:75vh;width:100%;border-radius:8px;"></div>',
sanitize=False, # trusted static markup; keep id/style
)

ui.timer(
Expand Down Expand Up @@ -287,14 +285,18 @@ def ros_main() -> None:

def print_access_hint() -> None:
scheme = "https" if USE_SSL else "http"
print(f"TruckObjectGUI ready. Open {scheme}://localhost:8420", flush=True)
print(f"GUI ready. Open {scheme}://localhost:8420", flush=True)


def configure_app() -> None:
global APP_CONFIGURED
if APP_CONFIGURED:
return

# Scripts for the fleet road map and the control panel map view.
if FLEET_STATIC_DIR.exists():
app.add_static_files(FLEET_STATIC_ROUTE, str(FLEET_STATIC_DIR))

if FLEET_MODE:
render_atosfleetmanagement_pages()
else:
Expand Down
Empty file.
Loading
Loading