@@ -13,18 +13,20 @@ DepthImageProjectorNode::DepthImageProjectorNode(const ros::NodeHandle& nh, cons
1313
1414 nh_.param <std::string>(" depth_frame_id" , depth_frame_id_, " d435_depth_optical" );
1515 nh_.param <std::string>(" map_frame_id" , map_frame_id_, " base_link_hor" );
16+ nh_.param <std::string>(" fixed_frame_id" , fixed_frame_id_, " map" );
1617 nh_.param <double >(" tf_wait_duration" , tf_wait_duration_, 0.1 );
1718
1819 int depthWidth, depthHeight;
1920 nh_.param <int >(" depth_width" , depthWidth , 640 );
2021 nh_.param <int >(" depth_height" , depthHeight, 360 );
2122
22- double gridMapLayerHeight, gridMapAccumulationWeight;
23+ double gridMapLayerHeight, gridMapAccumulationWeight, gridMapDecay ;
2324 nh_.param <int >(" grid_map_width" , gridMapWidth_ , 1000 );
2425 nh_.param <int >(" grid_map_height" , gridMapHeight_, 1000 );
2526 nh_.param <double >(" grid_map_resolution" , gridMapResolution_, 0.01 );
2627 nh_.param <double >(" grid_map_layer_height" , gridMapLayerHeight, 1 );
27- nh_.param <double >(" grid_map_accumulation_weight" , gridMapAccumulationWeight, 1 );
28+ nh_.param <double >(" grid_map_accumulation_weight" , gridMapAccumulationWeight, 0.001 );
29+ nh_.param <double >(" grid_map_decay" , gridMapDecay, 0.5 );
2830
2931 double minDepth, maxDepth, depthHitThreshold;
3032 int unknownDepthColor;
@@ -43,7 +45,7 @@ DepthImageProjectorNode::DepthImageProjectorNode(const ros::NodeHandle& nh, cons
4345 projector_ = std::make_unique<cgs::DepthImageProjector>(
4446 depthWidth, depthHeight,
4547 gridMapWidth_, gridMapHeight_, gridMapResolution_,
46- gridMapLayerHeight, gridMapAccumulationWeight,
48+ gridMapLayerHeight, gridMapAccumulationWeight, gridMapDecay,
4749 minDepth, maxDepth, depthHitThreshold, unknownDepthColor,
4850 vertexShader, geometryShader, fragmentShader,
4951 vertexShaderScaling, fragmentShaderScaling
@@ -64,8 +66,12 @@ void DepthImageProjectorNode::depthCallback(const sensor_msgs::Image::ConstPtr&
6466 ROS_ERROR_STREAM (" cv_bridge exception: " << e.what ());
6567 return ;
6668 }
69+
70+ // called first time
71+ if (!previousTimestamp_.isValid ())
72+ previousTimestamp_ = cameraInfoMsg->header .stamp ;
6773
68- std::array<float , 16 > depthToMap;
74+ std::array<float , 16 > depthToMap, mapToPreviousMap ;
6975 try
7076 {
7177 if (tfListener_.waitForTransform (map_frame_id_, cameraInfoMsg->header .frame_id ,
@@ -76,18 +82,32 @@ void DepthImageProjectorNode::depthCallback(const sensor_msgs::Image::ConstPtr&
7682 cameraInfoMsg->header .stamp , transform);
7783 getTransformMatrixArray (transform, depthToMap);
7884 }
85+
86+ if (tfListener_.waitForTransform (map_frame_id_, fixed_frame_id_,
87+ cameraInfoMsg->header .stamp , ros::Duration (tf_wait_duration_)))
88+ {
89+ tf::StampedTransform tramsform;
90+ tfListener_.lookupTransform (
91+ map_frame_id_, previousTimestamp_,
92+ map_frame_id_, cameraInfoMsg->header .stamp ,
93+ fixed_frame_id_, tramsform);
94+ getTransformMatrixArray (tramsform, mapToPreviousMap);
95+ }
7996 }
8097 catch (tf::TransformException& ex)
8198 {
8299 ROS_WARN (" Transform Exception in depthCallback(). %s" , ex.what ());
83100 return ;
84101 }
85102
103+ // Update previous timestamp
104+ previousTimestamp_ = cameraInfoMsg->header .stamp ;
105+
86106 // Update projector parameters with camera info
87107 projector_->updateProjectionMatrix (
88- {static_cast <float >(cameraInfoMsg->K [0 ]) , static_cast <float >(cameraInfoMsg->K [4 ])},
89- {static_cast <float >(cameraInfoMsg->K [2 ]) , static_cast <float >(cameraInfoMsg->K [5 ])},
90- depthToMap
108+ {static_cast <float >(cameraInfoMsg->K [0 ]), static_cast <float >(cameraInfoMsg->K [4 ])},
109+ {static_cast <float >(cameraInfoMsg->K [2 ]), static_cast <float >(cameraInfoMsg->K [5 ])},
110+ depthToMap, mapToPreviousMap
91111 );
92112
93113 // Perform projection
@@ -115,7 +135,6 @@ void DepthImageProjectorNode::depthCallback(const sensor_msgs::Image::ConstPtr&
115135 grid.data .reserve (size);
116136 std::copy (data, data + size, std::back_inserter (grid.data ));
117137 mapPublisher_.publish (grid);
118-
119138}
120139
121140void DepthImageProjectorNode::getTransformMatrixArray (const tf::Transform& transform, std::array<float , 16 >& matrix)
0 commit comments