ros2 subscription [closed]

asked 2021-10-27 04:28:24 -0600

OlexStup1996 gravatar image

Hello, i have a problem by creation of subscriber in ROS2.

I use ROS1 and it was easy to create Subscriber:

ros::Subscriber sub1 = n.subscribe("robot", 1000, robot_callback);

void robot_callback(const std_msgs::Bool &robot_callback_variable) { do what i want with my "robot_callback_variable" }

I migrate ROS-Publisher from ROS1 to ROS2 using this guide : https://docs.ros.org/en/foxy/Contribu... - but there is no example for Subscriber.

ROS2-Tutorials is using classes to create subscriber and publisher, what i dont check and i dont want to check classes (object oriented programing).

can someone help me to convert the lines above to ROS2, because i cannot parametrize my subscriber:

includes ....

//my callback - not sure what has to be in brackets void robot_pose_callback(geometry_msgs::msg::Pose::SharedPtr msg) { }

int main(int argc, char** argv) { rclcpp::init(argc, argv); auto move_group_node = rclcpp::Node::make_shared("move_group_interface_tutorial");

auto sub = move_group_node->create_subscription<geometry_msgs::msg::pose>("robot_pose",10, void(robot_pose_callback)); => Parameter in brackets dont work. I look in what have to be written, but i dont check the arguments:

Create and return a Subscription.

Parameters [in] topic_name The topic to subscribe on. [in] callback The user-defined callback function. [in] qos_profile The quality of service profile to pass on to the rmw implementation. [in] group The callback group for this subscription. NULL for no callback group. [in] ignore_local_publications True to ignore local publications. [in] msg_mem_strat The message memory strategy to use for allocating messages. [in] allocator Optional custom allocator. link: https://docs.ros2.org/beta3/api/rclcp...

Thanks in advance !!!!!!!!!!!!

edit retag flag offensive reopen merge delete

Closed for the following reason duplicate question by stevemacenski
close date 2021-10-27 18:11:47.501442