How do I use MAVLink Endpoints to get gamepad data?

Hi Rafael,

Thanks for your help

It’s definitely the preferred path. The alternative would be to use an iframe widget which would capture and send the joystick data via a websocket, but I thought that since joystick interfacing was built in, it wouldn’t be ideal to reinvent the wheel here.

The same goes for populating existing widgets with my own mavlink data, I could sidestep mavlink and just use a websocket+iframe with custom html widgets, but I want to make use of the widgets that you guys have already developed.

Good to know. This might explain why I can’t send mavlink messages to cockpit, but even with the SITL on, when I try to inject mavlink messages into the stream it crashes the autopilot. Would instantiating a router along side my python scripts allow me to send mavlink mesages to cockpit, to update it’s widgets?

For sure! I tested it this morning. When autopilot was enabled, it behaved exactly like the master branch. When I stopped the Autopilot, that’s where I noticed a difference.

When the autopilot is stopped, every time I reload the cockpit tab, this PR version of Cockpit sends an updated MANUAL_CONTROL message exactly once, but doesn’t continue to send repeatedly until autopilot is started up again.

For contrast, the master branch of Cockpit wouldn’t send messages at all on reload if the autopilot was off.

This makes me wonder… Is it because the mavlink router isn’t running? But then how would one message still make it through each time the cockpit web client connects?

It does seems like a step in the right direction though.

Can I just use common messages like AHRS to update the compass widget, like how ardupilot does? Or do you mean I would use this for sending data from the GCS to the robot?

It’s definitely the preferred path. The alternative would be to use an iframe widget which would capture and send the joystick data via a websocket, but I thought that since joystick interfacing was built in, it wouldn’t be ideal to reinvent the wheel here.

The same goes for populating existing widgets with my own mavlink data, I could sidestep mavlink and just use a websocket+iframe with custom html widgets, but I want to make use of the widgets that you guys have already developed.

Definitely better to reuse than as much as possible.

Good to know. This might explain why I can’t send mavlink messages to cockpit, but even with the SITL on, when I try to inject mavlink messages into the stream it crashes the autopilot. Would instantiating a router along side my python scripts allow me to send mavlink mesages to cockpit, to update it’s widgets?

Instantiating the router by your own would already solve the problem, yes, but another nice alternative would be to do a PR on BlueOS adding this feature (allowing disabling the auto-restart feature on the AutopilotManager) :slight_smile:

For sure! I tested it this morning. When autopilot was enabled, it behaved exactly like the master branch. When I stopped the Autopilot, that’s where I noticed a difference.

When the autopilot is stopped, every time I reload the cockpit tab, this PR version of Cockpit sends an updated MANUAL_CONTROL message exactly once, but doesn’t continue to send repeatedly until autopilot is started up again.

For contrast, the master branch of Cockpit wouldn’t send messages at all on reload if the autopilot was off.

This makes me wonder… Is it because the mavlink router isn’t running? But then how would one message still make it through each time the cockpit web client connects?

I will take a look, but it’s probably the router indeed.

Can I just use common messages like AHRS to update the compass widget, like how ardupilot does? Or do you mean I would use this for sending data from the GCS to the robot?

For sending data from the vehicle to the GCS, I recommend using the dedicated messages (like the AHRS). The COMMAND_LONG message would be to send commands from the GCS to the vehicle indeed.

1 Like