2 #include <mrpt/maps/CBeaconMap.h> 3 #include <mrpt/maps/COccupancyGridMap2D.h> 9 bool isFileExists(
const std::string &
name) {
10 std::ifstream
f(name.c_str());
21 ROS_INFO(
"READ PARAM FROM LAUNCH FILE");
23 ROS_INFO(
"rawlog_play_delay: %f", rawlog_play_delay_);
32 ROS_INFO(
"global_frame_id: %s", global_frame_id_.c_str());
35 ROS_INFO(
"odom_frame_id: %s", odom_frame_id_.c_str());
38 ROS_INFO(
"base_frame_id: %s", base_frame_id_.c_str());
41 ROS_INFO(
"sensor_source: %s", sensor_source_.c_str());
44 ROS_INFO(
"sensor_source: %s", sensor_source_.c_str());
47 ROS_INFO(
"update_sensor_pose: %s", (update_sensor_pose_?
"TRUE":
"FALSE"));
52 ROS_ERROR(
"Not able to read all parameters!");
81 nh.
advertise<geometry_msgs::PoseArray>(
"particlecloud", 1,
true);
84 nh.
advertise<geometry_msgs::PoseArray>(
"particlecloud_beacons", 1,
true);
86 nh.
advertise<visualization_msgs::MarkerArray>(
"/beacons_viz", 1);
89 std::vector<std::string> lstSources;
92 "*Fatal*: At least one sensor source must be provided in " 93 "~sensor_sources (e.g. " 94 "\"scan\" or \"beacon\")");
98 for (
size_t i = 0; i < lstSources.size(); i++) {
99 if (lstSources[i].
find(
"scan") != std::string::npos) {
114 mrpt::obs::CObservationOdometry::Ptr &odometry,
119 odometry = mrpt::obs::CObservationOdometry::Create();
121 odometry->hasEncodersInfo =
false;
122 odometry->hasVelocities =
false;
123 odometry->odometry.x() = poseOdom.
x();
124 odometry->odometry.y() = poseOdom.
y();
125 odometry->odometry.phi() = poseOdom.
yaw();
131 const std::string &source_frame,
const ros::Time &time,
136 polling_sleep_duration);
139 ROS_ERROR(
"Failed to get transform target_frame (%s) to source_frame (%s). " 140 "TransformException: %s",
141 target_frame.c_str(), source_frame.c_str(), ex.what());
151 CObservation2DRangeScan::Ptr laser = CObservation2DRangeScan::Create();
164 CObservationOdometry::Ptr odometry;
167 CObservation::Ptr
obs = CObservation::Ptr(laser);
187 CObservationBeaconRanges::Ptr beacon = CObservationBeaconRanges::Create();
199 CObservationOdometry::Ptr odometry;
202 CObservation::Ptr
obs = CObservation::Ptr(beacon);
225 #if MRPT_VERSION >= 0x199 245 mrpt::opengl::CSetOfObjects::Ptr objs;
247 objs = mrpt::opengl::CSetOfObjects::Create();
251 geometry_msgs::PoseArray poseArrayBeacons;
256 unsigned int objs_counter = 0;
260 poseArrayBeacons.poses.resize(objs_counter);
261 mrpt::opengl::CEllipsoid::Ptr beacon_particle;
263 for (
size_t i = 0; i < objs_counter; i++) {
266 poseArrayBeacons.poses[i]);
275 geometry_msgs::PoseArray poseArray;
291 visualization_msgs::MarkerArray ma;
292 visualization_msgs::Marker
marker;
294 marker.header.frame_id =
"/map";
297 marker.type = visualization_msgs::Marker::SPHERE;
298 marker.action = visualization_msgs::Marker::ADD;
300 marker.pose.position.x = 0;
301 marker.pose.position.y = 0;
302 marker.pose.position.z = 0;
303 marker.pose.orientation.x = 0.0;
304 marker.pose.orientation.y = 0.0;
305 marker.pose.orientation.z = 0.0;
306 marker.pose.orientation.w = 1.0;
307 marker.scale.x = 0.12;
308 marker.scale.y = 0.12;
309 marker.scale.z = 0.12;
310 marker.color.a = 1.0;
311 marker.color.r = 1.0;
312 marker.color.g = 0.0;
314 for (
unsigned int i = 0; i <
viz_beacons_.size(); i++) {
316 marker.type = visualization_msgs::Marker::SPHERE;
318 marker.pose.position.x = meanPose.
x();
319 marker.pose.position.y = meanPose.
y();
320 marker.pose.position.z = meanPose.z();
321 marker.color.r = 1.0;
322 marker.color.g = 0.0;
323 marker.color.b = 0.0;
325 ma.markers.push_back(marker);
328 marker.type = visualization_msgs::Marker::TEXT_VIEW_FACING;
329 marker.text = std::to_string(i);
331 marker.pose.position.x = meanPose.
x();
332 marker.pose.position.y = meanPose.
y();
333 marker.pose.position.z = meanPose.z() + 0.12;
334 marker.color.r = 1.0;
335 marker.color.g = 1.0;
336 marker.color.b = 1.0;
338 ma.markers.push_back(marker);
354 pose.
x() = translation.
x();
355 pose.
y() = translation.
y();
356 pose.z() = translation.
z();
359 for (
int c = 0;
c < 3;
c++)
360 for (
int r = 0;
r < 3;
r++)
375 for (
unsigned int i = 0; i <
data_.size(); i++) {
389 #if MRPT_VERSION >= 0x199 410 mrpt::opengl::CSetOfObjects::Ptr objs;
411 objs = mrpt::opengl::CSetOfObjects::Create();
414 geometry_msgs::PoseArray poseArrayBeacons;
418 unsigned int objs_counter = 0;
422 poseArrayBeacons.poses.resize(objs_counter);
423 mrpt::opengl::CEllipsoid::Ptr beacon_particle;
425 for (
size_t i = 0; i < objs_counter; i++) {
429 poseArrayBeacons.poses[i]);
438 geometry_msgs::PoseArray poseArray;
478 ROS_ERROR(
"Failed to subtract global_frame (%s) from odom_frame (%s). " 479 "TransformException: %s",
492 ros::Time transform_expiration = (stamp + transform_tolerance_);
void getEstimatedPosePDF(mrpt::poses::CPose3DPDFParticles &out_estimation) const
std::string global_frame_id_
/map frame
bool update_sensor_pose_
on true the sensor pose is updated on every sensor reading
tf::TransformListener listenerTF_
transform listener
void odometryForCallback(mrpt::obs::CObservationOdometry::Ptr &odometry, const std_msgs::Header &msg_header)
Get the odometry for received observation.
std::vector< ros::Subscriber > sensorSub_
list of sensors topics
void getMean(CPose3D &mean_pose) const MRPT_OVERRIDE
mrpt::slam::CMetricMapBuilderRBPF::TConstructionOptions rbpfMappingOptions_
options for SLAM from ini file
mrpt::utils::CTicTac tictac_
void observation(const mrpt::obs::CSensoryFrame::ConstPtr sensory_frame, const mrpt::obs::CObservationOdometry::ConstPtr odometry)
Calculate the actions from odometry model for current observation.
void publish(const boost::shared_ptr< M > &message) const
bool rawlogPlay()
Play rawlog file.
Subscriber subscribe(const std::string &topic, uint32_t queue_size, void(T::*fp)(M), T *obj, const TransportHints &transport_hints=TransportHints())
std::string rawlog_filename_
name of rawlog file
std::vector< std::pair< mrpt::obs::CActionCollection, mrpt::obs::CSensoryFrame > > data_
void laserCallback(const sensor_msgs::LaserScan &msg)
Callback function for the laser scans.
ros::Publisher beacon_viz_pub_
publishers for map and pose particles
mrpt::poses::CPose3DPDFParticles curPDF
current robot pose
std::string odom_frame_id_
/odom frame
void vizBeacons()
Correct visualization for ro slam.
bool getParams(const ros::NodeHandle &nh_p)
Read the parameters from launch file.
ros::Publisher pub_metadata_
float t_exec_
the time which take one SLAM update execution
void publishTF()
Publish tf tree.
void publishMapPose()
Publish beacon or grid map and robot pose.
std::map< std::string, mrpt::poses::CPose3D > beacon_poses_
beacon poses with respect to the map
bool waitForTransform(mrpt::poses::CPose3D &des, const std::string &target_frame, const std::string &source_frame, const ros::Time &time, const ros::Duration &timeout, const ros::Duration &polling_sleep_duration=ros::Duration(0.01))
Wait for transform between odometry frame and the robot frame.
bool init(ros::NodeHandle &nh)
Initialize publishers subscribers and RBPF slam.
void getAs3DObject(mrpt::opengl::CSetOfObjectsPtr &outObj) const MRPT_OVERRIDE
size_t particlesCount() const MRPT_OVERRIDE
GLuint GLenum GLenum transform
mrpt::gui::CDisplayWindow3D::Ptr win3D_
MRPT window.
ros::Publisher pub_particles_
TFSIMD_FORCE_INLINE const Vector3 & getRow(int i) const
struct mrpt_rbpf_slam::PFslam::Options options_
mrpt::obs::CSensoryFrame::Ptr sensory_frame_
observations
void readIniFile(const std::string &ini_filename)
Read ini file.
mrpt::slam::CMetricMapBuilderRBPF mapBuilder_
map builder
void updateSensorPose(const std::string &frame_id)
Update the pose of the sensor with respect to the robot.
TFSIMD_FORCE_INLINE const tfScalar & x() const
const CMultiMetricMap * getCurrentMostLikelyMetricMap() const
void initSlam(Options options)
initialize the SLAM
TFSIMD_FORCE_INLINE const tfScalar & z() const
void callbackBeacon(const mrpt_msgs::ObservationRangeBeacon &msg)
Callback function for the beacons.
mrpt::obs::CActionCollection::Ptr action_
actions
GLuint const GLchar * name
std::string sensor_source_
2D laser scans
bool param(const std::string ¶m_name, T ¶m_val, const T &default_val) const
#define ROS_ASSERT_MSG(cond,...)
TFSIMD_FORCE_INLINE const tfScalar & y() const
void readRawlog(const std::string &rawlog_filename, std::vector< std::pair< mrpt::obs::CActionCollection, mrpt::obs::CSensoryFrame >> &data)
Read pairs of actions and observations from rawlog file.
Publisher advertise(const std::string &topic, uint32_t queue_size, bool latch=false)
double rawlog_play_delay_
delay of replay from rawlog file
#define ROS_WARN_STREAM(args)
bool loadOptions(const ros::NodeHandle &nh, PFslam::Options &options)
mrpt::system::TTimeStamp timeLastUpdate_
last update of the pose and map
const mrpt::maps::CMultiMetricMap * metric_map_
receive map after iteration of SLAM to metric map
void convert(const ros::Time &src, mrpt::system::TTimeStamp &des)
bool rawlog_play_
true if rawlog file exists
std::map< std::string, mrpt::poses::CPose3D > laser_poses_
laser scan poses with respect to the map
const_iterator find(const KEY &key) const
std::string ini_filename_
name of ini file
GLdouble GLdouble GLdouble r
bool getParam(const std::string &key, std::string &s) const
ros::Publisher pub_particles_beacons_
tf::TransformBroadcaster tf_broadcaster_
transform broadcaster
std::vector< mrpt::opengl::CEllipsoid::Ptr > viz_beacons_
std::string base_frame_id_
robot frame
ProxyFilterContainerByClass< mrpt::maps::COccupancyGridMap2DPtr, TListMaps > m_gridMaps
#define ROS_ERROR_STREAM(args)
ROSCPP_DECL void spinOnce()
void BASE_IMPEXP tokenize(const std::string &inString, const std::string &inDelimiters, std::deque< std::string > &outTokens, bool skipBlankTokens=true) MRPT_NO_THROWS
mrpt::maps::CMultiMetricMapPDF mapPDF
CPose3D getParticlePose(int i) const
T::Ptr getMapByClass(const size_t &ith=0) const
void setRotationMatrix(const mrpt::math::CMatrixDouble33 &ROT)
GLdouble GLdouble GLdouble GLdouble GLdouble GLdouble f
void processActionObservation(mrpt::obs::CActionCollection &action, mrpt::obs::CSensoryFrame &observations)