Skip to content

Commit 99fa4a1

Browse files
authored
Fix inertial unit readings (#215)
* Update imu_device.py * Add inertial unit to TurtleBot3 * Update turtlebot3_burger_example.wbt * Fix orientation
1 parent d0f772b commit 99fa4a1

File tree

3 files changed

+17
-8
lines changed

3 files changed

+17
-8
lines changed

webots_ros2_core/webots_ros2_core/devices/imu_device.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,10 +87,11 @@ def step(self):
8787
msg.angular_velocity.y = interpolate_lookup_table(raw_data[1], self.__gyro.getLookupTable())
8888
msg.angular_velocity.z = interpolate_lookup_table(raw_data[2], self.__gyro.getLookupTable())
8989
if self.__inertial_unit:
90-
raw_data = self.__inertial_unit.getValues()
91-
msg.orientation.x = interpolate_lookup_table(raw_data[0], self.__inertial_unit.getLookupTable())
92-
msg.orientation.y = interpolate_lookup_table(raw_data[1], self.__inertial_unit.getLookupTable())
93-
msg.orientation.z = interpolate_lookup_table(raw_data[2], self.__inertial_unit.getLookupTable())
90+
raw_data = self.__inertial_unit.getQuaternion()
91+
msg.orientation.x = raw_data[0]
92+
msg.orientation.y = raw_data[1]
93+
msg.orientation.z = raw_data[2]
94+
msg.orientation.w = raw_data[3]
9495
self._publisher.publish(msg)
9596
else:
9697
self.__disable_imu()

webots_ros2_turtlebot/webots_ros2_turtlebot/turtlebot_driver.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ def __init__(self, args):
3434
self.start_device_manager({
3535
'robot': {'publish_base_footprint': True},
3636
'LDS-01': {'topic_name': '/scan'},
37-
'accelerometer+gyro': {'frame_id': 'imu_link', 'topic_name': '/imu'}
37+
'inertial_unit+accelerometer+gyro': {'frame_id': 'imu_link', 'topic_name': '/imu'}
3838
})
3939

4040

webots_ros2_turtlebot/worlds/turtlebot3_burger_example.wbt

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
#VRML_SIM R2020b utf8
1+
#VRML_SIM R2021a utf8
22
WorldInfo {
33
info [
44
"Simple TurtleBot3 Burger simulation that can be controlled by a ROS."
55
]
66
title "ROS2 simulation of the TurtleBot3 Burger robot"
77
}
88
Viewpoint {
9-
orientation 0.10641236421720016 -0.25207787332085546 -0.9618384243331832 2.039170527287739
10-
position -3.8306574674676366 4.499047968479621 23.02378266720472
9+
orientation -0.1500994671353544 -0.4810853207937876 -0.8637285824160397 3.5119475446104667
10+
position 9.974034902718383 6.242698326848728 4.5715004345304
1111
follow "TurtleBot3Burger:LDS-01"
1212
}
1313
TexturedBackground {
@@ -21,6 +21,14 @@ TurtleBot3Burger_enu {
2121
controllerArgs [
2222
""
2323
]
24+
extensionSlot [
25+
InertialUnit {
26+
rotation 0 1 0 3.14
27+
name "inertial_unit"
28+
}
29+
RobotisLds01 {
30+
}
31+
]
2432
}
2533
PottedTree {
2634
translation 7 -4 0

0 commit comments

Comments
 (0)