Added base encoder code

This commit is contained in:
Austen Adler 2016-07-22 13:07:03 -04:00
parent 69e7cddd45
commit ca5ee1198c
2 changed files with 56 additions and 0 deletions

View File

@ -0,0 +1,27 @@
package org.usfirst.frc.team2059.robot.structs;
public class EncoderValues {
private int count;
private double distance, period, rate;
private boolean direction, stopped;
public EncoderValues(int count, double distance, double period, double rate, boolean direction, boolean stopped) {
}
public int getCount() {
return count;
}
public double getDistance() {
return distance;
}
public double getPeriod() {
return period;
}
public double getRate() {
return rate;
}
public boolean getDirection() {
return direction;
}
public boolean getStopped() {
return stopped;
}
}
// vim: sw=2:ts=2:sts=2

View File

@ -0,0 +1,29 @@
package org.usfirst.frc.team2059.robot.subsystems;
import org.usfirst.frc.team2059.robot.RobotMap;
import org.usfirst.frc.team2059.robot.commands.Drive;
import edu.wpi.first.wpilibj.command.Subsystem;
import edu.wpi.first.wpilibj.Encoder;
import org.usfirst.frc.team2059.robot.structs.EncoderValues;
public class Encoderbase extends Subsystem {
Encoder enc = new Encoder(0, 1, false, Encoder.EncodingType.k4X);
public void initDefaultCommand() {
//TODO: Not sure if we need a default command, not settingo one
//TODO: These are just defaults, they wil lneed to be changed
enc.setMaxPeriod(.1);
enc.setMinRate(10);
enc.setDistancePerPulse(5);
enc.setReverseDirection(false);
enc.setSamplesToAverage(7);
}
public void resetEncoder() {
enc.reset();
}
public EncoderValues getValues() {
//TODO: There are two ways to get distance:
//enc.getDistance();
//enc.getRaw();
//figure out which to use
return new EncoderValues(enc.get() , enc.getRaw() , enc.getPeriod() , enc.getRate() , enc.getDirection() , enc.getStopped());
}
}
// vim: sw=2:ts=2:sts=2