Log in

View Full Version : DigitalInput.Get() always returns zero


skidad68
12-02-2013, 23:06
...well, almost always.

I'm using the IterativeRobot template and polling a DigitalInput within the AutonomousPeriodic() function.

I have a NO switch wired between GND and SIG on sidecar digital input #1.

The very first time through the loop, the call to Get() returns the correct value corresponding to the switch state.

Every time after that, it always returns zero, regardless of the state of the switch.

What is my issue, hardware or software?

Alan Anderson
13-02-2013, 00:00
Without seeing either your hardware or your software, it's impossible to say where your problem lies.

skidad68
13-02-2013, 09:06
Does this help? The problem is in the DriveWheel::calibrate() method.

DriveWheel.h

#ifndef DRIVEWHEEL_H
#define DRIVEWHEEL_H

#include "WPILib.h"

class DriveWheel
{
CANJaguar driveMotor;
CANJaguar steerMotor;
DigitalInput limitSw;
bool calibrated;

public:

DriveWheel(UINT8 driveID, UINT8 steerID, UINT8 limitID)
: driveMotor(driveID, CANJaguar::kPercentVbus),
steerMotor(steerID, CANJaguar::kPosition),
limitSw(limitID),
calibrated(false)
{

}


void init();

void calibrate(int clock);

void setValues(double drive, double rotation);
};
#endif


DriveWheel.cpp

#include "DriveWheel.h"

#define LIMIT_ACTIVE 0

void DriveWheel::calibrate(int clock)
{
int limit = limitSw.Get();
printf("limit %d\n", limit);

if (clock == 0)
{
printf("start calibrate\n");
if (limit == LIMIT_ACTIVE)
{
calibrated = true;
}
else
{
steerMotor.ChangeControlMode(CANJaguar::kPercentVb us);
steerMotor.EnableControl(0);
steerMotor.Set(0.1);
}
}
else if (!calibrated)
{
if (limit == LIMIT_ACTIVE)
{
steerMotor.Set(0);
calibrated = true;
init();
}
}
}

void DriveWheel::init()
{
steerMotor.ChangeControlMode(CANJaguar::kPosition) ;
steerMotor.SetPID(2000, 0.1, 0);
steerMotor.SetPositionReference(CANJaguar::kPosRef _QuadEncoder);
steerMotor.ConfigEncoderCodesPerRev(250);
steerMotor.EnableControl();

}

void DriveWheel::setValues(double drive, double rotation)
{
driveMotor.Set(drive);
steerMotor.Set(rotation);
}

skidad68
13-02-2013, 21:22
Problem solved.

Bad digital sidecar.

(Ugh! Hardware!)