Carl Is Learning To Follow Walls

Carl managed to learn to follow walls today. The algorithm is fragile, such as when the “too close” corrections drive the heading too much away from parallel to the wall, Carl falsely thinks the wall ended. Additionally, Carl kept seeing I2C errors:

2022-03-17 12:11:17,849 follow_wall: NO WALL
[Errno 121] I2C transfer: Remote I/O error
[Errno 121] I2C transfer: Remote I/O error
[Errno 121] I2C transfer: Remote I/O error
...
[Errno 121] I2C transfer: Remote I/O error
[Errno 121] I2C transfer: Remote I/O error
2022-03-17 12:11:24,033 backup_for_turning_room: BACKING UP 3.0 INCHES FOR TURNING CLEARANCE
2 Likes

I think he’s done bloody well mate!

Translation: “Like a Boss!”

For a “fragile” script, he’s doing damned well.  Huge kudos!

2 Likes

Wow - that’s great. Sure you’ll want to clean up loose ends. But agree with @jimrh - “Like a boss”.

Although if it were me I would have backed up 1.623 inches just for a little more breathing room :slight_smile:

I love the text to speech - great way to monitor progress.

/K

2 Likes

Actually, everytime I think about wall following, I come up with a different wall following algorithm that sounds better than the one I tried first.

This algorithm:

  • read (single) diagonal distance to wall
  • if diagonal distance indicates loss of wall, a wall corner, or obstacle in path - exit
  • if diagonal distance to wall is low, increase inside wheel speed (arc away from wall)
  • if diagonal distance to wall is high, decrease inside wheel speed (arc toward wall)
  • if in-zone travel straight
  • loop every 0.1s

is not good because the correction continues to increase as the bot gets closer to the desired causing the bot heading to be “highly cross zone” when in the zone.

Additionally because the bot does not compute its orientation to the wall, it is only correcting one of the two desired parameters {orientation parallel to wall, distance from wall}.

From the logging I can see that for the initial wall-on-the-right-follow, it was “in zone” around 1.5 seconds the first time, and about 2 seconds the second time. The algorithm might be converging on parallel wall following but not fast and the increasing bias as it approaches “in zone” is the opposite of what is desired to maximize the in-zone travel.

pi@Carl:~/Carl/Projects/WallFollowing $ ./test.py
2022-03-17 12:16:39,083 main: ==== WALL FOLLOWING ====
2022-03-17 12:16:39,084 main: Point me along a wall on my right side please
2022-03-17 12:16:53,844 main: OUTA MY WAY! I'm goin' till I can't
2022-03-17 12:16:57,380 follow_wall: distance reading: 9.8
2022-03-17 12:16:57,381 follow_wall: too close
2022-03-17 12:16:58,833 follow_wall: distance reading: 9.8 inside wheel bias: 0.75
2022-03-17 12:16:58,934 follow_wall: too close
2022-03-17 12:16:59,106 follow_wall: distance reading: 9.8 inside wheel bias: 1.5
2022-03-17 12:16:59,207 follow_wall: too close
2022-03-17 12:16:59,378 follow_wall: distance reading: 9.8 inside wheel bias: 2.25
2022-03-17 12:16:59,479 follow_wall: too close
2022-03-17 12:16:59,653 follow_wall: distance reading: 9.8 inside wheel bias: 3.0
2022-03-17 12:16:59,753 follow_wall: too close
2022-03-17 12:16:59,926 follow_wall: distance reading: 10.2 inside wheel bias: 3.75
2022-03-17 12:17:00,026 follow_wall: too close
2022-03-17 12:17:00,198 follow_wall: distance reading: 10.6 inside wheel bias: 4.5
2022-03-17 12:17:00,298 follow_wall: too close
2022-03-17 12:17:00,470 follow_wall: distance reading: 10.6 inside wheel bias: 5.25
2022-03-17 12:17:00,570 follow_wall: too close
2022-03-17 12:17:00,743 follow_wall: distance reading: 10.6 inside wheel bias: 6.0
2022-03-17 12:17:00,843 follow_wall: too close
2022-03-17 12:17:01,016 follow_wall: distance reading: 10.6 inside wheel bias: 6.75
2022-03-17 12:17:01,116 follow_wall: too close
2022-03-17 12:17:01,296 follow_wall: distance reading: 11.0 inside wheel bias: 7.5
2022-03-17 12:17:01,397 follow_wall: in zone       <<<<====== IN ZONE
2022-03-17 12:17:02,697 follow_wall: distance reading: 11.8 inside wheel bias: 0
2022-03-17 12:17:02,798 follow_wall: too far
2022-03-17 12:17:02,995 follow_wall: distance reading: 12.2 inside wheel bias: -0.75
2022-03-17 12:17:03,096 follow_wall: too far
2022-03-17 12:17:03,281 follow_wall: distance reading: 12.6 inside wheel bias: -1.5
2022-03-17 12:17:03,382 follow_wall: too far
2022-03-17 12:17:03,562 follow_wall: distance reading: 12.6 inside wheel bias: -2.25
2022-03-17 12:17:03,663 follow_wall: too far
2022-03-17 12:17:03,838 follow_wall: distance reading: 12.6 inside wheel bias: -3.0
2022-03-17 12:17:03,938 follow_wall: too far
2022-03-17 12:17:04,119 follow_wall: distance reading: 12.6 inside wheel bias: -3.75
2022-03-17 12:17:04,223 follow_wall: too far
2022-03-17 12:17:04,398 follow_wall: distance reading: 12.6 inside wheel bias: -4.5
2022-03-17 12:17:04,498 follow_wall: too far
2022-03-17 12:17:04,673 follow_wall: distance reading: 12.6 inside wheel bias: -5.25
2022-03-17 12:17:04,774 follow_wall: too far
2022-03-17 12:17:04,948 follow_wall: distance reading: 12.6 inside wheel bias: -6.0
2022-03-17 12:17:05,048 follow_wall: too far
2022-03-17 12:17:05,230 follow_wall: distance reading: 12.2 inside wheel bias: -6.75
2022-03-17 12:17:05,331 follow_wall: too far
2022-03-17 12:17:06,725 follow_wall: distance reading: 11.0 inside wheel bias: -7.5
2022-03-17 12:17:06,825 follow_wall: in zone       <<<<====== IN ZONE
2022-03-17 12:17:06,999 follow_wall: distance reading: 11.0 inside wheel bias: 0
2022-03-17 12:17:07,100 follow_wall: in zone       <<<<====== IN ZONE
2022-03-17 12:17:07,274 follow_wall: distance reading: 13.4 inside wheel bias: 0
2022-03-17 12:17:07,375 follow_wall: too far
2022-03-17 12:17:07,511 follow_wall: distance reading: 118.1 inside wheel bias: -0.75
2022-03-17 12:17:07,612 follow_wall: Traveled 748 mm following wall
2022-03-17 12:17:11,598 follow_wall: GOT A PROBLEM HERE
2022-03-17 12:17:15,689 follow_wall: NO WALL
2022-03-17 12:17:23,262 main: TURNING AROUND
2022-03-17 12:17:28,015 main: OUTA MY WAY! I'm goin' till I can't
2022-03-17 12:17:31,558 follow_wall: distance reading: 11.4
2022-03-17 12:17:31,559 follow_wall: in zone
2022-03-17 12:17:32,848 follow_wall: distance reading: 11.4 inside wheel bias: 0
2022-03-17 12:17:32,949 follow_wall: in zone
2022-03-17 12:17:33,120 follow_wall: distance reading: 11.8 inside wheel bias: 0
2022-03-17 12:17:33,220 follow_wall: too far
2022-03-17 12:17:33,392 follow_wall: distance reading: 11.8 inside wheel bias: -0.75
2022-03-17 12:17:33,493 follow_wall: too far
2022-03-17 12:17:33,665 follow_wall: distance reading: 11.8 inside wheel bias: -1.5
2022-03-17 12:17:33,766 follow_wall: too far
2022-03-17 12:17:33,938 follow_wall: distance reading: 12.2 inside wheel bias: -2.25
2022-03-17 12:17:34,039 follow_wall: too far
2022-03-17 12:17:34,216 follow_wall: distance reading: 12.2 inside wheel bias: -3.0
2022-03-17 12:17:34,317 follow_wall: too far
2022-03-17 12:17:34,496 follow_wall: distance reading: 12.2 inside wheel bias: -3.75
2022-03-17 12:17:34,597 follow_wall: too far
2022-03-17 12:17:34,776 follow_wall: distance reading: 12.2 inside wheel bias: -4.5
2022-03-17 12:17:34,876 follow_wall: too far
2022-03-17 12:17:35,059 follow_wall: distance reading: 12.2 inside wheel bias: -5.25
2022-03-17 12:17:35,160 follow_wall: too far
2022-03-17 12:17:35,343 follow_wall: distance reading: 11.8 inside wheel bias: -6.0
2022-03-17 12:17:35,443 follow_wall: too far
2022-03-17 12:17:36,846 follow_wall: distance reading: 11.4 inside wheel bias: -6.75
2022-03-17 12:17:36,947 follow_wall: in zone
2022-03-17 12:17:37,120 follow_wall: distance reading: 11.4 inside wheel bias: 0
2022-03-17 12:17:37,221 follow_wall: in zone       <<<<====== IN ZONE
2022-03-17 12:17:37,394 follow_wall: distance reading: 11.4 inside wheel bias: 0
2022-03-17 12:17:37,494 follow_wall: in zone       <<<<====== IN ZONE
2022-03-17 12:17:37,668 follow_wall: distance reading: 11.0 inside wheel bias: 0
2022-03-17 12:17:37,769 follow_wall: in zone       <<<<====== IN ZONE
2022-03-17 12:17:37,948 follow_wall: distance reading: 11.4 inside wheel bias: 0
2022-03-17 12:17:38,049 follow_wall: in zone       <<<<====== IN ZONE
2022-03-17 12:17:38,223 follow_wall: distance reading: 11.4 inside wheel bias: 0
2022-03-17 12:17:38,324 follow_wall: in zone       <<<<====== IN ZONE
2022-03-17 12:17:38,497 follow_wall: distance reading: 11.0 inside wheel bias: 0
2022-03-17 12:17:38,597 follow_wall: in zone       <<<<====== IN ZONE
2022-03-17 12:17:38,773 follow_wall: distance reading: 11.4 inside wheel bias: 0
2022-03-17 12:17:38,874 follow_wall: in zone       <<<<====== IN ZONE
2022-03-17 12:17:39,054 follow_wall: distance reading: 11.4 inside wheel bias: 0
2022-03-17 12:17:39,154 follow_wall: in zone       <<<<====== IN ZONE
2022-03-17 12:17:39,328 follow_wall: distance reading: 11.4 inside wheel bias: 0
2022-03-17 12:17:39,428 follow_wall: in zone       <<<<====== IN ZONE
2022-03-17 12:17:40,716 follow_wall: distance reading: 11.4 inside wheel bias: 0
2022-03-17 12:17:40,817 follow_wall: in zone       <<<<====== IN ZONE
2022-03-17 12:17:40,990 follow_wall: distance reading: 9.4 inside wheel bias: 0
2022-03-17 12:17:41,091 follow_wall: too close
2022-03-17 12:17:41,274 follow_wall: distance reading: 7.5 inside wheel bias: 0.75
2022-03-17 12:17:41,378 follow_wall: too close
2022-03-17 12:17:41,552 follow_wall: distance reading: 6.3 inside wheel bias: 1.5
2022-03-17 12:17:41,652 follow_wall: too close
2022-03-17 12:17:41,826 follow_wall: distance reading: 4.7 inside wheel bias: 2.25
2022-03-17 12:17:41,928 follow_wall: Traveled 768 mm following wall
2022-03-17 12:17:45,995 follow_wall: GOT A PROBLEM HERE
2022-03-17 12:17:50,223 follow_wall: AT OBSTACLE OR CORNER
2022-03-17 12:18:00,232 backup_for_turning_room: BACKING UP 1.6222222222222227 INCHES FOR TURNING CLEARANCE
2022-03-17 12:18:09,402 main: TURNING BACK AROUND
2022-03-17 12:18:13,414 main: ==== GUESS THAT'S ALL SHE WROTE ====

Next I want to try a bias proportional to the error, but it still is only driving one variable in a two variable equation, so it probably is wrong to be attempting to optimize a bad solution. I probably need to look at the slope of the error as well as the error (like understand how PID works maybe…)

Wall following just seemed simple (too close turn away from wall, too far turn toward wall) until I actually tried to do it.

1 Like

It must be simple - this little bot can do it. Carl, are you watching?

Also dramatically shows “Why TimeOfFlight Sensor Is Much Better Than Ultrasonic”!!

Guess I’ll have to learn “Blockly”:

1 Like

:rofl:  :rofl:  :rofl:  :rofl:

Or as Bugs Bunny would say:  “I’m diyyyyin!” - this sooo reminds me of what I thought when I started the New Remote Camera Robot.  “All I gotta do is substitute a joystick for the mouse, how difficult can that be?”

There’s a famous military figure of speech:  “No battle plan survives contact with the enemy.”  And it’s true for projects as well.

It shall be known henceforth as “Carl’s Law”:
“No project or plan survives contact with reality.”

2 Likes

Bloxter, (on the GoPiGo O/S - which is a Blockly clone), gets a bad rap because it’s not a “real” programming language.

I think this is a lot like what a famous roboticist said about VS Code remote on a bot and anti-Microsoft bias.

I think Bloxter is a great tool, especially for prototyping.

IMHO, it’s the programming equivalent of Lego blocks.  You’re not going to market with something made out of Legos, but it’s a great prototyping environment.  Likewise, Bloxter.  It’s a great way to “throw something together” and proof-of-concept ideas.

Once you get an idea proven in Bloxter, you can then implement and fine-tune in Python, C, or bare metal assembler as you see fit.

Maybe this should be Charlie’s next project?
“How to implement Blockly on a curl’d GoPiGo install over something like Legacy Raspbian - and make it work with the bot.”

2 Likes

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
2 Likes

The ending caught me by surprise - loved it.
And great progress.
/K

2 Likes

He’s already doing better than I can!  (A human.)

Get him to chew gum, walk, and talk at the same time and then you’ll really have something!

Then you’ll have to keep him outta the 'fridge and potty train him. :wink:

2 Likes

Actually I’d love a bot who could bring me a cold beer… :grinning: :beer:
/K

2 Likes

I saw a video of one - I think here somewhere - but it would break your bank to make it.

2 Likes