actionlib::ActionClient - How to save the GoalHandle of the client to control the goal evaluation

asked 2019-03-07 06:39:15 -0500

nikolay gravatar image

I need to send the Goal to ActionServer and want to save the GoalHandle reference to be able to controll the further evaluation. I am trying to do it like this:

actionlib::ActionClient<communication::assignmentAction>::GoalHandle my_goal_handle = this->client.sendGoal(goal, boost::bind(&cAssignment::doneCallBack, this));

However, this gives me a runtime error by evaluation.

The relevant part of my code is provided below:

typedef actionlib::ActionClient<communication::assignmentAction> tClient;

class cAssignment{

public:

    cAssignment();

    virtual ~cAssignment();

    void startAssignment();

    void doneCallBack();   

    void cancel();

private:

    tClient client;

    communication::assignmentGoal goal;

    actionlib::ActionClient<communication::assignmentAction>::GoalHandle my_goal_handle;    
};


cAssignment::cAssignment(communication::assignmentGoal goal): 
    my_goal_handle(),
    client("/assignment"){
    this->goal = goal;
}


void cAssignment::startAssignment(){
    this->client.waitForActionServerToStart();
    my_goal_handle = this->client.sendGoal(goal, boost::bind(&cAssignment::doneCallBack, this));
}


void cAssignment::cancel(){
    this->my_goal_handle.cancel();
}


void cAssignment::doneCallBack(){ 
    std::string str = my_goal_handle.getResult()->result.data.c_str();
    ... some code ...
}


cAssignment::~cAssignment(){}
edit retag flag offensive close merge delete

Comments

1

However, this gives me a runtime error by evaluation.

it would probably help if you would include the actual error in your post.

gvdhoorn gravatar image gvdhoorn  ( 2019-03-07 08:19:59 -0500 )edit

Error description:

communication: /usr/include/boost/smart_ptr/shared_ptr.hpp:648: typename boost::detail::sp_member_access<T>::type boost::shared_ptr<T>::operator->() const [with T = const communication::assignmentResult_<std::allocator<void> >; typename boost::detail::sp_member_access<T>::type = const communication::assignmentResult_<std::allocator<void> >*]: Assertion `px != 0' failed.
nikolay gravatar image nikolay  ( 2019-03-07 08:36:32 -0500 )edit