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

Why is 'ros::Publisher': no appropriate default constructor available ?

asked 2017-07-26 07:34:47 -0500

ChrisBecken gravatar image

Hi,

I want to send some IMU-data form my application ( vb.net ) to Ros on another pc. Therefore I use rosserial_windows. In my application you can choose which data you want to send. The best way is to build a dll. So I can publish the data I wish to. Unfortunately I get two errors with ros::Publisher. Here is piece of my code:

class Connect2ROS {
public:
    ros::NodeHandle nh;
    powerball_msgs::ExtPoseInput extPoseInput_msg;
    //ros::Publisher cmd_vel_pub("cmd_vel", extPoseInput_msg);
    ros::Publisher cmd_vel_pub ;//
    char *ros_master;
    Connect2ROS() {//here an error appears C2512 'ros::Publisher': no appropriate default constructor avialable
        ros::Publisher cmd_vel_pub("cmd_vel", &extPoseInput_msg);
    }

    void InitRosPublish(char *ros_master, std::string topic) { 
        this->ros_master = ros_master;
        printf("Connecting to server at %s\n", ros_master);
        nh.initNode(ros_master);
        printf("Advertising cmd_vel message\n");
        this->cmd_vel_pub = this->nh.advertise< powerball_msgs::ExtPoseInput>("cmd_vel", 1);
//here an error appears C2275 'powerball_msgs::ExtPoseInput':illegal use of this type in expression
        //ros::Publisher cmd_vel_pub("cmd_vel", &extPoseInput_msg);
        /*this->cmd_vel_pub = cmd_vel_pub;*/
        nh.advertise(this->cmd_vel_pub);
    }
    void PublishImuData_Rotation(double rel_vx, double rel_vy, double rel_vz, double x, double y, double z){...}
};

What is wrong? The error appears also when I use e.g. geometry_msgs::Twist as a message. I didn't find any help in the internet. I hope somebody can help me.

Thanks in advance!

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2017-07-26 23:58:05 -0500

Wolf gravatar image

Create you Publisher instance in the constructor using : Operator

Connect2ROS() :
cmd_vel_pub("cmd_vel", &extPoseInput_msg)
{
// Rest of constructor

It's a c++ issue, See member initializer lists For more information:

http://en.cppreference.com/w/cpp/lang...

edit flag offensive delete link more

Comments

Thank you very much Wolf!! It works.

ChrisBecken gravatar image ChrisBecken  ( 2017-07-27 05:28:38 -0500 )edit

Question Tools

2 followers

Stats

Asked: 2017-07-26 07:34:47 -0500

Seen: 287 times

Last updated: Jul 27 '17