Go to Post I don't think Brandon is actually doing this, I think he has CD-47 Bot and Archiver locked in a closet doing all this while he has fun - Mike Schroeder [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-02-2014, 22:48
miw14 miw14 is offline
Registered User
FRC #4840
 
Join Date: Feb 2014
Location: Michigan
Posts: 19
miw14 is an unknown quantity at this point
URGENT:Auto Problem trying to fix before tomorrow

On our first day of competition, we ran into some problems with our shooter. The shooter does not seem to be functioning right in autonomous, but it functions fine in teleoperated. We use the same methods for both, but they both yield different results. Any ideas as to why it works well in one and not the other? The launcher barely moves when we try it in auto, but works fine in teleoperated. The driving is fine in auto. Here is the code:

Autonomous method:

public void autonomous()
{ myDrive.setSafetyEnabled(false);
myDrive.drive(-.5, 0.0);
Timer.delay(3.5);
myDrive.stopMotor();
Timer.delay(1.5);
startRaisingLauncher();
Timer.delay(3.5);
stopMovingLauncher();

stopAll();

}

Raising launcher method:

private void startRaisingLauncher()
{
setLiftPower(-1);
}

set power method:
private void setLiftPower(double power)
{
M1.set(-power);
M2.set(power);
}
Reply With Quote
  #2   Spotlight this post!  
Unread 28-02-2014, 22:54
Domenic Rodriguez's Avatar
Domenic Rodriguez Domenic Rodriguez is offline
Registered User
FRC #0316 (LuNaTeCs)
Team Role: College Student
 
Join Date: Sep 2010
Rookie Year: 2011
Location: Grove City, PA
Posts: 213
Domenic Rodriguez has a spectacular aura aboutDomenic Rodriguez has a spectacular aura aboutDomenic Rodriguez has a spectacular aura about
Re: URGENT:Auto Problem trying to fix before tomorrow

Without seeing more of the code, it will be difficult to determine what the issue is. Are you having problems both on and off the field? Is there any way the power values to the motors could be different between Autonomous and Teleop modes?

Also, if you wrap your code in [code][/code] tags, it will format nicely, like this:
Code:
public void autonomous() { 
    myDrive.setSafetyEnabled(false);
    myDrive.drive(-.5, 0.0); 
    Timer.delay(3.5);
    myDrive.stopMotor(); 
    Timer.delay(1.5);
    startRaisingLauncher(); 
    Timer.delay(3.5); 
    stopMovingLauncher();

    stopAll();
}

// Raising launcher method:
private void startRaisingLauncher() { 
    setLiftPower(-1);
}

// set power method: 
private void setLiftPower(double power) { 
    M1.set(-power); 
    M2.set(power);
}
__________________

LuNaTeCs - Learning Under Nurturing Adults Teaching Engineering Concepts and Skills - Small and Mighty!

FRC 316 LuNaTeCs - Student (2011-2014), Lead Programmer (2011-2014), Team Captain (2013-2014), Operator (2013), Drive Coach (2014), Mentor (2015-????)
'11 Philly Regional Finalists, '13 Chestnut Hill Finalists, '13 Lenape Champions, '13 Archimedes Division, '14 Chestnut Hill Champions, '14 Lenape Champions
FTC 7071 EngiNerds - Founding Advisor (2013-2014) | FRC 5420 Velocity - Founding Advisor (2015)
Grove City College Class of '18, Electrical/Computer Engineering (B.S.E.E)

Reply With Quote
  #3   Spotlight this post!  
Unread 28-02-2014, 23:14
miw14 miw14 is offline
Registered User
FRC #4840
 
Join Date: Feb 2014
Location: Michigan
Posts: 19
miw14 is an unknown quantity at this point
Re: URGENT:Auto Problem trying to fix before tomorrow

Thanks, here is the full code:
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.SimpleRobot; 
import edu.wpi.first.wpilibj.Joystick; 
import edu.wpi.first.wpilibj.RobotDrive; 
import edu.wpi.first.wpilibj.Talon; 
import edu.wpi.first.wpilibj.Timer;
import edu.wpi.first.wpilibj.Victor; 
/** * * 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 Drive extends SimpleRobot 
{ 
private RobotDrive myDrive, Shooter; 
private Joystick driveStick; 
private Talon FrontRight, FrontLeft, BackRight, BackLeft; 
private Victor M1, M2; 
/** * * This function is called once each time the robot enters autonomous * mode. */
 public void robotInit() 
{ 
FrontRight = new Talon(4);
 BackLeft = new Talon(1); 
FrontLeft = new Talon(3); 
BackRight = new Talon(2); 
myDrive = new RobotDrive(FrontLeft, BackLeft, FrontRight, BackRight);
myDrive.setInvertedMotor(RobotDrive.MotorType.kFrontLeft, true);  myDrive.setInvertedMotor(RobotDrive.MotorType.kRearLeft, true); 
M1 = new Victor(5);
 M2 = new Victor(6); 
Shooter = new RobotDrive(M1, M2);
driveStick = new Joystick(1);
 } 
public void autonomous() { 
myDrive.setSafetyEnabled(false); 

 myDrive.drive(-.5, 0.0); 
Timer.delay(3.5);
 myDrive.stopMotor(); 
Timer.delay(1.5); 
startRaisingLauncher(); 
Timer.delay(3.5); 
stopMovingLauncher(); 
 stopAll();
 } 
public void operatorControl() { 
myDrive.setSafetyEnabled(true); 
while (isOperatorControl() && isEnabled()) 
{
myDrive.arcadeDrive(driveStick); 
 checkLauncherControl(); Timer.delay(0.01); 
} 
 
stopAll(); 
}

 private void checkLauncherControl() { 
int RAISE_BUTTON = 1; 
int LOWER_BUTTON = 2;
 if (driveStick.getRawButton(RAISE_BUTTON) == true) 
{ startRaisingLauncher(); 
} 
else if (driveStick.getRawButton(LOWER_BUTTON) == true) 
{ startLoweringLauncher(); 
}
 else 
{ stopMovingLauncher(); 
} 
} 
 private void stopAll() 
{ myDrive.stopMotor(); 
stopMovingLauncher(); }

private void stopMovingLauncher() 
{ setLiftPower(0);
 } 
 private void startRaisingLauncher() {
setLiftPower(-1); } 

private void startLoweringLauncher() { 
 setLiftPower(0.5); } 
private void setLiftPower(double power) { 
 M1.set(-power); 
M2.set(power); 
 }

Last edited by miw14 : 28-02-2014 at 23:22.
Reply With Quote
  #4   Spotlight this post!  
Unread 28-02-2014, 23:19
miw14 miw14 is offline
Registered User
FRC #4840
 
Join Date: Feb 2014
Location: Michigan
Posts: 19
miw14 is an unknown quantity at this point
Re: URGENT:Auto Problem trying to fix before tomorrow

Quote:
Originally Posted by DomenicR View Post
Without seeing more of the code, it will be difficult to determine what the issue is. Are you having problems both on and off the field? Is there any way the power values to the motors could be different between Autonomous and Teleop modes?

It did not seem too powerful when I tested it in the pits. I don't see how the power values can be different. They are set in the code at the max. I really don't understand how the same method could produce different results. Are our timer delays in the right spot?
Reply With Quote
  #5   Spotlight this post!  
Unread 28-02-2014, 23:32
Caleb Sykes's Avatar
Caleb Sykes Caleb Sykes is offline
Registered User
FRC #4536 (MinuteBots)
Team Role: Mentor
 
Join Date: Feb 2011
Rookie Year: 2009
Location: St. Paul, Minnesota
Posts: 1,062
Caleb Sykes has a reputation beyond reputeCaleb Sykes has a reputation beyond reputeCaleb Sykes has a reputation beyond reputeCaleb Sykes has a reputation beyond reputeCaleb Sykes has a reputation beyond reputeCaleb Sykes has a reputation beyond reputeCaleb Sykes has a reputation beyond reputeCaleb Sykes has a reputation beyond reputeCaleb Sykes has a reputation beyond reputeCaleb Sykes has a reputation beyond reputeCaleb Sykes has a reputation beyond repute
Re: URGENT:Auto Problem trying to fix before tomorrow

Did the driving movement for autonomous work properly?
Reply With Quote
  #6   Spotlight this post!  
Unread 28-02-2014, 23:35
Domenic Rodriguez's Avatar
Domenic Rodriguez Domenic Rodriguez is offline
Registered User
FRC #0316 (LuNaTeCs)
Team Role: College Student
 
Join Date: Sep 2010
Rookie Year: 2011
Location: Grove City, PA
Posts: 213
Domenic Rodriguez has a spectacular aura aboutDomenic Rodriguez has a spectacular aura aboutDomenic Rodriguez has a spectacular aura about
Re: URGENT:Auto Problem trying to fix before tomorrow

Quote:
Originally Posted by miw14 View Post
It did not seem too powerful when I tested it in the pits. I don't see how the power values can be different. They are set in the code at the max. I really don't understand how the same method could produce different results. Are our timer delays in the right spot?
Since the motor power is a constant, it should always behave the same. I did notice you have the myDrive.setSafetyEnabled() line commented out. Sometimes the MotorSafety timing out can cause the robot to behave oddly. Do you receive any error messages at the Driver Station or Netbeans while running autonomous, and have you tried it with that line uncommented?

You could add some System.out.println()s to verify the timing. My team uses IterativeRobot, so I'm not super familiar with SimpleRobot, but the timing looks ok to me. Have you ensured that the delay values are long enough for the robot to physically respond? You cold try increasing the delay between raising and stopping the arm to see what kind of effect time has.
__________________

LuNaTeCs - Learning Under Nurturing Adults Teaching Engineering Concepts and Skills - Small and Mighty!

FRC 316 LuNaTeCs - Student (2011-2014), Lead Programmer (2011-2014), Team Captain (2013-2014), Operator (2013), Drive Coach (2014), Mentor (2015-????)
'11 Philly Regional Finalists, '13 Chestnut Hill Finalists, '13 Lenape Champions, '13 Archimedes Division, '14 Chestnut Hill Champions, '14 Lenape Champions
FTC 7071 EngiNerds - Founding Advisor (2013-2014) | FRC 5420 Velocity - Founding Advisor (2015)
Grove City College Class of '18, Electrical/Computer Engineering (B.S.E.E)

Reply With Quote
  #7   Spotlight this post!  
Unread 28-02-2014, 23:35
miw14 miw14 is offline
Registered User
FRC #4840
 
Join Date: Feb 2014
Location: Michigan
Posts: 19
miw14 is an unknown quantity at this point
Re: URGENT:Auto Problem trying to fix before tomorrow

Quote:
Originally Posted by inkling16 View Post
Did the driving movement for autonomous work properly?
Yes, it did pull a little to the right. But it does that regardless of what stage it's in. The timing and speed both seemed fairly accurate on the driving.
Reply With Quote
  #8   Spotlight this post!  
Unread 28-02-2014, 23:37
miw14 miw14 is offline
Registered User
FRC #4840
 
Join Date: Feb 2014
Location: Michigan
Posts: 19
miw14 is an unknown quantity at this point
Re: URGENT:Auto Problem trying to fix before tomorrow

Quote:
Originally Posted by DomenicR View Post
Since the motor power is a constant, it should always behave the same. I did notice you have the myDrive.setSafetyEnabled() line commented out. Sometimes the MotorSafety timing out can cause the robot to behave oddly. Do you receive any error messages at the Driver Station or Netbeans while running autonomous, and have you tried it with that line uncommented?

You could add some System.out.println()s to verify the timing. My team uses IterativeRobot, so I'm not super familiar with SimpleRobot, but the timing looks ok to me. Have you ensured that the delay values are long enough for the robot to physically respond? You cold try increasing the delay between raising and stopping the arm to see what kind of effect time has.
Opps. That was not supposed to be commented out. It's uncommented in the actual code. It seemed like changing the delays did not have much of an effect.
Reply With Quote
  #9   Spotlight this post!  
Unread 28-02-2014, 23:40
Caleb Sykes's Avatar
Caleb Sykes Caleb Sykes is offline
Registered User
FRC #4536 (MinuteBots)
Team Role: Mentor
 
Join Date: Feb 2011
Rookie Year: 2009
Location: St. Paul, Minnesota
Posts: 1,062
Caleb Sykes has a reputation beyond reputeCaleb Sykes has a reputation beyond reputeCaleb Sykes has a reputation beyond reputeCaleb Sykes has a reputation beyond reputeCaleb Sykes has a reputation beyond reputeCaleb Sykes has a reputation beyond reputeCaleb Sykes has a reputation beyond reputeCaleb Sykes has a reputation beyond reputeCaleb Sykes has a reputation beyond reputeCaleb Sykes has a reputation beyond reputeCaleb Sykes has a reputation beyond repute
Re: URGENT:Auto Problem trying to fix before tomorrow

Are we confident that the argument for Timer.delay() is in seconds and not milliseconds? I don't remember off hand.
Reply With Quote
  #10   Spotlight this post!  
Unread 28-02-2014, 23:40
miw14 miw14 is offline
Registered User
FRC #4840
 
Join Date: Feb 2014
Location: Michigan
Posts: 19
miw14 is an unknown quantity at this point
Re: URGENT:Auto Problem trying to fix before tomorrow

Hmm... I think I may have figured out the problem. Would I also need to have the setSafetyEnabled method with the shooter object and the driver object?
I feel like that is the problem. When I changed the timer delays between on shooter and off shooter, it had not effect. I wonder if the setSafetyEnabled method has anything to do with that.
Reply With Quote
  #11   Spotlight this post!  
Unread 28-02-2014, 23:41
miw14 miw14 is offline
Registered User
FRC #4840
 
Join Date: Feb 2014
Location: Michigan
Posts: 19
miw14 is an unknown quantity at this point
Re: URGENT:Auto Problem trying to fix before tomorrow

Quote:
Originally Posted by inkling16 View Post
Are we confident that the argument for Timer.delay() is in seconds and not milliseconds? I don't remember off hand.
It should be. It's viewed as seconds in the driving portion.
Reply With Quote
  #12   Spotlight this post!  
Unread 28-02-2014, 23:48
Caleb Sykes's Avatar
Caleb Sykes Caleb Sykes is offline
Registered User
FRC #4536 (MinuteBots)
Team Role: Mentor
 
Join Date: Feb 2011
Rookie Year: 2009
Location: St. Paul, Minnesota
Posts: 1,062
Caleb Sykes has a reputation beyond reputeCaleb Sykes has a reputation beyond reputeCaleb Sykes has a reputation beyond reputeCaleb Sykes has a reputation beyond reputeCaleb Sykes has a reputation beyond reputeCaleb Sykes has a reputation beyond reputeCaleb Sykes has a reputation beyond reputeCaleb Sykes has a reputation beyond reputeCaleb Sykes has a reputation beyond reputeCaleb Sykes has a reputation beyond reputeCaleb Sykes has a reputation beyond repute
Re: URGENT:Auto Problem trying to fix before tomorrow

Quote:
Originally Posted by miw14 View Post
It should be. It's viewed as seconds in the driving portion.
I think you're right. Just making sure though, since some timer functions are measured in ms.
Reply With Quote
  #13   Spotlight this post!  
Unread 28-02-2014, 23:50
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: URGENT:Auto Problem trying to fix before tomorrow

Quote:
Originally Posted by miw14 View Post
Hmm... I think I may have figured out the problem. Would I also need to have the setSafetyEnabled method with the shooter object and the driver object?
I feel like that is the problem. When I changed the timer delays between on shooter and off shooter, it had not effect. I wonder if the setSafetyEnabled method has anything to do with that.
Ideally you wouldn't disable the safety enable. Now, given that you're at comp, i'm not going to suggest enabling it at this point. However, we can rearrange your code to ensure that the drive is updated enough.

Time is in milliseconds. Unlike other programming platforms, the crio really does not like long delays. Thus it's better for you to manage time, and adjust your motor outputs based on time.

Code:
public void autonomous() { 
        myDrive.setSafetyEnabled(false); 
        
        long startTime = System.currentTimeMillis();
        
        while(isAutonomous() && isEnabled()){
            long timePassed = System.currentTimeMillis() - startTime;
            if(timePassed < 3500){
                myDrive.drive(-.5, 0.0);
            }else if (timePassed < 5000){
                myDrive.stopMotor();
            }else if (timePassed < 8500){
                startRaisingLauncher();
            }else{
                stopMovingLauncher();
                //stopAll();
            }
            Timer.delay(0.01); 
        }
        
        stopAll();
    }
__________________
"Never let your schooling interfere with your education" -Mark Twain
Reply With Quote
  #14   Spotlight this post!  
Unread 28-02-2014, 23:56
miw14 miw14 is offline
Registered User
FRC #4840
 
Join Date: Feb 2014
Location: Michigan
Posts: 19
miw14 is an unknown quantity at this point
Re: URGENT:Auto Problem trying to fix before tomorrow

Quote:
Originally Posted by lineskier View Post
Ideally you wouldn't disable the safety enable. Now, given that you're at comp, i'm not going to suggest enabling it at this point. However, we can rearrange your code to ensure that the drive is updated enough.

Time is in milliseconds. Unlike other programming platforms, the crio really does not like long delays. Thus it's better for you to manage time, and adjust your motor outputs based on time.

Code:
public void autonomous() { 
        myDrive.setSafetyEnabled(false); 
        
        long startTime = System.currentTimeMillis();
        
        while(isAutonomous() && isEnabled()){
            long timePassed = System.currentTimeMillis() - startTime;
            if(timePassed < 3500){
                myDrive.drive(-.5, 0.0);
            }else if (timePassed < 5000){
                myDrive.stopMotor();
            }else if (timePassed < 8500){
                startRaisingLauncher();
            }else{
                stopMovingLauncher();
                //stopAll();
            }
            Timer.delay(0.01); 
        }
        
        stopAll();
    }
Thank you! I am a little bit confused though. You said time is in miliseconds, but it seemed like the Timer.delay worked fine with seconds with the mydrive.

Another question about the code. For the time conditions in the else statements, are the last two statements supposed to be greater than signs instead of less than signs? *Nevermind, I believe I understand this now.

Lastly, what do you think was the problem with the original code?

Last edited by miw14 : 01-03-2014 at 00:17.
Reply With Quote
  #15   Spotlight this post!  
Unread 01-03-2014, 04:52
pblankenbaker pblankenbaker is offline
Registered User
FRC #0868
 
Join Date: Feb 2012
Location: Carmel, IN, USA
Posts: 108
pblankenbaker is a glorious beacon of lightpblankenbaker is a glorious beacon of lightpblankenbaker is a glorious beacon of lightpblankenbaker is a glorious beacon of lightpblankenbaker is a glorious beacon of light
Re: URGENT:Auto Problem trying to fix before tomorrow

Is it possible that your shooter takes more than 3.5 seconds to reach it's raised state? If it is mechanically OK to raise your shooter while you are driving you could start raising it at the start of auton at the same time as you start driving forward and let it run longer:

Code:
public void autonomous() { 
    myDrive.setSafetyEnabled(false);

    // Start driving and lifting the launcher immediately
    myDrive.drive(-.5, 0.0); 
    startRaisingLauncher(); 

    // Stop driving after 3.5 seconds
    Timer.delay(3.5);
    myDrive.stopMotor(); 

    // Stop raising launcher after 4.5 more seconds (8 seconds total
    // raising launcher)
    Timer.delay(4.5); 
    stopMovingLauncher();

    stopAll();
}
You should be able to use your buttons in teleop mode to experiment with how long the total time should be in order to raise the shooter (don't assume the 8 seconds shown in the example above is the correct value).

Good Luck.
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:16.

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