Error when trying to run a ros node
I have this example ros publisher I have created for debugging purpose. It builds withouth any problem but when i rosrun the ros code, I get these errors and I dont where its coming from and why my publisher does not work. I will be happy with anyone who can help me. I used catkin clean to clean everything and build it again but it still did not work out.
**/home/EU/deagblep/svn/211001_Agblevor_thesis/4_Implementation/IMU/hfrImu/ws/src/hfrimu/src/port_publisher.cpp: line 6: /bin: Is a directory
/home/EU/deagblep/svn/211001_Agblevor_thesis/4_Implementation/IMU/hfrImu/ws/src/hfrimu/src/port_publisher.cpp: line 7: build: command not found
/home/EU/deagblep/svn/211001_Agblevor_thesis/4_Implementation/IMU/hfrImu/ws/src/hfrimu/src/port_publisher.cpp: line 8: build/: Is a directory
/home/EU/deagblep/svn/211001_Agblevor_thesis/4_Implementation/IMU/hfrImu/ws/src/hfrimu/src/port_publisher.cpp: line 9: syntax error near unexpected token `('
/home/EU/deagblep/svn/211001_Agblevor_thesis/4_Implementation/IMU/hfrImu/ws/src/hfrimu/src/port_publisher.cpp: line 9: `int main(int argc, char **argv)'**
source:
#include "ros/ros.h
#include "std_msgs/String.h
#include <sstream>
int main(int argc, char **argv)
{
ros::init(argc, argv, "port_publisher_node");
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;
}
It would be good if you could tell us in the question the exact commands used to compile and to run your executable. Also, check the content of the file (maybe you are running a bash script that has the same file of the executable).
I used catkin build the build my package. And then use rosrun hfrimu port_publisher.cpp to run the node. If you say I should check the content, which cotent are you talking about please?
Try
rosrun port_publisher_node
from inside from the same directory as the source code.