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

Using class inheritance in roscpp files [closed]

asked 2020-02-18 08:52:19 -0500

Sathyakumar Nanda gravatar image

updated 2020-02-18 10:20:54 -0500

Hi, I have a project requirement where it is very easy for me to use class Inheritance techniques! But I seem to find no luck in doing it. I was to make a class which inherits the moveit::planning_interface::MoveGroupInterface class. The namespace order is all fine! But it gives an error

no matching function for call to ‘moveit::planning_interface::MoveGroupInterface::MoveGroupInterface()

The MoveGroupInterface class works fine with all its functions in main though

System specs: ROS1.Kinetic, UBuntu 16.04LTS

Here is my code:

#include <exception>
#include <string>
#include <boost/shared_ptr.hpp>
#include <ros/ros.h>
#include <tf2_ros/static_transform_broadcaster.h>
#include <geometry_msgs/TransformStamped.h>

#include <tf2/LinearMath/Quaternion.h>
#include <tf2/LinearMath/Transform.h>

#include <ros/topic.h>
#include <string>
#include <moveit/move_group_interface/move_group_interface.h>

class Move_operations_class : public moveit::planning_interface::MoveGroupInterface
{
public:
int a,b;
const std::string PLANNING_GROUP = "arm_torso";
//moveit::planning_interface::MoveGroupInterface move_group("arm_torso");
//MoveGroupInterface move_group("arm_torso");
};

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();

Move_operations_class move_op;
return 0;
}
edit retag flag offensive reopen merge delete

Closed for the following reason the question is answered, right answer was accepted by Sathyakumar Nanda
close date 2020-02-23 17:14:05.519437

1 Answer

Sort by » oldest newest most voted
1

answered 2020-02-18 10:21:48 -0500

Delb gravatar image

When inheritting from a class you implicitly call its constructor when you instantiante the base class, which mean here : Move_operations_class move_op; You call the constructor (a default constructor since you didn't define it for your class) and since you inherit from moveit::planning_interface::MoveGroupInterface you also call its constructor, you didn't specify any parameters so the program tries to call the constructor with no arguments : moveit::planning_interface::MoveGroupInterface::MoveGroupInterface() as you can see in your error message.

I haven't tried it but specifying the parameters from your class constructor should solve the issue :

class Move_operations_class : public moveit::planning_interface::MoveGroupInterface
{
    public:
        //Your constructor (that should get the string too)
        //And give the string to the MoveGroupInterface constructor
        //Since the constructor of MoveGroupInterface can be called 
        //with a string as parameter :
        Move_operations_class(const std::string &name) : 
            moveit::planning_interface::MoveGroupInterface(name)
        {
            //Do constructor stuff
        }

        //Your other attributes/methods
};

int main(int argc, char** argv)
{
    //init ros
    //Instantiate your object
    //There is a string variable because the constructor wants a reference
    std::string name = "arm_torso";
    Move_operations_class move_op(arm_torso);
    return 0;
}

This should work since from the documentation of MoveGroupInterface you see that there is a constructor accepting only one string (and more parameters but they have defaults values) :

MoveGroupInterface(const std::string& group,
      const std::shared_ptr<tf2_ros::Buffer>& tf_buffer = std::shared_ptr<tf2_ros::Buffer>(),
      const ros::WallDuration& wait_for_servers = ros::WallDuration());
edit flag offensive delete link more

Comments

Thanks Delbaere! Appreciate it very much!Works now! With your info, I guess I need to call the constructor of all my parent classes with proper arguments if they dont have default constructors. Correct me if wrong. But I am not stuck with a new problem of creating a MoveGroupInterface object inside Move_operations_class i.e. creating a base class object inside derived class. I tried creating a MoveGroupInterface object inside the Move_operations_class without inheritance but that didn't work either. Please help me create a MoveGroupInterface object inside Move_operations_class.

Sathyakumar Nanda gravatar image Sathyakumar Nanda  ( 2020-02-18 11:37:57 -0500 )edit

If this has answered your question can you mark this answer as correct please ?

For your other question I would suggest you to open a new one explaining exactly what you want to do and what you have tried so far.

Delb gravatar image Delb  ( 2020-02-19 01:40:15 -0500 )edit

Yeah,Cool!

Sathyakumar Nanda gravatar image Sathyakumar Nanda  ( 2020-02-19 04:26:42 -0500 )edit

@Delb, The constructor only works in this case! It still does'nt work after constrcutor call. I would like to leave the ticket open as someone may provide a working solution! Thanks

Sathyakumar Nanda gravatar image Sathyakumar Nanda  ( 2020-02-19 06:50:23 -0500 )edit

The constructor only works in this case! It still does'nt work after constrcutor call

I don't understand, is it working or not ? Can you be more precize ? You can edit your question to add the new code (if it's still related to the original question otherwise you should ask another one) and detail exactly what isn't working. Right now I don't know what you are doing and how exactly.

Delb gravatar image Delb  ( 2020-02-19 06:57:58 -0500 )edit

Further doubts related to the question is clarified here!

https://answers.ros.org/question/3445...

Sathyakumar Nanda gravatar image Sathyakumar Nanda  ( 2020-02-23 17:13:51 -0500 )edit

Question Tools

1 follower

Stats

Asked: 2020-02-18 08:52:19 -0500

Seen: 435 times

Last updated: Feb 18 '20