15 double angle = theta + increment;
18 yaw = -180.0 - (180.0 - angle);
20 else if (angle < -180.0)
22 yaw = 180.0 - (-180.0 - angle);
31 const int sgn(
const int x) {
return (x > 0) ? 1 : (x < 0) ? -1 : 0; }
33 double degToRad(
double angle) {
return angle / 180.0 * CV_PI; }
35 double radToDeg(
double angle) {
return angle / CV_PI * 180.0; }
53 const double theta)
const 60 double FOV, resolution, range;
64 FOV =
config.laser_field_of_view;
65 range =
config.laser_max_sensor_distance + 0.5;
66 resolution =
config.laser_angular_resolution;
67 obstacleColor =
config.laser_obstacle_color;
71 FOV =
config.us_field_of_view;
72 range =
config.us_max_sensor_distance + 0.5;
73 resolution =
config.us_angular_resolution;
74 obstacleColor =
config.us_obstacle_color;
78 int nAngles = FOV / resolution;
79 std::vector<float> rangeArray = std::vector<float>(nAngles);
81 double maxDistance = range /
mapInfo.resolution;
83 for (
int a = 0; a < nAngles; a++)
87 P2.x = (int)round(sensorPos.x +
88 maxDistance * std::cos((-angle) * CV_PI /
90 P2.y = (int)round(sensorPos.y +
91 maxDistance * std::sin((-angle) * CV_PI /
94 cv::LineIterator it(
map, sensorPos, P2, 8);
95 cv::Point currentPos = it.pos();
96 for (
int i = 0; i < it.count; i++, ++it)
98 currentPos = it.pos();
99 if (
map.at<uchar>(currentPos) == obstacleColor)
104 double scannedRange = cv::norm(sensorPos - currentPos) *
mapInfo.resolution;
105 rangeArray[a] = scannedRange;
108 return std::make_shared<std::vector<float>>(rangeArray);
111 const double theta)
const 113 std::vector<float> rangeArray = *
getLaserScan(sensorPos, theta);
114 double minOfRange = rangeArray[0];
115 for (
auto current : rangeArray)
117 if (current < minOfRange)
119 minOfRange = current;
Header file for the rs::RangeSensor class.
pses_simulation::RangeSensorConfig config
nav_msgs::MapMetaData mapInfo
void setConfig(pses_simulation::RangeSensorConfig &config)
Sets the RangeSensorConfig object of this sensor simulation.
const rs::rangeArray_ptr getLaserScan(const cv::Point sensorPos, const double theta) const
Get a Laserscan at the current position/orientation.
RangeSensor(const SensorType &type)
rs::RangeSensor constructor.
This namespace groups typedefs and enums used in the rs::RangeSensor class and the rs::RangeSensor cl...
SensorType
Enumerator for supported sensor types.
std::shared_ptr< std::vector< float > > rangeArray_ptr
shortcut for a pointer to a vector of floats representing range readings in meters.
double radToDeg(double angle)
Conversion from radiants to degrees.
void setMap(const cv::Mat &map)
Sets the occupancy grid to be used by this sensor simulation.
const double getUSScan(const cv::Point sensorPos, const double theta) const
Get a ultra sonic range information at the current position/orientation.
const int sgn(const int x)
Get the sign of an interger.
void setMapMetaData(const nav_msgs::MapMetaData &mapInfo)
Sets the meta data of the occupancy grid to be used by this sensor simulation.
double degToRad(double angle)
Conversion from degrees to radiants.
double correctYawAngle(const double theta, const double increment)
Calculate a correct euler angle after incrementing/decrementing.