Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 21 additions & 9 deletions src/org/usfirst/frc/team2854/PID/DummyPIDOutput.java
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,31 @@

import edu.wpi.first.wpilibj.PIDOutput;

/**
* @author Kevin Palani
* Class that represents a Dummy PID Output
*/
public class DummyPIDOutput implements PIDOutput {

private double output;
private double output;

/**
* Default constructor
*/
public DummyPIDOutput() {
output = 0;
}

/**
* Sets PID output value to output.
*/
@Override
public void pidWrite(double output) {
//System.out.println("PId writing");
this.output = output;
}

public DummyPIDOutput() {
output = 0;
}

@Override
public void pidWrite(double output) {
// System.out.println("PId writing");
this.output = output;
}

public double getOutput() {
return output;
Expand Down
70 changes: 35 additions & 35 deletions src/org/usfirst/frc/team2854/robot/Robot.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,20 @@
import org.usfirst.frc.team2854.robot.subsystems.Restartabale;

/**
* The VM is configured to automatically run this class, and to call the functions corresponding to
* each mode, as described in the IterativeRobot 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.
* The VM is configured to automatically run this class, and to call the
* functions corresponding to each mode, as described in the IterativeRobot
* 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 Robot extends IterativeRobot {

public static OI oi;
Command autonomousCommand;
SendableChooser<Command> chooser = new SendableChooser<>();
private static HashMap<SubsystemNames, Subsystem> subsystems;
private static HashMap<SubsystemNames, Subsystem> subsystems;
private static SensorBoard sensors;


/**
* This function is run when the robot is first started up and should be used
* for any initialization code.
Expand All @@ -43,30 +43,32 @@ public void robotInit() {
subsystems.put(SubsystemNames.DRIVE_TRAIN, new DriveTrain());

sensors = new SensorBoard();
for(Subsystem s : subsystems.values()) {
if(s instanceof Restartabale) {

for (Subsystem s : subsystems.values()) {
if (s instanceof Restartabale) {
((Restartabale) s).enable();
}

}
// double fieldWidth = 5;
// double fieldHeight = 5;
// FieldMap map = new FieldMap(fieldWidth, fieldHeight);
// MapInput input = new EncoderBased();
// FieldMapDriver mapDrive = new FieldMapDriver(map, 720, 720, input);
//

// double fieldWidth = 5;
// double fieldHeight = 5;
// FieldMap map = new FieldMap(fieldWidth, fieldHeight);
// MapInput input = new EncoderBased();
// FieldMapDriver mapDrive = new FieldMapDriver(map, 720, 720, input);
//

}

/**
* This function is called once each time the robot enters Disabled mode. You
* can use it to reset any subsystem information you want to clear when the
* robot is disabled.
*/
@Override
public void disabledInit() {
for(Subsystem s : subsystems.values()) {
if(s instanceof Restartabale) {
for (Subsystem s : subsystems.values()) {
if (s instanceof Restartabale) {
((Restartabale) s).disable();
}
}
Expand All @@ -91,12 +93,12 @@ public void disabledPeriodic() {
*/
@Override
public void autonomousInit() {
for(Subsystem s : subsystems.values()) {
if(s instanceof Restartabale) {
for (Subsystem s : subsystems.values()) {
if (s instanceof Restartabale) {
((Restartabale) s).enable();
}
}

}

/**
Expand All @@ -109,13 +111,13 @@ public void autonomousPeriodic() {

@Override
public void teleopInit() {
for(Subsystem s : subsystems.values()) {
if(s instanceof Restartabale) {
for (Subsystem s : subsystems.values()) {
if (s instanceof Restartabale) {
((Restartabale) s).enable();
}
}
//OI.buttonA.whenPressed(new DriveMotionMagik());

// OI.buttonA.whenPressed(new DriveMotionMagik());

}

Expand All @@ -127,15 +129,14 @@ public void teleopPeriodic() {
SmartDashboard.putBoolean("NavX is Connected", sensors.getNavX().isConnected());
SmartDashboard.putBoolean("NavX is Calibrating", sensors.getNavX().isCalibrating());

((DriveTrain)getSubsystem(SubsystemNames.DRIVE_TRAIN)).writeToDashBoard();
// double angle = sensors.getNavX().getAngle();
// while(angle < 0) {
// angle += 360;
// }
// SmartDashboard.putNumber("Gyro", angle % 360);
((DriveTrain) getSubsystem(SubsystemNames.DRIVE_TRAIN)).writeToDashBoard();
// double angle = sensors.getNavX().getAngle();
// while(angle < 0) {
// angle += 360;
// }
// SmartDashboard.putNumber("Gyro", angle % 360);


Scheduler.getInstance().run();
Scheduler.getInstance().run();
}

/**
Expand All @@ -149,10 +150,9 @@ public void testPeriodic() {
public static Subsystem getSubsystem(SubsystemNames name) {
return subsystems.get(name);
}

public static SensorBoard getSensors() {
return sensors;
}



}
83 changes: 57 additions & 26 deletions src/org/usfirst/frc/team2854/robot/SensorBoard.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,16 @@ public class SensorBoard {
private AHRS navX;
private ADXRS450_Gyro spiGyro;
private BuiltInAccelerometer builtInacc;

private DriveTrain drive;

public SensorBoard() {

/**
* Default constructor.
*/


public SensorBoard() {

// navX = new AHRS(I2C.Port.kMXP);
String type = null;
Expand Down Expand Up @@ -73,37 +80,61 @@ public SensorBoard() {
// forwardAccel = new DualSensor("Forward Acceleration");
drive = (DriveTrain) Robot.getSubsystem(SubsystemNames.DRIVE_TRAIN);
}

/**
* Calibrates gyro and forward accelerometer.
*/
// public void calibrate(long time) {
// long startTime = System.nanoTime();
// while(System.nanoTime() - startTime < time) {
// gyro.addValue(spiGyro.getRate(), navX.getRate());
// forwardAccel.addValue(builtInacc.getX(), navX.getRawAccelY());
// }
// gyro.calibrate();
// forwardAccel.calibrate();
// }
/**
* Gets the value of the gyro.
* @return - value of the gyro
*/
// public double getGyroValue() {
// return gyro.calculateValue(spiGyro.getRate(), navX.getRate());
// }
/**
* Gets the value of the forward acceleration.
* @return - value of the forward acceleration
*/
// public double getForwardAccelValue() {
// return forwardAccel.calculateValue(builtInacc.getX(), navX.getRawAccelY());
// }
/**
* Gets gyro.
* @return - gyro
*/
// public DualSensor getGyro() {
// return gyro;
// }
/**
* Gets the forward acceleration.
* @return - forward acceleration.
*/
// public DualSensor getForwardAccel() {
// return forwardAccel;
// }

// public void calibrate(long time) {
// long startTime = System.nanoTime();
// while(System.nanoTime() - startTime < time) {
// gyro.addValue(spiGyro.getRate(), navX.getRate());
// forwardAccel.addValue(builtInacc.getX(), navX.getRawAccelY());
// }
// gyro.calibrate();
// forwardAccel.calibrate();
// }

// public double getGyroValue() {
// return gyro.calculateValue(spiGyro.getRate(), navX.getRate());
// }
//
// public double getForwardAccelValue() {
// return forwardAccel.calculateValue(builtInacc.getX(), navX.getRawAccelY());
// }
//
// public DualSensor getGyro() {
// return gyro;
// }
//
// public DualSensor getForwardAccel() {
// return forwardAccel;
// }

/**
* Getter method for the Accelerometer.
* @return - built in accelerometer.
*/
public BuiltInAccelerometer getAccelerometer() {
return builtInacc;
}

/**
* Getter method for NavX object.
* @return - NavX object
*/
public AHRS getNavX() {
return navX;
}
Expand Down
4 changes: 4 additions & 0 deletions src/org/usfirst/frc/team2854/robot/SubsystemNames.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
package org.usfirst.frc.team2854.robot;

/**
* @author Kevin Palani
* SubsystemNames
*/
public enum SubsystemNames {
DRIVE_TRAIN,
SHIFTER;
Expand Down
6 changes: 6 additions & 0 deletions src/org/usfirst/frc/team2854/robot/commands/DriveMotionMagik.java
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@
import org.usfirst.frc.team2854.robot.SubsystemNames;
import org.usfirst.frc.team2854.robot.subsystems.DriveTrain;

import com.ctre.phoenix.motion.MotionProfileStatus;
import com.ctre.phoenix.motorcontrol.ControlMode;

import edu.wpi.first.wpilibj.command.Command;


/** */
public class DriveMotionMagik extends Command {

Expand Down
72 changes: 36 additions & 36 deletions src/org/usfirst/frc/team2854/robot/commands/DriveThottle.java
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -9,40 +9,40 @@
/** */
public class DriveThottle extends Command {

private double percent;
private DriveTrain drive;

public DriveThottle(double percent) {
requires(Robot.getSubsystem(SubsystemNames.DRIVE_TRAIN));
this.percent = percent;
}

// Called just before this Command runs the first time
protected void initialize() {
drive = ((DriveTrain) Robot.getSubsystem(SubsystemNames.DRIVE_TRAIN));
}

// Called repeatedly when this Command is scheduled to run
protected void execute() {
System.out.println("Driving");
drive.drive(percent, percent, ControlMode.Velocity);
}

// 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() {
System.out.println("Stopping");
drive.stop();
}

// Called when another command which requires one or more of the same
// subsystems is scheduled to run
protected void interrupted() {
System.out.println("Interupted");
drive.stop();
}
private double percent;
private DriveTrain drive;

public DriveThottle(double percent) {
requires(Robot.getSubsystem(SubsystemNames.DRIVE_TRAIN));
this.percent = percent;
}

// Called just before this Command runs the first time
protected void initialize() {
drive = ((DriveTrain) Robot.getSubsystem(SubsystemNames.DRIVE_TRAIN));
}

// Called repeatedly when this Command is scheduled to run
protected void execute() {
System.out.println("Driving");
drive.drive(percent, percent, ControlMode.Velocity);
}

// 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() {
System.out.println("Stopping");
drive.stop();
}

// Called when another command which requires one or more of the same
// subsystems is scheduled to run
protected void interrupted() {
System.out.println("Interupted");
drive.stop();
}
}
Loading