üApp: picar-s: speed estimation from ultrasonic sensor

This task will do speed estimatin from ultrasonic sensor.

We know we are moving along a line with constant speed. We measure distance from ultrasonic sensor and we know by difference the speed of the car.

We need to do the following tasks

  1. Filter the sensor inputs so that we get a baseline from the ultrasonic sensor
  2. develop an algorithm that estimates the speed from this
  3. integrate this algorithm into the bangbang-integrated controller



I collected some data from a similiar run in the video shown. The speed measurement, imo, is not very reliable in this case. The car gradually reduce its speed as it approaches the object. I am using datetime library to get the system time in milliseconds to calculate speed using simple equation v=d/t. I appreciate any suggestion from you guys.

Hmmm…are there other timing services that you can use within python?

I used time.time() and its even worse, stackoverflow says datetime is a more reliable source. Also this method requires the object being present in the front contantly, any turn will result in that spike in the graph and result in some weird readings. Also, the distance reading is the average of 5 measurements, I will experiment that tomorrow see if that helps.

Now this looks a lot better, the speed is calculated based on distance while following a line controled by my hands, but there is a spike that I was not expecting. Generally looks decent. flat line is around 40cm/s

Ahh so it was as @raffromagno suspected. The turning of the car caused it to miss some of the ultrasonic wave pulses on return?

I manually directed the car so it should not miss the box, but I tried a dozen of times and this spike ALWAYS happened. If I can see the waveform of that sensor I think I might have a better understanding, might go to school and use an ocillioscope

@amitvasudevan @antonhristozov
Hi, sorry for not informing you guys here, I have made the pull request yesterday. Please check it when you have time. Thank you very much.

Hi @Arbalest1027 ,

Yeah, we usually plug in the PR within the forum thread and go from there. I have updated the OP to include the PR information, so that should be fine.

Let us wait for @antonhristozov , to give this a test.


1 Like

Hi, @amitvasudevan @raffromagno @antonhristozov
I was preparing for an interview last week so not getting many updates. I have currently started the process of converting the code to C++ as we mentioned from the previous meeting. It would be great if @antonhristozov could test my code and send some data back so I can fix some issues.

Thank you

@antonhristozov : Do you think you can give this a whirl?

Provide the pull request link.

It is already linked in the OP.

Which folder do we need to test?
is this the folder SensorIntegration_sonic_linefollowing ?

It should be a folder called speed_test, the code is called speed_regulator.py inside that folder.

There is no speed_test folder in uonjcoll branch:

git branch

  • uobjcoll
    (base) anton@anton-Precision-7720:~/uberwork/uapp-SunFounder_PiCar-S/example$ ls -l
    total 88
    drwxrwxr-x 3 anton anton 4096 Jul 26 14:30 bangbang_shared
    -rw-rw-r-- 1 anton anton 784 Jun 2 09:23 calibrate.py
    -rw-rw-r-- 1 anton anton 75 Jun 2 09:23 config
    drwxrwxr-x 2 anton anton 4096 Jun 2 09:23 imu_velocity
    -rw-rw-r-- 1 anton anton 0 Jun 2 09:20 init.py
    -rw-rw-r-- 1 anton anton 2817 Jun 2 09:20 light_follower.py
    -rw-rw-r-- 1 anton anton 4390 Jun 2 09:20 light_with_obsavoidance.py
    -rw-rw-r-- 1 anton anton 5573 Jun 2 09:23 line_follower_clib.py
    -rw-rw-r-- 1 anton anton 3712 Jun 2 09:23 line_follower.py
    -rw-rw-r-- 1 anton anton 1232 Jun 2 09:23 Performance.md
    -rw-rw-r-- 1 anton anton 767 Jun 2 09:23 Performance_Test.py
    lrwxrwxrwx 1 anton anton 29 Jun 2 09:23 picar → …/…/SunFounder_PiCar/picar/
    drwxrwxr-x 2 anton anton 4096 Jun 2 09:23 pid_kalmaan
    drwxrwxr-x 2 anton anton 4096 Jun 4 09:27 pid_shared
    -rw-rw-r-- 1 anton anton 2089 Jun 2 09:23 README.md
    drwxrwxr-x 2 anton anton 4096 Jul 26 12:51 SensorIntegration_sonic_linefollowing
    drwxrwxr-x 2 anton anton 4096 Jun 2 09:20 SunFounder_Light_Follower
    lrwxrwxrwx 1 anton anton 58 Jun 2 09:23 SunFounder_Line_Follower → …/…/SunFounder_PiCar-S/example/SunFounder_Line_Follower/
    drwxrwxr-x 2 anton anton 4096 Jun 2 09:20 SunFounder_Ultrasonic_Avoidance
    -rw-rw-r-- 1 anton anton 380 Jun 2 09:20 test_light_module.py
    -rw-rw-r-- 1 anton anton 191 Jun 2 09:20 test_line_module.py
    -rw-rw-r-- 1 anton anton 507 Jun 2 09:20 test_ultrasonic_module.py
    -rw-rw-r-- 1 anton anton 2558 Jun 2 09:20 ultra_sonic_avoid.py

Did you checkout the PR @antonhristozov ? It wont be on uobjcoll branch since its not merged yet…

I asked specifically for the PR URL already.

Here is the link