Carl has implemented the “simpler algorithm” in his slightly obtuse fashion, always learning new things about Python
(How to wait until finished speaking his mind, and also how to walk and talk at the same time.)
pi@Carl:~/Carl/Projects/WallFollowing $ ./guardwall.py
2022-03-23 12:17:45,663 main: ==== GUARD WALL ====
2022-03-23 12:17:45,664 main: Point me along a wall on my right side, about 20 cm away please
2022-03-23 12:17:51,676 init_robot: Created EasyGoPiGo3 with Distance Sensor on Pan Servo
2022-03-23 12:17:56,270 main: OUTA MY WAY! I'm goin' till I can't
2022-03-23 12:18:01,862 follow_wall: distance reading: 21.9 cm
2022-03-23 12:18:01,862 follow_wall: too close
2022-03-23 12:18:02,046 follow_wall: distance reading: 22.3 cm, steering value: -0.09
2022-03-23 12:18:02,096 follow_wall: too close
2022-03-23 12:18:02,269 follow_wall: distance reading: 22.9 cm, steering value: -0.08
2022-03-23 12:18:02,320 follow_wall: too close
2022-03-23 12:18:02,503 follow_wall: distance reading: 25.7 cm, steering value: -0.07
2022-03-23 12:18:02,554 follow_wall: too close
2022-03-23 12:18:02,730 follow_wall: distance reading: 28.1 cm, steering value: -0.02
2022-03-23 12:18:02,781 follow_wall: too far
2022-03-23 12:18:02,961 follow_wall: distance reading: 28.9 cm, steering value: 0.02
2022-03-23 12:18:03,011 follow_wall: too far
2022-03-23 12:18:03,190 follow_wall: distance reading: 28.8 cm, steering value: 0.04
2022-03-23 12:18:03,241 follow_wall: too far
2022-03-23 12:18:03,428 follow_wall: distance reading: 28.4 cm, steering value: 0.04
2022-03-23 12:18:03,479 follow_wall: too far
2022-03-23 12:18:03,657 follow_wall: distance reading: 26.8 cm, steering value: 0.03
2022-03-23 12:18:03,708 follow_wall: too close
2022-03-23 12:18:03,883 follow_wall: distance reading: 26.9 cm, steering value: -0.00
2022-03-23 12:18:03,934 follow_wall: too far
2022-03-23 12:18:04,109 follow_wall: distance reading: 28.0 cm, steering value: 0.00
2022-03-23 12:18:04,160 follow_wall: too far
2022-03-23 12:18:04,358 follow_wall: distance reading: 28.0 cm, steering value: 0.02
2022-03-23 12:18:04,409 follow_wall: too far
2022-03-23 12:18:04,584 follow_wall: distance reading: 27.9 cm, steering value: 0.02
2022-03-23 12:18:04,634 follow_wall: too far
2022-03-23 12:18:04,809 follow_wall: distance reading: 28.2 cm, steering value: 0.02
2022-03-23 12:18:04,860 follow_wall: too far
2022-03-23 12:18:05,038 follow_wall: distance reading: 27.8 cm, steering value: 0.02
2022-03-23 12:18:05,089 follow_wall: too far
2022-03-23 12:18:05,274 follow_wall: distance reading: 27.5 cm, steering value: 0.02
2022-03-23 12:18:05,325 follow_wall: too far
2022-03-23 12:18:05,501 follow_wall: distance reading: 26.6 cm, steering value: 0.01
2022-03-23 12:18:05,551 follow_wall: too close
2022-03-23 12:18:05,727 follow_wall: distance reading: 26.5 cm, steering value: -0.00
2022-03-23 12:18:05,777 follow_wall: too close
2022-03-23 12:18:05,955 follow_wall: distance reading: 25.1 cm, steering value: -0.01
2022-03-23 12:18:06,005 follow_wall: too close
2022-03-23 12:18:06,192 follow_wall: distance reading: 24.4 cm, steering value: -0.03
2022-03-23 12:18:06,242 follow_wall: too close
2022-03-23 12:18:06,417 follow_wall: distance reading: 26.5 cm, steering value: -0.05
2022-03-23 12:18:06,468 follow_wall: too close
2022-03-23 12:18:06,619 follow_wall: distance reading: 300.0 cm, steering value: -0.01
2022-03-23 12:18:06,669 follow_wall: TERMINATED
2022-03-23 12:18:07,948 follow_wall: Traveled 81.0 cm following wall
2022-03-23 12:18:13,161 follow_wall: NO WALL
2022-03-23 12:18:17,481 safe_turn: TURNING AROUND
2022-03-23 12:18:20,914 main: OUTA MY WAY! I'm goin' to the other end of this wall
2022-03-23 12:18:27,164 follow_wall: distance reading: 25.9 cm
2022-03-23 12:18:27,165 follow_wall: too close
2022-03-23 12:18:27,349 follow_wall: distance reading: 26.4 cm, steering value: -0.02
2022-03-23 12:18:27,399 follow_wall: too close
2022-03-23 12:18:27,577 follow_wall: distance reading: 28.1 cm, steering value: -0.01
2022-03-23 12:18:27,628 follow_wall: too far
2022-03-23 12:18:27,804 follow_wall: distance reading: 28.5 cm, steering value: 0.02
2022-03-23 12:18:27,855 follow_wall: too far
2022-03-23 12:18:28,037 follow_wall: distance reading: 28.1 cm, steering value: 0.03
2022-03-23 12:18:28,088 follow_wall: too far
2022-03-23 12:18:28,263 follow_wall: distance reading: 29.2 cm, steering value: 0.02
2022-03-23 12:18:28,313 follow_wall: too far
2022-03-23 12:18:28,487 follow_wall: distance reading: 28.1 cm, steering value: 0.04
2022-03-23 12:18:28,538 follow_wall: too far
2022-03-23 12:18:28,717 follow_wall: distance reading: 27.3 cm, steering value: 0.02
2022-03-23 12:18:28,768 follow_wall: too far
2022-03-23 12:18:28,950 follow_wall: distance reading: 25.9 cm, steering value: 0.01
2022-03-23 12:18:29,001 follow_wall: too close
2022-03-23 12:18:29,182 follow_wall: distance reading: 25.2 cm, steering value: -0.02
2022-03-23 12:18:29,233 follow_wall: too close
2022-03-23 12:18:29,415 follow_wall: distance reading: 27.5 cm, steering value: -0.03
2022-03-23 12:18:29,465 follow_wall: too far
2022-03-23 12:18:29,648 follow_wall: distance reading: 27.8 cm, steering value: 0.01
2022-03-23 12:18:29,699 follow_wall: too far
2022-03-23 12:18:29,873 follow_wall: distance reading: 27.4 cm, steering value: 0.02
2022-03-23 12:18:29,924 follow_wall: too far
2022-03-23 12:18:30,098 follow_wall: distance reading: 27.0 cm, steering value: 0.01
2022-03-23 12:18:30,148 follow_wall: too far
2022-03-23 12:18:30,331 follow_wall: distance reading: 26.7 cm, steering value: 0.00
2022-03-23 12:18:30,381 follow_wall: too close
2022-03-23 12:18:30,554 follow_wall: distance reading: 26.5 cm, steering value: -0.00
2022-03-23 12:18:30,604 follow_wall: too close
2022-03-23 12:18:30,780 follow_wall: distance reading: 26.9 cm, steering value: -0.01
2022-03-23 12:18:30,830 follow_wall: too far
2022-03-23 12:18:31,005 follow_wall: distance reading: 27.0 cm, steering value: 0.00
2022-03-23 12:18:31,056 follow_wall: too far
2022-03-23 12:18:31,238 follow_wall: distance reading: 26.8 cm, steering value: 0.00
2022-03-23 12:18:31,289 follow_wall: too close
2022-03-23 12:18:31,462 follow_wall: distance reading: 24.9 cm, steering value: -0.00
2022-03-23 12:18:31,512 follow_wall: too close
2022-03-23 12:18:31,687 follow_wall: distance reading: 19.8 cm, steering value: -0.04
2022-03-23 12:18:31,738 follow_wall: too close
2022-03-23 12:18:31,927 follow_wall: distance reading: 12.3 cm, steering value: -0.13
2022-03-23 12:18:31,979 follow_wall: TERMINATED
2022-03-23 12:18:33,300 follow_wall: Traveled 81.1 cm following wall
2022-03-23 12:18:38,419 follow_wall: OBSTACLE OR CORNER
2022-03-23 12:18:41,302 main: wall length about 105.7 cm
2022-03-23 12:18:48,939 backup_for_turning_room: distance reading: 5.2 cm
2022-03-23 12:18:48,940 backup_for_turning_room: BACKING UP 7.5 cm FOR TURNING CLEARANCE
2022-03-23 12:18:54,860 safe_turn: TURNING AROUND
2022-03-23 12:18:58,216 main: OUTA MY WAY! I'm goin' to center of wall
2022-03-23 12:19:04,071 follow_wall: distance reading: 24.6 cm
2022-03-23 12:19:04,072 follow_wall: too close
2022-03-23 12:19:04,263 follow_wall: distance reading: 24.1 cm, steering value: -0.04
2022-03-23 12:19:04,315 follow_wall: too close
2022-03-23 12:19:04,488 follow_wall: distance reading: 24.0 cm, steering value: -0.05
2022-03-23 12:19:04,539 follow_wall: too close
2022-03-23 12:19:04,712 follow_wall: distance reading: 25.2 cm, steering value: -0.05
2022-03-23 12:19:04,764 follow_wall: too close
2022-03-23 12:19:04,943 follow_wall: distance reading: 25.9 cm, steering value: -0.03
2022-03-23 12:19:04,995 follow_wall: too close
2022-03-23 12:19:05,178 follow_wall: distance reading: 26.4 cm, steering value: -0.02
2022-03-23 12:19:05,229 follow_wall: too close
2022-03-23 12:19:05,402 follow_wall: distance reading: 25.9 cm, steering value: -0.01
2022-03-23 12:19:05,453 follow_wall: too close
2022-03-23 12:19:05,628 follow_wall: distance reading: 25.5 cm, steering value: -0.02
2022-03-23 12:19:05,679 follow_wall: too close
2022-03-23 12:19:05,852 follow_wall: distance reading: 25.4 cm, steering value: -0.03
2022-03-23 12:19:05,903 follow_wall: too close
2022-03-23 12:19:06,088 follow_wall: distance reading: 27.4 cm, steering value: -0.03
2022-03-23 12:19:06,139 follow_wall: too far
2022-03-23 12:19:06,313 follow_wall: distance reading: 27.6 cm, steering value: 0.01
2022-03-23 12:19:06,364 follow_wall: TERMINATED
2022-03-23 12:19:07,646 follow_wall: Traveled 38.7 cm following wall
2022-03-23 12:19:11,959 follow_wall: travel limit of 34 cm reached
2022-03-23 12:19:15,363 main: TURNING TO GUARD WALL
2022-03-23 12:19:19,856 safe_turn: TURNING 90 DEGREES
2022-03-23 12:19:24,075 main: ==== NOBODY BETTER MESS WITH ME NOW ====
"""
FILE: wallfollowing.py
REF: https://www.youtube.com/watch?v=UhquY0m7qic
This module provides wall following based on 45 degree angle sensor readings::
Zones: 1) Corner or Obstacle (sensor readings less than 70% of desired)
2) Closer to Wall than desired, (sensor readings 70-100% of desired)
3) Farther From Wall than desired, (sensor readings 101-150% of desired)
4) Very Far From Wall (sensor reading greater than 150% of desired)
Starting Conditions:
1) Roughly aligned parallel to wall
2) Roughly spaced from wall by 19 cm
Target wall following path is 19 cm from wall
to allow clearance behind the robot to turn away from wall 90 or 180 degrees
Turning circle radius is roughly 16.5 cm. Allowing an extra 2.5 cm for baseboards.
Wall |
| <------- sensor
|
Baseboard |\
| | <--- robot's rear chassis
Floor |_|______________________________
Stopping Conditions (Diagonal Wall Following Distance = 27 cm):
- No Wall: Distance reading > 1.5 x Diagonal Distance (approx 40 cm)
- No Wall: Distance reading jumps up by 20% of Diagonal Distance (approx 5 cm)
- Obstacle or Corner: Distance Reading is less than 70% Diagonal Distance (19cm)
Control Algorithm - percent_error = ((reading - desired) / desired):
- Set inside wheel proportional to error (1-percent_error/2)
- Set outside wheel proportional to error (1+percent_error/2)
- Too Close: percent_error will be negative (inside wheel speeds up, outside slows)
- Too Far: percent_error will be positive (inside wheel slows down, outside speeds up)
- percent error allowed to vary in range from -50% to +50% of Diagonal Distance
Note: Only uses stock GoPiGo3 APIs
Pan Servo plugged into Servo1
WALL FOLLOWING MODULE API:
- wallfollowing.init_robot() # returns EasyGoPiGo3 object (with .pan and .ds attached objects)
- wallfollowing.safe_turn(egpg, angle) # will backup if needed to safely turn around
- wallfollowing.follow_wall(egpg, right0_left1=0, travel_limit_cm=0) # follow left or right wall
# returns distance traveled
- wallfollowing.wall_length_from_dist_traveled(egpg,dist_cm) # estimate wall length from travel
- wallfollowing.say(phrase,blocking=True) # speak phrase using espeak-ng, converts mm and cm
- wallfollowing.ps_off(egpg) # disables pan servo to conserve battery and allow free rotation
"""
Code and examples/test programs are here
Bring to your machine with:
wallfollowing.py module:
wget https://raw.githubusercontent.com/slowrunner/Carl/master/Projects/WallFollowing/wallfollowing.py
test wallfollowing.follow_wall with “Measure wall and take up guard position at center of wall”:
wget https://raw.githubusercontent.com/slowrunner/Carl/master/Projects/WallFollowing/guardwall.py
test all wallfollowing API functions by measuring a wall:
wget https://raw.githubusercontent.com/slowrunner/Carl/master/Projects/WallFollowing/measure_wall.py
test wallfollowing.safe_turn():
wget https://raw.githubusercontent.com/slowrunner/Carl/master/Projects/WallFollowing/safe_turn_test.py
test wallfollowing.say():
wget https://raw.githubusercontent.com/slowrunner/Carl/master/Projects/WallFollowing/testsay.py