0
$\begingroup$

Rosanswers logo

Im using gtest for writing test suites for my robot. Im trying to test a function that i use to convert my twist message being sent from the Nav Stack or joystick (cmd_vel topic) that is then converted into my individual wheel velocities for my roboteq motor controller. This function that i am testing is used in the cmd_vel subscriber callback in my roboteq driver node. So normally, when the callback is fired, i pass the reference of the twist, into my function like so (i type def'd geometry_msgs::Twist to TTwist, and TWheelMsg is my custom msg, also type def'd)

void    RosRoboteqDrv::CmdVelCallback(const TTwist::ConstPtr& twist_velocity)
{
    _wheelVelocity = RosRoboteqDrv::ConvertTwistToWheelVelocity(twist_velocity);

Where my my conversion function is defined like so:

TWheelMsg   ConvertTwistToWheelVelocity(const TTwist::ConstPtr& twist_velocity);

In my gtest class, im not sure how i can use this ConvertTwtistToWheelVelocity function since it is passing a reference. I tried looking up in the API docs where the reference originated from, and found that in the node handle subscriber template here it passes a boost shared pointer, which in my case i passed type geometry_msgs::Twist. So then i looked inside of the geometry_msgs source file, and found this:

typedef  ::geometry_msgs::Twist_< std::allocator< void > >  

Can someone please tell me what should i do to be able to pass some value (clearly has to be reference) into the ConvertTwistToWheelVelocity function? I dont know what to do since std::allocator is the template type.

Since in the API docs it says that the node handle subscribe function is a template


EDIT: here is what my subscriber call looks like:

_sub = _nh.subscribe("cmd_vel", 1, &RosRoboteqDrv::CmdVelCallback, this);

Originally posted by l0g1x on ROS Answers with karma: 1526 on 2014-08-18

Post score: 1

$\endgroup$

1 Answer 1

0
$\begingroup$

Rosanswers logo

The ConstPtrs in ROS behave like boost::shared_ptr, and you can use them similarly.

This should probably look something like:

// .. fill in your message fields
geometry_msgs::Twist msg;
msg.linear.x = 42;
geometry_msgs::Twist::ConstPtr msg_p(new geometry_msgs::Twist(msg));

// call your callback
driver.CmdVelCallback(msg_p);

Originally posted by ahendrix with karma: 47576 on 2014-08-19

This answer was ACCEPTED on the original site

Post score: 1


Original comments

Comment by l0g1x on 2014-08-20:
Going to try this out in a few hours after work. Will let you know how it goes. Thanks

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.