Ultrasonic sensor readings always zero
Hello there,
I'm following this link https://github.com/ROBOTIS-GIT/emanual/blob/master/docs/en/platform/turtlebot3/additional_sensors.md#Ultrasonic to add an Ultrasonic sensor HC-SR04 to my turtlebot3, burger model.
I installed the sensor, supplying it from the RaspberryPi 5V DCout and the Trigger and Echo pins respectively on the #3 and #4 OpenCR pins.
I'm using ROS melodic distribution: Ubuntu 19.04 in my machine, and Ubuntu 18.04 in the burger bot.
I'm using the following steps to launch the robot sonar example:
On the robot: roslaunch turtlebot3bringup turtlebot3robot.launch to initialize the robot;
On the robot: roslaunch turtlebot3example turtlebot3sonar.launch to initialize the sonar node.
When I get to "rostopic echo /sensor_state", all the measures from the Sonar sensor are bringing the zero value. I've already checked the pins and ports, and tested the sensor using an Arduino, so it's not broken.
Output from the rostopic echo:
header:
seq: 17497
stamp:
secs: 1583759548
nsecs: 226024932
frame_id: ''
bumper: 2
cliff: 92.0
sonar: 0.0
illumination: 642.0
led: 0
button: 0
torque: True
left_encoder: 3392
right_encoder: 1328
battery: 12.1099996567
---
header:
seq: 17498
stamp:
secs: 1583759548
nsecs: 258024932
frame_id: ''
bumper: 2
cliff: 92.0
sonar: 0.0
illumination: 620.0
led: 0
button: 0
torque: True
left_encoder: 3392
right_encoder: 1328
battery: 12.1499996185
Although Cliff and Ilumination values are non-zero, I'm not using any of these sensors.
How can I properly read the Ultrasonic sensor? I'm first trying to run the turtlebot3_sonar script, which only publishes a movement command to the robot if the distance measured is above certain valor, but unable to make it move due to the readings always being 0.
These are my ROS environment variables:
ROS_VERSION=1
ROS_PYTHON_VERSION=2
ROS_PACKAGE_PATH= omitted due to being too large :P
ROSLISP_PACKAGE_DIRECTORIES= same as above
ROS_ETC_DIR=/home/myuser/ros_catkin_ws/devel_isolated/ros_environment/etc/ros
ROSCONSOLE_CONFIG_FILE=/home/myuser/ros_catkin_ws/src/rosconsole/config/rosconsole.config
ROS_MASTER_URI=http://myrobot:11311
ROS_HOSTNAME=myrobot
ROS_ROOT=/home/myuser/ros_catkin_ws/src/ros/rosbuild
ROS_DISTRO=melodic
Thanks!
Asked by matheus on 2020-03-09 08:16:13 UTC
Answers
Hi, I'm facing a very similar issue, where the sonar always reads 0.0, then a few sequences later it does spit out a proper range. This is running ROS on noetic though.
Here is a good approach to troubleshoot the issue:
Assuming you're using the OpenCR 1.0 board. Connect it directly to development PC via USB (make sure it is a data-USB cable and not just charging).
Load the Arduino example file for Sonar found under: Examples -> ROS -> 02. Sensors -> c_Ultrasonic Open Serial Terminal and check the sonar sensors works as expected. If not troubleshoot your wiring / example program config.
modify the turtlebot3 program (I used turtlebot3_core). In the turtlebot3_core.ino around line 144 make sure to uncomment the
// TODO
// Update sonar data
// sensors.updateSonar(t);
After that it should work. Well at least intermittent as in my case. I'm still working on getting that resolved. I hope this will help someone and I will update if I find out more
Asked by USAotearoa on 2021-12-11 15:33:21 UTC
Comments