Shop OBEX P1 Docs P2 Docs Learn Events
How to perform an 'AND NOT' on a BS2e — Parallax Forums

How to perform an 'AND NOT' on a BS2e

TiboTibo Posts: 81
edited 2005-11-01 17:06 in BASIC Stamp
Hi,
I need a little help on logical operators :

I'm writing a turn decision routine as part of my robot brain running on BS2e, connected to a PWMPAL, two IR telemeters SHARP GPD2D02 and a SRF04 ultrasonic telemeter.
For that I'm using (probably like a noob) the two banks of the chip, seperating logics, sharing global variables, etc... (BTW thanks to EME systems for their applications notes)

Here is my problem :
Since there is no AND NOT operator on the BS2, i'd like to perform a bitwise operation on the irStatus Nib in order to take move decision.
I'm pretty sure there is a math trick to do so...but i dont remember [noparse]:([/noparse]

main :
  stopBit=%0 '----- debug
  DO
    leftIrFlag=%0
    rightIrFlag=%0
    irStatus=%0000
    DEBUG HOME, "IR-GAUCHE: ", DEC agregMeasures.BYTE0, " IR-DROITE: ", DEC agregMeasures.BYTE1, REP " "\4

    IF agregMeasures.BYTE0>=minDist THEN leftIrFlag=%1 'AgregMeasures come from IR detectors reading routine
    IF agregMeasures.BYTE1>=minDist THEN rightIrFlag=%1 'I'm checking if not at minimum distance offset

    ' update stop bit with last sr_IR computation (case both sr_IR = 1), needed for WIFI control
    stopBit = leftIrFlag & rightIrFlag

    DEBUG CRSRXY, 0, 1, "STOPBIT ",BIN2 stopBit, "   "
    DEBUG CRSRXY, 0, 2, "leftIrFlag ",BIN2 leftIrFlag, " rightIrFlag ",BIN2 rightIrFlag, REP " "\4

    ' check for turn needs
    IF NOT leftIrFlag & rightIrFlag THEN irStatus=%0000 ' forward ok
    IF leftIrFlag & rightIrFlag THEN irStatus=%1111 ' backward ok
    '[b]Here is my problem : both lines under are equals....so i cant know if left or right [/b]
    IF leftIrFlag=%0 & rightIrFlag =%1 THEN irStatus=%1011 ' left u trun 
    IF leftIrFlag=%1 & rightIrFlag =%0 THEN irStatus=%0111 ' right u turn 

    DEBUG CRSRXY, 0, 4, "irStatus :" ,BIN4 irStatus, REP " "\4

    SELECT irStatus
      CASE %0000
        DEBUG CRSRXY, 0, 6, "FORWARD", REP " "\20
      CASE %1111
        DEBUG CRSRXY, 0, 6, "BACKWARD", REP " "\20
      CASE %1011
        DEBUG CRSRXY, 0, 6, "LEFT UTURN", REP " "\20
      CASE %0111
        DEBUG CRSRXY, 0, 6, "RIGHT UTURN", REP " "\20
    ENDSELECT

    RUN 1
    
  LOOP



Thank you to help if you can turn.gif

Comments

  • Jon WilliamsJon Williams Posts: 6,491
    edited 2005-11-01 16:56
    You can invert the bits of any variable with ~, that should let you apply the original logic you desire.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
  • TiboTibo Posts: 81
    edited 2005-11-01 17:06
    Shame on me....
    thx Jon.
Sign In or Register to comment.