Quantcast
Channel: ROS Answers: Open Source Q&A Forum - RSS feed
Viewing all articles
Browse latest Browse all 314

Publishing on a topic using rosserial windows?

$
0
0
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/Tutorials/Hello%20World 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 #include #include "ros.h" #include #include 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 #include #include "ros.h" #include #include 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.

Viewing all articles
Browse latest Browse all 314

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>