Rviz Publisher

Hi!

I’d like to show you a tool I’ve been working on and that I think could be useful to many people.

I suppose more than once some of you have had to create an RVIZ plugin, and you’ve probably been quite lost the first time, as always happens when you enter a new world. In my case, I’ve always ended up looking for someone else’s plugin to learn how to do it and seeing everything the QT library could offer. In the end, I’d end up wasting a day or two just making a simple panel to debug my application.

To avoid having to deal with QT, whether learning or simply having to design the application yourself, I’ve prepared the following package:

With this package, we can generate our own RVIZ plugin. For now, just a panel with buttons, where we can publish any messages we want.

Still in development, it’s based on the rosidl_defaults_generator function, which, for those who don’t know, is the package we use to create our custom messages and does the magic so we can use them jajaja. Let me tell you a little about how it works:

First, we add the following lines to the CMakeLists.txt of the package that will generate a plugin:

find_package(rviz_publisher_cmake REQUIRED)

generate_rviz_panel(
  <path_to_the_yaml>
)

Next, we configure the yaml file we’re going to add to our CMakeLists.txt in a similar way:

panel:
  - name: "Hello"
    topic: "/example"
    topic_type: "std_msgs/msg/String"
    message:
      data: "Hello, world!"
  - name: "Forward"
    topic: "/cmd_vel"
    topic_type: "geometry_msgs/msg/Twist"
    message:
      linear:
        x: 0.5
  - name: "Move"
    topic: "/cmd_vel"
    topic_type: "geometry_msgs/msg/Twist"
    message:
      linear:
        x: 0.5
        y: 0.0
      angular:
        z: 0.5

Finally, we build, open rviz, add our panel, and magic happens.

So, nothing. I hope it’s useful to people who, as I’ve already said, don’t want to spend too much time creating their own plugin, although it’s always good to learn new things jeje.

And I’m posting this now, even though there’s still a lot missing, because I’d also like to gather ideas about what people would like to have, since I also plan to use it for actions, services, and to generate sliders…

Finally, I would like to say that I know that rviz is ultimately a tool used to visualize information, not to publish, and that rqt_publisher would also be used for that. However, having an all-in-one is always useful when you want to debug things, and having to switch windows or write in a terminal ends up being too repetitive, and I think this is going to help a lot.

Thank you very much for reading, and I hope it helps.

Best regards.

7 Likes

Very cool idea to quickly create command buttons!

If all you want is some buttons that do stuff in RViz and that you can quickly create, I would suggest trying out:

(Sorry the documentation there is a bit lacking which is why I haven’t announced the ROS 2 port yet, I think)

It has a QML display where you can specify a qml file to load (Absolute path or using package://PKG_NAME/, you can also specify a package share relative path).
When using this together with qml_ros2_plugin or the ROS 1 version, you can create these without any C++ code or the need to compile.

Your example would be

import QtQuick 2.3
import QtQuick.Controls 2.2
import QtQuick.Controls.Material 2.2
import QtQuick.Layouts 1.0
import Ros2 1.0

Item {
  id: page
  property var cmdVelPub: Ros2.createPublisher("/cmd_vel", "geometry_msgs/msg/Twist", 1)

  ColumnLayout {
    Button {
      property var pub: Ros2.createPublisher("/example", "std_msg/msg/String", 1)
      text: "Hello"
      onClicked: pub.publish({ data: "Hello world!" })
    }
    Button {
      text: "Forward"
      onClicked: cmdVelPub.publish({ linear: { x: 0.5 } })
    }
    Button {
      text: "Move"
      onClicked: cmdVelPub.publish({ linear: { x: 0.5 }, angular: { z: 0.5 } })
    }
}

There are additional examples also with services and actions in the repo.

Granted this would not create a separate panel but controls that are overlaid on the 3D scene in RViz.
However, it would probably be possible to create a Panel plugin for RViz that loads and displays a QML file.

In my opinion, QML makes the process of creating robot UI a lot easier compared to Qt which is really tough to get started and not very fun to develop with.

2 Likes

Great work @Juancams !!