Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   Java (http://www.chiefdelphi.com/forums/forumdisplay.php?f=184)
-   -   URGENT:Auto Problem trying to fix before tomorrow (http://www.chiefdelphi.com/forums/showthread.php?t=127331)

miw14 28-02-2014 22:48

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);
}

Domenic Rodriguez 28-02-2014 22:54

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);
}


miw14 28-02-2014 23:14

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);
 }


miw14 28-02-2014 23:19

Re: URGENT:Auto Problem trying to fix before tomorrow
 
Quote:

Originally Posted by DomenicR (Post 1351211)
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?

Caleb Sykes 28-02-2014 23:32

Re: URGENT:Auto Problem trying to fix before tomorrow
 
Did the driving movement for autonomous work properly?

Domenic Rodriguez 28-02-2014 23:35

Re: URGENT:Auto Problem trying to fix before tomorrow
 
Quote:

Originally Posted by miw14 (Post 1351226)
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.

miw14 28-02-2014 23:35

Re: URGENT:Auto Problem trying to fix before tomorrow
 
Quote:

Originally Posted by inkling16 (Post 1351236)
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.

miw14 28-02-2014 23:37

Re: URGENT:Auto Problem trying to fix before tomorrow
 
Quote:

Originally Posted by DomenicR (Post 1351237)
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.

Caleb Sykes 28-02-2014 23:40

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.

miw14 28-02-2014 23:40

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.

miw14 28-02-2014 23:41

Re: URGENT:Auto Problem trying to fix before tomorrow
 
Quote:

Originally Posted by inkling16 (Post 1351242)
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.

Caleb Sykes 28-02-2014 23:48

Re: URGENT:Auto Problem trying to fix before tomorrow
 
Quote:

Originally Posted by miw14 (Post 1351244)
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.

mwtidd 28-02-2014 23:50

Re: URGENT:Auto Problem trying to fix before tomorrow
 
Quote:

Originally Posted by miw14 (Post 1351243)
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();
    }


miw14 28-02-2014 23:56

Re: URGENT:Auto Problem trying to fix before tomorrow
 
Quote:

Originally Posted by lineskier (Post 1351247)
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?

pblankenbaker 01-03-2014 04:52

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.


All times are GMT -5. The time now is 13:16.

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