View Single Post
  #2   Spotlight this post!  
Unread 21-02-2012, 07:51
ksanger's Avatar
ksanger ksanger is offline
Registered User
FRC #0211 (MaK)
 
Join Date: Mar 2010
Rookie Year: 2010
Location: Rochester NY
Posts: 62
ksanger is on a distinguished road
Re: Only First Digital Input Works

Incorrectly stated first instantiated DigitalInput object is the one that works while it is actually the last one.

Also if its relevant the DigitalInput that works is on Channel 14.

Examples:
We are using the following for our encoder:

package frc3838.robot.subsystems;

import edu.wpi.first.wpilibj.Counter;
import edu.wpi.first.wpilibj.Victor;
import edu.wpi.first.wpilibj.command.Subsystem;
import edu.wpi.first.wpilibj.smartdashboard.SmartDashboar d;
import frc3838.robot.RobotMap;
import frc3838.robot.Setup;
import frc3838.robot.commands.ReportThrowSpeedCommand;
import frc3838.robot.utils.LOG;

public class ThrowerSubsystem extends Subsystem
{
private static double ENCODER_SCALE = 60/32;

private static Counter throwMotorEncoder;
private static void initThrowMotor()
{
try
{
if (Setup.isThrowMotorEnabled() && throwMotor == null)
{
LOG.trace("initializing throw motor");
throwMotorEncoder = new Counter(RobotMap.DigitalIO.THOW_MOTOR_ENCODER);
throwMotorEncoder.reset();
throwMotorEncoder.start();
}
else
{
LOG.info("ThrowMotor is disabled. Will not initialize it.");
}
}
catch (Exception e)
{
LOG.error("An exception occurred when ThrowerSubsystem.initThrowMotor was executed.", e);
}
}

public int getCount()
{
return throwMotorEncoder.get();
}

public double getSpeed() // Returns speed in RPM
{
double speed;

speed = throwMotorEncoder.getPeriod(); // Returns time in sec.
if (speed == 0)
{
return 0.0;
}
else
{
speed = ENCODER_SCALE/speed; // speed in RPM. Note 32 Counts/Rev.
return speed;
}
}
}

Here is what we do for the Limit Switches:
package frc3838.robot.subsystems;

import edu.wpi.first.wpilibj.PWM;
import edu.wpi.first.wpilibj.command.Subsystem;
import edu.wpi.first.wpilibj.smartdashboard.SmartDashboar d;
import edu.wpi.first.wpilibj.Encoder;
import edu.wpi.first.wpilibj.DigitalInput;
import frc3838.robot.RobotMap;
import frc3838.robot.Setup;
import frc3838.robot.commands.shooting.OperateTurretComma nd;
import frc3838.robot.utils.LOG;

public class TurretSubsystem extends Subsystem
{

private static PWM turretPanMotorPWM;
private static int turretPanSetting = RobotMap.Constants.TURRET_MOTOR_PWM_START;
private static Encoder turretEncoder;
private static DigitalInput turretCWLimit;
private static DigitalInput turretCCWLimit;

//static initializer block

static
{
LOG.trace("TurretSubsystem initializer block executing");

LOG.debug("TurretSubsystem initializer block exiting");
}

private static void initTurretMotorPWM()
{
try
{
if (Setup.isTurretPanMotorEnabled() && turretPanMotorPWM == null)
{
LOG.trace("initializing turretMotorPWM");
turretPanMotorPWM = new PWM(RobotMap.PWMChannels.TURRET_MOTOR_CHANNEL);
turretPanMotorPWM.setRaw(turretPanSetting);
if (RobotMap.IN_DEBUG_MODE)
{
SmartDashboard.putInt("TURRET_MOTOR", turretPanSetting);
}
LOG.trace("initializing turretEncoder");
turretEncoder = new Encoder(RobotMap.DigitalIO.TURRET_ENCODER_A, RobotMap.DigitalIO.TURRET_ENCODER_B);
turretEncoder.reset();
turretEncoder.start();
turretCWLimit = new DigitalInput(RobotMap.DigitalIO.TURRET_LIMIT_CW);
turretCCWLimit = new DigitalInput(RobotMap.DigitalIO.TURRET_LIMIT_CCW);

}
}
catch (Exception e)
{
LOG.error("An exception occurred when TurretSubsystem.initturretMotor"
+ "PWM was executed.", e);
}
}

public boolean getTurretCWLimit()
{
return turretCWLimit.get();
}

public boolean getTurretCCWLimit()
{
return turretCCWLimit.get();
}

public int getPosition()
{
return turretEncoder.get();
}
}

End of Examples:
Our trace log shows that these methods are called and the Digital Inputs are the same as shown on the SmartDashboard.

What do we try next? All suggestions are extremely appreciated.
Reply With Quote