Problem reading UltraBoard values with threading
Forums:
Hi,
I just start my first python script for my robot (yetiborg with 4 ultrasonic sensors) and thunderborg motor control. My first code test offers a problem when reading the ultraborg values using threads. If I used time-sleep to better check the values readed all worked fine, if commented it, I got reading errors like nonreading , none type values, values with decimals like 567,3275839273747 etc. I added my scriupt and a kind of log, where you can see the errors. Any ideas, what the reason is? Many thx in advance.
One further question. How long measure the ultrasonic im meters? If there are more than I 4 or 5 meter I've got no value? How can I catch this in my script?
regardly
Peter
piborg
Thu, 07/11/2019 - 14:43
Permalink
The reason you see values
The reason you see values with decimals on occasion is because the
readdistance
thread updates the global values twice. This means the other thread can read the value after the first update, but before the second.For example:
Without the sleep this occurs more often, but it will happen occasionally even with the sleep. This can be fixed by only changing the global values once:
in this case the temporary
read_dist
values can only be seen by thereaddistance
thread, not thecontrol
thread.In the
readdistance
thread you can also catch when the values failed to read:This can happen if the UltraBorg failed to respond in time.
The HC-SR04 ultrasonic sensor has a maximum range of 4 meters. The distance returned should be 0 if the sensor did not get a valid reading.
peter.demharter...
Fri, 07/12/2019 - 08:49
Permalink
Your answer
Many thx for your tipps and hints!!!!!! Great.
regardly
Peter
peter.demharter...
Fri, 07/19/2019 - 15:06
Permalink
Hi Ultrasonic doesn't recognize things like chair - legs etc.
Hi,
could it be possibel that the ultrasonic sensor doesn't recognize smaller things like chair legs and so on. I have no problems with wall, stores on the floor.
Many thx
regardly
Peter
piborg
Sat, 07/20/2019 - 13:20
Permalink
Ultrasonic sensors and small objects
You are right, the ultrasonic sensors do struggle with small / narrow objects, especially when they are further away.
From experimenting they also work best when directly facing the flat surface, too much angle and they do not detect things at all :)
peter.demharter...
Mon, 07/22/2019 - 12:03
Permalink
Is there an alternative
Hi
Can you recomment an alternative Which bettet Works?
Peter
piborg
Mon, 07/22/2019 - 13:19
Permalink
Ultrasonic sensor limitations
Unfortunately all ultrasonic sensors have this type of limitation, although some are better than others. Most sensors quote the range they will sense over and the angles they work for, but not how small an object they can detect :(
With small objects you may have more luck with an IR sensor or a LiDAR.
Almost all distance sensors work on signals reflected back, so they will all have some kind of angle limitation for sensing.