Go to the documentation of this file.
13 ROS_INFO(
"Initialized laser scanner simulator");
49 ROS_INFO(
"Started laser scanner simulator update loop");
56 ROS_INFO(
"Stopped laser scanner simulator");
64 double l_x, l_y, l_theta;
74 nav_msgs::GetMapRequest req;
75 nav_msgs::GetMapResponse resp;
79 ROS_INFO_STREAM(
"Got a " <<
map.info.width <<
"x" <<
map.info.height <<
" map with resolution " <<
map.info.resolution);
84 ROS_WARN_THROTTLE(10,
"No map received - service '/static_map' not available (will publish only max_range)");
97 ROS_INFO(
"Updated parameters of simulated laser");
112 *x = 0.0; *y = 0.0, *theta * 0.0;
133 std::vector<float> ranges;
140 for (
unsigned int i=0; i<=
l_beams; i++)
150 ranges.push_back(this_range);
169 int start_x, start_y;
172 if (start_x<0 || start_y<0 || start_x >=
map.info.width || start_y >=
map.info.height)
175 double delta_x = abs(
map.info.origin.position.x - x);
176 double delta_y = abs(
map.info.origin.position.y - y);
177 double intersect_x = x + (dir[0] * delta_x);
178 double intersect_y = y + (dir[1] * delta_y);
182 current[0] = start_x;
183 current[1] = start_y;
190 double voxel_border[2];
192 voxel_border[0] -= 0.5 *
map.info.resolution;
193 voxel_border[1] -= 0.5 *
map.info.resolution;
196 for (
unsigned int i=0;i<2;i++)
199 if (dir[i] > 0.0)
step[i] = 1;
200 else if (dir[i] < 0.0)
step[i] = -1;
209 voxel_border[i] += (float) (
step[i] *
map.info.resolution);
212 tMax[i] = (voxel_border[i] - origin[i]) / dir[i];
214 tDelta[i] =
map.info.resolution / fabs(dir[i]);
218 tMax[i] = std::numeric_limits<double>::max();
219 tDelta[i] = std::numeric_limits<double>::max();
234 if (tMax[0] < tMax[1]) dim = 0;
237 current[dim] +=
step[dim];
238 tMax[dim] += tDelta[dim];
241 if (current[0] < 0 || current[0] >=
map.info.width || current[1] < 0 || current[1] >=
map.info.height)
246 double current_range = sqrt(pow((current[0] - start_x),2) + pow((current[1] - start_y),2)) *
map.info.resolution;
257 else return current_range;
290 ROS_WARN_STREAM(
"Noise model weighting sums not normalized (sum is " << z_sum <<
"), normalizing them");
302 selector = std::uniform_real_distribution<double>(0.0,1.0);
307 *map_x = (int) (std::floor((world_x -
map.info.origin.position.x) /
map.info.resolution));
308 *map_y = (int) (std::floor((world_y -
map.info.origin.position.y) /
map.info.resolution));
314 *world_x = (map_x *
map.info.resolution) +
map.info.origin.position.x + 0.5*
map.info.resolution;
315 *world_y = (map_y *
map.info.resolution) +
map.info.origin.position.y + 0.5*
map.info.resolution;
322 return map.data[y*
map.info.width + x];
double apply_range_noise(double range_reading)
bool call(const std::string &service_name, MReq &req, MRes &res)
#define ROS_WARN_THROTTLE(period,...)
void set_noise_params(bool use_model, double sigma_hit_reading, double lambda_short_reading, double z_hit, double z_short, double z_max, double z_rand)
void update_loop(const ros::TimerEvent &event)
void update_scan(double x, double y, double theta)
int get_map_occupancy(int x, int y)
double find_map_range(double x, double y, double theta)
sensor_msgs::LaserScan output_scan
void publish(const boost::shared_ptr< M > &message) const
Publisher advertise(AdvertiseOptions &ops)
static double getYaw(const geometry_msgs::Quaternion &msg_q)
#define ROS_WARN_STREAM(args)
std::exponential_distribution< double > p_short
void get_laser_pose(double *x, double *y, double *theta)
nav_msgs::OccupancyGrid map
#define ROS_INFO_STREAM(args)
std::normal_distribution< double > p_hit
void set_laser_params(std::string frame_id, double fov, unsigned int beam_count, double max_range, double min_range, double l_frequency)
std::uniform_real_distribution< double > selector
T param(const std::string ¶m_name, const T &default_val) const
void get_map2world_coordinates(int map_x, int map_y, double *x, double *y)
std::default_random_engine rand_gen
void get_world2map_coordinates(double x, double y, int *map_x, int *map_y)
Timer createTimer(Duration period, const TimerCallback &callback, bool oneshot=false, bool autostart=true) const
LaserScannerSimulator(ros::NodeHandle *nh)
std::uniform_real_distribution< double > p_rand