View Single Post
  #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