Ask Your Question
0

enter 2 arguments into a void function

asked 2015-08-18 13:05:50 -0600

Emilio gravatar image

updated 2015-08-18 16:39:26 -0600

Hi all!!

I want to make a function that has two vectors as arguments like this:

geometry_msgs::Point point; geoemtry_msgs::Point posac; geoemtry_msgs::Point suma;

void make_suma ( const geometry_msgs::Point& point, const geometry_msgs::Point& posac)

{

suma.x=point.x + posac.x;

suma.y=point.y + posac.y;

suma.z=point.z + posac.z;

}

I get the following error when i compile it.

/home/usuario/catkin_ws/src/prueba/firmware/p1.cpp:33:60: error: invalid conversion from ‘void ()(const geometry_msgs::Point&, const geometry_msgs::Point&)’ to ‘ros::Subscriber<geometry_msgs::point>::CallbackT {aka void ()(const geometry_msgs::Point&)}’ [-fpermissive]

ros::Subscriber<geometry_msgs::point> sub("operacion", make_suma);

In file included from /home/usuario/catkin_ws/build/prueba/ros_lib/ros/node_handle.h:84:0,

from /home/usuario/catkin_ws/build/prueba/ros_lib/ros.h:38,

from /home/usuario/catkin_ws/src/prueba/firmware/p1.cpp:8:

/home/usuario/catkin_ws/build/prueba/ros_lib/ros/subscriber.h:65:7: error: initializing argument 2 of ‘ros::Subscriber<msgt>::Subscriber(const char, ros::Subscriber<msgt>::CallbackT, int) [with MsgT = geometry_msgs::Point; ros::Subscriber<msgt>::CallbackT = void ()(const geometry_msgs::Point&)]’ [-fpermissive]

Subscriber(const char * topic_name, CallbackT cb, int endpoint=rosserial_msgs::TopicInfo::ID_SUBSCRIBER) :

make[7]: * [CMakeFiles/p1.dir/p1.cpp.obj] Error 1

make[6]: * [CMakeFiles/p1.dir/all] Error 2

make[5]: * [CMakeFiles/p1.dir/rule] Error 2

make[4]: * [p1] Error 2

make[3]: * [prueba/CMakeFiles/prueba_firmware_p1] Error 2

make[2]: * [prueba/CMakeFiles/prueba_firmware_p1.dir/all] Error 2

make[1]: * [prueba/CMakeFiles/prueba_firmware_p1.dir/rule] Error 2

make: * [prueba_firmware_p1] Error 2

Invoking "make prueba_firmware_p1 -j4 -l4" failed

edit retag flag offensive close merge delete

2 Answers

Sort by » oldest newest most voted
0

answered 2015-08-18 19:47:58 -0600

kramer gravatar image

You need to provide more of your code. However, it appears to me that you misunderstand subscriptions.

That is, a topic is associated with a particular type of message; for instance, a geometry_msgs::Point. The callback for a particular subscriber processes the specified type of message declared when the subscriber is instantiated (through a NodeHandle). Typically, the code looks like this:

// this is NOT valid code!!! (e.g., no main()!)
ros::Subscriber m_sub;
ros::NodeHandle nh;
...
void pointCallback(const geometry_msgs::Point &point) {
   // do something with point message
}
...
// topic: /some_point, message type: geometry_msgs::Point
// queue size: 1, callback method: pointCallback
m_sub = nh.subscribe<geometry_msgs::Point>("/some_point", 1, &pointCallback);
...
// begin processing messages
ros::spin();

It appears that you want to process two Points on one topic. ROS doesn't work that way.

You have multiple solutions, though. You could:

  • Create two subscribers (each with a callback) and process the points as you receive them (you likely want to synchronize them)
  • Look into the Message Filters package (likely, ApproximateTime)
  • Create a publisher for a new message type containing both Points (left as an exercise for the poster)
  • Some other solution

If that doesn't help, again: post more of your code so that what you are attempting is (more) clear.

edit flag offensive delete link more
0

answered 2015-08-18 15:17:02 -0600

duck-development gravatar image

I do not understand what you like but you have a function and a variable with the same name! This is not allowed in c++

edit flag offensive delete link more

Comments

I'm sorry, i make mistake copying the code.

Emilio gravatar imageEmilio ( 2015-08-18 16:41:18 -0600 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2015-08-18 13:05:50 -0600

Seen: 102 times

Last updated: Aug 18 '15