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

Revision history [back]

click to hide/show revision 1
initial version

Thanks, that clears a lot, I'll give it a try. For the laser scan, I have tried rviz, but what I'd like to do is to access the 'ranges' array within sensor_msgs/LaserScan. How could I do that? I want to access those numbers to program the case when an obstacle is too close (let's say, 2 meters) and then the robot should turn left (for instance).

I changed the code adapting it to my case to this:

#include "ros/ros.h"
//#include "geometry_msgs/Twist.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<geometry_msgs::Twist>("cmd_vel", 1000);   
  ros::Rate loop_rate(10);

 int count = 0;
  while (ros::ok())
  {
    geometry_msgs::Twist msg;
    msg.linear.x = 10;
    msg.angular.z = 5;    
    chatter_pub.publish(msg);
    ros::spinOnce();
    loop_rate.sleep();
    ++count;
  }
  return 0;
}

But this is the problems I get to compile.

  /home/alonsoj1/ros_workspace/prueba/src/publisher.cpp: In function ‘int main(int, char**)’:
  /home/alonsoj1/ros_workspace/prueba/src/publisher.cpp:12: error: ‘geometry_msgs’ was not declared in this scope
  /home/alonsoj1/ros_workspace/prueba/src/publisher.cpp:12: error: parse error in template argument list
  /home/alonsoj1/ros_workspace/prueba/src/publisher.cpp:12: error: no matching function for call to ‘ros::NodeHandle::advertise(const char [8], int)’
  /home/alonsoj1/ros_workspace/prueba/src/publisher.cpp:20: error: ‘geometry_msgs’ is not a class or namespace
  /home/alonsoj1/ros_workspace/prueba/src/publisher.cpp:20: error: expected ‘;’ before ‘msg’
  /home/alonsoj1/ros_workspace/prueba/src/publisher.cpp:21: error: ‘msg’ was not declared in this scope

I get I have to define geometry_msgs, but how can I know with '#include' to put in the beginning of the code?

Thanks!