uORB topics vs. messages? (actuator_controls)

Hello, I am seeking to create an actuator_controls listener over a ROS2 bridge, similar to #96. How do I specify that I want to listen to a specific topic (actuator_controls_0) within the message actuator_controls? (But not the topic, actuator_controls, which I see is never published.)

I have updated urtps_bridge_topics.yaml on both sides of the bridge:

  - msg:     actuator_controls_0
    send:    true

However, when I make px4_sitl_rtps jmavsim I get the following error:

FileNotFoundError: [Errno 2] No such file or directory: '/home/<nsimon>/PX4-Autopilot/msg/actuator_controls_0.msg'

Am I making the correct edit to the .yaml file? Where should I specify that I would like to bridge to the actuator_controls_0 topic specifically, within the actuator_controls message?

Thank you!

I think they work like this:

-msg: actuator_controls_0
 base: actuator_controls
 send: true

Let me know if it works :smiley:

1 Like

Thank you, @aksuns ! On the px4_ros_com side .yaml, I have:

  - base: ActuatorControls
    msg: ActuatorControls0
    send: true

This seems to match the convention with vehicle_odometry and other messages with a base. However, when I run ./build_ros2_workspace.bash this yields the error:

The multi-topic message base type 'ActuatorControls' does not exist.

Did you run into this error as well?

No problem.
I haven’t run into the problem you mentioned.
Have you tried cleaning your workspace first?
If that doesn’t work, I tend to use colcon build command instead of scripts, maybe that could help:

colcon build --symlink-install --packages-select px4_msgs px4_ros_com

After sourcing ROS2 of course.

1 Like

Hi @aksuns, thank you for your help! I was able to get this to work. The key was to include actuator_controls as a message and as a base:

  - msg:     actuator_controls
    send: true
  - msg:     actuator_controls_0
    base:    actuator_controls
    send:    true

Thanks for your help!

1 Like

Hi @aksuns, one follow-up question. When writing a ROS2 publisher/subscriber, do you happen to know the correct syntax when referring to a ‘base’ vs. ‘msg’? I am writing an actuator_controls_0 listener based on the sensor_combined listener example.

In the code, if I refer to: msg::ActuatorControls0, there is a build error: ‘ActuatorControls0’ is not a member of ‘px4_msgs::msg’; did you mean ‘ActuatorControls’?. But if I replace all with ActuatorControls, then the node doesn’t subscribe to the actuator_controls_0 message!

Do you happen to know the right syntax for specifying:

- base: ActuatorControls
  msg: ActuatorControls0`

in the ROS2 publisher subscriber? I’ve pasted the full code below for reference (based on sensor_combined_listener).

 #include <rclcpp/rclcpp.hpp>
 #include <px4_msgs/msg/actuator_controls.hpp>

 * @brief Actuator Controls uORB topic data callback
class ActuatorControls0Listener : public rclcpp::Node
	explicit ActuatorControls0Listener() : Node("actuator_controls_0_listener") {
		subscription_ = this->create_subscription<px4_msgs::msg::ActuatorControls0>(
			[this](const px4_msgs::msg::ActuatorControls0::UniquePtr msg) {
			std::cout << "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n";
			std::cout << "RECEIVED ACTUATOR CONTROL DATA"   << std::endl;
			std::cout << "============================="   << std::endl;
            std::array<float, 8> control = {msg->control};
			std::cout << "control: " << std::endl;
            for (int i{ 0 }; i < control.size(); ++i)
                std::cout << control[i] << ' ';

	rclcpp::Subscription<px4_msgs::msg::ActuatorControls0>::SharedPtr subscription_;

int main(int argc, char *argv[])
	std::cout << "Starting actuator_controls_0 listener node..." << std::endl;
	setvbuf(stdout, NULL, _IONBF, BUFSIZ);
	rclcpp::init(argc, argv);

	return 0;

Hello again,
I think the problem here is that you used #include <px4_msgs/msg/actuator_controls.hpp> which lets you use only px4_msgs::msg::ActuatorControls not px4_msgs::msg::ActuatorControls0.
Changing it to #include <px4_msgs/msg/actuator_controls0.hpp> should solve your problem.

1 Like