Go to Post The strength of an alliance is not defined strictly by the sum of its parts. - Jared Russell [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 18-02-2014, 15:56
Team1605 Team1605 is offline
Registered User
FRC #1605
 
Join Date: Feb 2012
Location: toronto
Posts: 30
Team1605 is an unknown quantity at this point
Question Autonomous

Code:
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2008. All Rights Reserved.                             */
/* Open Source Software - may be modified and shared by FRC teams. The code   */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project.                                                               */
/*----------------------------------------------------------------------------*/

package edu.wpi.first.wpilibj.templates;


import edu.wpi.first.wpilibj.*;
import edu.wpi.first.wpilibj.Joystick; 
import edu.wpi.first.wpilibj.RobotDrive; 
import edu.wpi.first.wpilibj.SimpleRobot; 
import edu.wpi.first.wpilibj.Timer; 



/**
 * The VM is configured to automatically run this class, and to call the
 * functions corresponding to each mode, as described in the SimpleRobot
 * documentation. If you change the name of this class or the package after
 * creating this project, you must also update the manifest file in the resource
 * directory.
 */
public class Team1605 extends SimpleRobot {
    
    
    Joystick stickDriverLeft = new Joystick(1);
    Joystick stickDriverRight = new Joystick(2);
    
    
    Jaguar leftMotor = new Jaguar(2);
    Jaguar rightMotor = new Jaguar(1);
    Victor shooterMotor = new Victor(3);
    Victor gatherMotor1 = new Victor(4); 
    Victor bridgeHandMotor = new Victor(6);
    
    RobotDrive robotDrive = new RobotDrive(leftMotor,rightMotor);
    
   
    
    /**
     * This function is called once each time the robot enters autonomous mode.
     */
    public void autonomous() {
        robotDrive.drive(0.5,0.0);//drive at 50% speed 0% turn
        Timer.delay(5.0);//wait 5 seconds
        //robotDrive.drive(0.0,0.0);//stop
        //Timer.delay(10.0);// wait 10 seconds
        
        //leftMotor.set(-1);
        //yrightMotor.set(1);
        //Timer.delay(15);
        //leftMotor.set(0);
        //rightMotor.set(0);
        //Timer.delay(3);
        
        
        
    }

    /**
     * This function is called once each time the robot enters operator control.
     */
    public void operatorControl() {
      while(isOperatorControl() && isEnabled())
    {
        
    
     robotDrive.tankDrive(stickDriverLeft.getAxis(Joystick.AxisType.kY), stickDriverRight.getAxis(Joystick.AxisType.kY));
    
        
       
        if(stickDriverRight.getButton(Joystick.ButtonType.kTrigger)) {
           shooterMotor.set(1);
        }
        else {
            shooterMotor.set(0);
        }
        
        
        if(stickDriverLeft.getButton(Joystick.ButtonType.kTrigger)) {
            gatherMotor1.set(-1);
            
        }
        else {
            gatherMotor1.set(0);
            
        }
       
        bridgeHandMotor.set(stickDriverLeft.getAxis(Joystick.AxisType.kY)); 
               
        
        Timer.delay(.01);
    }

    }
}
This is my code... i need help with the autonomous. i want it to go straight for about 5 seconds. But it only goes straight for about half to 1 second...
Reply With Quote
  #2   Spotlight this post!  
Unread 18-02-2014, 22:23
Dinnesy Dinnesy is offline
Registered User
FRC #4968 (Robo Hawks)
Team Role: Teacher
 
Join Date: Dec 2013
Rookie Year: 2014
Location: Lively
Posts: 19
Dinnesy is an unknown quantity at this point
Re: Autonomous

Quote:
Originally Posted by Team1605 View Post
Code:
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2008. All Rights Reserved.                             */
/* Open Source Software - may be modified and shared by FRC teams. The code   */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project.                                                               */
/*----------------------------------------------------------------------------*/

package edu.wpi.first.wpilibj.templates;


import edu.wpi.first.wpilibj.*;
import edu.wpi.first.wpilibj.Joystick; 
import edu.wpi.first.wpilibj.RobotDrive; 
import edu.wpi.first.wpilibj.SimpleRobot; 
import edu.wpi.first.wpilibj.Timer; 



/**
 * The VM is configured to automatically run this class, and to call the
 * functions corresponding to each mode, as described in the SimpleRobot
 * documentation. If you change the name of this class or the package after
 * creating this project, you must also update the manifest file in the resource
 * directory.
 */
public class Team1605 extends SimpleRobot {
    
    
    Joystick stickDriverLeft = new Joystick(1);
    Joystick stickDriverRight = new Joystick(2);
    
    
    Jaguar leftMotor = new Jaguar(2);
    Jaguar rightMotor = new Jaguar(1);
    Victor shooterMotor = new Victor(3);
    Victor gatherMotor1 = new Victor(4); 
    Victor bridgeHandMotor = new Victor(6);
    
    RobotDrive robotDrive = new RobotDrive(leftMotor,rightMotor);
    
   
    
    /**
     * This function is called once each time the robot enters autonomous mode.
     */
    public void autonomous() {
        robotDrive.drive(0.5,0.0);//drive at 50% speed 0% turn
        Timer.delay(5.0);//wait 5 seconds
        //robotDrive.drive(0.0,0.0);//stop
        //Timer.delay(10.0);// wait 10 seconds
        
        //leftMotor.set(-1);
        //yrightMotor.set(1);
        //Timer.delay(15);
        //leftMotor.set(0);
        //rightMotor.set(0);
        //Timer.delay(3);
        
        
        
    }

    /**
     * This function is called once each time the robot enters operator control.
     */
    public void operatorControl() {
      while(isOperatorControl() && isEnabled())
    {
        
    
     robotDrive.tankDrive(stickDriverLeft.getAxis(Joystick.AxisType.kY), stickDriverRight.getAxis(Joystick.AxisType.kY));
    
        
       
        if(stickDriverRight.getButton(Joystick.ButtonType.kTrigger)) {
           shooterMotor.set(1);
        }
        else {
            shooterMotor.set(0);
        }
        
        
        if(stickDriverLeft.getButton(Joystick.ButtonType.kTrigger)) {
            gatherMotor1.set(-1);
            
        }
        else {
            gatherMotor1.set(0);
            
        }
       
        bridgeHandMotor.set(stickDriverLeft.getAxis(Joystick.AxisType.kY)); 
               
        
        Timer.delay(.01);
    }

    }
}
This is my code... i need help with the autonomous. i want it to go straight for about 5 seconds. But it only goes straight for about half to 1 second...

Your autonomous function should look like

Code:
 
public void autonomous() {

     while(isAutonomous()){  //Place everything in a loop.
        robotDrive.drive(0.5,0.0);//drive at 50% speed 0% turn
        Timer.delay(5.0);//wait 5 seconds
     }
Reply With Quote
  #3   Spotlight this post!  
Unread 18-02-2014, 22:37
NWChen's Avatar
NWChen NWChen is offline
Alum
no team
 
Join Date: Oct 2012
Rookie Year: 2012
Location: New York City
Posts: 205
NWChen is a splendid one to beholdNWChen is a splendid one to beholdNWChen is a splendid one to beholdNWChen is a splendid one to beholdNWChen is a splendid one to beholdNWChen is a splendid one to beholdNWChen is a splendid one to behold
Re: Autonomous

Quote:
Originally Posted by Dinnesy View Post
Your autonomous function should look like

Code:
 
public void autonomous() {

     while(isAutonomous()){  //Place everything in a loop.
        robotDrive.drive(0.5,0.0);//drive at 50% speed 0% turn
        Timer.delay(5.0);//wait 5 seconds
     }
You don't need to iterate in autonomous; assuming you have a sequence of statements (e.g. drive forwards, stop, shoot) they should only execute once each. Look at this example.

Try the following instead:
Code:
public void autonomous() {
        robotDrive.setSafetyEnabled(false);
        robotDrive.drive(0.5,0.0);//drive at 50% speed 0% turn
        Timer.delay(5.0);//wait 5 seconds
}
When setSafetyEnabled is true (by default it is), the robot won't drive if the code continues for too long. That's probably causing your robot to stop entirely after ~0.1 seconds.

Last edited by NWChen : 18-02-2014 at 22:40.
Reply With Quote
  #4   Spotlight this post!  
Unread 18-02-2014, 22:49
mwtidd's Avatar
mwtidd mwtidd is offline
Registered User
AKA: mike
FRC #0319 (Big Bad Bob)
Team Role: Mentor
 
Join Date: Feb 2005
Rookie Year: 2003
Location: Boston, MA
Posts: 714
mwtidd has a reputation beyond reputemwtidd has a reputation beyond reputemwtidd has a reputation beyond reputemwtidd has a reputation beyond reputemwtidd has a reputation beyond reputemwtidd has a reputation beyond reputemwtidd has a reputation beyond reputemwtidd has a reputation beyond reputemwtidd has a reputation beyond reputemwtidd has a reputation beyond reputemwtidd has a reputation beyond repute
Re: Autonomous

Another option would be to use the system clock:

We used similar code on an alliance partner's robot at week 0 and it worked flawlessly.

Code:
public void autonomous() {
     long startTime = System.currentTimeMills();
     while(isAutonomous()){  //Place everything in a loop.
        long timePassed = System.currentTimeMills() - startTime;
        if(timePassed < 5000){
                //in the first 5 seconds of auto
                robotDrive.drive(0.1,0.0);
        }else {
                robotDrive.drive(0,0.0);
        }
        Timer.delay(.05);
     }
This code should not cause any drive not updated enough issues because the delay is only .05 second, and you should still be able to have the safety enabled.

Also you'll noticed I chanced the speed to .01, you only need to cross the line, so I would slowly increment the speed until it matches your needs. Driving at half speed for 5 seconds could have some unintended consequences.
__________________
"Never let your schooling interfere with your education" -Mark Twain

Last edited by mwtidd : 18-02-2014 at 22:54.
Reply With Quote
  #5   Spotlight this post!  
Unread 19-02-2014, 18:11
otherguy's Avatar
otherguy otherguy is offline
sparkE
AKA: James
FRC #2168 (The Aluminum Falcons)
Team Role: Mentor
 
Join Date: Feb 2010
Rookie Year: 2009
Location: CT
Posts: 434
otherguy is a splendid one to beholdotherguy is a splendid one to beholdotherguy is a splendid one to beholdotherguy is a splendid one to beholdotherguy is a splendid one to beholdotherguy is a splendid one to beholdotherguy is a splendid one to behold
Re: Autonomous

It's important to actually tell your motors to stop after commanding the drivetrain to move forward for 5 seconds. Otherwise your code will go on its merry way, but the drivetrain will continue to be commanded.

Regardless of how you end up implementing the code you need to explicitly command the motors to 0.

lineskier's code does this:
Code:
robotDrive.drive(0.0, 0.0);
It's an important item that should not be overlooked.
__________________
http://team2168.org
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 13:22.

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