ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
0

roscpp error listener.cpp and talker.cpp

asked 2020-03-22 14:01:03 -0500

ishaniis gravatar image

The same talker and listener works perfectly with a python file and why it fails to work with a cpp file.

rosrun ros_basic_tutorials talker.cpp

Error

/home/ishan/catkin_ws/src/ros_basic_tutorials/src/talker.cpp: line 6: /bin: Is a directory /home/ishan/catkin_ws/src/ros_basic_tutorials/src/talker.cpp: line 7: listener.cpp: command not found /home/ishan/catkin_ws/src/ros_basic_tutorials/src/talker.cpp: line 8: /: No such file or directory /home/ishan/catkin_ws/src/ros_basic_tutorials/src/talker.cpp: line 9: syntax error near unexpected token (' /home/ishan/catkin_ws/src/ros_basic_tutorials/src/talker.cpp: line 9:int main(int argc, char *argv)'

talker.cpp

#include "ros/ros.h"
#include "std_msgs/String.h"

#include <sstream>

int main(int argc, char **argv)
{

  ros::init(argc, argv, "talker");



 ros::NodeHandle n;

  ros::Publisher chatter_pub = n.advertise<std_msgs::String>("chatter", 1000);

  ros::Rate loop_rate(10);

  int count = 0;
  while (ros::ok())
  {

    std_msgs::String msg;

std::stringstream ss;
ss << "hello world " << count;
msg.data = ss.str();

ROS_INFO("%s", msg.data.c_str());

chatter_pub.publish(msg);

ros::spinOnce();

loop_rate.sleep();
++count;
  }

  return 0;
}
edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2020-03-22 14:21:05 -0500

you can't run a .cpp file.

The command should be

rosrun beginner_tutorials talker

assuming you completed the section 3 Building your nodes of the WritingPublisherSubscriber(c++) tutorial

edit flag offensive delete link more

Comments

Ahaan! Missing out on the important step. Thank you so much.

ishaniis gravatar image ishaniis  ( 2020-03-22 15:38:23 -0500 )edit

Question Tools

1 follower

Stats

Asked: 2020-03-22 14:01:03 -0500

Seen: 547 times

Last updated: Mar 22 '20