Getting Started¶
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
# setup
shape = rosys.geometry.Prism.default_robot_shape()
rosys.hardware.SerialCommunication.search_paths = ['/dev/ttyUSB0']
is_real = rosys.hardware.SerialCommunication.is_possible()
if is_real:
communication = rosys.hardware.SerialCommunication()
robot_brain = rosys.hardware.RobotBrain(communication)
can = rosys.hardware.CanHardware(robot_brain)
wheels = rosys.hardware.WheelsHardware(robot_brain,
can=can,
left_can_address=0x100,
right_can_address=0x000,
m_per_tick=0.01571,
width=0.207,
is_right_reversed=True)
robot = rosys.hardware.RobotHardware([can, wheels], robot_brain)
else:
wheels = rosys.hardware.WheelsSimulation()
robot = rosys.hardware.RobotSimulation([wheels])
odometer = rosys.driving.Odometer(wheels)
steerer = rosys.driving.Steerer(wheels)
# ui
rosys.driving.keyboard_control(steerer)
with ui.scene():
rosys.driving.robot_object(shape, odometer)
ui.label('hold SHIFT to steer with the keyboard arrow keys')
if is_real:
ui.button('configure microcontroller', on_click=robot.configure).props('outline')
# 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:
Explanation¶
Imports¶
The user interface is built with NiceGUI.
The individual RoSys modules come in packages driving
, geometry
, hardware
and others.
Setup¶
In this example we create a Steerer
which needs an Odometer
.
Here we work without real hardware, so two wheels are simulated.
Please see Hardware for an example which can actually be used on a mobile robot.
For visualization purposes we also need the approximate robot shape.
User Interface¶
The user interface consists of keyboard control with access to the steerer as well as a 3D view of the scene.
The latter only contains the RobotObject
with the given shape.
The robot pose is constantly updated from the odometer.
See NiceGUI for more details about its API.
Start¶
NiceGUI provides a ui.run
command which launches the web server and opens the corresponding web application.
If you modify the code, a reload is triggered automatically.
This is very convenient, but can be deactivated by passing reload=False
.