[SOLVED] Code Walkthrough - IntelligentObjectAvoider: Two angle questions?

gopigo3
project

#1

(@RobertLucian , )

I’m attempting to walk through the IntelligentObjectAvoider robot project code, and have two questions:

  1. Why is the angle recorded with each distance sample offset toward the vehicle heading?

When collecting samples, the obstacle_finder() function stuffs range samples longer than the distance_trigger (=25 guessing cm) into a sonar_samples list, with an “adjusted” angle value for each sample rotated 90 degrees to be relative to the vehicle heading.

The value saved is not the actual angle (relative to vehicle heading) from which the sample was obtained, but is “adjusted” to be offset by “step degrees” (=10) toward the vehicle heading.

                    servo.rotate_servo(current_servo_position)
                    sleep(servo_delay)
                    distance = distance_sensor.read()
                    current_servo_position += step
                    if distance > distance_trigger:
                        sonar_samples.append([distance, 90 - current_servo_position])
  1. How is angle_to_turn (150) chosen?

When no path is found within the searched sector (120 + 2 * one-half-FOVsensor degrees) centered on the vehicle heading, the vehicle is commanded to turn 150 degrees.

The new DI Distance Sensor based on the VL53L0X Infrared Time Of Flight chip has a stated field of view of 25 degrees, half of which would be 12.5 degrees, meaning the searched area was at best, about 145 degrees.

The name sonar_samples implies this code may have begun life with the ultrasonic distance sensor which has a much wider FOV (something like 60 degrees up close narrowing to 45 degrees around 150 cm). I’m guessing this wider FOV might have covered half the un-searched 60 degree sector in each directed sector scan.

For the new DI Distance Sensor, turning 150 degrees would seem to leave a small sector un-searched, perhaps 10 degrees?

Should the angle_to_turn be different when using the new DI Distance Sensor, like 135, 140, or 145 degrees? (Perhaps this is a “Who cares?” kind of difference. Mainly, I just want to understand what my bot it “thinking” when it is being an “Intelligent” Object Avoider.)


#3

Hi @cyclicalobsessive,

1st Question

Why is the angle recorded with each distance sample offset toward the vehicle heading?

I looked over the code, tested it on mine, and yes, you were right. It didn’t make sense to adjust the servo position before putting it in the queue for further processing. So basically, the robot was off by that step number (10 degrees) all the time.

For this problem and for a couple other I created a PR on GitHub. You can browse it here:

The PR has already been merged, so you can update your code and run the project again with the said changes.

2nd Question

How is angle_to_turn (150) chosen?

This value was chosen empirically. Even though the distance sensor misses a couple of degrees of view due to its smaller FOV, in my tests I noticed that it performs better if I turn the robot by 150 degrees when surrounded by a bunch of obstacles (aka dead end).

And think about it for a second: if it so happens that it misses a couple of degrees, you can always be sure that small FOV will be checked once the robot rotates 150 degrees. Heck, you could even push it to 180 degrees and still be sure that space will be analyzed with the next reading of the distance sensor.


If there are any other questions, please feel free to ask us.

Thank you!


#4

Thanks for the explanation on the angle_to_turn of 150.

Thinking more about this, it might be said to be “intelligent behavior” to skip apriori a “too small to drive the bot through” sector when turning, which brings my “paper guess” turn right inline with your empirical “better performing” turn.

(The code is using a 120 degree scan with a 25 degree FOV sensor, so I would think that a 180 degree turn would leave 35 degrees un-searched. This is thinking too much…)

Thanks for taking the time with me. I am learning a lot about Python, while re-learning the vector and matrix math, and geometry I have not used in 50 years. About time I used that learning.


#5

Hi @cyclicalobsessive,

I’m glad I was of help to you.

Wow, coming back to a passion after 50 years is something.

I will now put a timer on this thread and mark it as solved.

Thank you!


#6

This topic was automatically closed after 42 hours. New replies are no longer allowed.