I have been trying to get a counter to track the direction. It seem that all the configurations of the counter object want an input for up/down mode not an internal Boolean. Thing is we don’t need a huge amount of acraccy here just sort of want to know with out adding a potentiometer or other more complicated feedback source. Here are some code snips:
Subsystem:
package org.usfirst.frc3244.FloorPick.subsystems;
import org.usfirst.frc3244.FloorPick.commands.*;
import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard;
import edu.wpi.first.wpilibj.command.Subsystem;
import edu.wpi.first.wpilibj.Counter;
import edu.wpi.first.wpilibj.Spark;
public class CargoFloorPick extends Subsystem {
private Spark speedController1;
private Counter seatSensor;
public CargoFloorPick() {
speedController1 = new Spark(0);
addChild("Speed Controller 1",speedController1);
speedController1.setInverted(false);
seatSensor = new Counter(0);
seatSensor.setUpDownCounterMode();
}
@Override
public void initDefaultCommand() {
setDefaultCommand(new CargoFloorPickJog());
}
@Override
public void periodic() {
// Put code here to be run every loop
SmartDashboard.putNumber("Seat Counts", my_GetSeatSensor());
}
public void my_Jog(double speed){
speedController1.set(speed);
}
public int my_GetSeatSensor() {
return seatSensor.get();
}
public void my_setReverseDirection(boolean r){
seatSensor.setReverseDirection(r);
SmartDashboard.putBoolean("Dir", r);
}
}
Command:
package org.usfirst.frc3244.FloorPick.commands;
import edu.wpi.first.wpilibj.command.Command;
import org.usfirst.frc3244.FloorPick.Robot;
public class CargoFloorPickJog extends Command {
public CargoFloorPickJog() {
requires(Robot.cargoFloorPick);
}
@Override
protected void initialize() {
}
@Override
protected void execute() {
double power = -Robot.oi.joystick1.getRawAxis(1);
if (power>0){
Robot.cargoFloorPick.my_setReverseDirection(false);
}else{
Robot.cargoFloorPick.my_setReverseDirection(true);
}
Robot.cargoFloorPick.my_Jog(power);
}
@Override
protected boolean isFinished() {
return false;
}
@Override
protected void end() {
}
@Override
protected void interrupted() {
}
}