This library provides convenient access of ROS2 concepts and functionalities in QML.
Note: Currently, only Linux is supported. Other platforms have not been tested.
To install qml_ros2_plugin
from source, clone the repo. Now, you have two options: You can either install the plugin in your ROS2 overlay which makes the plugin available only if you've sourced the overlay in your environment. Alternatively, you can enable the global install, to install it system-wide on linux.
cd
into your workspace root directory and colcon build
. Re-source your ìnstall/setup.bash
.
cd
into the repo folder. To install create a build folder, cd
into that folder and run cmake -DGLOBAL_INSTALL=ON ..
followed by make
and sudo make install
.
mkdir build && cd build
cmake -DGLOBAL_INSTALL=ON ..
make -j8 # Replace 8 by the number of cpu cores
sudo make install
To use the plugin import Ros2
in QML.
import Ros2 1.0
Now, you can use the provided components such as Subscription
and TfTransform
and the Ros2 Singleton
to create a Publisher
, a ServiceClient
, or an ActionClient
.
As a simple example, a Subscription
can be created as follows:
Subscription {
id: mySubscription
topic: "/intval"
}
For more in-depth examples, check out the Examples
section.
Before a Subscription
can receive messages, a Publisher
can publish messages, etc. the node has to be initialized.
ApplicationWindow {
/* ... */
Component.onCompleted: {
Ros2.init("node_name");
}
}
To make your application quit when ROS shuts down, e.g., because of a Ctrl+C
in the console, you can connect to the Shutdown
signal:
ApplicationWindow {
Connections {
target: Ros2
onShutdown: Qt.quit()
}
/* ... */
}
For more on that, check out the Ros2 Singleton
.