Skip to content

Commit 4f3dd67

Browse files
iche033chapulinaNate Koenig
authored
Parse new param for enabling / disabling IMU orientation output (#899)
* parse imu orientation param Signed-off-by: Ian Chen <[email protected]> * use enable_orientation sdf elem Signed-off-by: Ian Chen <[email protected]> * use joinPaths Signed-off-by: Ian Chen <[email protected]> * add test world file Signed-off-by: Ian Chen <[email protected]> Co-authored-by: Louise Poubel <[email protected]> Co-authored-by: Nate Koenig <[email protected]>
1 parent 3fbddd1 commit 4f3dd67

File tree

3 files changed

+130
-0
lines changed

3 files changed

+130
-0
lines changed

src/systems/imu/Imu.cc

+7
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,13 @@ void ImuPrivate::CreateImuEntities(EntityComponentManager &_ecm)
186186
// Set topic
187187
_ecm.CreateComponent(_entity, components::SensorTopic(sensor->Topic()));
188188

189+
// Set whether orientation is enabled
190+
if (data.ImuSensor())
191+
{
192+
sensor->SetOrientationEnabled(
193+
data.ImuSensor()->OrientationEnabled());
194+
}
195+
189196
this->entitySensorMap.insert(
190197
std::make_pair(_entity, std::move(sensor)));
191198

test/integration/imu_system.cc

+40
Original file line numberDiff line numberDiff line change
@@ -206,3 +206,43 @@ TEST_F(ImuTest, ModelFalling)
206206
EXPECT_EQ(imuMsgs.back().entity_name(), scopedName);
207207
mutex.unlock();
208208
}
209+
210+
/////////////////////////////////////////////////
211+
// The test checks to make sure orientation is not published if it is deabled
212+
TEST_F(ImuTest, OrientationDisabled)
213+
{
214+
imuMsgs.clear();
215+
216+
// Start server
217+
ServerConfig serverConfig;
218+
const auto sdfFile = common::joinPaths(std::string(PROJECT_SOURCE_PATH),
219+
"test", "worlds", "imu_no_orientation.sdf");
220+
serverConfig.SetSdfFile(sdfFile);
221+
222+
Server server(serverConfig);
223+
EXPECT_FALSE(server.Running());
224+
EXPECT_FALSE(*server.Running(0));
225+
226+
const std::string sensorName = "imu_sensor";
227+
228+
auto topic =
229+
"world/imu_sensor/model/imu_model/link/link/sensor/imu_sensor/imu";
230+
231+
// subscribe to imu topic
232+
transport::Node node;
233+
node.Subscribe(topic, &imuCb);
234+
235+
// step world and verify imu's orientation is not published
236+
// Run server
237+
size_t iters200 = 200u;
238+
server.Run(true, iters200, false);
239+
240+
// Check we received messages
241+
EXPECT_GT(imuMsgs.size(), 0u);
242+
mutex.lock();
243+
for (const auto &msg : imuMsgs)
244+
{
245+
EXPECT_FALSE(msg.has_orientation());
246+
}
247+
mutex.unlock();
248+
}

test/worlds/imu_no_orientation.sdf

+83
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
<?xml version="1.0" ?>
2+
<sdf version="1.6">
3+
<world name="imu_sensor">
4+
<gravity>0 0 -5</gravity>
5+
<physics name="1ms" type="ode">
6+
<max_step_size>0.001</max_step_size>
7+
<real_time_factor>1.0</real_time_factor>
8+
</physics>
9+
<plugin
10+
filename="ignition-gazebo-physics-system"
11+
name="ignition::gazebo::systems::Physics">
12+
</plugin>
13+
<plugin
14+
filename="ignition-gazebo-imu-system"
15+
name="ignition::gazebo::systems::Imu">
16+
</plugin>
17+
18+
<model name="ground_plane">
19+
<static>true</static>
20+
<link name="link">
21+
<collision name="collision">
22+
<geometry>
23+
<plane>
24+
<normal>0 0 1</normal>
25+
<size>100 100</size>
26+
</plane>
27+
</geometry>
28+
</collision>
29+
<visual name="visual">
30+
<geometry>
31+
<plane>
32+
<normal>0 0 1</normal>
33+
<size>100 100</size>
34+
</plane>
35+
</geometry>
36+
<material>
37+
<ambient>0.8 0.8 0.8 1</ambient>
38+
<diffuse>0.8 0.8 0.8 1</diffuse>
39+
<specular>0.8 0.8 0.8 1</specular>
40+
</material>
41+
</visual>
42+
</link>
43+
</model>
44+
45+
<model name="imu_model">
46+
<pose>4 0 3.0 0 0.0 3.14</pose>
47+
<link name="link">
48+
<pose>0.05 0.05 0.05 0 0 0</pose>
49+
<inertial>
50+
<mass>0.1</mass>
51+
<inertia>
52+
<ixx>0.000166667</ixx>
53+
<iyy>0.000166667</iyy>
54+
<izz>0.000166667</izz>
55+
</inertia>
56+
</inertial>
57+
<collision name="collision">
58+
<geometry>
59+
<box>
60+
<size>0.1 0.1 0.1</size>
61+
</box>
62+
</geometry>
63+
</collision>
64+
<visual name="visual">
65+
<geometry>
66+
<box>
67+
<size>0.1 0.1 0.1</size>
68+
</box>
69+
</geometry>
70+
</visual>
71+
<sensor name="imu_sensor" type="imu">
72+
<always_on>1</always_on>
73+
<update_rate>30</update_rate>
74+
<visualize>true</visualize>
75+
<imu>
76+
<enable_orientation>false</enable_orientation>
77+
</imu>
78+
</sensor>
79+
</link>
80+
</model>
81+
82+
</world>
83+
</sdf>

0 commit comments

Comments
 (0)