18
18
import us .ihmc .perception .camera .CameraIntrinsics ;
19
19
import us .ihmc .perception .cuda .CUDABodyCollisionFilter ;
20
20
import us .ihmc .perception .filters .CUDAFlyingPointsFilter ;
21
- import us .ihmc .perception .heightMap .TerrainMapData ;
22
21
import us .ihmc .perception .opencv .OpenCVTools ;
23
22
import us .ihmc .perception .tools .PerceptionMessageTools ;
24
23
import us .ihmc .robotModels .FullHumanoidRobotModel ;
28
27
import us .ihmc .scs2 .simulation .collision .Collidable ;
29
28
import us .ihmc .sensorProcessing .heightMap .HeightMapData ;
30
29
import us .ihmc .sensorProcessing .heightMap .HeightMapParameters ;
30
+ import us .ihmc .sensorProcessing .heightMap .HeightMapTools ;
31
31
32
32
import java .time .Instant ;
33
33
import java .util .ArrayList ;
@@ -40,7 +40,6 @@ public class RapidHeightMapManager
40
40
{
41
41
private final HeightMapParameters heightMapParameters ;
42
42
private final RapidHeightMapExtractorCUDA rapidHeightMapExtractor ;
43
- private final SnappingTerrainExtractor snappedFootstepsExtractor ;
44
43
45
44
private final Point3D sensorOrigin = new Point3D ();
46
45
private final FramePose3D cameraPose = new FramePose3D ();
@@ -56,6 +55,7 @@ public class RapidHeightMapManager
56
55
private final ROS2Publisher <ImageMessage > heightMapPublisher ;
57
56
private final ImageMessage croppedHeightMapImageMessage = new ImageMessage ();
58
57
private final BytePointer compressedCroppedHeightMapPointer = new BytePointer ();
58
+ private final GpuMat deviceCroppedHeightMap ;
59
59
60
60
public RapidHeightMapManager (ROS2Node ros2Node ,
61
61
RobotCollisionModel robotCollisionModel ,
@@ -76,8 +76,10 @@ public RapidHeightMapManager(ROS2Node ros2Node,
76
76
rapidHeightMapDriftOffset = new RapidHeightMapDriftOffset (controllerFootstepQueueMonitor );
77
77
flyingPointsFilter = new CUDAFlyingPointsFilter ();
78
78
79
+ int croppedCenterIndex = HeightMapTools .computeCenterIndex (heightMapParameters .getCroppedWidthInMeters (), heightMapParameters .getCellSizeInMeters ());
80
+ int cellsPerAxisCropped = 2 * croppedCenterIndex + 1 ;
81
+ deviceCroppedHeightMap = new GpuMat (cellsPerAxisCropped , cellsPerAxisCropped , opencv_core .CV_16UC1 );
79
82
rapidHeightMapExtractor = new RapidHeightMapExtractorCUDA (1 , heightMapParameters );
80
- snappedFootstepsExtractor = new SnappingTerrainExtractor (heightMapParameters );
81
83
82
84
// We use a notification to only call resetting the height map in one place
83
85
heightMapPublisher = ros2Node .createPublisher (PerceptionAPI .HEIGHT_MAP_CROPPED );
@@ -96,15 +98,14 @@ public RapidHeightMapManager(ROS2Node ros2Node,
96
98
}
97
99
}
98
100
99
- public void updateAndPublishHeightMap (RawImage depthImage , ReferenceFrame cameraFrame , ReferenceFrame cameraZUpFrame ) throws Exception
101
+ public void updateAndPublishHeightMap (RawImage depthImage , ReferenceFrame cameraFrame , ReferenceFrame cameraZUpFrame )
100
102
{
101
103
RawImage depthImageCopy = depthImage .get ();
102
104
Mat latestDepthImage = depthImageCopy .getCpuImageMat ();
103
105
Instant acquisitionTime = depthImageCopy .getAcquisitionTime ();
104
106
CameraIntrinsics depthIntrinsicsCopy = depthImageCopy .getIntrinsicsCopy ();
105
107
106
108
// -------- Update the Height Map with the latest depth image from the sensor --------------
107
- GpuMat deviceCroppedHeightMap = new GpuMat ();
108
109
updateInternal (latestDepthImage , deviceCroppedHeightMap , depthIntrinsicsCopy , cameraFrame , cameraZUpFrame );
109
110
110
111
// Publish the height map to anyone who is subscribing
@@ -121,16 +122,18 @@ public void updateAndPublishHeightMap(RawImage depthImage, ReferenceFrame camera
121
122
hostCroppedHeightMap .cols (),
122
123
(float ) heightMapParameters .getHeightScaleFactor ());
123
124
124
- deviceCroppedHeightMap .close ();
125
125
hostCroppedHeightMap .close ();
126
126
depthImageCopy .release ();
127
127
}
128
128
129
+ /**
130
+ * Update the Height Map with the latest depth image from the sensor
131
+ */
129
132
private void updateInternal (Mat latestDepthImage ,
130
133
GpuMat deviceHeightMapToPack ,
131
134
CameraIntrinsics depthIntrinsicsCopy ,
132
135
ReferenceFrame cameraFrame ,
133
- ReferenceFrame cameraZUpFrame ) throws Exception
136
+ ReferenceFrame cameraZUpFrame )
134
137
{
135
138
// Option that gets triggered from a message sent from the user
136
139
if (lowerHeightMapBackdropRequested .poll ())
@@ -194,7 +197,7 @@ private void updateInternal(Mat latestDepthImage,
194
197
sensorOrigin ,
195
198
computeFootHeight ());
196
199
197
- GpuMat deviceCroppedHeightMap = rapidHeightMapExtractor .getVisualizedHeightMap ();
200
+ GpuMat deviceCroppedHeightMap = rapidHeightMapExtractor .getCroppedHeightMap ();
198
201
// We have used the depth image without the robot, close this to avoid creating a memory leak
199
202
depthImageWithoutRobot .close ();
200
203
@@ -209,30 +212,24 @@ private void updateInternal(Mat latestDepthImage,
209
212
210
213
// Don't close this mat as its being used in the extractor till that finish's
211
214
deviceCroppedHeightMap .convertTo (deviceHeightMapToPack , deviceCroppedHeightMap .type ());
212
-
213
- // Now extract the maps to be used in the footstep planning algorithm
214
- snappedFootstepsExtractor .update (rapidHeightMapExtractor .getTerrainHeightMapImage (), sensorOrigin );
215
- }
216
-
217
- public TerrainMapData getTerrainMapData ()
218
- {
219
- return snappedFootstepsExtractor .getTerrainMapData ();
220
215
}
221
216
222
217
public HeightMapData getLatestHeightMapData ()
223
218
{
224
219
HeightMapData latestHeightMapData = new HeightMapData ((float ) heightMapParameters .getCellSizeInMeters (),
225
- (float ) heightMapParameters .getTerrainWidthInMeters (),
220
+ (float ) heightMapParameters .getCroppedWidthInMeters (),
226
221
sensorOrigin .getX (),
227
222
sensorOrigin .getY ());
228
223
229
- Mat heightMapMat = getTerrainMapData ().getHeightMap ();
230
- PerceptionMessageTools .convertToHeightMapData (heightMapMat ,
224
+ Mat heightMap = new Mat ();
225
+ deviceCroppedHeightMap .download (heightMap );
226
+ PerceptionMessageTools .convertToHeightMapData (heightMap ,
231
227
latestHeightMapData ,
232
228
sensorOrigin ,
233
- (float ) heightMapParameters .getTerrainWidthInMeters (),
229
+ (float ) heightMapParameters .getCroppedWidthInMeters (),
234
230
(float ) heightMapParameters .getCellSizeInMeters (),
235
231
heightMapParameters );
232
+ heightMap .close ();
236
233
237
234
return latestHeightMapData ;
238
235
}
@@ -257,8 +254,8 @@ private double computeFootHeight()
257
254
public void destroy ()
258
255
{
259
256
rapidHeightMapExtractor .destroy ();
260
- snappedFootstepsExtractor .close ();
261
257
flyingPointsFilter .destroy ();
258
+ deviceCroppedHeightMap .close ();
262
259
compressedCroppedHeightMapPointer .close ();
263
260
}
264
261
}
0 commit comments