Making an action client to send goals within hardware_interface

asked 2020-04-14 04:53:12 -0500

azerila gravatar image

I have a code snippet from here where the the following object is made within main() and is used by its attribute:

actionlib::SimpleActionClient<actionlib_tutorials::FibonacciAction> ac("fibonacci", true);
actionlib_tutorials::FibonacciGoal goal;
ac.sendGoal(goal);

Being new to c++ I think I have a very clear syntax mistake which should be visible to anyone with a bit more experienced than myself.

In my own codes I think header file where I want to first declare "ac" and then use it in another cpp file in a class. Being new to c++ however, I am pretty lost what my mistake is. The way I tried changing the header file is like the following. the "..." are just the parts of the code I have removed here for readablity and am sure does not contribute the error:

...
#include <actionlib/client/simple_action_client.h>
#include <actionlib/client/terminal_state.h>
#include "dummy_sim2/JointsStateAction.h"

class ROBOTHardwareInterface : public hardware_interface::RobotHW 
{
    public:
       ...

    protected:
        actionlib::SimpleActionClient<dummy_sim2::JointsStateAction> ac;//("muj_simread_joint_state", true);

    ...
};

and my cpp file looks like this which I am not sure how to modfy it to have the ac.sendGoal(goal) in the read() function:

#include <muj_hw.h>
#include <iostream>
#include <string>
#include <fstream> 

ROBOTHardwareInterface::ROBOTHardwareInterface(ros::NodeHandle& nh) : nh_(nh) {
    init();
    ...
}

ROBOTHardwareInterface::~ROBOTHardwareInterface() {
}

void ROBOTHardwareInterface::init() {

 ...
}

void ROBOTHardwareInterface::update(const ros::TimerEvent& e) {
    read();
}

void ROBOTHardwareInterface::read() {
    //dummy_sim2::JointsStateActionGoal goal;
    //ac.sendGoal(goal);
    ...

                                  }

void ROBOTHardwareInterface::write(ros::Duration elapsed_time) {

                                                                }

int main(int argc, char** argv) 
{
    ros::init(argc, argv, "mujoco_hardware_interface");
    ros::NodeHandle nh;
    ROBOTHardwareInterface ROBOT(nh);
    ros::MultiThreadedSpinner spinner(4);
    spinner.spin();
    ros::spin();
    return 0;
}

and later I get this error:

/home/alireza/amira/ws/src/amira_simulation/dummy_sim2/src/muj_hw_interface_node.cpp: In constructor ‘ROBOTHardwareInterface::ROBOTHardwareInterface(ros::NodeHandle&)’:
/home/alireza/amira/ws/src/amira_simulation/dummy_sim2/src/muj_hw_interface_node.cpp:9:77: error: no matching function for call to ‘actionlib::SimpleActionClient<dummy_sim2::JointsStateAction_<std::allocator<void> > >::SimpleActionClient()’
 ROBOTHardwareInterface::ROBOTHardwareInterface(ros::NodeHandle& nh) : nh_(nh) {
                                                                             ^
In file included from /home/alireza/amira/ws/src/amira_simulation/dummy_sim2/include/muj_hw.h:15:0,
                 from /home/alireza/amira/ws/src/amira_simulation/dummy_sim2/src/muj_hw_interface_node.cpp:1:
/opt/ros/melodic/include/actionlib/client/simple_action_client.h:109:3: note: candidate: actionlib::SimpleActionClient<ActionSpec>::SimpleActionClient(ros::NodeHandle&, const string&, bool) [with ActionSpec = dummy_sim2::JointsStateAction_<std::allocator<void> >; std::__cxx11::string = std::__cxx11::basic_string<char>]
   SimpleActionClient(ros::NodeHandle & n, const std::string & name, bool spin_thread = true)
   ^~~~~~~~~~~~~~~~~~
/opt/ros/melodic/include/actionlib/client/simple_action_client.h:109:3: note:   candidate expects 3 arguments, 0 provided
/opt/ros/melodic/include/actionlib/client/simple_action_client.h:93:3: note: candidate: actionlib::SimpleActionClient<ActionSpec>::SimpleActionClient(const string&, bool) [with ActionSpec = dummy_sim2::JointsStateAction_<std::allocator<void> >; std::__cxx11::string = std::__cxx11::basic_string<char>]
   SimpleActionClient(const std::string & name, bool spin_thread = true)
   ^~~~~~~~~~~~~~~~~~
/opt/ros/melodic/include/actionlib/client/simple_action_client.h:93:3: note:   candidate expects 2 arguments, 0 provided
make[2]: *** [CMakeFiles/muj_hw_interface_node.dir/src/muj_hw_interface_node.cpp.o] Error 1
make[1]: *** [CMakeFiles/muj_hw_interface_node.dir/all] Error 2
make: *** [all] Error 2
edit retag flag offensive close merge delete