Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   Java (http://www.chiefdelphi.com/forums/forumdisplay.php?f=184)
-   -   Autonomous Help (http://www.chiefdelphi.com/forums/showthread.php?t=114601)

Mr.Roboto3335 03-03-2013 20:31

Autonomous Help
 
I wanted to know how to make a motor wait and then move in autonomous.

Autonomous Code So Far:
Code:

public void autonomousPeriodic()
    {
        ShooterFront.set(50);
        ShooterBack.set(50);
      //Wanted to add 3 second wait
        servo.setAngle(90);
      //Wanted to add 3 second wait 
        servo.setAngle(180);
      //Wanted to add 3 second wait
        servo.setAngle(90);
      //Wanted to add 3 second wait 
        servo.setAngle(180);
      //Wanted to add 3 second wait 
        servo.setAngle(90);
      //Wanted to add 3 second wait 
        servo.setAngle(180);
    }


F22Rapture 03-03-2013 23:20

Re: Autonomous Help
 
Are you using the Command-Based template? Create a command for each thing you want to do, then string them together with a Command Group.

In RobotMain

Code:

private Command autonomousCommand;

public void autonomousInit() {
        autonomousCommand = new Auton0();   
        autonomousCommand.start();
    }

public void autonomousPeriodic() {
        Scheduler.getInstance().run();
    }

In command group

Code:

public class Auton0 extends CommandGroup {
   
    public Auton0() {
        addSequential(new SetFrontSpeed(50);
        addParallel(new SetBackSpeed(50);
        addSequential(new SetAngle(90));
        addSequential(new WaitCommand(3));
        addSequential(new SetAngle(45));
   
        etc. etc.
    }


Mr.Roboto3335 04-03-2013 10:54

Re: Autonomous Help
 
I'm writing in Iterative Template

tuXguy15 04-03-2013 11:09

Re: Autonomous Help
 
Hey maybe this can be some help.

public void autonomousPeriodic()
{
ShooterFront.set(50);
ShooterBack.set(50);
Timer.delay(3.0);
servo.setAngle(90);
Timer.delay(3.0);
servo.setAngle(180);
Timer.delay(3.0);
servo.setAngle(90);
Timer.delay(3.0);
servo.setAngle(180);
Timer.delay(3.0);
servo.setAngle(90);
Timer.delay(3.0);
servo.setAngle(180);
}

The Timer.delay(); sets the amount of time to wait before the execution of the next string of code.

notmattlythgoe 04-03-2013 12:45

Re: Autonomous Help
 
Just as a warning, you currently have 18 seconds of waits for a 15 second autonomous period. Once you get it tested you'll probably want to trim down some of the wait times if you can.

Mr.Roboto3335 04-03-2013 17:07

Re: Autonomous Help
 
Quote:

Originally Posted by Zer0 (Post 1243346)
Hey maybe this can be some help.

public void autonomousPeriodic()
{
ShooterFront.set(50);
ShooterBack.set(50);
Timer.delay(3.0);
servo.setAngle(90);
Timer.delay(3.0);
servo.setAngle(180);
Timer.delay(3.0);
servo.setAngle(90);
Timer.delay(3.0);
servo.setAngle(180);
Timer.delay(3.0);
servo.setAngle(90);
Timer.delay(3.0);
servo.setAngle(180);
}

The Timer.delay(); sets the amount of time to wait before the execution of the next string of code.

What if I wanted the Front and Back Shooters motors to move the whole time?

Team3266Spencer 04-03-2013 17:18

Re: Autonomous Help
 
Quote:

Originally Posted by Mr.Roboto3335 (Post 1243559)
What if I wanted the Front and Back Shooters motors to move the whole time?

They are in this example, they're never set to stop.

cgmv123 04-03-2013 17:26

Re: Autonomous Help
 
Quote:

Originally Posted by Mr.Roboto3335 (Post 1243559)
What if I wanted the Front and Back Shooters motors to move the whole time?

They both will. The delay will leave both at the levels they were set at.

tuXguy15 04-03-2013 18:07

Re: Autonomous Help
 
It won't stop. It would only stop if you threw ShooterBack.set(0.0); in there some where. Also are you using jaguars for the motor controllers?

Joe Ross 04-03-2013 23:01

Re: Autonomous Help
 
Quote:

Originally Posted by Zer0 (Post 1243346)
Hey maybe this can be some help.

public void autonomousPeriodic()
{
ShooterFront.set(50);
ShooterBack.set(50);
Timer.delay(3.0);
servo.setAngle(90);
Timer.delay(3.0);
servo.setAngle(180);
Timer.delay(3.0);
servo.setAngle(90);
Timer.delay(3.0);
servo.setAngle(180);
Timer.delay(3.0);
servo.setAngle(90);
Timer.delay(3.0);
servo.setAngle(180);
}

The Timer.delay(); sets the amount of time to wait before the execution of the next string of code.

This won't work in the iterative framework (but it will in the simple framework). The AutonomousPeriodic needs to execute quickly and then return. Here's an (untested) way to do the same thing, that will work in the iterative framework

Code:

    double startTime;
    public void autonomousInit() {
        startTime = Timer.getFPGATimestamp();
    }
    public void autonomousPeriodic() {
        if ((Timer.getFPGATimestamp() - startTime) < 3000)
        {
            ShooterFront.set(50);
            ShooterBack.set(50);
        }
        else if ((Timer.getFPGATimestamp() - startTime) < 6000)
        {
            servo.setAngle(90);
        }
        else if ((Timer.getFPGATimestamp() - startTime) < 9000)
        {
            servo.setAngle(180);
        }
  }

etc

Mr.Roboto3335 06-03-2013 11:25

Re: Autonomous Help
 
I will try that and let you know if it works.

JohnFogarty 06-03-2013 22:47

Re: Autonomous Help
 
I'll send you a copy of my code tomorrow but I use a state machine switch case in which I create a timer instance. Start it. and compare if the timer is greater than 100 microseconds. if it is move to the next case in the switch, reset the timer, start it again, chose the next amount of wait time needed, compare the value of the timer until it is greater than or equal to the new wait time. and repeat. It's easier to understand what I do once you see my code.

tuXguy15 09-03-2013 16:39

Re: Autonomous Help
 
It worked for my team last year and this year and we use the Iterative framework. You just have to use up the full 15 seconds or tell it to do nothing when your done executing everything or it will start over.


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

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