Go to Post But if we just re-play "Triple Play" then what in the world will the Game Design Committee do with all that new-found free time? Since they wouldn't have to come up with a new game, they would have to concentrate on other things - like how to enforce the proposed "no metal on robots" rule. - dlavery [more]
Home
Go Back   Chief Delphi > Technical > Programming > Java
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Reply
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 02-03-2010, 23:57
The Engineer The Engineer is offline
Registered User
FRC #2607
 
Join Date: Jan 2010
Location: America
Posts: 14
The Engineer is an unknown quantity at this point
Multiple Autons

I want to run different autonomous modes for different starting positions and i was wondering A) How do you do that in the code and B) can it be set from the Classmate and if not can it be set from a controller
Reply With Quote
  #2   Spotlight this post!  
Unread 03-03-2010, 02:01
davidalln's Avatar
davidalln davidalln is offline
World's Worst Coder
AKA: David Allen
FRC #2415 (The Westminster Wiredcats)
Team Role: Programmer
 
Join Date: Mar 2009
Rookie Year: 2008
Location: Atlanta, GA
Posts: 108
davidalln is on a distinguished road
Send a message via AIM to davidalln
Re: Multiple Autons

The simplest way to do this is to have a switch/case taking in a variable that you predetermine before a match and having the separate autonomous modes there. For example...

Code:
int position = 1;
switch(position) {
  case 1:
    // autonomous mode for close
    break;
  case 2:
    // autonomous mode for mid
    break;
  case 3:
    // autonomous mode for far
    break;
}
It is also legal to have a "switch" of some sorts on your robot plugged into your sidecar that you flip before the match as you set up your bot to determine position (in which case your code would still look similar to the code above).
__________________
SANTOSH ANDREW DECKER RICK WYNNIE SEAN DEREK MATT
(alamo (semis), p'tree (CHAMPS!), nc (CHAMPS!), newton (quarters))


Best four years of my life. Thanks to everyone who made it happen.
Reply With Quote
  #3   Spotlight this post!  
Unread 06-03-2010, 21:46
AlexD744 AlexD744 is offline
Registered User
FRC #0744 (744 Shark Attack)
Team Role: Alumni
 
Join Date: Jan 2009
Rookie Year: 2008
Location: Ft. Lauderdale, FL
Posts: 639
AlexD744 has a reputation beyond reputeAlexD744 has a reputation beyond reputeAlexD744 has a reputation beyond reputeAlexD744 has a reputation beyond reputeAlexD744 has a reputation beyond reputeAlexD744 has a reputation beyond reputeAlexD744 has a reputation beyond reputeAlexD744 has a reputation beyond reputeAlexD744 has a reputation beyond reputeAlexD744 has a reputation beyond reputeAlexD744 has a reputation beyond repute
Re: Multiple Autons

Our robot has 16 different autonomous modes that can be programmed. We simply put 4 switches onto the robot and used the get() method to get true or false. Then we converted true (or false, depending on preference). Into 1's and 0's. Finally, we multiplied the values together into a variable and switch/case/breaked it. Although for readability we made a seperate method for each case, and called the specific method.

edit: the switches work only on the robot, i beleive, because we tried control board switches last year and it did not read them, therefore we had to switch to robot switches. But both are easy to use. Also not it's good to write down what each autonomous position is, oh yeah and make copies of it.
__________________
www.sharkattack744.com
Reply With Quote
  #4   Spotlight this post!  
Unread 07-03-2010, 22:35
ideasrule's Avatar
ideasrule ideasrule is offline
Registered User
FRC #0610 (Coyotes)
Team Role: Programmer
 
Join Date: Jan 2010
Rookie Year: 2009
Location: Toronto
Posts: 108
ideasrule is a jewel in the roughideasrule is a jewel in the roughideasrule is a jewel in the roughideasrule is a jewel in the rough
Re: Multiple Autons

You can definitely do it from the Classmate. Just go to the I/O tab and select one or more of the digital inputs. In the code, use station.getInstance().getDigitalInput(number) to get the value of the input, where station is the name of the DriverStation object. There are 10 digital inputs, so you can have 2^10-1=1023 different autonomous programs.
Reply With Quote
  #5   Spotlight this post!  
Unread 07-03-2010, 22:55
The Engineer The Engineer is offline
Registered User
FRC #2607
 
Join Date: Jan 2010
Location: America
Posts: 14
The Engineer is an unknown quantity at this point
Re: Multiple Autons

where do you assign the switch between the autons in the code do you do it in disabled periodic or robot init
Reply With Quote
  #6   Spotlight this post!  
Unread 08-03-2010, 21:02
LukeS LukeS is offline
4272 mentor, 1024 alumnus
AKA: Luke Shumaker
FRC #4272
Team Role: Mentor
 
Join Date: Mar 2009
Rookie Year: 2009
Location: Indianapolis, IN
Posts: 60
LukeS is an unknown quantity at this point
Re: Multiple Autons

Quote:
Originally Posted by ideasrule View Post
You can definitely do it from the Classmate. Just go to the I/O tab and select one or more of the digital inputs. In the code, use station.getInstance().getDigitalInput(number) to get the value of the input, where station is the name of the DriverStation object. There are 10 digital inputs, so you can have 2^10-1=1023 different autonomous programs.
Yes, but I'm fairly certain that you cannot read from the driver station input in autonomous mode.

Also, 1024 different autonomous programs, you only subtract 1 to get the highest number you can represent, so you can represent 0-1023, which is 1024 integers total.

Last edited by LukeS : 08-03-2010 at 21:04. Reason: typo
Reply With Quote
  #7   Spotlight this post!  
Unread 08-03-2010, 21:21
Tom Bottiglieri Tom Bottiglieri is offline
Registered User
FRC #0254 (The Cheesy Poofs)
Team Role: Engineer
 
Join Date: Jan 2004
Rookie Year: 2003
Location: San Francisco, CA
Posts: 3,187
Tom Bottiglieri has a reputation beyond reputeTom Bottiglieri has a reputation beyond reputeTom Bottiglieri has a reputation beyond reputeTom Bottiglieri has a reputation beyond reputeTom Bottiglieri has a reputation beyond reputeTom Bottiglieri has a reputation beyond reputeTom Bottiglieri has a reputation beyond reputeTom Bottiglieri has a reputation beyond reputeTom Bottiglieri has a reputation beyond reputeTom Bottiglieri has a reputation beyond reputeTom Bottiglieri has a reputation beyond repute
Re: Multiple Autons

Quote:
Originally Posted by LukeS View Post
Yes, but I'm fairly certain that you cannot read from the driver station input in autonomous mode.
You can in disabled. We use a push button on our control board to cycle through autonomous modes. The dashboard gives a read out of the current selection.
Reply With Quote
  #8   Spotlight this post!  
Unread 09-03-2010, 08:59
ideasrule's Avatar
ideasrule ideasrule is offline
Registered User
FRC #0610 (Coyotes)
Team Role: Programmer
 
Join Date: Jan 2010
Rookie Year: 2009
Location: Toronto
Posts: 108
ideasrule is a jewel in the roughideasrule is a jewel in the roughideasrule is a jewel in the roughideasrule is a jewel in the rough
Re: Multiple Autons

Quote:
Originally Posted by LukeS View Post
Yes, but I'm fairly certain that you cannot read from the driver station input in autonomous mode.
I'm very certain that you can because that's exactly what our team did during the Finger Lake Regionals. I put 3 if statements in autonomousInit() and had each of them start a new thread.

Quote:
Also, 1024 different autonomous programs, you only subtract 1 to get the highest number you can represent, so you can represent 0-1023, which is 1024 integers total.
Oops, you're right; I was getting confused.
Reply With Quote
  #9   Spotlight this post!  
Unread 10-03-2010, 17:19
The Engineer The Engineer is offline
Registered User
FRC #2607
 
Join Date: Jan 2010
Location: America
Posts: 14
The Engineer is an unknown quantity at this point
Re: Multiple Autons

Ok i really have very little preference to how the switch is made i am just looking for help with the code. if you can tell me anyway to set and switch between autons that would be fantastic
Reply With Quote
  #10   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
  #11   Spotlight this post!  
Unread 11-03-2010, 14:30
ideasrule's Avatar
ideasrule ideasrule is offline
Registered User
FRC #0610 (Coyotes)
Team Role: Programmer
 
Join Date: Jan 2010
Rookie Year: 2009
Location: Toronto
Posts: 108
ideasrule is a jewel in the roughideasrule is a jewel in the roughideasrule is a jewel in the roughideasrule is a jewel in the rough
Re: Multiple Autons

Quote:
Originally Posted by The Engineer View Post
Ok i really have very little preference to how the switch is made i am just looking for help with the code. if you can tell me anyway to set and switch between autons that would be fantastic
Since it doesn't seem like you're the programmer who coded autonomous, get that programmer to do it. It's not a good idea to mess around with somebody else's code because it's very easy to break something or make an error that's super hard to fix.
Reply With Quote
  #12   Spotlight this post!  
Unread 11-03-2010, 17:51
The Engineer The Engineer is offline
Registered User
FRC #2607
 
Join Date: Jan 2010
Location: America
Posts: 14
The Engineer is an unknown quantity at this point
Re: Multiple Autons

It is my code i am just relatively new to java
Reply With Quote
  #13   Spotlight this post!  
Unread 11-03-2010, 20:26
The Engineer The Engineer is offline
Registered User
FRC #2607
 
Join Date: Jan 2010
Location: America
Posts: 14
The Engineer is an unknown quantity at this point
Re: Multiple Autons

I wrote a code that can switch between i am wondering were i can put it that it will be accessible in disabled and in autonomous.
if it helps my code looks like this(


private boolean AutonMode0() {
if (driveStick.getRawButton(1))
return false;
if (driveStick.getRawButton(2))
return false;
if (driveStick.getRawButton(3))
return true;
if (driveStick.getRawButton(4))
return true;
else {
return false;
}
}
private boolean AutonMode1() {
if (driveStick.getRawButton(1))
return false;
if (driveStick.getRawButton(2))
return true;
if (driveStick.getRawButton(3))
return false;
if (driveStick.getRawButton(4))
return true;
else {
return false;
}
}



)
Reply With Quote
  #14   Spotlight this post!  
Unread 11-03-2010, 23:30
ideasrule's Avatar
ideasrule ideasrule is offline
Registered User
FRC #0610 (Coyotes)
Team Role: Programmer
 
Join Date: Jan 2010
Rookie Year: 2009
Location: Toronto
Posts: 108
ideasrule is a jewel in the roughideasrule is a jewel in the roughideasrule is a jewel in the roughideasrule is a jewel in the rough
Re: Multiple Autons

That works,and you'd put it inside the brackets enclosing the class, except you have to change the method declarations from private boolean Name to private static boolean Name.

There's a much simpler way to do this. In autonomousInit(), do:

if (driveStick.getRawButton(1)) {
run whatever;
}
if (driveStick.getRawButton(2)) {
run whatever;
}
and so on
Reply With Quote
  #15   Spotlight this post!  
Unread 12-03-2010, 09:46
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

Will these work if you are standing 5 feet away from your controls? If you are using a joystick as your method for selecting an autonomous mode, you need to do it in disabledPeriodic. And you need to set a VARIABLE to some value in response to the input. Your joystick methods are state calls. They don't remember what was done in the past. You store the input in a GLOBAL variable that can be examined by autonomous.

Do not place your autonomous code in autonomousInit, as this is called only once on the way to autonomousPeriodic. Initialize variables and motors and perhaps decide which auton to run in autonomousPeriodic.

HINT: see my code above
__________________
I don't need a signature.
Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
[FTC]: Multiple Programs or One Program with Multiple Auto Modes kevin51292 FIRST Tech Challenge 4 02-01-2009 20:37
Hosting multiple sites in multiple VMs EHaskins Website Design/Showcase 6 22-12-2007 01:09
Multiple Auton's Joe Clohessy Programming 17 11-02-2005 18:46
Multiple RCX's Noah Melamed FIRST Lego League 1 25-01-2005 15:55


All times are GMT -5. The time now is 11:02.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi