25 gridMap_({
"ground",
"nonground",
"permanent",
"vehicle_hitbox",
26 "current_probability",
"occupancy",
"elevation_min"}),
60 gridMap_[
"ground"].setConstant(20.0);
61 gridMap_[
"nonground"].setConstant(0.0);
62 gridMap_[
"permanent"].setConstant(0.0);
63 gridMap_[
"vehicle_hitbox"].setConstant(0.0);
64 gridMap_[
"current_probability"].setConstant(0.5);
65 gridMap_[
"elevation_min"].setConstant(FLT_MAX);
75 geometry_msgs::Pose frontLeft;
78 geometry_msgs::Pose frontRight;
81 geometry_msgs::Pose backLeft;
84 geometry_msgs::Pose backRight;
103 ROS_ERROR(
"Unable to configure obstacle filter chain");
109 ROS_ERROR(
"Unable to configure map operations filter chain");
173 ROS_DEBUG(
"Not long enough since last odom update. Ignoring.");
177 geometry_msgs::Pose pose = odom->pose.pose;
178 ROS_DEBUG_THROTTLE(1,
"Moving local map to postion: %f, %f", pose.position.x, pose.position.y);
181 if (
moveMap(pose.position.x, pose.position.y) > 0)
203 int mapInCurrentBounds = 0;
206 mapInCurrentBounds = 1;
223 ground = (ground.array().isNaN()).select(-1, ground);
224 elevationMin = (elevationMin.array().isNaN()).select(FLT_MAX, elevationMin);
225 nonground = (nonground.array().isNaN()).select(0, nonground);
226 permanent = (permanent.array().isNaN()).select(0, permanent);
227 currentProb = (currentProb.array().isNaN()).select(0.5, currentProb);
233 layer = (layer.array().isNaN()).select(-1, layer);
238 vehicleHitBox.setConstant(0);
248 geometry_msgs::Pose tempPose;
249 for(geometry_msgs::Pose pose :
corners_)
259 vehicleHitBox(index(0), index(1)) = 100;
263 catch (
const std::exception &e)
265 ROS_WARN(
"Unable to find transform: %s. Disabling bounding box filter for this iteration.", e.what());
268 return mapInCurrentBounds;
281 ROS_DEBUG(
"Not long enough since last nonground point update. Ignoring.");
293 sensor_msgs::PointCloud2 tfCloud;
314 ground.setConstant(0.0);
319 for (
auto it = _pointCloud.begin(); it < _pointCloud.end(); it++)
326 ground(index(0), index(1)) += 1;
329 if (std::isnan(elevation_min(index(0), index(1))) || it->z < elevation_min(index(0), index(1)))
331 elevation_min(index(0), index(1)) = it->z;
354 sensor_msgs::PointCloud2 tfCloud;
377 double vehicleHeight = 0;
385 vehicleHeight = transform.transform.translation.z;
388 catch (
const std::exception &e)
390 ROS_WARN(
"Unable to find transform: %s. Disabling height filter for this iteration.", e.what());
391 runHeightFilter =
false;
400 historyLayer.setConstant(0);
403 for (
auto it = _pointCloud.begin(); it < _pointCloud.end(); it++)
422 historyLayer(index(0), index(1)) += 1;
483 gridMap_[
"nonground"].setConstant(0);
488 ROS_ERROR(
"Unable to run obstacle filter chain.");
501 gridMap_[
"nonground"] = (gridMap_[
"nonground"].array() > 100).select(100, gridMap_[
"nonground"]);
507 ROS_ERROR(
"Unable to run map operations filter chain.");
529 geometry_msgs::TransformStamped tfStamp;
537 catch (
const std::exception &e)
539 ROS_WARN(
"Unable to perform transform: %s", e.what());
546 geometry_msgs::PoseStamped gridMapStamped;
550 geometry_msgs::PoseStamped staticMapStamped;
560 gridMapStamped.pose.position.x = pos.x();
561 gridMapStamped.pose.position.y = pos.y();
566 grid_map::Position staticMapPos(staticMapStamped.pose.position.x, staticMapStamped.pose.position.y);
571 gridMapLayer(index(0), index(1)) = 100;
594 ROS_WARN(
"Recieved Marker not inside of map.");
599 double radius = marker.scale.x;
629 ROS_INFO(
"Map Size: %d, %d", size(0, 0), size(1, 0));
631 ROS_INFO(
"Position: %f, %f", pos(0), pos(1));
663 nav_msgs::OccupancyGrid message;
674 grid_map_msgs::GridMap gridMapMessage;
697 ROS_DEBUG_THROTTLE(1,
"Trying to transform from: %s to %s", _inCloud.header.frame_id.c_str(), _outFrame.c_str());
700 catch (
const std::exception &e)
702 std::cerr << e.what() <<
'\n';
SensorMap()
Constructor to initialize mapping.
void setGeometry(const Length &length, const double resolution, const Position &position=Position::Zero())
ros::Subscriber markerSub_
Subscriber for marker topic to add points to map.
ros::Subscriber groundPointsSub_
Receives point cloud of ground points.
float & atPosition(const std::string &layer, const Position &position)
grid_map::GridMap staticMap_
Storage for static map. For optimization we only want to receive it once.
std::string obstacleFilterNs
Filter chain for filtering sensor data into obstacles.
void publish(const boost::shared_ptr< M > &message) const
void odomCb(const nav_msgs::Odometry::ConstPtr)
Odometry callback function to update map position.
bool getPosition(const Index &index, Position &position) const
#define ROS_DEBUG_THROTTLE(rate,...)
Subscriber subscribe(const std::string &topic, uint32_t queue_size, void(T::*fp)(M), T *obj, const TransportHints &transport_hints=TransportHints())
void staticMapCb(const nav_msgs::OccupancyGrid &)
const std::string & getFrameId() const
std::string staticMapSubTopic
Sub topic for static maps that should be integrated with our dynamic map.
double permanentFilterProb
Probability required to declare a cell as a permanent obstacle.
ros::Publisher gridMapPub_
Publisher for the whole grid map using grid map msgs.
virtual geometry_msgs::TransformStamped lookupTransform(const std::string &target_frame, const std::string &source_frame, const ros::Time &time, const ros::Duration timeout) const
std::string nonGroundPointSubTopic
Ros topic with nonground (obstacle) points.
void markerCb(const visualization_msgs::Marker &)
static void toMessage(const grid_map::GridMap &gridMap, grid_map_msgs::GridMap &message)
bool enablePermanentObstacles
Whether to try and save permanent obstacles.
std::string mapFrameId
TF frame that the map should use.
std::string gridmapOutputTopic
Topic to output the full grid map on.
void fromROSMsg(const sensor_msgs::PointCloud2 &cloud, pcl::PointCloud< T > &pcl_cloud)
grid_map::Length len
Size of the map, assumed to be square.
static bool fromOccupancyGrid(const nav_msgs::OccupancyGrid &occupancyGrid, const std::string &layer, grid_map::GridMap &gridMap)
int tfTransformCloud(const sensor_msgs::PointCloud2 &, sensor_msgs::PointCloud2 &, std::string)
void doTransform(const T &data_in, T &data_out, const geometry_msgs::TransformStamped &transform)
ros::Time odomLastUpdate_
Keeps track of last time we updated position of map.
static void toOccupancyGrid(const grid_map::GridMap &gridMap, const std::string &layer, float dataMin, float dataMax, nav_msgs::OccupancyGrid &occupancyGrid)
bool move(const Position &position, std::vector< BufferRegion > &newRegions)
int getOccupancyGrid(nav_msgs::OccupancyGrid &)
Compiles the ground and nonground layers to create an occupancy grid.
int runFilter()
Run the grid map through the filter chain.
bool enablePointHeightFilter
Whether to filter points by height.
std::string odomSubTopic
Ros topic holding odometry information.
grid_map::GridMap gridMap_
Mapping data storage container.
double getResolution() const
int updateNongroundPts(const PointCloud &)
Updates cells in the map that may have nonground (obstacle) points.
bool isInside(const Position &position) const
double footPrintLen
Length of robot.
double resolution
Cell size of map.
std::string occupancyOutputTopic
Topic the occupancy map should be output on.
bool recStaticMap_
Stateful variable for receiving static map.
int updateGroundPts(const PointCloud &)
Records cells in the gridmap where the ground points landed.
TFSIMD_FORCE_INLINE const tfScalar & x() const
Publisher advertise(const std::string &topic, uint32_t queue_size, bool latch=false)
bool enableBoundingBoxFilter
Whether to filter lidar points if they are inside the hitbox of the vehicle.
std::string historyLayerPrefix
Prefix to use for history layers.
double footPrintWidth
Width of robot.
int numHistoryLayers
Number of layers to hold for history.
ros::NodeHandle nh_
Passed in node handle for namespace.
void addVertex(const Position &vertex)
filters::FilterChain< grid_map::GridMap > mapOperationsFilterChain_
after updating points
uint64_t readingsReceived_
Records how many readings we have received.
double maxPointHeight
If height filter is enabled, filter points more than this height above vehicle.
float & at(const std::string &layer, const Index &index)
ros::Time groundLastUpdate_
Keeps track of the last time we updated ground points.
filters::FilterChain< grid_map::GridMap > obstacleFilterChain_
Filters to modify obstacle state of map.
bool pointBoundingBoxFilter(const pcl::PointXYZ)
tf2_ros::TransformListener tfListener_
Used in tfBuffer_.
void add(const std::string &layer, const double value=NAN)
ros::Time nongroundLastUpdate_
Keeps track of the last time we updated non ground points.
std::vector< geometry_msgs::Pose > corners_
Holds corner of vehicle which will create polygon bounding box.
ros::Subscriber nonGroundPointsSub_
Receives point cloud of nonground points.
bool pointHeightFilter(const pcl::PointXYZ, double _vehicleHeight=0)
void setFrameId(const std::string &frameId)
bool update(const T &data_in, T &data_out)
bool configure(std::string param_name, ros::NodeHandle node=ros::NodeHandle())
std::string vehicleFrameId
Frame id of the robot.
virtual bool canTransform(const std::string &target_frame, const std::string &source_frame, const ros::Time &target_time, const ros::Duration timeout, std::string *errstr=NULL) const
T & transform(const T &in, T &out, const std::string &target_frame, ros::Duration timeout=ros::Duration(0.0)) const
void nonGroundPointCb(const sensor_msgs::PointCloud2 &)
Callback function for nonground points.
std::string groundPointSubTopic
Ros topic with ground points.
void setFrameId(const std::string &frameId)
ros::Subscriber odomSub_
Subscribes to odom topic to position map within frame.
int moveMap(double, double)
Move the center of the map to follow ego.
std::string mapOperationsFilterNs
Filter chain for map operations after obstacles have been determined.
void setTimestamp(const Time timestamp)
bool getIndex(const Position &position, Index &index) const
std::string markerSubTopic
Ros topic to recieve obstacles from other sources.
ros::Subscriber staticMapSub_
Will subscripe to the static map topic. ASSUMPTION: Only one static map.
tf2_ros::Buffer tfBuffer_
Holds transformations from tf tree.
const Size & getSize() const
void groundPointCb(const sensor_msgs::PointCloud2 &)
Callback function for ground points.
ros::Publisher occPub_
Publisher of occupancy grid.
std::string mapName
Name that will refer to this instance of map.
pcl::PointCloud< pcl::PointXYZ > PointCloud