Go to Post Robot: Aww, the FMS doesn't want to chat with me anymore. Was it something I said? - EricVanWyk [more]
Home
Go Back   Chief Delphi > Technical > Programming > C/C++
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Reply
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 02-12-2013, 11:06 PM
skidad68 skidad68 is offline
Registered User
FRC #2506
 
Join Date: Feb 2013
Location: United States
Posts: 4
skidad68 is an unknown quantity at this point
DigitalInput.Get() always returns zero

...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?
Reply With Quote
  #2   Spotlight this post!  
Unread 02-13-2013, 12:00 AM
Alan Anderson's Avatar
Alan Anderson Alan Anderson is offline
Software Architect
FRC #0045 (TechnoKats)
Team Role: Mentor
 
Join Date: Feb 2004
Rookie Year: 2004
Location: Kokomo, Indiana
Posts: 9,112
Alan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond repute
Re: DigitalInput.Get() always returns zero

Without seeing either your hardware or your software, it's impossible to say where your problem lies.
Reply With Quote
  #3   Spotlight this post!  
Unread 02-13-2013, 09:06 AM
skidad68 skidad68 is offline
Registered User
FRC #2506
 
Join Date: Feb 2013
Location: United States
Posts: 4
skidad68 is an unknown quantity at this point
Re: DigitalInput.Get() always returns zero

Does this help? The problem is in the DriveWheel::calibrate() method.

DriveWheel.h

Code:
#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

Code:
#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::kPercentVbus);
            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);
}
Reply With Quote
  #4   Spotlight this post!  
Unread 02-13-2013, 09:22 PM
skidad68 skidad68 is offline
Registered User
FRC #2506
 
Join Date: Feb 2013
Location: United States
Posts: 4
skidad68 is an unknown quantity at this point
Re: DigitalInput.Get() always returns zero

Problem solved.

Bad digital sidecar.

(Ugh! Hardware!)
Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -5. The time now is 10:33 AM.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi