尝试使用rosserial-windows连接到ROS。 IP地址出错

时间:2018-03-03 20:31:47

标签: c++ char ip ros const-char

我正在尝试使用rosserial窗口连接到ROS。我正在关注ROS网站上提供的教程(http://wiki.ros.org/rosserial_windows/Tutorials/Hello%20World) 这是我的代码的样子: // ConsoleApplication1.cpp:定义控制台应用程序的入口点。 //

#include "stdafx.h"
#include <string>
#include <stdio.h>
#include "ros.h"
#include <std_msgs/Float32.h>
#include <windows.h>

using std::string;

int main(int argc, _TCHAR * argv[]){
    ros::NodeHandle nh;
    char* ros_master = "172.17.194.162"; //error1
    printf("Connecting to server at %s\n", ros_master);
    nh.initNode(ros_master);//error2
    printf("Advertising message\n");
    std_msgs::Float32 a;
    ros::Publisher cmd("/truevision/throttle_cmd", &a);
    nh.advertise(cmd);
    printf("Go Car!\n");
    while (1){
        nh.spinOnce();
        Sleep(100);
    }
    printf("All done\n");
    return 0;
}

它给了我错误

E0144 - const cahr cannot be used to initialize an entity of type char
C2664 - cannot convert argument 1 from const char to char 

但这正是本教程中的完成方式。似乎无法弄清楚这里有什么问题。

2 个答案:

答案 0 :(得分:0)

此代码似乎更像是普通的C,并且许多约定都是错误的,但请尝试将char* ros_master = "172.17.194.162";更改为std::string ros_master = "172.17.194.162";

此代码的更好形式将使用std::cout(因为它是C ++的一部分,而不是C)并且不会使用while (1)(因为while(true)会更具可读性)。

答案 1 :(得分:0)

除了主机名外,您还必须在ros_master中添加“主机名:端口”。 ros serial的默认端口为11411。然后您的代码应为ros_master="171.17.194.162:11411"

相关问题