Go to Post It's over, done, let's move on and be positive. Next year maybe everything will be perfect. :cool: - Ed Sparks [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 28-03-2016, 21:48
MRT45's Avatar
MRT45 MRT45 is offline
Registered User
FRC #0253 (Mills Robotics Team)
Team Role: Programmer
 
Join Date: Feb 2014
Rookie Year: 2013
Location: CA
Posts: 15
MRT45 is an unknown quantity at this point
Autonomous not stopping. Constantly running... during enabling

Hey Guys,
I decided to get autonomous to work this year and ran into the problem of an unlimited run time despite a set stopping point.

Can someone check this out and find the problem? I honestly don't know what the problem is.

I may be overlooking something simple, but I am clearly not seeing it.
Code:
 
    public void autonomousInit() {
        // schedule the autonomous command (example)
       // if (autonomousCommand != null) autonomousCommand.start();
    	//autonomousCommand.start();
    	  // Reset timer to 0sec
    	edu.wpi.first.wpilibj.Timer myTimer = new edu.wpi.first.wpilibj.Timer();
        myTimer.reset();

        // Start timer
        myTimer.start();
    	
       // move(-0.5,3.0);

    }

    /**
     * This function is called periodically during autonomous
     */



 public void autonomousPeriodic() {
// link  -https://www.reddit.com/r/FRC/comments/3zcc2d/timer_not_working/
        // If is has been less than 2 seconds since autonomous started, drive forwards
    	
    	edu.wpi.first.wpilibj.Timer myTimer = new edu.wpi.first.wpilibj.Timer();
        if(myTimer.get() < 2.0){
        	Robot.drivetraintank.setLeft_Back(0.5);
        	Robot.drivetraintank.setLeft(0.5);
        	Robot.drivetraintank.setRight(0.5);
        	Robot.drivetraintank.setRight_Back(0.5);
        }

        // If more than 2 seconds have elapsed, stop driving and turn off the timer
        else {
        	Robot.drivetraintank.setLeft_Back(0.5);
        	Robot.drivetraintank.setLeft(0.5);
        	Robot.drivetraintank.setRight(0.5);
        	Robot.drivetraintank.setRight_Back(0.5);
            myTimer.stop();
        }

    }
    	
    	
       // Scheduler.getInstance().run();
__________________
Member of the MILLS ROBOTICS TEAM - 253

"Everyone and everything is like a formula. You may seem small, but God has spent a long time making you right." - Wayne Phillips
Reply With Quote
  #2   Spotlight this post!  
Unread 28-03-2016, 21:57
euhlmann's Avatar
euhlmann euhlmann is offline
CTO, Programmer
AKA: Erik Uhlmann
FRC #2877 (LigerBots)
Team Role: Leadership
 
Join Date: Dec 2015
Rookie Year: 2015
Location: United States
Posts: 322
euhlmann has much to be proud ofeuhlmann has much to be proud ofeuhlmann has much to be proud ofeuhlmann has much to be proud ofeuhlmann has much to be proud ofeuhlmann has much to be proud ofeuhlmann has much to be proud ofeuhlmann has much to be proud of
Re: Autonomous not stopping. Constantly running... during enabling

In your else block, you don't seem to be stopping the motors. Try changing all those calls to set 0.

Also, I noticed that you're using the command based framework (based on the code you left commented out).
Why not make an autonomous command and use the internal timer of each command to run your autonomous? Something like this:

Code:
class AutoCommand extends Command {
    public AutoCommand(){
    }

    public void init(){
         setTimeout(2); // here's where you set the internal timer of commands
    }

    public void execute(){
        Robot.drivetraintank.setLeft_Back(0.5);
        Robot.drivetraintank.setLeft(0.5);
        Robot.drivetraintank.setRight(0.5);
        Robot.drivetraintank.setRight_Back(0.5);
    }

    public boolean isFinished(){
        return isTimedOut(); // this ends the command once the 2 seconds you set in init() are up
    }

    // in the last 2 methods, clean up by zeroing out the motors
    // this ensures that motor output stops once the command ends or is cancelled
    public void end(){
        Robot.drivetraintank.setLeft_Back(0);
        Robot.drivetraintank.setLeft(0);
        Robot.drivetraintank.setRight(0);
        Robot.drivetraintank.setRight_Back(0);
    }

    public void interrupted(){
        Robot.drivetraintank.setLeft_Back(0);
        Robot.drivetraintank.setLeft(0);
        Robot.drivetraintank.setRight(0);
        Robot.drivetraintank.setRight_Back(0);
    }
}
Then in your robot class

Code:
    Command autoCommand = new AutoCommand();

    public void autonomousInit(){
        autoCommand.start();
    }

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

    public void teleopInit(){
         // it's always good practice to do this, in case you make some change to your auto command that ends up taking too long to run
         // we put code in interrupted() to handle this case
         autoCommand.cancel();
    }

Last edited by euhlmann : 28-03-2016 at 22:03. Reason: add suggestion about using commands
Reply With Quote
  #3   Spotlight this post!  
Unread 28-03-2016, 22:09
heuristics heuristics is offline
Registered User
FRC #3634
Team Role: Mentor
 
Join Date: Jan 2014
Rookie Year: 2014
Location: Trumbull, CT
Posts: 21
heuristics is on a distinguished road
Re: Autonomous not stopping. Constantly running... during enabling

Your else block is not turning the motors off. In addition, you should make your timer a member variable of the class.

Declare it outside of (usually above) your functions:
Code:
Timer myTimer;
Initialize it inside autonomousInit()
Code:
myTimer = new Timer();
myTimer.reset();
myTimer.start();
Then you can use it inside your autonomousPeriodic() function.

This way the timer will give you the time since auto mode started which is what you're looking for.

Last edited by heuristics : 28-03-2016 at 22:11.
Reply With Quote
  #4   Spotlight this post!  
Unread 28-03-2016, 22:23
RufflesRidge RufflesRidge is offline
Registered User
no team
 
Join Date: Jan 2012
Location: USA
Posts: 989
RufflesRidge has a brilliant futureRufflesRidge has a brilliant futureRufflesRidge has a brilliant futureRufflesRidge has a brilliant futureRufflesRidge has a brilliant futureRufflesRidge has a brilliant futureRufflesRidge has a brilliant futureRufflesRidge has a brilliant futureRufflesRidge has a brilliant futureRufflesRidge has a brilliant futureRufflesRidge has a brilliant future
Re: Autonomous not stopping. Constantly running... during enabling

Either of the two posts above should put you down the path of solving the issue.

The code you have now (in addition to not actually stopping the motors in the else) is creating a new timer every time autonomousPeriodic is called. This timer is never started so it will return 0. You can either create the timer once as 'heuristics' has suggested or scrap this and use a command with setTimout() and isTimedOut() as 'euhlmann' has suggested.
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


All times are GMT -5. The time now is 09:18.

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