Thread: RELAY!!
View Single Post
  #6   Spotlight this post!  
Unread 03-11-2010, 15:51
Dave Scheck's Avatar
Dave Scheck Dave Scheck is online now
Registered User
FRC #0111 (WildStang)
Team Role: Engineer
 
Join Date: Feb 2003
Rookie Year: 2002
Location: Arlington Heights, IL
Posts: 574
Dave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond repute
Re: RELAY!!

The code you have definitely won't work. It doesn't look like you're creating instances of the classes. Assuming that I'm misunderstanding your code, your problem comes in with what Relay::Set expects as input vs what Victor::Set or Jaguar::Set expect. Compare the prototypes that are found in WPILib
Code:
void Jaguar::Set(float speed)
{
}

void Victor::Set(float speed)
{
}

void Relay::Set(Relay::Value value)
{
}
See how Victor and Jaguar take in a float? That happens to be what Joystick::GetY is returning. In the case of Relay::Set, it expects a Value type. That can be found in Relay.h as
Code:
typedef enum {kOff, kOn, kForward, kReverse} Value;
So, in order to call Relay::Set, you need to pass in a Relay::kOff, Relay::kOn, Relay::kForward, or Relay::kReverse (look at Relay.h for a description of what they each mean)

In order to do what you want to do, you'll need some logic. Here's an example for using a forward and reverse threshold (I'm using .5 as my threshold in either direction) to set the state of the relay. Don't forget to turn it off if the stick is between the thresholds.

Spoiler for For Jared:
Code:
#define FORWARD_THRESH  .5
#define REV_THRESH  -.5
...
Relay r1(1);
Joystick j1(1);
...
int inSpeed = j1.GetY();
Relay::Value outSpeed;

if(inSpeed > FORWARD_THRESH)
{
    outSpeed = Relay::kForward;
}
else if(inSpeed < REV_THRESH)
{
    outSpeed = Relay::kReverse;
}
else
{
    outSpeed = Relay::kOff;
}

r1.Set(outSpeed);

Last edited by Dave Scheck : 03-11-2010 at 16:13.
Reply With Quote