ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
0

subscriber's callback in C++

asked 2022-09-29 14:41:52 -0500

Kostas Tzias gravatar image

I want to extract data from a topic in which ticks from encoders are published but i dont know the syntax for this process

So for example i have written this callback :

void left_ecn_cb(const std_msgs::UInt16::ConstPtr& lTick_msg)
{
  // here i need to store the values coming from topic 
 // into the variable lTick  
}

which is the proper syntax to do that ?

Also is there any book or pdf or web page which using a lot of examples to learn c++ and ros

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2022-09-29 21:39:25 -0500

JustinBlack02 gravatar image

which is the proper syntax to do that ?

void left_ecn_cb(const std_msgs::msg::UInt16::ConstPtr& ltick_msg) {
  auto ltick = ltick_msg->data;
}

Also is there any book or pdf or web page which using a lot of examples to learn c++ and ros

A good place to start with tons of examples is the official documentation page. However, if you are interested in more structured learning then maybe look at TheConstruct. There are some books out there but I don't know if they are any good.

edit flag offensive delete link more

Comments

The callback prototype also seems to suggest ROS 1. The example code you show appears to be ROS 2.

The OP labelled his question with noetic, which would be ROS 1.

The book link also appears to link to a ROS 2 book.

gvdhoorn gravatar image gvdhoorn  ( 2022-09-30 00:52:55 -0500 )edit

Could you explain to me what auto does . I used this syntax without auto and it worked perfectly . Is auto important ? Do i have to add it too ? Also i am doing this in ROS1

Kostas Tzias gravatar image Kostas Tzias  ( 2022-10-03 04:07:20 -0500 )edit

Question Tools

1 follower

Stats

Asked: 2022-09-29 14:41:52 -0500

Seen: 47 times

Last updated: Sep 29 '22