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.

gsquaredxc
  • 1,024
  • 12
  • 28
sdcguy
  • 11
  • 1

2 Answers2

0

This code seems more like just plain C, and many conventions are wrong, but try changing char* ros_master = "172.17.194.162"; to std::string ros_master = "172.17.194.162";

A better form of this code would use std::cout (as it is part of C++, not C) and wouldn't use while (1) (as while(true) would be more readable).

gsquaredxc
  • 1,024
  • 12
  • 28
0

You have to add "hostname: port" to the ros_master other than only the hostname. The default port for ros serial is 11411. Then your code should ros_master="171.17.194.162:11411" .

Dinusha
  • 1
  • 1