Thread: variable?
View Single Post
  #4   Spotlight this post!  
Unread 28-03-2003, 03:21
Greg Ross's Avatar
Greg Ross Greg Ross is offline
Grammar Curmudgeon
AKA: gwross
FRC #0330 (Beach 'Bots)
Team Role: Mentor
 
Join Date: Jun 2001
Rookie Year: 1998
Location: Hermosa Beach, CA
Posts: 2,245
Greg Ross has a reputation beyond reputeGreg Ross has a reputation beyond reputeGreg Ross has a reputation beyond reputeGreg Ross has a reputation beyond reputeGreg Ross has a reputation beyond reputeGreg Ross has a reputation beyond reputeGreg Ross has a reputation beyond reputeGreg Ross has a reputation beyond reputeGreg Ross has a reputation beyond reputeGreg Ross has a reputation beyond reputeGreg Ross has a reputation beyond repute
Send a message via AIM to Greg Ross Send a message via Yahoo to Greg Ross
Re: autonomous code sample?

Quote:
Originally posted by manodrum
...also if anyone has any simple autonomous code that works and would like to share, i just need to see how you worked it into the main code and detecting if auton_mode = 1
and all that jazz...
Thanks,
manodrum
This is probably a lot more than you wanted to know, but here are excerpts which provide a a pretty good idea of how our autonomous mode is implemented:

Slot 0 pretty much just contains the normal pre-main-loop initialization stuff.

Slot 1 (BB2003MainLoop):
Code:
<snip>
' Since auton_mode, comp_mode, and user_display_mode won't
' be changing that much, it will be safe to print out the new state
' whenever one of them changes.
if (auton_mode <> Autonomous) then
  if (auton_mode = 1) then
    debug "Autonomous", cr
  else
    debug "Operator Controlled", cr
  endif
endif

if (comp_mode <> Disabled) then
  if (comp_mode = 1) then
    debug "Disabled", cr
  else
    debug "Enabled", cr
  endif
endif

if (user_display_mode <> UserDisplay) then
  if (user_display_mode = 1) then
    debug "User Display On", cr
  else
    debug "User Display Off", cr
  endif
endif

' Save the various flags from the PBASIC mode (byte) variable to
' dedicated bit variables so that the byte variable may be reused
' as a temporary variable.

Disabled = comp_mode
Autonomous = auton_mode
UserDisplay = user_display_mode
And later in slot 1:
Code:
EEPROM_AUTON_PROG_NUM     data 1

' If this is the first time through this code (i.e. immediately after
' power-up) then the scratchpad location which holds our selected
' autonomous program number will be zero (an invalid program
' number) so read the default prog number from EEPROM (or the
' last one saved there.)
get AUTON_PROG_NUM, autonProgNum
if autonProgNum = 0 then
  read EEPROM_AUTON_PROG_NUM, autonProgNum
  put AUTON_PROG_NUM, autonProgNum
  put PROG_SELECT_TIMER, 0
endif

' Select autonomous mode program
get AUTON_PROG_NUM, autonProgNum

' Delay a little before allowing selector change again.
get PROG_SELECT_TIMER, progSelectTimer
progSelectTimer = progSelectTimer min 1 - 1
put PROG_SELECT_TIMER, progSelectTimer
'debug ?progSelectTimer


{$if (Disabled = 1)}
  ' Make sure that the match timer doesn't start ticking until we're
  ' enabled. (AND that it gets reset any time we get disabled!)
  put MATCH_TIMER_LOW, 0
  put MATCH_TIMER_HIGH, 0

  if UserDisplay = 1 then
    ' We are disabled, and in user display mode, so allow selection
    ' of a different autonomous program.

    if progSelectTimer = 0 then
      if p4_sw_top = 1 then
        ' The program select button is down! Reset the autorepeat
        ' timer, and select the next program number.
        put PROG_SELECT_TIMER, 10

        select autonProgNum
          case < LAST_AUTON_PROG
            autonProgNum = autonProgNum + 1
          case LAST_AUTON_PROG
            autonProgNum = FIRST_LEARN_PROG
          case FIRST_LEARN_PROG to LAST_LEARN_PROG - 1
            autonProgNum = autonProgNum + 1
          case LAST_LEARN_PROG
            autonProgNum = FIRST_PLAYBACK_PROG
          case FIRST_PLAYBACK_PROG to LAST_PLAYBACK_PROG - 1
            autonProgNum = autonProgNum + 1
          case else
            autonProgNum = 1
        endselect

        ' Again, we won't be changing auton programs so often that
        ' we dare not print out the currently selected program name.
        select autonProgNum
          case DEAD_IN_THE_WATER_PROG
            debug "Mars rock dance", cr
          case LINE_FOLLOW_LEFT_PROG
            debug "Follow line from left", cr
          case LINE_FOLLOW_RIGHT_PROG
            debug "Follow line from right", cr
          case DEAD_RECKON_FROM_RIGHT_SIDE
            debug "Dead reckon from right", cr
          case DEAD_RECKON_FROM_LEFT_SIDE
            debug "Dead reckon from left", cr
          case WAIT_BY_WALL_FROM_RIGHT_SIDE
            debug "Wait by wall from right", cr
          case WAIT_BY_WALL_FROM_LEFT_SIDE
            debug "Wait by wall from left", cr
          case LIMBO_UNDER_BAR_SLOW
            debug "Slow limbo", cr
          case LIMBO_UNDER_BAR_FAST
            debug "Fast limbo", cr
          case LEARN6
            debug "Learn for Playback 6", cr
          case LEARN7
            debug "Learn for Playback 7", cr
          case LEARN6 + 100
            debug "Playback 6", cr
          case LEARN7 + 100
            debug "Playback 7", cr
        endselect

        put AUTON_PROG_NUM, autonProgNum
      endif
    endif ' progSelectTimer = 0
    p4_sw_top = 0 ' Prevent the button from being acted upon for
                  ' its normal purpose
  else
    ' We are disabled, but not in user display mode. If the
    ' autonomous program selector has changed, save it to
    ' EEPROM.
    read EEPROM_AUTON_PROG_NUM, prevAutonProgNum
    if autonProgNum <> prevAutonProgNum then
      debug "Saving ", ? autonProgNum
      write EEPROM_AUTON_PROG_NUM, autonProgNum
    endif
  endif
{$endif Disabled}



get MATCH_TIMER_LOW, matchTimer.byte0
get MATCH_TIMER_HIGH, matchTimer.byte1

if matchTimer < [I'm not ready to release this information yet;)] then
  matchTimer = matchTimer + 1 + delta_t   
  put MATCH_TIMER_LOW, matchTimer.byte0   
  put MATCH_TIMER_HIGH, matchTimer.byte1
else
  [Excised]
endif
And a little later in slot 1:
Code:
if Autonomous = 1 then
  Run BB2003_AUTON_PROG1
endif
Slot 2 contains nothing having to do with auto mode except this... just before it would normally call the "output data" slot:
Code:
' If autonProgNum is one of the auto-learn programs, then record the robot actions.

if (Disabled = 0) then
  get AUTON_PROG_NUM, autonProgNum
  if (autonProgNum >= FIRST_LEARN_PROG) and \
     (autonProgNum <= LAST_LEARN_PROG) then
    get MATCH_TIMER_LOW, matchTimer.byte0
    get MATCH_TIMER_HIGH, matchTimer.byte1

    'debug "Learning for playback -- ", dec? matchTimer
    select autonProgNum
      case LEARN6
        run BB2003_PLAYBACK6
      case LEARN7
        run BB2003_PLAYBACK7
      case else
        debug "Invalid ", dec? autonProgNum
    endselect
  endif
endif



Run BB2003_OUTPUT_DATA
Slot 3 (BB2003_OUTPUT_DATA) contains the serout... and this... which controls the digital display on the operator interface when it is in user display mode:
Code:
if UserDisplay then
  ' Display SOMETHING on the OI
  get AUTON_PROG_NUM, autonProgNum
  {$if (Disabled = 1)}
    temp10 = autonProgNum
  {$elseif (Autonomous = 1) or \
           ((autonProgNum >= FIRST_LEARN_PROG) and (autonProgNum <= LAST_LEARN_PROG))}
    ' Display the number of seconds left in autonomous mode (or
    ' the number of seconds left to record for later playback in auto
    ' mode.
    get MATCH_TIMER_LOW, matchTimer.lowbyte
    get MATCH_TIMER_HIGH, matchTimer.highbyte
    temp10 = 573  - (matchTimer max 573) / 38
  {$else}
    get GRIPPER_POSITION_SENSOR, temp10
  {$endif} ' Disabled

  outh = temp10
else
  ' Use PWM 1 and 2 Reverse LEDs on OI to provide visual
  ' feedback of the state of [Excised;)]
endif ' UserDisplay
Note the strange {$...} syntax. These are directives to my BASIC Stamp Preporcessor which translates these to legal PBASIC 2.0 statements. My preprocessor is still a work in progress. An earlier version is available in the White papers section. I don't know whether all the code I'm quoting here will work with that version. You shouldn't have difficulty modding this code to work with either of the currently available BASIC Stamp Editors, but if you're really a "bleeding edge" type, I'll let you have a copy of the current program.

continued...
__________________
Greg Ross (The Grammar Curmudgeon formerly known as gwross)
S/W Engineer, Team 330, the Beach 'Bots
<--The Grammar Curmudgeon loves this cartoon.
“Life should not be a journey to the grave with the intention of arriving safely in a pretty and well preserved body, but rather to skid in broadside in a cloud of smoke, thoroughly used up, totally worn out, and loudly proclaiming "Wow! What a Ride!" Hunter S. Thompson
"Playing a practical joke means doing something mean and calling it funny." Me

Last edited by Greg Ross : 28-03-2003 at 03:32.