View Full Version : 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
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 tags, it will format nicely, like this:
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);
}
Thanks, here is the full 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.kFro ntLeft, true); myDrive.setInvertedMotor(RobotDrive.MotorType.kRea rLeft, 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);
}
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
Did the driving movement for autonomous work properly?
Domenic Rodriguez
28-02-2014, 23:35
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.
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.
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
Are we confident that the argument for Timer.delay() is in seconds and not milliseconds? I don't remember off hand.
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.
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
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.
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.
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();
}
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.
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
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:
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.
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:
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.
I bumped up the timer delay to 5 seconds and it did not seem to affect it at all. It should only take a second or two for it to fire.
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?
Sorry I should clarify. My time was in mills, hence the System.currentTimeMills(). Delay is in seconds. So the delay is 100th of a second in my case where as the first segment is 3500 mills.
Yes, putting a greater than time would be redundant in this case. The second if (first else if) can only occur if its >= 3500 mills, as the first if reserves behavior from 0 to 3499 mills.
Sounds like you understood this, but I just wanted to make sure I conveyed it a little better.
pblankenbaker
01-03-2014, 18:45
Can you add the following SmartDashboard outputs to observe the time the launcher should be raising and run your auton code in the pits with your robot up on blocks without loading a ball?
public void autonomous() {
myDrive.setSafetyEnabled(false);
// Start driving and lifting the launcher immediately
myDrive.drive(-.5, 0.0);
startRaisingLauncher();
SmartDashboard.putBoolean("Raising Launcher", true);
// 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();
SmartDashboard.putBoolean("Raising Launcher", false);
stopAll();
}
If the delays are working properly and all of the code is being executed, you should observe a new value "Raising Launcher" appear on your smart dashboard and you should see it go true at the start of auton and then change to "false" roughly 8 seconds later. If you don't see it turn to "false" it indicates something has failed somewhere (you will probably have a stack trace in your console window on NetBeans).
Also, would it be possible for you to post your current code so we can see how your fire the ball in teleop? Maybe there is a step or procedure missing in auton.
vBulletin® v3.6.4, Copyright ©2000-2017, Jelsoft Enterprises Ltd.