ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
0

ROS2 + Python Qt5

asked 2020-04-08 07:13:17 -0500

robbertfm gravatar image

Hi there,

I've built a Qt5 GUI in python 3 from code (not from the Qt editor, so I don't use qml files). I want it to be able to subscribe to ROS2 topics and update the GUI according to the messages received, and publish data when a button is clicked. The problem is that Qt requires app.exec(), and ROS requires node.spin() to be run, both of which are infinite loops. There seem to be some tutorials online for ROS + Qt, but all of them are focused on ROS1. I can't find any example code for ROS2 + Qt. I'm using Dashing on Ubuntu 18.04.

How can I integrate my Qt5 GUI with ROS2?

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
0

answered 2020-04-23 05:38:15 -0500

robbertfm gravatar image

I eventually ended up writing two bridge nodes (for incoming and outgoing communication) and used the Qt Networking library to communicate over TCP with these bridge nodes.

edit flag offensive delete link more

Comments

Would spin_once() or spin_some() not do what you need? See #q296480.

There's no need for two "infinite loops". Not even in ROS 1.

gvdhoorn gravatar image gvdhoorn  ( 2020-04-23 05:47:23 -0500 )edit
0

answered 2020-04-23 12:11:35 -0500

tfoote gravatar image

ROS does not need to be in the main thread. You can just spin ROS in a separate thread.

It's also not required to call spin in that way for ROS. There are many other options like @gvdhoorn mentions which could also work. If you'd like to see examples of using ROS 2 + Qt both of our main visualization tools rqt and rviz2 are both Qt based and working well in ROS 2.

edit flag offensive delete link more

Question Tools

2 followers

Stats

Asked: 2020-04-08 07:13:17 -0500

Seen: 2,659 times

Last updated: Apr 23 '20