|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
| Thread Tools | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
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); } |
|
#2
|
||||
|
||||
|
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);
}
|
|
#3
|
|||
|
|||
|
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. |
|
#4
|
|||
|
|||
|
Re: URGENT:Auto Problem trying to fix before tomorrow
Quote:
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? |
|
#5
|
||||
|
||||
|
Re: URGENT:Auto Problem trying to fix before tomorrow
Did the driving movement for autonomous work properly?
|
|
#6
|
||||
|
||||
|
Re: URGENT:Auto Problem trying to fix before tomorrow
Quote:
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. |
|
#7
|
|||
|
|||
|
Re: URGENT:Auto Problem trying to fix before tomorrow
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.
|
|
#8
|
|||
|
|||
|
Re: URGENT:Auto Problem trying to fix before tomorrow
Quote:
|
|
#9
|
||||
|
||||
|
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.
|
|
#10
|
|||
|
|||
|
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. |
|
#11
|
|||
|
|||
|
Re: URGENT:Auto Problem trying to fix before tomorrow
It should be. It's viewed as seconds in the driving portion.
|
|
#12
|
||||
|
||||
|
Re: URGENT:Auto Problem trying to fix before tomorrow
I think you're right. Just making sure though, since some timer functions are measured in ms.
|
|
#13
|
||||
|
||||
|
Re: URGENT:Auto Problem trying to fix before tomorrow
Quote:
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();
}
|
|
#14
|
|||
|
|||
|
Re: URGENT:Auto Problem trying to fix before tomorrow
Quote:
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. |
|
#15
|
|||
|
|||
|
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();
}
Good Luck. |
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|