1

I am trying to connect to ROS using rosserial windows. I am following the tutorial given on the ROS website (http://wiki.ros.org/rosserial_windows/Tutorials/Hello%20World) here is what my code looks like: // ConsoleApplication1.cpp : Defines the entry point for the console application. //

#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;
}

It is giving me errors

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

But this is exactly how it is done in the tutorial. can't seem to figure out what is wrong here.

4

2 回答 2

0

您必须将“主机名:端口”添加到 ros_master 而不仅仅是主机名。ros 串口的默认端口是 11411。那么你的代码应该ros_master="171.17.194.162:11411".

于 2020-02-26T03:04:35.977 回答
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)它更具可读性)。

于 2018-03-03T20:42:28.737 回答