Skip to content

Commit 13d15c3

Browse files
srmainwaringmergify[bot]
authored andcommitted
EnvironmentPreload visualise static environments (#3138)
## Summary This PR fixes an issue where a static environment loaded by the EnvironmentPreload system would not display using the Environment Visualization Resolution and Point Cloud GUI widgets. There is also a fix that prevents segmentation faults in the VisualizationTool caused by copying a DataFrame which may invalidate the session iterators. ## Details Before this change, if the `<ignore_time>` element is added to the EnvironmentPreload system xml it is ignored when visualising the point cloud data. ```xml <plugin filename="gz-sim-environment-preload-system" name="gz::sim::systems::EnvironmentPreload"> <data>environmental_data.csv</data> <dimensions> <ignore_time>1</ignore_time> <time>timestamp</time> <space> <x>x</x> <y>y</y> <z>z</z> </space> </dimensions> </plugin> ``` This means that if only the time zero data is provided, for example: ```bash # environmental_data.csv - modified to only contain data for timestamp = 0 timestamp,humidity,x,y,z 0,80,-1,-1,-1 0,80,-1,-1, 1 0,80,-1, 1,-1 0,80,-1, 1, 1 0,90, 1,-1,-1 0,90, 1,-1, 1 0,90, 1, 1,-1 0,90, 1, 1, 1 ``` the VisualizationTool would never display the point cloud data. A workaround for this is to set a very large timestamp for a second copy of data. This is unsatisfactory because it doubles the size of the environment data required (which may be significant for large vector fields), and also requires a temporal interpolation when none is required, which results in a performance penalty. The other fix is to pay attention to unintended copies when using the auto keyword to obtain aliases to the data frame objects. The main change is ```diff - auto frame = _data->frame[this->pubs.begin()->first]; + const auto &frame = _data->frame[this->pubs.begin()->first]; ``` The problem is that the session iterators will in general be invalid for the copied frame, and this may result in a segmentation fault when they are dereferenced later in the code. In this particular case the check that the iterator was in range in the interpolation code failed resulting in a out of range access violation a few lines later. This type of error can be difficult to trace. With this change, and some other related fixes to the environmental data system, large static vector fields can be loaded and viewed in the GUI. Below is an example for a wind field containing 64000 rows of data. <img width="1312" height="940" alt="05-1-gz-wind-pc-x-axis" src="https://github.com/user-attachments/assets/72d9bd99-3640-456d-975a-9fc2d6387884" /> --------- Signed-off-by: Rhys Mainwaring <[email protected]> (cherry picked from commit bddeeea) # Conflicts: # examples/worlds/environmental_sensor.sdf # src/systems/environment_preload/EnvironmentPreload.cc # src/systems/environment_preload/VisualizationTool.cc # src/systems/environment_preload/VisualizationTool.hh
1 parent 04d144c commit 13d15c3

File tree

4 files changed

+887
-0
lines changed

4 files changed

+887
-0
lines changed
Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
<?xml version="1.0" ?>
2+
<!--
3+
This example show cases how to load and unload environmental data.
4+
Before opening this file in a separate terminal run:
5+
gz topic -e -t /sensors/humidity
6+
Then open this file by running:
7+
gz sim environmental_sensor.sdf
8+
9+
Optionally, enable environment visualization in the 3D window by opening
10+
two GUI plugins via top right GUI plugin menu:
11+
- `Environment Visualization` and
12+
- `Point Cloud`: Click on `refresh` button and set `Point size` to a
13+
reasonable value, e.g. 5
14+
15+
Play the simulation and you should see a data stream of increasing numbers in
16+
the separate terminal, which eventually stops at 90.
17+
-->
18+
<sdf version="1.6">
19+
<world name="environmental_sensor_example">
20+
<plugin
21+
filename="gz-sim-physics-system"
22+
name="gz::sim::systems::Physics">
23+
</plugin>
24+
<plugin
25+
filename="gz-sim-user-commands-system"
26+
name="gz::sim::systems::UserCommands">
27+
</plugin>
28+
<plugin
29+
filename="gz-sim-scene-broadcaster-system"
30+
name="gz::sim::systems::SceneBroadcaster">
31+
</plugin>
32+
33+
<!-- The system specifies where to preload -->
34+
<plugin
35+
filename="gz-sim-environment-preload-system"
36+
name="gz::sim::systems::EnvironmentPreload">
37+
<data>environmental_data.csv</data>
38+
<dimensions>
39+
<ignore_time>0</ignore_time>
40+
<time>timestamp</time>
41+
<space>
42+
<x>x</x>
43+
<y>y</y>
44+
<z>z</z>
45+
</space>
46+
</dimensions>
47+
</plugin>
48+
49+
<!-- The system is added to the world, so it handles all environmental data in the world-->
50+
<plugin
51+
filename="gz-sim-environmental-sensor-system"
52+
name="gz::sim::systems::EnvironmentalSystem">
53+
</plugin>
54+
55+
<light type="directional" name="sun">
56+
<cast_shadows>true</cast_shadows>
57+
<pose>0 0 10 0 0 0</pose>
58+
<diffuse>0.8 0.8 0.8 1</diffuse>
59+
<specular>0.2 0.2 0.2 1</specular>
60+
<attenuation>
61+
<range>1000</range>
62+
<constant>0.9</constant>
63+
<linear>0.01</linear>
64+
<quadratic>0.001</quadratic>
65+
</attenuation>
66+
<direction>-0.5 0.1 -0.9</direction>
67+
</light>
68+
69+
<model name="ground_plane">
70+
<static>true</static>
71+
<link name="link">
72+
<collision name="collision">
73+
<geometry>
74+
<plane>
75+
<normal>0 0 1</normal>
76+
<size>100 100</size>
77+
</plane>
78+
</geometry>
79+
</collision>
80+
<visual name="visual">
81+
<geometry>
82+
<plane>
83+
<normal>0 0 1</normal>
84+
<size>100 100</size>
85+
</plane>
86+
</geometry>
87+
<material>
88+
<ambient>0.8 0.8 0.8 1</ambient>
89+
<diffuse>0.8 0.8 0.8 1</diffuse>
90+
<specular>0.8 0.8 0.8 1</specular>
91+
</material>
92+
</visual>
93+
</link>
94+
</model>
95+
96+
<model name="model_with_sensor">
97+
<pose>0 0 0.05 0 0 0</pose>
98+
<link name="link">
99+
<inertial>
100+
<mass>0.1</mass>
101+
<inertia>
102+
<ixx>0.000166667</ixx>
103+
<iyy>0.000166667</iyy>
104+
<izz>0.000166667</izz>
105+
</inertia>
106+
</inertial>
107+
<collision name="collision">
108+
<geometry>
109+
<box>
110+
<size>0.1 0.1 0.1</size>
111+
</box>
112+
</geometry>
113+
</collision>
114+
<visual name="visual">
115+
<geometry>
116+
<box>
117+
<size>0.1 0.1 0.1</size>
118+
</box>
119+
</geometry>
120+
</visual>
121+
<!-- Here's our custom sensor -->
122+
<sensor name="custom_sensor" type="custom" gz:type="environmental_sensor/humidity">
123+
<always_on>1</always_on>
124+
<update_rate>30</update_rate>
125+
<topic>sensors/humidity</topic>
126+
</sensor>
127+
</link>
128+
</model>
129+
130+
</world>
131+
</sdf>

0 commit comments

Comments
 (0)