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

Can't create MoveGroupInterface object in my own class

asked 2020-02-19 06:57:57 -0600

Sathyakumar Nanda gravatar image

updated 2020-02-19 07:19:30 -0600

Delb gravatar image

Hi, I have a project requirement where I want object of moveit::planning_interface::MoveGroupInterface class inside my own class as a class member. But I couldn't' as it gives the following error. I tried some digging but can't figure it out myself. I tried inheritance but it doesn't work and makes things too much complicated. Please help to create a working object of MoveGroupInterface class inside my own class ROS1.Kinetic - Ubuntu 16.04LTS , c++11 Errors:

  1. expected identifier before string constant moveit::planning_interface::MoveGroupInterface move_group("arm_torso");
  2. ‘move_group’ does not name a type move_group.setPoseReferenceFrame("base_footprint");

    #include <moveit/move_group_interface/move_group_interface.h>
    
    class Move_operations_class 
    {
        public:
        int a,b;
    
        moveit::planning_interface::MoveGroupInterface move_group("arm_torso");
    
        //The following format works below but doesn't let me use any MoveGroupInterface class fucntions
        //moveit::planning_interface::MoveGroupInterface move_group(const std::string name="arm_torso");
        //This does'nt work in any case
        //movegroup.setPoseReferenceFrame("base_footprint");
    
        //Constructor
        Move_operations_class(const std::string &move_group_name) 
                {
                    //The below line works but the variable gets deleted after constructor call
                    moveit::planning_interface::MoveGroupInterface  move_group(name);
    
            }
    
    };
    
    int main(int argc, char** argv)
    {
        ros::init(argc, argv, "move_operations");
        ROS_INFO("Starting application ...");
        ros::NodeHandle nh;
        ros::AsyncSpinner spinner(1);
        spinner.start();
    
        //This line works fine though
        moveit::planning_interface::MoveGroupInterface move_group_main("arm_torso");
        Move_operations_class move_op("arm_torso");
        return 0;
    }
    
edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted
1

answered 2020-02-19 07:46:26 -0600

Delb gravatar image

That's not ROS related but only C++, I would advise to start learning the language first and then come back to ROS.

As for your question if you want to have an object of type moveit::planning_interface::MoveGroupInterface you will need to declare an attribute pointing to an object of this type because if you don't the object will be destroyed at the end of the function (in your case the constructor). With a pointer the memory is allocated until you call delete :

#include <moveit/move_group_interface/move_group_interface.h>

class Move_operations_class 
{
    public:
        //Constructor
        Move_operations_class(const std::string &move_group_name) 
        {
            //Now DEFINE your pointer to MoveGroupInterface object
            move_group_ptr_ = new moveit::planning_interface::MoveGroupInterface(move_group_name);
        };

       //Destructor to dealocate memory
        ~Move_operations_class()
       {
           delete move_group_ptr_;
       }

        //DECLARE the pointer
        moveit::planning_interface::MoveGroupInterface *move_group_ptr_;
};

int main(int argc, char** argv)
{
    //ROS init

    Move_operations_class move_group_main("arm_torso");
    move_group_main.move_group_ptr_->setPoseReferenceFrame("base_footprint");

    return 0;
}
edit flag offensive delete link more

Question Tools

2 followers

Stats

Asked: 2020-02-19 06:57:57 -0600

Seen: 639 times

Last updated: Feb 19 '20