Finally, we will use this virtual joystick and the canbus client / service connection to control the Amiga to complete the full Virtual Joystick example.
Control the Amiga
This is done with a third forever-running
asyncio task for
sending CAN messages.
This task waits for a
RUNNING canbus client state,
to ensure there is feedback on the measured speeds before sending
This is a must for closed loop control!
RawCanbusMessage encodes an
auto control request that is forward by the canbus service to the
This includes requested state, speed, and angular rate of the
As you can see, the requested speed and angular rate are based on
the position of the
AmigaRpdo1 message is only a request. The vehicle control
unit (VCU) in the Amiga dashboard has safety critical logic that
prevents unsafe auto control.
Because this is a bi-directional stream, a response is returned
RawCanbusMessage the generator yields.
We can check the status of each of these responses, and exit the
generator loop if the service does not respond with a confirmed
Once the canbus service is ready for streaming control again, it
should re-initiate automatically.
The pose generator yields an
(auto control command) for the canbus client to send on the bus
at the specified period (recommended 50hz) based on the on-screen
Each loop of the generator we sleep to enforce the ideal rate of
AmigaRpdo1 CAN messages, which is 50 hz.
You can modify the period parameter, but go too slow and you lose
responsiveness, and go too fast and you risk saturating the CAN
bus, which can cause loss of communication between all components
on the bus.
Add this as a task
Remember to add the
send_can_msgs() method to the
Task in our list in
Now sync the app to the Brain and launch it.
Make sure all your cables are disconnected from the Amiga and no one is in the way of the Amiga before driving around!
Everything should look just like the last checkpoint, but now you can drive the Amiga the the virtual joystick!
Navigate to the auto tab on the dashboard and enter the
The Brain should take control and enter the
Auto Active state
right away, allowing you to drive with the screen.
You should see the state on the dashboard match that displayed on
the Brain in your app.