ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | Q&A answers.ros.org
Ask Your Question
0

Ultrasonic sensor readings always zero

asked 2020-03-09 08:17:35 -0600

matheus gravatar image

Hello there,

I'm following this link https://github.com/ROBOTIS-GIT/emanua... 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 turtlebot3_bringup turtlebot3_robot.launch to initialize the robot;

On the robot: roslaunch turtlebot3_example turtlebot3_sonar.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!

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2021-12-11 14:33:21 -0600

USAotearoa gravatar image

updated 2021-12-11 14:37:22 -0600

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:

  1. 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).

  2. 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.

  3. 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

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

Stats

Asked: 2020-03-09 08:16:13 -0600

Seen: 545 times

Last updated: Dec 11 '21