Ask Your Question

gtest testing function with subscriber reference [closed]

asked 2014-08-18 10:38:18 -0500

l0g1x gravatar image

updated 2014-08-18 10:40:17 -0500

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);
edit retag flag offensive reopen merge delete

Closed for the following reason the question is answered, right answer was accepted by l0g1x
close date 2015-04-02 21:49:23.805852

1 Answer

Sort by ยป oldest newest most voted

answered 2014-08-19 00:39:58 -0500

ahendrix gravatar image

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
edit flag offensive delete link more


Going to try this out in a few hours after work. Will let you know how it goes. Thanks

l0g1x gravatar image l0g1x  ( 2014-08-20 10:00:19 -0500 )edit

Question Tools

1 follower


Asked: 2014-08-18 10:38:18 -0500

Seen: 435 times

Last updated: Aug 19 '14