Shop OBEX P1 Docs P2 Docs Learn Events
Penguin Another re-work on the Parallax AutonomousNavigation code. — Parallax Forums

Penguin Another re-work on the Parallax AutonomousNavigation code.

InteractInteract Posts: 79
edited 2007-09-08 04:28 in Robotics
A smaller, smarter program with more functions.
·
This is a re-work of the PenguinAutonomousNavigation.bpx (again) last time I worked on the move routine, now I’ve attacked the Main program.
First I cleaned·up a few mistakes and duplicate, or redundant lines from the original code.
Additional functions have been added to the penguin. It can now move in 6 directions: Forward, Forward-Left, Forward-Right, Backwards, Backwards-Left and Backwards-Right.
The penguin now makes much better decisions and sticks to them. Since it can now turn left or right while backing up, Its object avoidance has been greatly improved. The penguin now takes several steps to avoid an object. It tends to not get stuck trying to figure out where to go and what to do. There is a step counter that is used for events, in this case it chirps after 11 unblocked steps. The·step counter can be used for many other creative events like “stop and waddle after 15 then play a song after 20 etc.
The penguin will try to go toward the light. If it needs to turn to accomplish this, it will turn while still moving forward and indicate a “1” for a right turn and a 2 for a left turn decision on the LED display. If the penguin makes it 11 steps without encountering an object in its way, it will chirp, and continue.
·If an object is in its way, It will indicate this on the LED (as before) and it will back-away left, or back-away right from the object, depending on which side the object is on. ·If the object is directly in front of it, then it will back-away so the penguin is facing the lighter direction.
I put 20 paper coffee cups on my kitchen floor and it did a great job of weaving in and out trying to find the brightest spot.
·
All this and less memory?
Yes its true, saves 5 bytes over the original Parallax code for PenguinAutonomousNavigation.bpx , and I still left the compass routines and their variables in there. They aren’t needed for this program but were left in for comparison to the original program size. Attached : PenguinAutonomousNavigation_3.bpx
The second attachment PenguinAutonomousNavigationNoCompas_3.bpx saves 114 more bytes. This leaves·two thirds·of the memory page free·for all those special events [noparse]:)[/noparse]
·


Post Edited (Interact) : 9/5/2007 12:49:53 AM GMT

Comments

  • InteractInteract Posts: 79
    edited 2007-09-04 23:30
    Sorry, Those of you who downloadad this in it's first hour after posting, I had changed one line and not resaved the attached files. No bugs in the first hour version, but the version now attached above is a bit smarter.
  • MinimumWageMinimumWage Posts: 72
    edited 2007-09-05 04:44
    This is really nice, I got to play around with it for a few minutes tonight. I like the obstacle avoidance - it works a lot better than before and the debug "chirps" and numbers are a great addition to the code. I just wish I had more time to play around and make my penguin learn some new tricks, but this code is a great head-start!
  • InteractInteract Posts: 79
    edited 2007-09-05 17:38
    Another thing about this re-work is that the step routines take into acount which foot is allready forward. this was another reason the poor guy would get "stuck".

    Also.. ·object avoidance logic with this simple routine.. The line below in the main loop that has the red hilighted Chirp - 2 can be adjusted to 4 for better results on·most objects. The result is that after the penguin takes a few steps backwards while turning away from an object it will go straight for (in this case 2) steps before resuming looking for the light. It will still look for obstructions during this time. If ojects are white the penguin will see them sooner than dark colored objects etc. If objects are big or small also causes a slight change to the ideal logic here. I found that Chirp = 4 is best for most things.

    Also make sure your penguin·CAN walk straight! if it tends go drift left, re-calibrate him/her so that he/she leans a bit to the right. Just setting it up so that it is perfectly vertical dosen't mean it will walk straight.

    DO
    StrideCounter = StrideCounter - 1··············· ' Make a noise if no obstructions for Chirp number of strides.
    IF StrideCounter = 0 THEN
    · StrideCounter = Chirp
    · FREQOUT Speaker, 500, 800·············'chirp
    ENDIF
    IF StrideCounter > Chirp THEN···················· ' If Penguin is taking Avoidance steps.
    · IF TurnDirection = Backward THEN··········· ·' If object is directly in front, back away so penguin faces the light.
    ··· IF LeftLDR > RightLDR THEN TurnDirection = Right ELSE TurnDirection = Left
    · ENDIF
    · GOSUB WalkBackward
    ELSE
    · GOSUB ReadIr······································ ·' Check for IR reflections
    · TurnDirection = LeftIr * 2 + RightIr········· · ' Step away from obstruction
    · IF TurnDirection = Forward· THEN············ ·' If un-obstructed
    ··· LEDDisplay = $F·························' Clear the display
    ··· GOSUB ReadLDR································· ·' Read the photoresistors
    ··· IF ABS(LeftLDR - RightLDR) > (LeftLDR + RightLDR) ** LDRDeadzone THEN
    ····· IF LeftLDR > RightLDR THEN················ ·' Check for a sufficient· difference in light readings
    ······· TurnDirection = Right····················· ·· ' and go toward the light
    ······· LEDDisplay = 1························'Display "1" for right turn
    ····· ELSE
    ······· TurnDirection = Left
    ······· LEDDisplay = 2························ ' Display "2" for left turn
    ····· ENDIF
    ··· IF StrideCounter > Chirp - 2 THEN TurnDirection = Forward ' how long to go straight after backward avoidance steps
    ··· ENDIF
    ··· GOSUB walkforward
    · ELSE················································· ' If obstructed by an object
    ··· StrideCounter = AvoidanceSteps··········· ' Set the number of steps to take in avoidance of the object
    ··· LEDDisplay = 9 + TurnDirection············ ·' Set the display to indicate direction of obstruction
    · ENDIF
    ENDIF
    LOOP

  • slashsplatslashsplat Posts: 63
    edited 2007-09-08 04:28
    Great work. I am not getting really clean steps, and this really shows that. I will work on the ski poles...

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    slashsplat
    /* Ira Chandler */
    http://BotConnect.com
Sign In or Register to comment.