First install RoSys with pip or Docker.
Then create a directory to host your code and put it under version control.
Name your entry file
main.py and add the following content:
#!/usr/bin/env python3 from nicegui import ui import rosys import rosys.ui # setup runtime = rosys.Runtime() rosys.ui.configure(ui, runtime) # keyboard control rosys.ui.keyboard_control() # 3d scene with ui.scene() as scene: robot = rosys.ui.robot_object() ui.label('hold SHIFT to steer with the keyboard arrow keys') # start ui.run(title='RoSys')
If you launch the program, your browser will open the url http://0.0.0.0:8080/ and present a 3d view:
As you can read up in the "Architecture" chapter RoSys provides a runtime to manage the actors which operate on the world.
rosys.ui.configure(ui, runtime) connects the user interface with the runtime.
rosys.ui.keyboard_control() you create a keyboard event listener which will steer the robot.
There are also other possibilities of steering the robot like a Joystick or clicking in the 3d scene.
As it is common for groups of UI elements in NiceGUI, a 3d scene is created by using context through Python's
Every command "inside" is applied to the created scene.
Here a 3d representation of the robot is created (
ui.timer ensures its position is updated every 50 ms.
ui.label is used afterwards to explain the keyboard interaction.
Note: The label is on the same intendation level as the
ui.scene object, not within.
See NiceGUI for a complete API reference.
NiceGUI provides a
ui.run command which launches the webserver and presents the interface as configured above.
If you modify the code, an automatic reload is triggered.
This is very convenient, but can be deactivated by passing