8 #include <octomap/octomap.h> 9 #include <octomap_msgs/Octomap.h> 10 #include <octomap_msgs/conversions.h> 11 #include <octomap_ros/conversions.h> 20 mPointCloudPub = this->nh->
advertise<sensor_msgs::PointCloud2>(
"/orbslam2/pointcloud", 100);
21 mOctomapPub = this->nh->
advertise<octomap_msgs::Octomap>(
"/orbslam2/octomap", 5);
22 mOccupancyMapPub = this->nh->
advertise<octomap_msgs::Octomap>(
"/orbslam2/occupancymap", 5);
23 mOdomPub = this->nh->
advertise<nav_msgs::Odometry>(
"/orbslam2/odometry", 5);
25 mpPointCloudDataCache = mpPointCloudMapping->GetPointCloudDataCache();
26 miPointCloudDataCacheIndex = mpPointCloudMapping->GetPointCloudDataCacheIndex();
38 sensor_msgs::PointCloud2 pointCloud;
39 octomap::Pointcloud octo_cloud;
41 octomap_msgs::Octomap octomap_msg;
43 octomap::OcTree tree( 0.05 );
44 octomap_msgs::Octomap occupancymap_msg;
47 if (
RET_SUCCESS == mpPointCloudDataCache->GetDataByIndex(miPointCloudDataCacheIndex,tempPointCloud))
50 toROSMsg(tempPointCloud, pointCloud);
52 pointCloud.header.frame_id =
"camera_link";
53 cout<<
"Publish PointCloud: "<<count<<
" 点云个数云:"<<tempPointCloud.points.size()<<endl;
54 mPointCloudPub.publish(pointCloud);
57 for (
auto p:tempPointCloud.points)
67 tree.updateNode( octomap::point3d(p.x, p.y, p.z),
true );
70 tree.updateInnerOccupancy();
72 octomap_msgs::fullMapToMsg(tree, octomap_msg);
73 octomap_msg.header.frame_id =
"camera_link";
75 mOctomapPub.publish(octomap_msg);
78 octomap_msgs::binaryMapToMsg(tree, occupancymap_msg);
79 occupancymap_msg.header.frame_id =
"camera_link";
81 occupancymap_msg.id = 1;
82 occupancymap_msg.binary = 1;
83 occupancymap_msg.resolution = tree.getResolution();
84 mOccupancyMapPub.publish(octomap_msg);
95 world_frame_id =
"odom";
96 base_frame_id =
"base_link";
97 camera_frame_id =
"camera_link";
99 bool warn_flag =
false;
100 float x,
y,
z, qx, qy, qz, qw;
104 nav_msgs::Odometry odom;
108 if (SLAM->GetTrackingState() != 2)
119 unique_lock<mutex> lock(MutexPose);
120 ret_val = getPose(x, y, z, qx, qy, qz, qw);
136 if (get_base_to_camera)
140 ROS_INFO(
"Get TF form '%s' to '%s', Publish TF '%s' to '%s'.", base_frame_id.data(), camera_frame_id.data(), world_frame_id.data(), base_frame_id.data());
144 output_tf = base_to_camera * sensordata_tf * camera_to_base;
156 ROS_WARN(
"Can`t get TF form '%s' to '%s',Publish TF '%s' to '%s' instead.", base_frame_id.data(), camera_frame_id.data(), world_frame_id.data(), camera_frame_id.data());
159 output_tf = sensordata_tf;
165 tf_broadcaster.sendTransform(odom_trans);
168 odom.header.stamp = pose_sync_time;
169 odom.header.frame_id = world_frame_id;
176 odom.pose.pose.orientation.x = output_tf.
getRotation().x();
177 odom.pose.pose.orientation.y = output_tf.
getRotation().y();
178 odom.pose.pose.orientation.z = output_tf.
getRotation().z();
179 odom.pose.pose.orientation.w = output_tf.
getRotation().w();
180 odom.pose.covariance[0] = 1e-3;
181 odom.pose.covariance[7] = 1e-3;
182 odom.pose.covariance[14] = 1e-6;
183 odom.pose.covariance[21] = 1e-6;
184 odom.pose.covariance[28] = 1e-6;
185 odom.pose.covariance[35] = 1e-3;
193 mOdomPub.publish(odom);
202 if (
RET_SUCCESS == mpTcwDataCache->GetDataByIndex(miTcwDataCacheIndex,Tcw))
206 cv::Mat R = Tcw.rowRange(0, 3).colRange(0, 3);
207 cv::Mat tcw = Tcw.rowRange(0, 3).col(3);
213 y = -Ow.at<
float>(0);
214 z = -Ow.at<
float>(1);
228 bool warn_flag =
false;
240 bool ret = tf_listener.waitForTransform(base_frame_id, camera_frame_id, t,
ros::Duration(1.0));
242 tf_listener.lookupTransform(base_frame_id, camera_frame_id, t, base_to_camera_tf);
248 ROS_WARN(
"Could not get initial transform from '%s' to '%s' frame, %s", base_frame_id.data(), camera_frame_id.data(), ex.what());
251 get_base_to_camera =
false;
254 base_to_camera = base_to_camera_tf;
255 camera_to_base = base_to_camera.
inverse();
258 get_base_to_camera =
true;
268 cout <<
"vector from reference frame to to child frame: " << tfVec.
getX() <<
"," << tfVec.
getY() <<
"," << tfVec.
getZ() << endl;
270 cout <<
"orientation of child frame w/rt reference frame: " << endl;
272 cout << tfVec.
getX() <<
"," << tfVec.
getY() <<
"," << tfVec.
getZ() << endl;
274 cout << tfVec.
getX() <<
"," << tfVec.
getY() <<
"," << tfVec.
getZ() << endl;
276 cout << tfVec.
getX() <<
"," << tfVec.
getY() <<
"," << tfVec.
getZ() << endl;
278 cout <<
"quaternion: " << quat.x() <<
", " << quat.y() <<
", " 279 << quat.z() <<
", " << quat.w() << endl;
285 cout <<
"frame_id: " << sTf.
frame_id_ << endl;
287 tf = get_tf_from_stamped_tf(sTf);
PointCloudPublisher(ros::NodeHandle *nh, ORB_SLAM2::System *SLAM)
void printTf(tf::Transform tf)
int getPose(float &x, float &y, float &z, float &qx, float &qy, float &qz, float &qw)
TFSIMD_FORCE_INLINE const tfScalar & getY() const
static std::vector< float > toQuaternion(const cv::Mat &M)
TFSIMD_FORCE_INLINE const tfScalar & y() const
TFSIMD_FORCE_INLINE const tfScalar & getZ() const
TFSIMD_FORCE_INLINE const Vector3 & getRow(int i) const
int32_t GetTcwDataCacheIndex()
TFSIMD_FORCE_INLINE const tfScalar & x() const
Publisher advertise(const std::string &topic, uint32_t queue_size, bool latch=false)
TFSIMD_FORCE_INLINE const tfScalar & z() const
tf::Transform get_tf_from_stamped_tf(tf::StampedTransform sTf)
pcl::PointCloud< PointT > PointCloud
TFSIMD_FORCE_INLINE const tfScalar & getX() const
DataCache< cv::Mat > * GetTcwDataCache()
shared_ptr< PointCloudMapping > GetPointCloudMapping()
void printStampedTf(tf::StampedTransform sTf)