[Turtlebot3] How to increase the publish frequency for the IMU topic
I'm using a TurtleBot3 waffle pi, and it works on ROS2 foxy.
I try to get the acceleration of the turtlebot3, which is contained in the /imu topic, at a higher frequency (about 200Hz). By default, the publish frequency for the /imu topic is around 20Hz (This can be confirmed by running the command "ros2 topic hz /imu").
Is there any way to increase the publish frequency for the /imu topic?
Thanks.
Asked by te26 on 2021-06-12 22:39:38 UTC
Answers
you can increase the queue_size = (your choosen number)
Asked by vishal_bakshi on 2021-06-13 12:20:33 UTC
Comments
Yes, but you'll have to dig into the weeds of the firmware a bit. Trying to give you an answer has been a journey...
IMU update period is seems to be defined here, but if you look at the source of the update function, you'll actually find that INTERVAL_MS_TO_UPDATE_CONTROL_ITEM
goes unused.
So I think you actually need to change either:
- the
_imu.begin()
calls in turtlebot3_sensor.cpp to_imu.begin(200)
to set the sensor update rate to 200Hz, or - change IMU.h to set the default update frequency to 200Hz - oh wait, its already 200 by default... (frustration increases)
That's about as much help as I can offer, without knowing what firmware you are currently running...
Looking at the datasheet for the Turtlebot IMU, you should be able to achieve sampling rates of up to 8000Hz, so if you are asking for 200Hz and only getting 20, I think the OpenCR itself may be a bottleneck or there may be an underlying issue in the firmware (in that case, consider opening an issue.
I'll leave it to you to dig a bit further and see what sort of update rate you can squeeze out.
Asked by shonigmann on 2021-06-14 10:53:55 UTC
Comments
Thanks for your help.
I modified the opencr firmware and was able to upload to turtlebot3 with arduino IDE successfully. However, when I run bringup, I get the following error. I also get this error if I upload the firmware without modifying it.
[turtlebot3_ros-3] terminate called after throwing an instance of 'rclcpp::exceptions::RCLError'
[turtlebot3_ros-3] what(): could not create publisher: rcl node's context is invalid, at /tmp/binarydeb/ros-foxy-rcl-1.1.11/src/rcl/node.c:441
[ERROR] [turtlebot3_ros-3]: process has died [pid 2402, exit code -6, cmd '/home/ubuntu/turtlebot3_ws/install/turtlebot3_node/lib/turtlebot3_node/turtlebot3_ros -i /dev/ttyACM0 --ros-args --params-file /home/ubuntu/turtlebot3_ws/install/turtlebot3_bringup/share/turtlebot3_bringup/param/waffle_pi.yaml'].
My environments: - ubuntu20.04 - Arduino IDE 1.8.15 - opencr1.4.18 - dynamixel2arduino 0.4.7
Asked by te26 on 2021-06-24 08:02:25 UTC
It seemed difficult to solve this problem, so I used another accelerometer instead. Now, I'm using a mpu6050 connected via i2c to the raspberry pi, and I have an enough sampling frequency.
Asked by te26 on 2021-06-24 08:02:46 UTC
I'm glad you found a solution that worked for you. I believe I have seen the ROS2 bringup error you got; if I recall correctly, in my case it occurred when a) I was using incompatible firmware (e.g. ROS1 firmware with ROS2 running on the Pi), or b) was specifying the wrong USB port (e.g. /dev/ttyACM0 instead of ACM1 or whatever the OpenCR was actually connected to)
Asked by shonigmann on 2021-06-24 11:17:18 UTC
Comments