ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange |
1 | initial version |
Alternatively, use a lambda, since lambdas can access variables of the same scope by reference / value
ros::Publisher pub = ...;
ros::Subscriber sub = nh.subscribe<my_package::my_message>("/my_topic", 1,
[&](const my_package::my_message::ConstPtr& msg)
{
pub.publish(...);
});
2 | No.2 Revision |
Alternatively, use a lambda, since lambdas can access variables of the same scope by reference / value
ros::Publisher pub = ...;
ros::Subscriber sub = nh.subscribe<my_package::my_message>("/my_topic", 1,
[&](const my_package::my_message::ConstPtr& msg)
msg) //replace & with = to access by value
{
pub.publish(...);
});
3 | No.3 Revision |
Alternatively, use a lambda, since lambdas can access variables of the same scope by reference / value
ros::Publisher pub = ...;
ros::Subscriber sub = nh.subscribe<my_package::my_message>("/my_topic", 1,
[&](const my_package::my_message::ConstPtr& msg) //replace & with = to access by value
{
pub.publish(...);
});
ros::spin()
4 | No.4 Revision |
Alternatively, use a lambda, since lambdas can access variables of the same scope by reference / value
ros::Publisher pub = ...;
ros::Subscriber sub = nh.subscribe<my_package::my_message>("/my_topic", 1,
[&](const my_package::my_message::ConstPtr& msg) //replace & with = to access by value
{
pub.publish(...);
});
ros::spin()