Thread: Multiple Autons
View Single Post
  #2   Spotlight this post!  
Unread 10-03-2010, 18:13
TubaMorg TubaMorg is offline
Programmermechanicalelect ricalcoach
AKA: Dan
FRC #1480 (Robatos Locos)
Team Role: Mentor
 
Join Date: Jan 2006
Rookie Year: 2005
Location: Houston
Posts: 450
TubaMorg has a reputation beyond reputeTubaMorg has a reputation beyond reputeTubaMorg has a reputation beyond reputeTubaMorg has a reputation beyond reputeTubaMorg has a reputation beyond reputeTubaMorg has a reputation beyond reputeTubaMorg has a reputation beyond reputeTubaMorg has a reputation beyond reputeTubaMorg has a reputation beyond reputeTubaMorg has a reputation beyond reputeTubaMorg has a reputation beyond repute
Re: Multiple Autons

Here is a sniippet of our code that handles auton switiching. It is sanitized, and not all variables are shown declared.
Switching takes place during disabledPeriodic. Care should be taken in teleopinit to clean up after autonomous before heading into teleop mode so that nothing unexpected happens.

Code:
public void autonomousPeriodic()
    {
        this.getWatchdog().feed();
        switch (autoMode)
        {
            case 1:
                // Add kick three balls in goal code here
                message("Performing auto in FAR field");
                break;
            case 2:
                // Add kick two balls in goal code here
                message("Performing auto in MID field");
                break;
            case 3:
                // Add kick one ball in goal here
                message("Performing auto in NEAR field");
                break;
            default:
                // Auto program isn't working so do this instead
                message("Doing nothing");
                break;
        }
    }

    public void disabledInit()
    {
        this.getWatchdog().feed();
    }

    public void disabledPeriodic()
    {
        this.getWatchdog().feed();
        // Using joystick trigger to switch modes
        if (!autoTrigger && js_right.getRawButton(1))
        {
            if (autoMode < 4)
            {
                autoMode++;
            } else
            {
                autoMode = 1;
            }
            autoTrigger = true;
        } else if (!js_right.getRawButton(1))
        {
            autoTrigger = false;
        }
        // Update message at driverstation to reflect current
        // mode selection
        switch (autoMode)
        {
            case 1:
                message("1. Autonomous for FAR field");
                break;
            case 2:
                message("2. Autonomous for  MID field");
                break;
            case 3:
                message("3. Autonomous for NEAR field");
                break;
            default:
                message("Do Nothing...in any position!");
                break;
        }
    }
public void message(String s)
    {
        String temp = s;
        if (!temp.equals(userMessage))
        {
            //System.out.println(s);
            userMessage = temp;
            int length = s.length();
            //int numRows = 1;
            String[] row = new String[6];
            for (int i = 0; i < 6; i++)
            {
                row[i] = "";
            }
            if (length > 20)
            {
                int backwards = 5;
                int index = 0;
                // Each line can only hold 21 characters, so
                // break the line in reverse at a space.
                // This will end up not working if a message is STILL
                // too long.  Program must ensure not to send messages
                // too long.
                while (length > 20 && backwards >= 0)
                {
                    index = temp.lastIndexOf(' ', 20);
                    row[backwards] = temp.substring(index);
                    row[backwards].trim();
                    temp = temp.substring(0, index).trim();
                    length = temp.length();
                    backwards--;
                }
                row[backwards]=temp;
            } else
            {
                row[5] = temp;
            }
            // Erase the message box
            DriverStationLCD.getInstance().println(DriverStationLCD.Line.kMain6, 1, "                      ");
            DriverStationLCD.getInstance().println(DriverStationLCD.Line.kUser2, 1, "                      ");
            DriverStationLCD.getInstance().println(DriverStationLCD.Line.kUser3, 1, "                      ");
            DriverStationLCD.getInstance().println(DriverStationLCD.Line.kUser4, 1, "                      ");
            DriverStationLCD.getInstance().println(DriverStationLCD.Line.kUser5, 1, "                      ");
            DriverStationLCD.getInstance().println(DriverStationLCD.Line.kUser6, 1, "                      ");
            DriverStationLCD.getInstance().updateLCD();
            // Now write the data
            DriverStationLCD.getInstance().println(DriverStationLCD.Line.kMain6, 1, row[0]);
            DriverStationLCD.getInstance().println(DriverStationLCD.Line.kUser2, 1, row[1]);
            DriverStationLCD.getInstance().println(DriverStationLCD.Line.kUser3, 1, row[2]);
            DriverStationLCD.getInstance().println(DriverStationLCD.Line.kUser4, 1, row[3]);
            DriverStationLCD.getInstance().println(DriverStationLCD.Line.kUser5, 1, row[4]);
            DriverStationLCD.getInstance().println(DriverStationLCD.Line.kUser6, 1, row[5]);
            DriverStationLCD.getInstance().updateLCD();
        }
    }
__________________
I don't need a signature.

Last edited by TubaMorg : 10-03-2010 at 18:21.
Reply With Quote