This year as part of our climber we want to hook up a Current Sensor to monitor when the motor hits the rung (to shut it off).
In my Subsystem I setup the sensor as an AnalogChannel on channel 1, However whenever I run said code it crashes and give a "Analog Channel 1 on Module 1 is already allocated. I have no idea why this is happening... Help is much appreciated!!!!
I will post the important files below, need anymore and I will gladly post them too.
Subsystem:
Code:
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package edu.wpi.first.wpilibj.templates.subsystems;
import edu.wpi.first.wpilibj.AnalogChannel;
import edu.wpi.first.wpilibj.command.Subsystem;
import edu.wpi.first.wpilibj.templates.commands.PrintCurrent;
/**
*
* @author Gustave Michel
*/
public class CurrentDetector extends Subsystem {
// Put methods for controlling this subsystem
// here. Call these from Commands.
AnalogChannel sensor;
public CurrentDetector() {
sensor = new AnalogChannel(2);
}
public void initDefaultCommand() {
// Set the default command for a subsystem here.
//setDefaultCommand(new MySpecialCommand());
setDefaultCommand(new PrintCurrent());
}
public double get() {
return sensor.getVoltage();
}
}
CommandBase
Code:
package edu.wpi.first.wpilibj.templates.commands;
import edu.wpi.first.wpilibj.Gyro;
import edu.wpi.first.wpilibj.command.Command;
import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard;
import edu.wpi.first.wpilibj.templates.OI;
import edu.wpi.first.wpilibj.templates.subsystems.CurrentDetector;
import edu.wpi.first.wpilibj.templates.subsystems.ExampleSubsystem;
import edu.wpi.first.wpilibj.templates.subsystems.SpikeLoad;
/**
* The base for all commands. All atomic commands should subclass CommandBase.
* CommandBase stores creates and stores each control system. To access a
* subsystem elsewhere in your code in your code use CommandBase.exampleSubsystem
* @author Author
*/
public abstract class CommandBase extends Command {
public static OI oi;
// Create a single static instance of all of your subsystems
public static ExampleSubsystem exampleSubsystem = new ExampleSubsystem();
CurrentDetector currentDetector = new CurrentDetector();
SpikeLoad spikeLoad = new SpikeLoad();
public static void init() {
// This MUST be here. If the OI creates Commands (which it very likely
// will), constructing it during the construction of CommandBase (from
// which commands extend), subsystems are not guaranteed to be
// yet. Thus, their requires() statements may grab null pointers. Bad
// news. Don't move it.
oi = new OI();
// Show what command your subsystem is running on the SmartDashboard
SmartDashboard.putData(exampleSubsystem);
}
public CommandBase(String name) {
super(name);
}
public CommandBase() {
super();
}
}
Command:
Code:
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package edu.wpi.first.wpilibj.templates.commands;
import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard;
/**
*
* @author Gustave Michel
*/
public class PrintCurrent extends CommandBase {
public PrintCurrent() {
// Use requires() here to declare subsystem dependencies
// eg. requires(chassis);
requires(currentDetector);
}
// Called just before this Command runs the first time
protected void initialize() {
}
// Called repeatedly when this Command is scheduled to run
protected void execute() {
SmartDashboard.putNumber("CurrentDetector", currentDetector.get());
}
// 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() {
}
// Called when another command which requires one or more of the same
// subsystems is scheduled to run
protected void interrupted() {
}
}
__________________

Programmer - A creature known for converting Caffeine into Code.
Studying Computer Science @ Louisiana Tech University
Associate Consultant @ Fenway Group
2012-13: 3946 - Head of Programming, Electrical and Web
2014 - 3468 - Programming Mentor
2015 - Present - Lurker