Publishing on a topic using rosserial windows?
Hi, So I have a ROS running on my Linux machine and I am following the tutorial given here: http://wiki.ros.org/rosserial_windows... The code given in the tutorial looks like this:
// rosserial_hello_world.cpp : Example of sending command velocities from Windows using rosserial
//
#include "stdafx.h"
#include <string>
#include <stdio.h>
#include "ros.h"
#include <geometry_msgs/Twist.h>
#include <windows.h>
using std::string;
int _tmain (int argc, _TCHAR * argv[])
{
ros::NodeHandle nh;
char *ros_master = "1.2.3.4";
printf ("Connecting to server at %s\n", ros_master);
nh.initNode (ros_master);
printf ("Advertising cmd_vel message\n");
geometry_msgs::Twist twist_msg;
ros::Publisher cmd_vel_pub ("cmd_vel", &twist_msg);
nh.advertise (cmd_vel_pub);
printf ("Go robot go!\n");
while (1)
{
twist_msg.linear.x = 5.1;
twist_msg.linear.y = 0;
twist_msg.linear.z = 0;
twist_msg.angular.x = 0;
twist_msg.angular.y = 0;
twist_msg.angular.z = -1.8;
cmd_vel_pub.publish (&twist_msg);
nh.spinOnce ();
Sleep (100);
}
printf ("All done!\n");
return 0;
}
I want to publish a message type Float32 on a topic name "/truevision/throttle_cmd" what changes do I need to make? This 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";
printf("Connecting to server at %s\n", ros_master);
nh.initNode (ros_master);
printf("Advertising message\n");
std_msgs::Float32 a;
ros::Publisher cmd("/truevision/throttle_cmd", &a);
nh.advertise(cmd);
printf("Go Car!\n");
while (1)
{
a = 1.0;
cmd.publish(a);
nh.spinOnce();
Sleep(100);
}
printf("All done\n");
return 0;
}
THis is giving me the following errors:
(So apparently 1.0 is not of type float32, how do I change that?)
Severity Code Description Project File Line Suppression State
Error (active) E0349 no operator "=" matches these operands ConsoleApplication1 c:\Users\kaela\source\repos\ConsoleApplication1\ConsoleApplication1\ConsoleApplication1.cpp 32
Severity Code Description Project File Line Suppression State
Error (active) E0413 no suitable conversion function from "std_msgs::Float32" to "const ros::Msg *" exists ConsoleApplication1 c:\Users\kaela\source\repos\ConsoleApplication1\ConsoleApplication1\ConsoleApplication1.cpp 33
Thank you.
Can you clarify how this is related to #q284292?