Auterion / px4-ros2-interface-lib

Library to interface with PX4 from a companion computer using ROS 2
BSD 3-Clause "New" or "Revised" License
68 stars 21 forks source link

Generic subscriptions #16

Closed DanMesh closed 11 months ago

DanMesh commented 11 months ago

Allows adding subscriptions to arbitrary ROS topics. Users can register (multiple) callbacks or simply poll the last-received message.

Example usage

px4_ros2::Subscription<px4_msgs::msg::VehicleLocalPosition> ros_sub(context, "/fmu/out/vehicle_local_position");

// Create callback
ros_sub.onUpdate([](px4_msgs::msg::VehicleLocalPosition msg) {
    std::cout << "Local pos from callback: " << msg.x << " " << msg.y << " " << msg.z << std::endl;
});

// Poll latest message
px4_msgs::msg::VehicleLocalPosition msg = ros_sub.last();
std::cout << "Local pos latest: " << msg.x << " " << msg.y << " " << msg.z << std::endl;