Roundup Mentor Bot: Operator Mode Scripting

After posting the Round Up Mentor Bot: Programming Challenge, a few people wondered how the bobcat would perform in the operator mode when tubes were scattered or leaning on each other rather than being nicely stacked for pickup.

One strategy is to pick up one tube at a time and retain it on the plunger while another is picked up.  This is continued until 3 or 4 tubes have been stacked and then they are scored.   This sequence requires quick positioning of the plunger height synchronized with open and closing the gripper.   With two joysticks and lots of practice, this can be done efficiently with one operator on the lift/grip and the other steering.   However, with scripting, this can be reduced to a  one operator task.   The software posted in my last blog contained no capability for scripting in the manual mode.   I have rewritten the scripting logic to accommodate this.

Video of some scripting used during driver control is here.

Code is on Vex forum.

New Script Highlights:

1) Only one script can be run at a time.

2)Scripting is activated by special joystick buttons or Autonomous mode logic.  A new script can only be started when  no script is currently running. No script running  is signaled when the global variable “step” = END_STEP.

3)An running script is exited when the script is done or  a disconnect script button is pushed.

4)A running script takes control of the pwm command to motors used only by the script.  Other motor commands  remain under joystick control.  For example, when a lift script runs, it sets bauto_lift to true.  This is used by the operator() function to bypass all joystick buttons that generate lift commands.   When the script is done, it sets bauto_lift to false and the normal joystick lift commands are restored.  In addition to bauto_lift there is bauto_move, bauto_turn and bauto_grip.

5) All scripts are stacked in one big script that is a bunch of  nested sequential if else tests.   All valid scripts must be continuous sequential integer steps.   When a script set is completed, a break in the step number sequence signals that the script is done.  A script is selected solely by its entry step number.    The last step in the big script  puts step = END_STEP.  In this program, there are five  scripts,  the autonomous script and four manual mode scripts. The starting numbers are set by defines. I.E.

#define START_STEP_AUTONOMOUS (int)1 //you can start your script at something other than 1
#define START_STEP_STACK (int)100
#define START_STEP_LIFT_STACK (int)200
#define START_STEP_LIFT_BASE_DROP (int)300
#define START_STEP_LOW_HANG (int)15
#define END_STEP (int)-999 // this will signal no script in progress

6) If step = END_STEP then no script will run and a sys_reset flag is true.

7) To call a script, simply set step = start_script_no. E.G. step = START_STEP_STACK.   When the scripting engine sees that step!=END_STEP then it begins the script at start_script_no.  The script function is responsible for resetting the sys_reset flag to false after it has initialized.  So the sys_reset flag is true for only one pass during initialization.

8) Manual and Autonomous scripts are not differentiated.  Both are run by the same scripting engine.  The only difference is where the script starts and this is determined by the script caller function.

Operator Scripts:

One button on joystick is assigned to these scripts.

a)Raise lift to stack height (just above a single tube on ground)

b)Stack single tube onto plunger (opens grip, moves lift down, closes grip and returns to stack height)

c)Raise lift to drop height for movable scoring base

d)Perform low hang. (performs the final steps used in the programming challenge script)

Basic Logic to Call Scripts:

In Operator() function Joystick buttons are used to initiate scripts:

if(RT_5Down && step == END_STEP) step = START_STEP_STACK;
if(RT_5Up && lift_state == LIFT_DOWN && step == END_STEP)  step = START_STEP_LIFT_STACK;
if(RT_6Down && step == END_STEP) step = START_STEP_LIFT_BASE_DROP;
if(RT_6Up && (lift_state != LIFT_UP || lift_state != LIFT_BASE_DROP )
&& step == END_STEP)  step = START_STEP_LOW_HANG;

Note that  step==END_STEP   is required prerequisite to start new script.

RT_5Up,RT_5Down,RT_6Up,RT_6Down are joystick button logic inputs.

Modification to scripting functions:

Each scripting function has a bauto_lift Boolean type to take control of the pwm generated by the function from the joystick. E.G.

int set_lift(int goal, int pwm_input )
{
static int imdone = 0;

if(sys_reset)
{
bauto_lift = true; //This flag inhibits pwm_lift commands from joystick
pwm_lift = pwm_input;
imdone = 0;
return 0;
}
else
{

if(lift_state != goal  && !imdone) return 0;
else
{
bauto_lift = false; //Restore joystick control of pwm_lift command.
pwm_lift = 0;
imdone = 1;
return 1;
}
}
}

What happens in the Operator() function:

We simply don’t compute pwm commands for any auto scripting motor commands.  E.G.

Operator()

{

if(!bauto_move)
{
pwm_sym  computed from joystick inputs.
}
// set turn rate
if(!bauto_turn)
{
pwm_turn computed from joystick inputs.
}
if(!bauto_lift)
{
pwm_lift  computed from joystick input.
}
}
if(!bauto_plunger)
{
plunger_command computed from joystick inputs.
}

…..

}

What does the new script look like?


void autonomous_script() {

//START PURE AUTONOMOUS SCRIPT****************************************************************************
if(step  == 1)
{

done =set_lift(LIFT_DOWN,-40);// reset lift

}
else
if(step == 2)
{
done = set_lift(LIFT_PICKUP,70); // ready lift for pickup

}
else
.

. //steps 3 through 14 not shown

.

// START MANUAL OR AUTOMATIC LOW HANG  **************************************************************************
if(step  == 15)
{
bauto_line_enable=true;
if(move_encoder(-600,90)==1 || bback_bumper) done = 1 ; //move back till bumper hit, 90 pwm
if(done) bauto_line_enable = false;
}
else
.

. // steps 16 through 24 not shown.

.
else
if(step == 25)
{
done = set_lift_manual(-30, -127,2000);//hold inner lift  and lower outer lift for 2 sec

}

//autonomous script will terminate here since step 26 doesn’t exist.
// STACK SCRIPT ***************************************************************************************
else
if(step == 100)
{
done = set_grip(DROP,0);
}
else
if(step == 101)
{
done = set_lift(LIFT_DOWN,-70);
}
else
if(step == 102)
{
done = set_grip(HOLD,0);
}
else
if(step == 103)
{
done = set_lift(LIFT_STACK,+70);
}

//stack script will terminate here because step 104 doesn’t exist

// RAISE LIFT TO STACK HEIGHT SCRIPT ***********************************************************************
else
if(step == 200)
{
int done1 = set_lift(LIFT_STACK,+70);
int done2 = ms_timer_T1(2000);
if(done1 == 1 || done2 == 1)
{
done = 1;
bauto_lift = false;//release the lift
}
}
else
// RAISE LIFT TO DROP HEIGHT SCRIPT *********************************************************************
if(step == 300)
{
done = set_lift(LIFT_BASE_DROP, 70);
}
else
{
bauto_debug_mode=false;
step = END_STEP;  //Note if the next script step doesn’t exist, the program flow will drop to this step where  step = END_STEP.  This terminates all scripts.
}

//*****************************BOTTOM OF SCRIPT *****************************************************************
}

More related links:

Posted pictures on the vex site:

High Hang??

Low Hang.

More blog stuff:

https://vamfun.wordpress.com/2010/08/05/roundup-mentor-bot/

https://vamfun.wordpress.com/2010/07/01/vexnet-joystick-stuff/

https://vamfun.wordpress.com/2010/06/10/vex-cortex-notes/

Advertisements

One Response to Roundup Mentor Bot: Operator Mode Scripting

  1. […] sure others would rather use separate script functions.  Review Bobcat scripting concepts here […]

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: