33 #include <geometry_msgs/PoseWithCovarianceStamped.h> 34 #include <nav_msgs/Odometry.h> 36 #include "sensor_msgs/PointCloud2.h" 47 : debugInfoProvider(0)
49 , lastGetMapUpdateIndex(-100)
51 , map__publish_thread_(0)
52 , initial_pose_set_(false)
53 , pause_scan_processing_(false)
57 std::string mapTopic_ =
"map";
98 private_nh_.
param(
"laser_min_dist", tmp, 0.4);
101 private_nh_.
param(
"laser_max_dist", tmp, 30.0);
104 private_nh_.
param(
"laser_z_min_value", tmp, -1.0);
107 private_nh_.
param(
"laser_z_max_value", tmp, 1.0);
112 ROS_INFO(
"HectorSM publishing debug drawings");
118 ROS_INFO(
"HectorSM publishing debug info");
133 int mapLevels = slamProcessor->getMapLevels();
136 for (
int i = 0; i < mapLevels; ++i)
141 std::string mapTopicStr(mapTopic_);
145 mapTopicStr.append(
"_" + boost::lexical_cast<std::string>(i));
148 std::string mapMetaTopicStr(mapTopicStr);
149 mapMetaTopicStr.append(
"_metadata");
268 ROS_INFO(
"lookupTransform %s to %s timed out. Could not transform laser scan into base_frame.",
p_base_frame_.c_str(), scan.header.frame_id.c_str());
285 Eigen::Vector3f start_estimate(Eigen::Vector3f::Zero());
303 start_estimate = Eigen::Vector3f(stamped_pose.
getOrigin().getX(), stamped_pose.
getOrigin().getY(), yaw);
332 ROS_INFO(
"HectorSLAM Iter took: %f milliseconds", duration.
toSec()*1000.0f );
350 nav_msgs::Odometry tmp;
369 ROS_ERROR(
"Transform failed during publishing of map_odom transform: %s",e.what());
385 ROS_INFO(
"HectorSM sysMsgCallback, msg contents: %s",
string.data.c_str());
387 if (
string.data ==
"reset")
395 nav_msgs::GetMap::Response &res)
397 ROS_INFO(
"HectorSM Map service called");
403 std_srvs::Trigger::Response &res)
405 ROS_INFO(
"HectorSM Reset map service called");
411 hector_mapping::ResetMapping::Response &res)
428 std_srvs::SetBool::Response &res)
437 nav_msgs::GetMap::Response& map_ (mapPublisher.
map_);
446 int size = sizeX * sizeY;
448 std::vector<int8_t>& data = map_.map.data;
451 memset(&data[0], -1,
sizeof(int8_t) * size);
458 for(
int i=0; i < size; ++i)
478 map_.map.header.stamp = timestamp;
485 size_t size = scan.ranges.size();
487 float angle = scan.angle_min;
489 dataContainer.
clear();
491 dataContainer.
setOrigo(Eigen::Vector2f::Zero());
493 float maxRangeForContainer = scan.range_max - 0.1f;
495 for (
size_t i = 0; i < size; ++i)
497 float dist = scan.ranges[i];
499 if ( (dist > scan.range_min) && (dist < maxRangeForContainer))
502 dataContainer.
add(Eigen::Vector2f(
cos(angle) * dist,
sin(angle) * dist));
505 angle += scan.angle_increment;
511 size_t size = pointCloud.points.size();
514 dataContainer.
clear();
516 tf::Vector3 laserPos (laserTransform.
getOrigin());
517 dataContainer.
setOrigo(Eigen::Vector2f(laserPos.x(), laserPos.y())*scaleToMap);
519 for (
size_t i = 0; i < size; ++i)
522 const geometry_msgs::Point32& currPoint(pointCloud.points[i]);
524 float dist_sqr = currPoint.x*currPoint.x + currPoint.y* currPoint.y;
528 if ( (currPoint.x < 0.0f) && (dist_sqr < 0.50f)){
532 tf::Vector3 pointPosBaseFrame(laserTransform * tf::Vector3(currPoint.x, currPoint.y, currPoint.z));
534 float pointPosLaserFrameZ = pointPosBaseFrame.z() - laserPos.z();
538 dataContainer.
add(Eigen::Vector2f(pointPosBaseFrame.x(),pointPosBaseFrame.y())*scaleToMap);
546 Eigen::Vector2f mapOrigin (gridMap.
getWorldCoords(Eigen::Vector2f::Zero()));
549 map_.map.info.origin.position.x = mapOrigin.x();
550 map_.map.info.origin.position.y = mapOrigin.y();
551 map_.map.info.origin.orientation.w = 1.0;
555 map_.map.info.width = gridMap.
getSizeX();
556 map_.map.info.height = gridMap.
getSizeY();
559 map_.map.data.resize(map_.map.info.width * map_.map.info.height);
612 ROS_INFO(
"[HectorSM]: Mapping paused");
616 ROS_INFO(
"[HectorSM]: Mapping no longer paused");
625 ROS_INFO(
"[HectorSM]: Setting initial pose with world coords x: %f y: %f yaw: %f",
void projectLaser(const sensor_msgs::LaserScan &scan_in, sensor_msgs::PointCloud &cloud_out, double range_cutoff=-1.0, int channel_options=channel_option::Default)
tf::TransformBroadcaster * tfB_
const GridMap & getGridMap(int mapLevel=0) const
ros::Publisher odometryPublisher_
bool p_pub_map_scanmatch_transform_
tf::MessageFilter< geometry_msgs::PoseWithCovarianceStamped > * initial_pose_filter_
HectorDebugInfoProvider * debugInfoProvider
double p_update_factor_free_
void publishMap(MapPublisherContainer &map_, const hectorslam::GridMap &gridMap, ros::Time timestamp, MapLockerInterface *mapMutex=0)
float p_sqr_laser_max_dist_
const Eigen::Vector3f & getLastScanMatchPose() const
void resetPose(const geometry_msgs::Pose &pose)
laser_geometry::LaserProjection projector_
void staticMapCallback(const nav_msgs::OccupancyGrid &map)
const geometry_msgs::PoseStamped & getPoseStamped()
boost::thread * map__publish_thread_
ros::Time lastMapPublishTime
Subscriber subscribe(const std::string &topic, uint32_t queue_size, void(T::*fp)(M), T *obj, const TransportHints &transport_hints=TransportHints())
void rosLaserScanToDataContainer(const sensor_msgs::LaserScan &scan, hectorslam::DataContainer &dataContainer, float scaleToMap)
std::vector< MapPublisherContainer > mapPubContainer
static double getYaw(const Quaternion &bt_q)
const geometry_msgs::PoseWithCovarianceStamped & getPoseWithCovarianceStamped()
bool p_map_with_known_poses_
void update(const Eigen::Vector3f &slamPose, const Eigen::Matrix3f &slamCov, const ros::Time &stamp, const std::string &frame_id)
bool mapCallback(nav_msgs::GetMap::Request &req, nav_msgs::GetMap::Response &res)
void setOrigo(const DataPointType &origoIn)
static double getYawFromQuat(const geometry_msgs::Quaternion &quat)
bool isOccupied(int xMap, int yMap) const
ros::Publisher mapPublisher_
bool restartHectorCallback(hector_mapping::ResetMapping::Request &req, hector_mapping::ResetMapping::Response &res)
ros::ServiceServer reset_map_service_
double p_map_update_distance_threshold_
PoseInfoContainer poseInfoContainer_
int p_map_multi_res_levels_
std::string p_scan_topic_
ros::Subscriber scanSubscriber_
const Eigen::Matrix3f & getLastScanMatchCovariance() const
float getCellLength() const
const tf::Transform & getTfTransform()
ServiceServer advertiseService(const std::string &service, bool(T::*srv_func)(MReq &, MRes &), T *obj)
bool p_use_tf_pose_start_estimate_
nav_msgs::GetMap::Response map_
MapLockerInterface * getMapMutex(int i)
hectorslam::HectorSlamProcessor * slamProcessor
bool p_advertise_map_service_
Eigen::Vector3f initial_pose_
ros::ServiceServer dynamicMapServiceServer_
bool pause_scan_processing_
void sysMsgCallback(const std_msgs::String &string)
TFSIMD_FORCE_INLINE tfScalar angle(const Quaternion &q1, const Quaternion &q2)
HectorDrawings * hectorDrawings
Eigen::Vector2f getWorldCoords(const Eigen::Vector2f &mapCoords) const
ros::Publisher scan_point_cloud_publisher_
std::string p_tf_map_scanmatch_transform_frame_name_
sensor_msgs::PointCloud laser_point_cloud_
ros::Subscriber sysMsgSubscriber_
bool param(const std::string ¶m_name, T ¶m_val, const T &default_val) const
void publish(const boost::shared_ptr< M > &message) const
ros::Publisher posePublisher_
bool isFree(int xMap, int yMap) const
void scanCallback(const sensor_msgs::LaserScan &scan)
double p_map_update_angle_threshold_
std::string p_odom_frame_
bool p_pub_map_odom_transform_
float p_laser_z_max_value_
Publisher advertise(const std::string &topic, uint32_t queue_size, bool latch=false)
std::string p_pose_update_topic_
ros::Publisher mapMetadataPublisher_
bool p_use_tf_scan_transformation_
float getScaleToMap() const
float p_sqr_laser_min_dist_
void toggleMappingPause(bool pause)
double p_update_factor_occupied_
void publishMapLoop(double p_map_pub_period_)
hectorslam::DataContainer laserScanContainer
std::string p_sys_msg_topic_
int p_scan_subscriber_queue_size_
ros::ServiceServer restart_hector_service_
ros::Publisher poseUpdatePublisher_
void setTime(const ros::Time &time)
void initialPoseCallback(const geometry_msgs::PoseWithCovarianceStampedConstPtr &msg)
INLINE Rall1d< T, V, S > cos(const Rall1d< T, V, S > &arg)
virtual void unlockMap()=0
ros::ServiceServer toggle_scan_processing_service_
void update(const DataContainer &dataContainer, const Eigen::Vector3f &poseHintWorld, bool map_without_matching=false)
uint32_t getNumSubscribers() const
void rosPointCloudToDataContainer(const sensor_msgs::PointCloud &pointCloud, const tf::StampedTransform &laserTransform, hectorslam::DataContainer &dataContainer, float scaleToMap)
void setServiceGetMapData(nav_msgs::GetMap::Response &map_, const hectorslam::GridMap &gridMap)
void add(const DataPointType &dataPoint)
std::string p_base_frame_
INLINE Rall1d< T, V, S > sin(const Rall1d< T, V, S > &arg)
bool resetMapCallback(std_srvs::Trigger::Request &req, std_srvs::Trigger::Response &res)
tf::Transform map_to_odom_
float p_laser_z_min_value_
tf::TransformListener tf_
int getUpdateIndex() const
message_filters::Subscriber< geometry_msgs::PoseWithCovarianceStamped > * initial_pose_sub_
bool pauseMapCallback(std_srvs::SetBool::Request &req, std_srvs::SetBool::Response &res)
Connection registerCallback(const C &callback)
int lastGetMapUpdateIndex