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

robot mapper please

asked 2016-05-02 07:16:18 -0500

Emilien gravatar image

updated 2016-05-02 13:29:58 -0500

Hi, I have ultrasound sensor connecter to arduino and i want to create a map. I try to convert range sonar to laser scan, but i don't recieve data of sensor. what can i do to receive data on rvis and create a map on it please? This is my code and a picture of rvis:

 #include "math.h"
#if defined(ARDUINO) && ARDUINO >= 100
#include "Arduino.h"
#else
#include "WProgram.h"
#endif

// ROS includes
#include <ros.h>
#include <ros/time.h>
#include <sensor_msgs/LaserScan.h>

sensor_msgs::LaserScan CDLaser_msg;
#define echoPin A1
#define trigPin A0
//
float f_angle_min;
float f_angle_max;
float f_angle_increment;
float f_time_increment;
float f_scan_time;
float f_range_min;
float f_range_max;
float f_ranges[5]; // max of 30 measurements
float f_intensities[5];

int publisher_timer;


ros:: Publisher pub_Laser("LaserData", &CDLaser_msg);
ros::NodeHandle nh;
long duration;
float getRange(){
  int val = 0;
  for(int i=0; i<4; i++){
    digitalWrite(trigPin, LOW);
    delayMicroseconds(2);
    digitalWrite(trigPin, HIGH);
    delayMicroseconds(10);
    digitalWrite(trigPin, LOW);
    duration = pulseIn(echoPin, HIGH);
    val += duration;
  }
  val=(val/232.8);
  return val;
}
void setup() 
{
  nh.initNode();
  nh.advertise(pub_Laser);
  pinMode(trigPin, OUTPUT);
  pinMode(echoPin, INPUT);
  f_angle_min = -1.57;
  f_angle_max = 1.57;
  f_angle_increment = 0.785;  // 3.14/4   - 5 measurement points
  f_time_increment = 10;
  f_scan_time = 4;
  f_range_min = 0.1;
  f_range_max = 30;

  CDLaser_msg.ranges_length = 5;
  CDLaser_msg.intensities_length = 5;

  // create the test data
  for (int z = 0 ; z<5; z++)
  {
    f_ranges[z] = getRange();
    f_intensities[z] = 10;

 }
}

void loop() 
{
  if (millis() > publisher_timer)
  {
    CDLaser_msg.header.stamp = nh.now();
    CDLaser_msg.header.frame_id = "laser_frame";
    CDLaser_msg.angle_min = f_angle_min;
    CDLaser_msg.angle_max = f_angle_max;
    CDLaser_msg.angle_increment = f_angle_increment;
    CDLaser_msg.time_increment = f_time_increment;
    CDLaser_msg.scan_time = f_scan_time;
    CDLaser_msg.range_min = f_range_min;
    CDLaser_msg.range_max = f_range_max;

    for (int z = 0 ; z<5; z++)
    {
      CDLaser_msg.ranges[z] = f_ranges[z];
      CDLaser_msg.intensities[z] = f_intensities[z];
    }

    publisher_timer = millis() + 1000;
    pub_Laser.publish(&CDLaser_msg);

  }
  nh.spinOnce();
  delay(50);
}

image description

edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted
0

answered 2016-05-02 07:52:40 -0500

Orhan gravatar image

updated 2016-05-02 08:17:34 -0500

Mapping with Sonar Data? - ROS Answers

Alright, I'm editing my answer too.

Use:

ros::Publisher pub_scan;
pub_scan = nh.advertise<sensor_msgs::LaserScan> ("/scan", 100);

And related to this error: array bound is not an integer constant before ‘]’ token, The size of an array must be a constant known at compile-time:

Use:

#define NUM_READINGS 20
edit flag offensive delete link more

Comments

i try to convert range to laser scan like above but i have somme error .. could you help me to correct them?

Emilien gravatar image Emilien  ( 2016-05-02 08:02:39 -0500 )edit

Edited answer.

Orhan gravatar image Orhan  ( 2016-05-02 08:32:09 -0500 )edit

this code provides error:

ros::Publisher pub_scan;
pub_scan = nh.advertise<sensor_msgs::LaserScan> ("/scan", 100);

but this code is OK: #define NUM_READINGS 20 Now i have error in resize which is non-classe type 'float*' and this: no matching function for call to ‘ros::Publisher::pu..

Emilien gravatar image Emilien  ( 2016-05-02 08:41:42 -0500 )edit

Are you adding sensor_msgs to Your CmakeLists.txt's find_package part?

Orhan gravatar image Orhan  ( 2016-05-02 08:54:21 -0500 )edit

yes ofcourse

Emilien gravatar image Emilien  ( 2016-05-02 09:01:57 -0500 )edit

i edit my question

Emilien gravatar image Emilien  ( 2016-05-02 13:30:21 -0500 )edit

Question Tools

1 follower

Stats

Asked: 2016-05-02 07:16:18 -0500

Seen: 232 times

Last updated: May 02 '16