Since your function takes a calibration_camera_lidar::Euler_val::ConstPtr
as its argument, you should try to make one of those to pass in. Creating an object of that type should be similar (but maybe not quite the same) to the code that you would use to create and publish that message in the publisher.
boost::shared_ptr<calibration_camera_lidar::Euler_val> my_arr(new calibration_camera_lidar::Euler_val());
for ( int i=0; i<3; i++) {
my_arr->Euler_angles[i] = i;
}
callback2(my_arr);
A quick walk-through:
boost::shared_ptr<calibration_camera_lidar::Euler_val> my_arr(new calibration_camera_lidar::Euler_val());
Creates a shared_pointer to your message type, named my_arr
, and initializes it my allocating a new object. Shared pointers are similar to regular pointers and use much of the same syntax, but they automatically delete the object that they're pointing to when the last shared pointer to that object is destructed.
for ( int i=0; i<3; i++) {
my_arr->Euler_angles[i] = i;
}
Initialize each item in the array. Note that since my_arr
is a shared pointer, you use the ->
syntax to access its members. Since you declared the Euler_angles
member as a fixed-size array, we can use the []
syntax with it. (if it was a variable-sized array, it would be a std::vector
and would start at zero size, so you would need to use push_back
or one of the other modifier functions to expand the array before putting an item on the end).
callback2(my_arr);
Call you callback!
Originally posted by ahendrix with karma: 47576 on 2018-09-16
This answer was ACCEPTED on the original site
Post score: 2
Original comments
Comment by surabhi96 on 2018-09-16:
This worked, thanks much!
Comment by surabhi96 on 2018-09-16:
Btw, I was actually trying to write an example of what I was trying to do by adding dummy variables.. and I just pasted the original error.
Comment by surabhi96 on 2018-09-17:
@ahendrix Here we are passing a pointer to the callback2 function. This node also subscribes to another topic which publishes an array as defined in the msg file. So when this message arrives callback2 is called with an array as the func argument. Do we pass a ptr or an array to the callback func?
Comment by ahendrix on 2018-09-17:
Similar to the above (and really, for any C++ function call) you want to construct an object that matches the function's parameter type to pass in.