Skip to content

Commit 5a6e812

Browse files
Switch to the new method to pack the message to be faster (#878)
1 parent 23abbbf commit 5a6e812

File tree

5 files changed

+34
-35
lines changed

5 files changed

+34
-35
lines changed

ihmc-high-level-behaviors/src/libgdx/java/us/ihmc/rdx/ui/graphics/ros2/RDXROS2HeightMapVisualizer.java

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -108,19 +108,27 @@ public void acceptHeightMapMessage(HeightMapMessage heightMapMessage)
108108
if (sequenceId > 1)
109109
{
110110
// We add +1 here because the height map is
111-
cellsPerAxis = (int) (heightMapMessage.getGridSizeXy() / heightMapMessage.getXyResolution()) + 1;
111+
int centerIndex = HeightMapTools.computeCenterIndex(4.0, 0.02);
112+
cellsPerAxis = 2 * centerIndex + 1;
112113
}
113114

114115
heightMapCenter.setX(heightMapMessage.getGridCenterX());
115116
heightMapCenter.setY(heightMapMessage.getGridCenterY());
116-
latestHeightMapData = HeightMapMessageTools.unpackMessageToHeightMapData(heightMapMessage);
117-
if (heightMap == null)
117+
heightMap = HeightMapMessageTools.unpackMessageToMat(heightMapMessage, heightMapParameters);
118+
119+
if (latestHeightMapData == null)
118120
{
119-
heightMap = new Mat(latestHeightMapData.getCellsPerAxis(),
120-
latestHeightMapData.getCellsPerAxis(),
121-
opencv_core.CV_16UC1);
121+
latestHeightMapData = new HeightMapData(heightMapMessage.getXyResolution(),
122+
heightMapMessage.getGridSizeXy(),
123+
heightMapMessage.getGridCenterX(),
124+
heightMapMessage.getGridCenterY());
122125
}
123-
HeightMapTools.convertHeightMapDataToMat(heightMap, latestHeightMapData, heightMapParameters);
126+
HeightMapTools.convertToHeightMapData(heightMap,
127+
latestHeightMapData,
128+
heightMapCenter,
129+
(float) heightMapParameters.getGlobalWidthInMeters(),
130+
(float) heightMapParameters.getCellSizeInMeters(),
131+
heightMapParameters);
124132

125133
// This prevents the rendering from happening to early, it was throwing exceptions
126134
if (stopwatch.lapElapsed() > 3)
@@ -272,4 +280,4 @@ public RDXOpenCVVideoVisualizer getHeightMapImageVisualizer()
272280
{
273281
return heightMapImageVisualizer;
274282
}
275-
}
283+
}

ihmc-perception/src/main/java/us/ihmc/perception/gpuHeightMap/RapidHeightMapExtractor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -542,7 +542,7 @@ private void deallocateFloatPointer(FloatPointer hostPointer, Pointer devicePoin
542542

543543
public GpuMat getHeightMap()
544544
{
545-
return scaledHeightMap.clone();
545+
return globalMeanMap;
546546
}
547547

548548
public GpuMat getTerrainCroppedHeightMap()

ihmc-perception/src/main/java/us/ihmc/perception/gpuHeightMap/RapidHeightMapManager.java

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,10 @@ public class RapidHeightMapManager
4040

4141
private final ROS2Publisher<HeightMapMessage> heightMapMessagePublisher;
4242
private final BytePointer compressedHeightMapPointer = new BytePointer();
43-
private final HeightMapData latestHeightMapData;
4443
private final HeightMapData latestTerrainHeightMapData;
4544
private final Point3D gridCellLocation = new Point3D();
45+
// This is created globally cause it takes compute time to create it in the update loop
46+
private final HeightMapMessage heightMapMessage = new HeightMapMessage();
4647
private long sequenceId = 0;
4748

4849
public RapidHeightMapManager(ROS2Node ros2Node,
@@ -54,10 +55,7 @@ public RapidHeightMapManager(ROS2Node ros2Node,
5455
{
5556
this.heightMapCenter = heightMapCenter;
5657
this.heightMapParameters = heightMapParameters;
57-
latestHeightMapData = new HeightMapData((float) heightMapParameters.getCellSizeInMeters(),
58-
(float) heightMapParameters.getGlobalWidthInMeters(),
59-
0.0,
60-
0.0);
58+
6159
latestTerrainHeightMapData = new HeightMapData((float) heightMapParameters.getCellSizeInMeters(),
6260
(float) heightMapParameters.getTerrainWidthInMeters(),
6361
0.0,
@@ -79,9 +77,7 @@ public RapidHeightMapManager(ROS2Node ros2Node,
7977
public void updateAndPublishHeightMap(GpuMat latestDepthImage, CameraIntrinsics depthIntrinsics, ReferenceFrame cameraFrame, ReferenceFrame cameraZUpFrame)
8078
{
8179
// Update the sensor origin here with the latest reference frame
82-
RigidBodyTransform transformToWorldFrame = cameraFrame.getTransformToWorldFrame();
8380
RigidBodyTransform heightMapFrameToWorldFrame = heightMapCenter.getTransformToWorldFrame();
84-
Point3D sensorOrigin = new Point3D(transformToWorldFrame.getTranslation());
8581
Point3D heightMapCenterOrigin = new Point3D(heightMapFrameToWorldFrame.getTranslation());
8682

8783
updateInternal(latestDepthImage, depthIntrinsics, cameraFrame, cameraZUpFrame, heightMapCenterOrigin);
@@ -96,7 +92,6 @@ public void updateAndPublishHeightMap(GpuMat latestDepthImage, CameraIntrinsics
9692
publishHeightMap(hostGlobalHeightMap, heightMapCenterOrigin);
9793

9894
hostGlobalHeightMap.close();
99-
deviceGlobalHeightMap.close();
10095
}
10196

10297
private void publishHeightMap(Mat hostGlobalHeightMap, Point3D heightMapCenterOrigin)
@@ -109,15 +104,11 @@ private void publishHeightMap(Mat hostGlobalHeightMap, Point3D heightMapCenterOr
109104
FramePose3D cameraPose = new FramePose3D();
110105
cameraPose.getTranslation().set(gridCellLocation);
111106

112-
HeightMapTools.convertToHeightMapData(hostGlobalHeightMap,
113-
latestHeightMapData,
114-
gridCellLocation,
115-
(float) heightMapParameters.getGlobalWidthInMeters(),
116-
(float) heightMapParameters.getCellSizeInMeters(),
117-
heightMapParameters);
118-
119-
HeightMapMessage heightMapMessage = new HeightMapMessage();
120-
HeightMapMessageTools.toMessage(latestHeightMapData, heightMapMessage);
107+
HeightMapMessageTools.toMessage(hostGlobalHeightMap,
108+
heightMapMessage,
109+
gridCellLocation,
110+
heightMapParameters.getGlobalWidthInMeters(),
111+
heightMapParameters.getCellSizeInMeters());
121112
sequenceId++;
122113
heightMapMessage.setSequenceId(sequenceId);
123114
heightMapMessagePublisher.publish(heightMapMessage);

ihmc-perception/src/main/java/us/ihmc/perception/heightMap/HeightMapTools.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package us.ihmc.perception.heightMap;
22

3-
import org.bytedeco.opencv.global.opencv_core;
43
import org.bytedeco.opencv.opencv_core.Mat;
54
import us.ihmc.commons.InterpolationTools;
65
import us.ihmc.euclid.tuple3D.Point3D;
@@ -10,17 +9,17 @@
109
/**
1110
* Height map indexing tools. The height map spans a square region and is parametrized by the following values:
1211
* - A discretization value
13-
* - The grid size, i.e. side length of the square region it covers
14-
* - Grid center, an xy coordinate which is the middle of the grid
15-
*
12+
* - The grid size, i.e., side length of the square region it covers
13+
* - a Grid center, a xy coordinate which is the middle of the grid
14+
* <p>
1615
* Cells are indexed two ways:
17-
* - A unique integer key, which is zero-indexed and starts at the corner of the grid which is the negative-most x and y coordinates.
16+
* - A unique integer key, which is zero-indexed and starts in the corner of the grid which is the negative-most x and y coordinates.
1817
* - An (x,y) integer index pair, which is zero at the negative-most cell along each axis
1918
*/
2019
public class HeightMapTools
2120
{
2221
/**
23-
* The xy-indices of the center of the grid.
22+
* The xy-indices of the center, of the grid.
2423
*/
2524
public static int computeCenterIndex(double gridSize, double resolution)
2625
{
@@ -87,7 +86,7 @@ public static double getCoordinateFromIndex(int index, double resolution, int of
8786
public static double[] getRedGreenBlue(double height)
8887
{
8988
// Using interpolation between key color points
90-
double r = 0, g = 0, b = 0;
89+
double r, g, b;
9190
double magentaR = 1.0, magentaG = 0.0, magentaB = 1.0;
9291
double orangeR = 1.0, orangeG = 200.0 / 255.0, orangeB = 0.0;
9392
double yellowR = 1.0, yellowG = 1.0, yellowB = 0.0;
@@ -160,7 +159,8 @@ public static void convertHeightMapDataToMat(Mat heightMapToPack, HeightMapData
160159
int colMajorIndex = col * cellsPerAxis + row;
161160

162161
// Get the height as for row major, and save it as column major
163-
short height = (short) (((float) heightsAsDoubles[rowMajorIndex] + (float) heightMapParameters.getHeightOffset()) * heightMapParameters.getHeightScaleFactor());
162+
short height = (short) (((float) heightsAsDoubles[rowMajorIndex] + (float) heightMapParameters.getHeightOffset())
163+
* heightMapParameters.getHeightScaleFactor());
164164
heightsAsFloats[colMajorIndex] = height;
165165
}
166166
}

ihmc-perception/src/test/java/us/ihmc/perception/heightmap/HeightMapToolsTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ public void testSpeedConvertMatToHeightMapData()
7979

8080
System.out.printf("Average time per pack: %.3f ms%n", averageTimePerIteration);
8181
}
82-
82+
8383
@Test
8484
public void testIndexing()
8585
{

0 commit comments

Comments
 (0)