Proposed 599_Competition_Scripting_Template

On my TBD list was to adapt the mentor Bobcat program to a competition format.  I decided to propose a generic template with a few changes to the scripting concept which might be adopted by 599 and possibly other teams if they like it.  This differs from the Bobcat scripting in that is uses C switch() statements to step through the scripts instead of nested if else statements. Also, it uses separate script functions rather than stacking the scripts in a single function.   I actually prefer stacking them, but I’m sure others would rather use separate script functions.  Review Bobcat scripting concepts here first.

New program features:

The new RobotC program is called 599_Competition_Scripting_Template.c and uses an include 599_Competition_Scripting_Template.h .

The program keeps the same structure for both autonomous and user control modes.  Only the script selection routines differ and kill_switch logic.   Most teams use entirely different structures.  The main features are summarized here:

AUTONOMOUS

-autonomous scripts are selected by sensor inputs (plugs or potentiometer)

-Select_autonomous_script()  picks the script to run.

-kill_switch can be enabled.  auto_debug_mode is inhibited.

Top level progrom flow:

void Autonomous599()
{
while(true)
{

if((SensorValue[kill_sw] < 127)&& ENABLE_KILL_SWITCH) //kill button on robot is A/D port to save digital ports
{

if(script != no_script) // stop scripts by reinitializing
{
Initialize();
bsingle_step_mode = false;
}

allMotorsOff();
break;
}
Process_sensors(); // read and process sensors to get variables needed for functions

Operator(); // read driver commands from joystick which are not under script control

Select_autonomous_script();//call autonomous script based upon cortex input auto_select (in8) port status

Run_scripts();// Runs the selected script from Select_autonomous_script() to get commnads from scripts

//call core functions here that use commands from operator() and run_scripts() functions

Core_functions();

}//end while
}

USER CONTROL

-user scripts are selected by joystick buttons during competition

_Select_user_script() picks the script to run.  Otherwise top level logic is about the same as shown above in Autonomous599().

– In auto_debug_mode,   autonomous scripts are selected by joystick buttons.  So this can be the primary test mode for AUTONOMOUS scripts.   Once debugged, the names are put into Select_autonomous_script().

-ENABLE_AUTO_DEBUG  and ENABLE_KILL_SWITCH defines can be use to enable these modes for testing and disable them for competition.  If auto_debug_mode is enabled, then single_step_mode feature can also be used.

-joystick Btn8R is used for auto_debug_mode engagement and script disconnect

-joystick Btn8L is used for single_step_mode engagement and single_stepping.

Simulated script function testing :

The template has simulated functions that allow check out of the scripting logic.   Just need a Cortex and a Joystick, no motors etc.   Instructions are in the 599_competition_scripting_template.h file.

Quit here if you are going to download the software otherwise

here are some of the introduction comments in the .h file:

//RobotC 599_Competition_Script_Template.h
//This program is a suggested template with dummy scripting for both user and autonomous modes testing.
//Simulated pwm commands are generated by joystick and scripting functions
//The pwm commands are integrated to create simulated distances, dist1,dist2 and dist3 which
//are functons of joystick axes 1,2 and 3 respectively.
//Download to cortex and use the Vexnet debug competition mode control (DISABLE,AUTONOMOUS,USER CONTROL)
//to exercise the software logic and  and watch global variables move with the joystick and scripts.
//DISABLE…nothing but timer moves
//AUTONOMOUS…runs auto_script_2 and stops.  auto_script_2 is determined by sensor port in8 (auto_select).
//USER CONTROL…move joystick axes 1,2 and 3 and watch dist1,dist2 and dist3 move.
//Then select scripts with buttons 5U,5D,6U,6D and notice how the scripts take control of its axis and
//allows the remaining joystick axes to function as normal to joystick inputs.
//If you hold button 8L down for 3 sec, you can then use single stepping of selected scripts with subsequent 8L pushes.
//USER CONTROL …. auto_debug_mode.  Allows autonomous scripts to be tested in USER CONTROL mode.
//Hold 8R down for 3 sec and now you can use the same buttons (5U,5D,6U,6D) to select auto_scripts.
//Single stepping works here too.  Disconnect auto_debug_mode anytime with another 8R push.

//More details below:
//Driver operation with no scripts active
//Joystick Ch1 controls pwm_cmd1 which sets the speed that dist1 moves.  Same for (Ch2,pwm_cmd2,dist2)
//and (C3,pwm_cmd3,dist3).

//Script calling during driver operation (uses buttons 5U,5D,6U,6D)
//Btn5D calls script = name_1;//moves relative distance 1 up by 500 and restores it
//Btn5U calls script = name_2;//moves relative distance 2 up by 500 and restores it
//Btn6D calls script = name_3;//moves relative distance 3 up by 500 and restores it
//Btn6U calls script = name_4;//script increments total time by 1000,2000 and 3000 ms in three script steps.

//auto_debug_mode allows autonomous scripts to be called by 5U,5D,6U,6D
//Set with Btn8R 3 second push and follow with push of script button.
//Btn5D calls script = auto_name_1;//moves relative distance 1 up by 500 and restores it
//Btn5U calls script = auto_name_2;//moves relative distance 2 up by 500 and restores it
//Btn6D calls script = auto_name_3;//moves relative distance 3 up by 500 and restores it
//Btn6U calls script = auto_name_4;//script increments total time by 1000,2000 and 3000 ms in three script steps.

//single_step_mode
//Set by Btn8L 3 second push. Subsequent Btn8L pushes cause the script step to increment by 1.
//Stepping can be used for both manual and autonomous scripts.
//Single_step_mode is reset by kill_sw or button 8R push once a script has been initiated.

//Script Reset
//Running scripts are reset when they complete, when the kill_sw is hit or when Btn8R is hit.

//Can set defines  ENABLE_AUTO_DEBUG and ENABLE_KILL_SW  to enable use in testing or disable for competition.

Here is the new Run_scripts():

void Run_scripts()

{ //Do not modify

static int last_script = no_script;

if(last_script != script && script != no_script)

{

step=0;

bsys_reset = true;

}

last_script = script;

if(script == no_script) return;

switch(script)

{

//Modify to match your script names and scripts

case name_1:

Script_name_1();

break;

case name_2:

Script_name_2();

break;

case name_3:

Script_name_3();

break;

case name_4:

Script_name_4();

break;

case auto_name_1:

Script_auto_name_1();

break;

case auto_name_2:

Script_auto_name_2();

break;

case auto_name_3:

Script_auto_name_3();

break;

case auto_name_4:

Script_auto_name_4();

break;

//do not modify between here and end of function

default:

Reset_scripts();

return;

}

if(done == 1 && script != no_script)

{

if(bsingle_step_mode)

{

if(bsingle_step)

{

step++;//increment to go to next step if button 8L is pushed

bsingle_step = false;

bsys_reset = true; //this is used to initialize each do_something script function

}

}

else

{

step++;

bsys_reset = true; //this is used to initialize each do_something script function

}

}

}

Here is a new typical script:

void Script_name_1()
{
switch(step)
{
case 0: //initialize script
//your init code here
done = 1;
break;

case 1:
done= Move_dist_ch1(500, 50); //command a rate of pwm 100 amd move to dist1 = 500
break;

case 2:
done= Move_dist_ch1(-500, 50);//command a rate of pwm 100 and move back -500 back to zero
break;

default:
Reset_scripts();

}

More related links:

Posted pictures on the vex site:

High Hang??

Low Hang.

More blog stuff:

https://vamfun.wordpress.com/2010/09/01/roundup-mentor-bot-operator-mode-scripting/

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

2 Responses to Proposed 599_Competition_Scripting_Template

  1. Sam says:

    Looks good!
    Can’t wait to see a finished working code!
    Hope you will post one
    Sam

  2. vamfun says:

    Hi Sam,
    The template is actually working code that contains a simulation. But if you were referring to an actual robot, the code posted here {http://www.vexforum.com/local_links.php?action=jump&catid=26&id=190} is essentially what the working code will look like except for the slight differences in how the scripts are called. All I would do is just repackage the scripts into functions rather than a stack put the contents of task main() into functions 599Autonomous and 599User.
    Cheers

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: