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

How to get the info from a goal with more than one type in a goalCB?

asked 2013-03-12 03:46:38 -0500

DIDI gravatar image

updated 2014-01-28 17:15:38 -0500

ngrennan gravatar image

Hey, I encountered the following problem: My goal definition in my action file has two types and I only know how to get one of this values from the acceptNewGoal().

My goal definition is:

#goal definition

float32 linear

float32 angular

---

and my goalCB:

void goalCB()

{

goal_.linear = as_.acceptNewGoal()->linear;

steer_.linear = goal_.linear*15/2;  
steer_.angular = goal_.angular*45/2; 
steer_pub_.publish(steer_);

}

As you can see I can only manage to get one value, not both. Anyone an idea how to do it? Or is it even possible? Thanks in advance!

edit retag flag offensive close merge delete

2 Answers

Sort by » oldest newest most voted
2

answered 2013-03-12 04:37:42 -0500

thebyohazard gravatar image

updated 2013-03-12 05:02:33 -0500

You need to save the entire goal to a variable, rather than just the linear portion of the goal.

EDIT: acceptNewGoal() returns a boost ConstPtr, so you'll need to change the type of goal_. For example if your declaration was car_joy::Velocity goal_;, you'd need to change it to car_joy::Velocity::ConstPtr goal_ and then use -> operators instead of . operators.

Try this:

void goalCB()
{
    //where goal_ is some kind of ConstPtr
    goal_ = as_.acceptNewGoal();
    steer_.linear = goal_->linear*15/2;  
    steer_.angular = goal_->angular*45/2; 
    steer_pub_.publish(steer_);
}
edit flag offensive delete link more

Comments

I tried it before, it gives me an error. Like: no correspondence for »operator=«. And I tried with goal_ as car_joy::SteerCarGoal goal_; and car_joy::Velocity goal_; (Velocity is a custom msg with linear and angular float types.

DIDI gravatar image DIDI  ( 2013-03-12 04:50:33 -0500 )edit

Thanks for this answer! Been trying to figure this on and off for a week.

TheMilkman92 gravatar image TheMilkman92  ( 2021-04-20 22:27:29 -0500 )edit
1

answered 2013-03-12 05:38:11 -0500

DIDI gravatar image

It works now! Thanks a lot! But it did not work with

car_joy::Velocity::ConstPtr goal_

,it seems goal_ have to be ConstPtr type from the SteerCarGoal.h.

So it worked with:

car_joy::SteerCarGoal::ConstPtr goal_;
edit flag offensive delete link more

Question Tools

Stats

Asked: 2013-03-12 03:46:38 -0500

Seen: 159 times

Last updated: Mar 12 '13