From ca5ee1198cd89b2ee7f10f9d1b7bcbdc11ce6a31 Mon Sep 17 00:00:00 2001 From: Austen Adler Date: Fri, 22 Jul 2016 13:07:03 -0400 Subject: [PATCH] Added base encoder code --- .../team2059/robot/structs/EncoderValues.java | 27 +++++++++++++++++ .../robot/subsystems/Encoderbase.java | 29 +++++++++++++++++++ 2 files changed, 56 insertions(+) create mode 100644 src/org/usfirst/frc/team2059/robot/structs/EncoderValues.java create mode 100644 src/org/usfirst/frc/team2059/robot/subsystems/Encoderbase.java diff --git a/src/org/usfirst/frc/team2059/robot/structs/EncoderValues.java b/src/org/usfirst/frc/team2059/robot/structs/EncoderValues.java new file mode 100644 index 0000000..fe1a44d --- /dev/null +++ b/src/org/usfirst/frc/team2059/robot/structs/EncoderValues.java @@ -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 diff --git a/src/org/usfirst/frc/team2059/robot/subsystems/Encoderbase.java b/src/org/usfirst/frc/team2059/robot/subsystems/Encoderbase.java new file mode 100644 index 0000000..0ae8cae --- /dev/null +++ b/src/org/usfirst/frc/team2059/robot/subsystems/Encoderbase.java @@ -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