Shop OBEX P1 Docs P2 Docs Learn Events
Penguin turning 90 degrees left and right — Parallax Forums

Penguin turning 90 degrees left and right

Capt.KerryCapt.Kerry Posts: 28
edited 2010-02-05 14:27 in Robotics
Hi, am trying to scan left and right with the Penguin and PING)) sensor. I can use the "heading" value to find out where the Penguin is pointing and its easy to add or subtract 90 to establish what direction to scan to.·How·would I then store that (those)·values without it getting overwritten each time the penguin checks its current heading as the program loops?
Thanks for any suggestions.

Comments

  • FranklinFranklin Posts: 4,747
    edited 2010-02-03 23:08
    Store them in a variable that you don't write to unless you want to change the value. Could you explain more fully?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - Stephen
  • Capt.KerryCapt.Kerry Posts: 28
    edited 2010-02-04 10:05
    Thanks for the reply Stephen.
    Sorry, new at all this so am stealing bits from other programs and trying to jam them together!

    Basically for the moment just trying to get the Penguin to sense his heading using a subroutine which polls the compass and converts it to degrees and stores it in a variable called Heading
    '
    Read Compass Heading

    ReadCompass: ' Compass reading subr
    HIGH Enable ' Send reset command to HM55B
    LOW Enable ' P4 controls HM55B's /Enable
    SHIFTOUT Compass, Clock, MSBFIRST, [noparse][[/noparse]Reset\4]
    HIGH Enable ' Start HM55B measurement
    LOW Enable ' P4 controls HM55B's /Enable
    SHIFTOUT Compass, Clock, MSBFIRST, [noparse][[/noparse]Measure\4]
    status = 0 ' Clear previous status flags
    DO ' Status flag checking loop
    HIGH Enable ' Measurement status command
    LOW Enable ' P4 controls HM55B's /Enable
    SHIFTOUT Compass, Clock, MSBFIRST, [noparse][[/noparse]Report\4]
    SHIFTIN Compass, Clock, MSBPOST, [noparse][[/noparse]Status\4]
    LOOP UNTIL status = Ready ' Exit loop if status is ready
    SHIFTIN Compass,Clock,MSBPOST,[noparse][[/noparse]x\11,y\11] ' Get x & y axis values
    HIGH Enable ' Disable module
    IF (y.BIT10 = 1) THEN y = y | NegMask ' Store 11-bits as signed word
    IF (x.BIT10 = 1) THEN x = x | NegMask ' Repeat for other axis
    Heading = x ATN -y ' Convert x and y to brads
    Heading = Heading */ 360 ' Convert brads to degrees
    RETURN


    Then I take that value and subtract 90 (degrees) from it and tell the penguin to turn that way using something like:

    IF Heading > (Heading -90 ) THEN TurnLeft

    Obviously this wont work because when the program loops to read the compass to see if the penguin has turned 90 degrees the Heading variable gets updated and he turns in a circle.

    I need to be able to somehow store the 90 degree direction in a different variable which doesn't get changed until the penguin has achieved it. (Which is what you suggest)

    Could you give me a bit of direction (+/- 90 Degrees!) on how to store in in a variable that doesn't get updated each time?
  • HumanoidoHumanoido Posts: 5,770
    edited 2010-02-04 13:37
    You could simply store values in eeprom and then read out the
    numbers when needed. When flagging compass directions, to
    improve performance, a range of values is suggested. If the
    number bumps around, it may not see the +90 or -90 value.
    So, an envelope around 5 degrees is workable. For experimenting
    with this effect, try using the tuner on the Penguin Robot Radio.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    humanoido
    *Stamp SEED Supercomputer *Basic Stamp Supercomputer *TriCore Stamp Supercomputer
    *Minuscule Stamp Supercomputer *Three Dimensional Computer *Penguin with 12 Brains
    *Penguin Tech *StampOne News! *Penguin Robot Society
    *Handbook of BASIC Stamp Supercomputing
    *Ultimate List Propeller Languages
    *MC Prop Computer
  • Capt.KerryCapt.Kerry Posts: 28
    edited 2010-02-04 14:41
    Humanoido·said...
    You could simply store values in eeprom...
    Thats easy for you to say!....·ok will get into it, Thanks for the tip.
  • HumanoidoHumanoido Posts: 5,770
    edited 2010-02-04 22:52
    Look through some of the completed penguin programs suite
    for sections involving writes to the eeprom as examples. It's
    not as challenging as you might think. The Penguin reset
    button code, when converted to a virtual keyboard, makes
    use of the eeprom, for one example. There's code to do this
    in the master program for the Penguin Superhero too. The
    SEED Stamp Supercomputer also uses a technique of storing
    into eeprom memory, i.e. each life form will memorize its own
    unique self determinations. The code understanding is
    principally the same for a Penguin robot. You are welcome
    to use any sections of this code for your project. The STAMP
    book and software have excellent examples too.

    humanoido
  • Capt.KerryCapt.Kerry Posts: 28
    edited 2010-02-05 14:27
    Thanks humanoido, I was only (partly) kidding, I really enjoy the challenge and you're right, its never quite as difficult as anticipated. The whole thing rocks! To think I used to believe RC was cool!
Sign In or Register to comment.