Go to Post I'd like to think that I'm at least a sometimes useful mentor. - artdutra04 [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 19-03-2014, 10:14
fireXtract fireXtract is offline
MegaHertz_Lux
FRC #2847 (Mega Hertz)
Team Role: Programmer
 
Join Date: Jan 2013
Rookie Year: 2012
Location: fmt
Posts: 42
fireXtract is an unknown quantity at this point
PIDSubsystem works once then disables the entire RobotDrive

I can enable, drive, then use the pid to setpoint my drivetrain, drive somemore but if i reenable the pid it breaks the drivetrain.

Code:
/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package us.mn.k12.fairmont.robotics.subsystems;

import edu.wpi.first.wpilibj.Encoder;
import edu.wpi.first.wpilibj.RobotDrive;
import edu.wpi.first.wpilibj.Timer;
import edu.wpi.first.wpilibj.command.PIDSubsystem;
import edu.wpi.first.wpilibj.networktables.NetworkTable;
import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard;
import us.mn.k12.fairmont.robotics.RobotMap;
import us.mn.k12.fairmont.robotics.commands.CommandBase;
import us.mn.k12.fairmont.robotics.commands.DriveWithJoysticks;

/**
 *
 * @author Teacher
 */
public class DriveTrain extends PIDSubsystem {
    // Put methods for controlling this subsystem
    // here. Call these from Commands.

    RobotDrive drive = new RobotDrive(RobotMap.frontLeftMotor, RobotMap.rearLeftMotor, RobotMap.frontRightMotor, RobotMap.rearRightMotor);
    Encoder enc = new Encoder(RobotMap.frontRightEncA, RobotMap.frontRightEncB);
//    Timer timer = new Timer();
    
    public DriveTrain() {
        super("Drivetrain", 6, 0, 0);
        setAbsoluteTolerance(10);
        enc.start();
    }
    
    public void initDefaultCommand() {
        // Set the default command for a subsystem here.
        setDefaultCommand(new DriveWithJoysticks());
    }

    public void driveMechanum_Cartesian(double rightJoyY, double rightJoyX, double rotation) {
        drive.mecanumDrive_Cartesian((rightJoyY * -1), rotation, rightJoyX * -1, 0); // Mechanam wheel rollers should form an x when looking directaly down from the top
    }

    
    public void putPID() {
        CommandBase.table.putNumber("p", 8.0); // change it to smartdashboard getnumber tomorrow when you arent bored of deploying 
        CommandBase.table.putNumber("i", 0.0); // HOLY shoot YOU FIXED THE MOMORY LIEEK
        CommandBase.table.putNumber("d", 0.0);
    }

    public double updateStatus() {
        SmartDashboard.putNumber("Enc", enc.getRaw());
        return enc.getRaw();
    }

    public void reset() {
        enc.reset();
        reset();
    }

    public double returnPIDInput() {
        return enc.getRaw();
    }

    public void setSetpoint(int setpoint) {
        setSetpoint(setpoint);
    }

    public void getSetpoint(int setpoint) {
        getSetpoint();
    }

    public void getPosition(int position) {
        getPosition();
    }

    public void updatePID() {
        RobotMap.p = CommandBase.table.getNumber("p", 8);
        RobotMap.i = CommandBase.table.getNumber("i", 0);
        RobotMap.d = CommandBase.table.getNumber("d", 0);
        getPIDController().setPID(RobotMap.p, RobotMap.i, RobotMap.d);
    }

    public void usePIDOutput(double output) {
        driveMechanum_Cartesian(output, output, 0);
    }

    
}
Code:
package us.mn.k12.fairmont.robotics.commands;

public class DriveToDistance extends CommandBase {

    boolean go;
    double setpoint;

    /**
     * Require the drive train and store the desired setpoint.
     *
     * @param setpoint The desired setpoint for the drive train.
     */
    public DriveToDistance(boolean go, double setpoint) {
        requires(drivetrain);
        this.go = go;
        this.setpoint = setpoint;
    }

    // Called just before this Command runs the first time
    /**
     * Set the setpoint to the stored value and enable PID on the drivetrain.
     */
    protected void initialize() {
        System.out.println(this);
        if (go) {
            drivetrain.enable();
            drivetrain.setSetpoint(setpoint);
        }
    }

    // Called repeatedly when this Command is scheduled to run
    protected void execute() {
    }

    // Make this return true when this Command no longer needs to run execute()
    /**
     * @return true when it's close enough to the setpoint
     */
    protected boolean isFinished() {
        return drivetrain.onTarget();
    }

    // Called once after isFinished returns true
    /**
     * When this command ends, disable the drivetrain's PID
     */
    protected void end() {
        System.out.println("done");
        go = false;
        drivetrain.disable();
    }

    // Called when another command which requires one or more of the same
    // subsystems is scheduled to run
    /**
     * When this command exits, disable the drivetrain's PID
     */
    protected void interrupted() {
        end();
    }
}
Code:
/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package us.mn.k12.fairmont.robotics.commands;

/**
 *
 * @author Teacher
 */
public class DriveWithJoysticks extends CommandBase {
    
    public DriveWithJoysticks() {
        // Use requires() here to declare subsystem dependencies
        requires(drivetrain);
    }

    // Called just before this Command runs the first time
    protected void initialize() {
        System.out.println(this);
    }

    // Called repeatedly when this Command is scheduled to run
    protected void execute() {
        drivetrain.driveMechanum_Cartesian(oi.getRightJoyY(), oi.getRightJoyX(), oi.getRightJoyR());
        
//        drivetrain.drivetest(oi.getRightJoyY(), oi.getLeftJoyY());
    }

    // Make this return true when this Command no longer needs to run execute()
    protected boolean isFinished() {
        return false;
    }

    // Called once after isFinished returns true
    protected void end() {
    }

    // Called when another command which requires one or more of the same
    // subsystems is scheduled to run
    protected void interrupted() {
    }
}
Does anybody see what is wrong with the code?
Reply With Quote
  #2   Spotlight this post!  
Unread 19-03-2014, 10:27
Joe Ross's Avatar Unsung FIRST Hero
Joe Ross Joe Ross is offline
Registered User
FRC #0330 (Beachbots)
Team Role: Engineer
 
Join Date: Jun 2001
Rookie Year: 1997
Location: Los Angeles, CA
Posts: 8,590
Joe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond repute
A description of what happens when it breaks the drivetrain would be helpful.
Reply With Quote
  #3   Spotlight this post!  
Unread 19-03-2014, 11:39
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: PIDSubsystem works once then disables the entire RobotDrive

A couple of things:

First thing, in the initialize function of drive to distance, you should reset the PID. Otherwise the second time you call it the PID isn't zero'd

Quote:
driveTrain.getPIDController().reset();
Second thing,

Quote:
public void usePIDOutput(double output) {
driveMechanum_Cartesian(output, output, 0);
}
This seems wrong. I would assume that you only want to use the output on a single axis of the mecanum drive. I would expect it to be
Quote:
driveMechanum_Cartesian(output, 0, 0);
__________________
"Never let your schooling interfere with your education" -Mark Twain
Reply With Quote
  #4   Spotlight this post!  
Unread 20-03-2014, 09:29
fireXtract fireXtract is offline
MegaHertz_Lux
FRC #2847 (Mega Hertz)
Team Role: Programmer
 
Join Date: Jan 2013
Rookie Year: 2012
Location: fmt
Posts: 42
fireXtract is an unknown quantity at this point
Re: PIDSubsystem works once then disables the entire RobotDrive

A description would be that it spams RobotDrive not updated enough and everything on the robot works except the drivetrain, and I deploying the suggestions of lineskier.
Thanks for the input
EDIT:
Code:
[cRIO] edu.wpi.first.wpilibj.networktables2.server.ServerConnectionAdapter@a entered connection state: CONNECTED_TO_CLIENT
[cRIO] 
[cRIO] Affirmitive. I read you dave.
[cRIO] 
[cRIO] Open the door HAL!
[cRIO] DriveWithJoysticks
[cRIO] DriveToDistance
[cRIO] done
[cRIO] DriveWithJoysticks
[cRIO] DriveToDistance
[cRIO] Robot Drive... Output not updated often enough.
[cRIO] Robot Drive... Output not updated often enough.
[cRIO] Robot Drive... Output not updated often enough.
And i changed 2 parts

Code:
package us.mn.k12.fairmont.robotics.commands;

public class DriveToDistance extends CommandBase {

    boolean go;
    double setpoint;

    /**
     * Require the drive train and store the desired setpoint.
     *
     * @param setpoint The desired setpoint for the drive train.
     */
    public DriveToDistance(boolean go, double setpoint) {
        requires(drivetrain);
        this.go = go;
        this.setpoint = setpoint;
    }

    // Called just before this Command runs the first time
    /**
     * Set the setpoint to the stored value and enable PID on the drivetrain.
     */
    protected void initialize() {
        System.out.println(this);
        if (go) {
            drivetrain.getPIDController().reset();
            drivetrain.getPIDController().enable();
            drivetrain.getPIDController().setSetpoint(setpoint);
        }
    }

    // Called repeatedly when this Command is scheduled to run
    protected void execute() {
    }

    // Make this return true when this Command no longer needs to run execute()
    /**
     * @return true when it's close enough to the setpoint
     */
    protected boolean isFinished() {
        return drivetrain.getPIDController().onTarget();
    }

    // Called once after isFinished returns true
    /**
     * When this command ends, disable the drivetrain's PID
     */
    protected void end() {
        System.out.println("done");
        go = false;
        drivetrain.getPIDController().disable();
    }

    // Called when another command which requires one or more of the same
    // subsystems is scheduled to run
    /**
     * When this command exits, disable the drivetrain's PID
     */
    protected void interrupted() {
        end();
    }
}
Code:
 /*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package us.mn.k12.fairmont.robotics.subsystems;

import edu.wpi.first.wpilibj.Encoder;
import edu.wpi.first.wpilibj.RobotDrive;
import edu.wpi.first.wpilibj.Timer;
import edu.wpi.first.wpilibj.command.PIDSubsystem;
import edu.wpi.first.wpilibj.networktables.NetworkTable;
import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard;
import us.mn.k12.fairmont.robotics.RobotMap;
import us.mn.k12.fairmont.robotics.commands.CommandBase;
import us.mn.k12.fairmont.robotics.commands.DriveWithJoysticks;

/**
 *
 * @author Teacher
 */
public class DriveTrain extends PIDSubsystem {
    // Put methods for controlling this subsystem
    // here. Call these from Commands.

    RobotDrive drive = new RobotDrive(RobotMap.frontLeftMotor, RobotMap.rearLeftMotor, RobotMap.frontRightMotor, RobotMap.rearRightMotor);
    Encoder enc = new Encoder(RobotMap.frontRightEncA, RobotMap.frontRightEncB);
//    Timer timer = new Timer();
    
    public DriveTrain() {
        super("Drivetrain", 6, 0, 0);
        setAbsoluteTolerance(10);
        enc.start();
    }
    
    public void initDefaultCommand() {
        // Set the default command for a subsystem here.
        setDefaultCommand(new DriveWithJoysticks());
    }

    public void driveMechanum_Cartesian(double rightJoyY, double rightJoyX, double rotation) {
        drive.mecanumDrive_Cartesian((rightJoyY * -1), rotation, rightJoyX * -1, 0); // Mechanam wheel rollers should form an x when looking directaly down from the top
    }

    
    public void putPID() {
        CommandBase.table.putNumber("p", 8.0); // change it to smartdashboard getnumber tomorrow when you arent borend of deploying 
        CommandBase.table.putNumber("i", 0.0); // HOLY shoot YOU FIXED THE MOMORY LIEEK
        CommandBase.table.putNumber("d", 0.0);
    }

    public double updateStatus() {
        SmartDashboard.putNumber("Enc", enc.getRaw());
        return enc.getRaw();
    }

    public void reset() {
        enc.reset();
        reset();
    }

    public double returnPIDInput() {
        return enc.getRaw();
    }

    public void updatePID() {
        RobotMap.p = CommandBase.table.getNumber("p", 8);
        RobotMap.i = CommandBase.table.getNumber("i", 0);
        RobotMap.d = CommandBase.table.getNumber("d", 0);
        getPIDController().setPID(RobotMap.p, RobotMap.i, RobotMap.d);
    }

    public void usePIDOutput(double output) {
        driveMechanum_Cartesian(output,0, 0);
    }

    
}

Last edited by fireXtract : 20-03-2014 at 09:44.
Reply With Quote
  #5   Spotlight this post!  
Unread 21-03-2014, 09:34
fireXtract fireXtract is offline
MegaHertz_Lux
FRC #2847 (Mega Hertz)
Team Role: Programmer
 
Join Date: Jan 2013
Rookie Year: 2012
Location: fmt
Posts: 42
fireXtract is an unknown quantity at this point
Re: PIDSubsystem works once then disables the entire RobotDrive

I have more detail after playing around with what triggers it.
  1. Deploy code
  2. enable robot
  3. drive robot
  4. press button 11 to activate the DriveToDistance command
  5. robot uses pid to drive robot to the setpoint
  6. command ends and i resume driving and shooting
  7. press button 11 again to reactivate the DriveToDistance command
  8. [cRIO] Robot Drive... Output not updated often enough *100
  9. robot wont listen to any commands related to drivetrain but shooting still works
  10. Disable robot
  11. enable robot, and [cRIO] Robot Drive... Output not updated often enough
  12. Redeploy to fix robot temporarily; until i activate drive to distance twice
Reply With Quote
  #6   Spotlight this post!  
Unread 21-03-2014, 10:11
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: PIDSubsystem works once then disables the entire RobotDrive

https://www.google.com/search?q=recu...sm=93&ie=UTF-8


Try the "Did you mean".

Now look at this line of code:

Quote:
public void reset() {
enc.reset();
reset();
}
I'm not going to give you the full answer, but here's a little mod to help you figure it out.

Quote:
private int i = 0;
public void reset() {
i++;
if(i > 1000) System.out.println("Please, please, please, STOP RESETTING ME!");
enc.reset();
reset();
}
__________________
"Never let your schooling interfere with your education" -Mark Twain

Last edited by mwtidd : 21-03-2014 at 10:14.
Reply With Quote
  #7   Spotlight this post!  
Unread 24-03-2014, 16:58
fireXtract fireXtract is offline
MegaHertz_Lux
FRC #2847 (Mega Hertz)
Team Role: Programmer
 
Join Date: Jan 2013
Rookie Year: 2012
Location: fmt
Posts: 42
fireXtract is an unknown quantity at this point
Re: PIDSubsystem works once then disables the entire RobotDrive

Quote:
Originally Posted by lineskier View Post
https://www.google.com/search?q=recu...sm=93&ie=UTF-8


Try the "Did you mean".

Now look at this line of code:



I'm not going to give you the full answer, but here's a little mod to help you figure it out.
I fixed my recursion error i believe, but its still yielding the same problem.
Output with my comments:
Code:
[cRIO] [Squawk VM] Version: 2011 FRC, Nov  5 2011, 14:34:13
[cRIO] FPGA Hardware GUID: 0x1394f6dc1feb42ec6910e5767ed1d22c
[cRIO] FPGA Software GUID: 0xa14c11bde4bb64aef6a86fc52a294cd9
[cRIO] 
[cRIO] Affirmitive. I read you dave.
[cRIO] 
[cRIO] edu.wpi.first.wpilibj.networktables2.server.ServerConnectionAdapter@1d entered connection state: GOT_CONNECTION_FROM_CLIENT
[cRIO] edu.wpi.first.wpilibj.networktables2.server.ServerConnectionAdapter@1d entered connection state: CONNECTED_TO_CLIENT
[cRIO] Open the door HAL!
[cRIO] Robot Drive... Output not updated often enough. // right when i enable, what is that all about?
[cRIO] DriveWithJoysticks // i move around the floor and read output from the enc on my smartboard
[cRIO] DriveToDistance //press button 11 and it goes to setpoint 100
[cRIO] done
[cRIO] DriveWithJoysticks //drive around some more and then disable, if i dont disable and reenable same thing happens so it doesnt matter
[cRIO] Robot Drive... Output not updated often enough.
[cRIO] Open the door HAL! //enable and press button 11
[cRIO] DriveToDistance
[cRIO] Robot Drive... Output not updated often enough.
[cRIO] Robot Drive... Output not updated often enough.
[cRIO] Robot Drive... Output not updated often enough.
[cRIO] Robot Drive... Output not updated often enough.
[cRIO] Robot Drive... Output not updated often enough.
[cRIO] Robot Drive... Output not updated often enough.
[cRIO] Robot Drive... Output not updated often enough.
[cRIO] Robot Drive... Output not updated often enough.
[cRIO] Robot Drive... Output not updated often enough.
[cRIO] Robot Drive... Output not updated often enough.
[cRIO] Robot Drive... Output not updated often enough.
[cRIO] Robot Drive... Output not updated often enough.
[cRIO] Robot Drive... Output not updated often enough.
[cRIO] Robot Drive... Output not updated often enough.
[cRIO] Robot Drive... Output not updated often enough.
[cRIO] Robot Drive... Output not updated often enough.
[cRIO] Robot Drive... Output not updated often enough.
[cRIO] Robot Drive... Output not updated often enough.
[cRIO] Robot Drive... Output not updated often enough.
[cRIO] Robot Drive... Output not updated often enough.
[cRIO] Robot Drive... Output not updated often enough.
[cRIO] Robot Drive... Output not updated often enough. // here stuff works but not any drivetrain stuff

//////// Here i turn off(physical switch) and turn back on the robot and now it works again!

[cRIO] Open the door HAL!
[cRIO] DriveWithJoysticks
[cRIO] DriveToDistance
[cRIO] done
[cRIO] DriveWithJoysticks
Drivetrain sub
Code:
/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package us.mn.k12.fairmont.robotics.subsystems;

import edu.wpi.first.wpilibj.Encoder;
import edu.wpi.first.wpilibj.RobotDrive;
import edu.wpi.first.wpilibj.Timer;
import edu.wpi.first.wpilibj.command.PIDSubsystem;
import edu.wpi.first.wpilibj.networktables.NetworkTable;
import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard;
import us.mn.k12.fairmont.robotics.RobotMap;
import us.mn.k12.fairmont.robotics.commands.CommandBase;
import us.mn.k12.fairmont.robotics.commands.DriveWithJoysticks;

/**
 *
 * @author Teacher
 */
public class DriveTrain extends PIDSubsystem {
    // Put methods for controlling this subsystem
    // here. Call these from Commands.

    RobotDrive drive = new RobotDrive(RobotMap.frontLeftMotor, RobotMap.rearLeftMotor, RobotMap.frontRightMotor, RobotMap.rearRightMotor);
    Encoder enc = new Encoder(RobotMap.frontRightEncA, RobotMap.frontRightEncB);
//    Timer timer = new Timer();
    
    public DriveTrain() {
        super("Drivetrain", 6, 0, 0);
        setAbsoluteTolerance(10);
        enc.start();
    }
    
    public void initDefaultCommand() {
        // Set the default command for a subsystem here.
        setDefaultCommand(new DriveWithJoysticks());
    }

    public void driveMechanum_Cartesian(double rightJoyY, double rightJoyX, double rotation) {
        drive.mecanumDrive_Cartesian((rightJoyY * -1), rotation, rightJoyX * -1, 0); // Mechanam wheel rollers should form an x when looking directaly down from the top
    }

    
    public void putPID() {
        CommandBase.table.putNumber("p", 8.0); // change it to smartdashboard getnumber tomorrow when you arent borend of deploying 
        CommandBase.table.putNumber("i", 0.0); // HOLY shoot YOU FIXED THE MOMORY LIEEK
        CommandBase.table.putNumber("d", 0.0);
    }
//
//    public boolean autoDrive(int dist, double speed) {
//        System.out.println("going fishes");
//        enc.reset();
//        while (enc.get() <= dist - 100) {
////          tal.set(speed*(.1*(dist-enc.get())));
//            if (enc.get() <= dist - 100) {
//                driveMechanum_Cartesian(speed, speed, 0);
//            } else if (enc.get() >= dist + 100) {
//                driveMechanum_Cartesian(-speed, -speed, 0);
//            }
//
//        }
//        return true;
//    }
//
//    // credit to team 1160's github for pieces of this
//    public void autoTimeDrive(double time, boolean run) {
//        timer.start();
//        timer.reset();
//        while (run) {
//            driveMechanum_Cartesian(.3, .3, 0);
//            System.out.println(timer.get());
//            if (timer.get() >= time) {
//                driveMechanum_Cartesian(0, 0, 0);
//                run = false;
//            }
//        }
//    }

    public double updateStatus() {
        SmartDashboard.putNumber("Enc", enc.getRaw());
        return enc.getRaw();
    }

    public void resetthing() {
        enc.reset();
        getPIDController().reset();
    }

    public double returnPIDInput() {
        return enc.getRaw();
    }

    public void updatePID() {
        RobotMap.p = CommandBase.table.getNumber("p", 8);
        RobotMap.i = CommandBase.table.getNumber("i", 0);
        RobotMap.d = CommandBase.table.getNumber("d", 0);
        getPIDController().setPID(RobotMap.p, RobotMap.i, RobotMap.d);
    }

    public void usePIDOutput(double output) {
        driveMechanum_Cartesian(output/4,0, 0);
    }

    
}
drive to distance
Code:
package us.mn.k12.fairmont.robotics.commands;

public class DriveToDistance extends CommandBase {

    boolean go;
    double setpoint;

    /**
     * Require the drive train and store the desired setpoint.
     *
     * @param setpoint The desired setpoint for the drive train.
     */
    public DriveToDistance(boolean go, double setpoint) {
        requires(drivetrain);
        this.go = go;
        this.setpoint = setpoint;
    }

    // Called just before this Command runs the first time
    /**
     * Set the setpoint to the stored value and enable PID on the drivetrain.
     */
    protected void initialize() {
        System.out.println(this);
        if (go) {
            drivetrain.getPIDController().reset();
            drivetrain.getPIDController().enable();
            drivetrain.getPIDController().setSetpoint(setpoint);
        }
    }

    // Called repeatedly when this Command is scheduled to run
    protected void execute() {
    }

    // Make this return true when this Command no longer needs to run execute()
    /**
     * @return true when it's close enough to the setpoint
     */
    protected boolean isFinished() {
        return drivetrain.getPIDController().onTarget();
    }

    // Called once after isFinished returns true
    /**
     * When this command ends, disable the drivetrain's PID
     */
    protected void end() {
        System.out.println("done");
        go = false;
        drivetrain.getPIDController().disable();
    }

    // Called when another command which requires one or more of the same
    // subsystems is scheduled to run
    /**
     * When this command exits, disable the drivetrain's PID
     */
    protected void interrupted() {
        end();
    }
}
Reply With Quote
  #8   Spotlight this post!  
Unread 25-03-2014, 09:30
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: PIDSubsystem works once then disables the entire RobotDrive

It looks to me like your DriveToDistance command will only work one time the way you have it coded. The "go" flag was being set to "false" in the original end() method in the original implementation. Once the flag is set to false, then your drive train PID was never enabled on any subsequent invocation (until you power cycle).

Can you try refactoring it without the "go" flag to something like:

Code:
package us.mn.k12.fairmont.robotics.commands;

public class DriveToDistance extends CommandBase {

    double setpoint;

    /**
     * Require the drive train and store the desired setpoint.
     *
     * @param setpoint The desired setpoint for the drive train.
     */
    public DriveToDistance(double setpoint) {
        requires(drivetrain);
        this.setpoint = setpoint;
    }

    // Called just before this Command runs the first time
    /**
     * Set the setpoint to the stored value and enable PID on the drivetrain.
     */
    protected void initialize() {
        System.out.println(this);
        drivetrain.enable();
        drivetrain.setSetpoint(setpoint);
    }

    // Called repeatedly when this Command is scheduled to run
    protected void execute() {
    }

    // Make this return true when this Command no longer needs to run execute()
    /**
     * @return true when it's close enough to the setpoint
     */
    protected boolean isFinished() {
        return drivetrain.onTarget();
    }

    // Called once after isFinished returns true
    /**
     * When this command ends, disable the drivetrain's PID
     */
    protected void end() {
        System.out.println("done");
        drivetrain.disable();
    }

    // Called when another command which requires one or more of the same
    // subsystems is scheduled to run
    /**
     * When this command exits, disable the drivetrain's PID
     */
    protected void interrupted() {
        end();
    }
}
You may also want to add a time out parameter to your command. For example, if you know it should always take less than 5 seconds for the command to complete, set the timeout to 5 seconds to make sure you get back manual control should something go wrong in reaching the set point (like a broken encoder).
Reply With Quote
  #9   Spotlight this post!  
Unread 25-03-2014, 09:59
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: PIDSubsystem works once then disables the entire RobotDrive

Quote:
Originally Posted by pblankenbaker View Post
It looks to me like your DriveToDistance command will only work one time the way you have it coded. The "go" flag was being set to "false" in the original end() method in the original implementation. Once the flag is set to false, then your drive train PID was never enabled on any subsequent invocation (until you power cycle).

You may also want to add a time out parameter to your command. For example, if you know it should always take less than 5 seconds for the command to complete, set the timeout to 5 seconds to make sure you get back manual control should something go wrong in reaching the set point (like a broken encoder).
Good catch!

Both of these suggestions look solid to me.
__________________
"Never let your schooling interfere with your education" -Mark Twain
Reply With Quote
  #10   Spotlight this post!  
Unread 26-03-2014, 09:37
fireXtract fireXtract is offline
MegaHertz_Lux
FRC #2847 (Mega Hertz)
Team Role: Programmer
 
Join Date: Jan 2013
Rookie Year: 2012
Location: fmt
Posts: 42
fireXtract is an unknown quantity at this point
Re: PIDSubsystem works once then disables the entire RobotDrive

Thank you both, I'm testing this now. I was looking at the documentation on how commands are called and i wasn't sure if the go thing was necessary.
EDIT: IT WORK ZOMGLOLOLOL IM SO HAPPY I LOVE YOU ALL I CAN SETPOINT AS MUCH AS I WANT AND NOMORE ROBOTDRIVE TIMING OUT!!>!>!>!>!>>!!
Thanks lineskier and pblankenbaker! It ended up being the go bool and I'm looking into the timeout thing. I'm so happy because we go to competition today, and i can make code for the main robot now!

Last edited by fireXtract : 26-03-2014 at 10:03.
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 12:36.

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