Make your GoPiGo3 Spin 360, and Show What It "Sees"

I have written an example project Scan360 on github to spin the GoPiGo 360 degrees,
taking Distance Sensor readings as fast as possible,
then printing out the 360 degree view as the GoPiGo3 saw the world.

This example does not use the servo.
(If you have the distance sensor mounted on a servo, center the servo before running the example.)

SPIN 360 AND SCAN at speed=100

Map:                                  90 deg
 ----------------------------------------------------------------------------- 48 cm
|                                                                             |
|                                                                             |
|                                                                             |
|                                                                             |
|                                                 o                           |
|                                                                             |
|                                           o        o                        |
|                            o                                                |
|                        o        o    o                o                     |
|                                    o o                                      |
|                      o                                  o                   |
|                                                                             |
|                                                         o                   |
|                 o                                                           |
|                                                            o                |
|                                                              o              |
|             o                                                               |
|                  o                   +                         o            0  180 deg
|                                                                             |
|                 o                                                o          |
|                                                                             |
|                   o                                                         |
|                     o                                               o       |
|                                                                             |
|                      o                                                      |
|                                            o     o                    o     |
|                       o        o   o                           o            |
|                           o          o   o                                  |
|                                                                             |
|                                                                             |
|                                                                             |
|                                                                             |
|                                                                             |
|                                                                             |
|                                                                             |
 --------------------------------------0-------------------------------------- 48 cm
Each '-' is 1.3 cm      Each '|' is 2.7 cm
Closest Object: 23.5 cm  Farthest Valid Object: 48.1 cm
Farthest Reading: 300.0 cm

It uses the view360() function in the project’s printmaps.py module to display the world.
(I’m going to post a separate topic on the printmaps.py module because it has lots more goodies.)

BTW, I tried using the distance sensor’s continuous mode but got timeout errors.

The read_mm() (EasyDistanceSensor) and read_range_single() (DistanceSensor) seemed to take 60-70ms. The read_range_continuous() with set_continuous(), and no time specified, took 9-11ms but seemed to need a delay of 5ms to ensure not retrieving a reading twice, so it came out to about 16ms.

Example program for timing a single read of the Dexter Industries Distance Sensor.
Distance from object: 291 mm
Timing: 0.053
Distance from object: 296 mm
Timing: 0.067
Distance from object: 295 mm
Timing: 0.068
Distance from object: 299 mm
Timing: 0.068
Distance from object: 292 mm
Timing: 0.067
Distance from object: 295 mm
Timing: 0.068
Distance from object: 291 mm
Timing: 0.068
Distance from object: 294 mm
Timing: 0.068
Distance from object: 294 mm
Timing: 0.067
Distance from object: 292 mm
Timing: 0.069



Example program for timing continuous mode reads of the Dexter Industries Distance Sensor.
Distance from object: 1119 mm
Timing: 0.012
Distance from object: 1118 mm
Timing: 0.010
Distance from object: 1122 mm
Timing: 0.009
Distance from object: 1150 mm
Timing: 0.009
Distance from object: 1146 mm
Timing: 0.009
Distance from object: 1161 mm
Timing: 0.010
Distance from object: 1145 mm
Timing: 0.009
Distance from object: 1136 mm
Timing: 0.009
Distance from object: 1129 mm
Timing: 0.009
Distance from object: 1135 mm
Timing: 0.009

Not sure how to use continuous read mode while spinning the bot. Since the loop is ony:

  • check motors running - get_motor_status()
  • read encoders (maybe can get these values from the motor running check)
  • read distance
  • average encoder readings
  • stuff average into list
  • stuff distance into list

I don’t think the loop could run any faster if it was running in a separate thread.

In either threaded or not, I could use separate right and left encoder lists and calculate the averages after the loop to speed it up a little. Since I have to read the encoders for each reading,
it can only go so fast.

I guess this goes hand in hand with:

I’m wondering if the distance sensor can be made to run faster. @Matt, what do you think?

1 Like