-
Notifications
You must be signed in to change notification settings - Fork 238
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Why is Sonar disabled in the code? #233
Comments
@OleIdole |
@ROBOTIS-Will Thanks in advance. |
I continued fault-finding on the issue and managed to read the sonar data. Turns out I got it working a couple of days ago by enabling the code that was disabled for sonar in the Turtlebot3 code. But I didn't see that it worked because when I launched the node, nothing was in the range of the ultrasonic sensor, which resulted in no echo. And with the current code, this seems to wait a full second before the signal is counted as not returned/lost. The problem is that the sonar is requested to ping many times every second, and with no object in range, this will clog up a buffer where messages are sent only once a second. It works fine if I launch the node with something within distance. So the issue I started is considered solved! My next focus now will be to find some way of handling the buffer where it doesn't store old information and doesn't wait a full second for each signal that isn't returned. Thank you for helping. |
Hi @OleIdole. |
@TThetier I solved it by replacing the ping implementation with functionality from the NewPing library, which only waits for as long as the sensor can possibly take to return a ping. E.g. if the sensor is capable of measuring up to 2 meters, then the roundtrip time is approximately 0.12 seconds for max distance. We don't need to wait longer after that, because the sensor is not capable of further distances. That is what the NewPing library uses to determine its max wait time. Implementing it solved all issues of measurements clogging up. To implement it, download the NewPing library, include it in turtlebot3_sensor.cpp and replace existing sonar ping function with the one from NewPing. You also need to uncomment the sonar functions in turtlebot3_core.ino as the code will not call and include sonar in its range scans otherwise. |
Hey :) I had the same problem with no sensor output oft he sonar either and was able to fix it just at the moment, but on a different way than Oleldole did.
I set every make_pulse and get_duration == TRUE. So this is how my code looks like: (the part with the Sonar) void Turtlebot3Sensor::initSonar(void) pinMode(sonar_pin_.trig, OUTPUT); void Turtlebot3Sensor::updateSonar(uint32_t t) float distance, duration; if (make_pulse == TRUE) if (get_duration == TRUE)
} sonar_data_ = distance; float Turtlebot3Sensor::getSonarData(void) distance1 = sonar_data_; return distance1; I am kind of new to this whole ros thing and programming at all - so feel free to give some advice how the time part did work :) I just decided to replace it by some code I understand and it works out fine for me:p Now I am going to add a couple more sonars to my robot. When I figured out how to change the code I will let you know! Have a nice day! |
I got it work now with multiple sensors. Maybe its not the most elegant solution but it was kind of easy for me to implement it. I did copy the whole Sonar Part (initSonar, updateSonar, getSonarDate) and changed all variables for sonar 1 to ...1, for Sonar 2 to ...2 and so on. With my solution you won't be able to see all the distances objects have from the sonar. I decided to set a min function to define the getSonarData: distance = (std::min)(sonar_data_1, sonar_data_2); As I already said I am not familiar to programming at all so there might be a more elegant way to solve this problem :) Although I decided to share mine with you guys as it is working and I could not find a solution to this in the internet. This is how my sensor.cpp looks with 2 sensors (I am going to add some more): // code for sensor 1 void Turtlebot3Sensor::initSonar1(void) pinMode(sonar_pin_.trig1, OUTPUT); void Turtlebot3Sensor::updateSonar1(void) float distance1, duration1; if (make_pulse1 == TRUE) if (get_duration1 == TRUE)
} sonar_data_1 = distance1; float Turtlebot3Sensor::getSonarData1(void) distance1 = sonar_data_1; return distance1; //**************************************************************** void Turtlebot3Sensor::initSonar2(void) pinMode(sonar_pin_.trig2, OUTPUT); void Turtlebot3Sensor::updateSonar2(void) float distance2, duration2; if (make_pulse2 == TRUE) if (get_duration2 == TRUE)
} sonar_data_2 = distance2; float Turtlebot3Sensor::getSonarData2(void) distance2 = sonar_data_2; return distance2; //********************************************************************************** float Turtlebot3Sensor::getSonarData(void) distance = (std::min)(sonar_data_1, sonar_data_2); return distance; |
Hi I had the same problem. Please refer to the link below. thanks |
Hi, I need to use a HC-SR04 ultrasonic sensor on Turtlebot3 with ROS. The problem is that the sensor_state node reads sonar distance as 0 constantly. Upon further inspection, I noticed that sensor_state_msg.sonar = sensors.getSonarData() is disabled in turtlebot3_core, it is also disabled in several other sections in the code and marked with // TODO.
I am confused why it is disabled as there are examples in ROS which uses sonar. Is there any old version of the code that has Sonar implemented or a way I can enable it? Or is it simply incomplete?
The text was updated successfully, but these errors were encountered: