View Full Version : Spike Relay Help!!!
blazingswrd
18-02-2012, 10:08
Hey all,
My team is using a spike relay to power a motor in our elevator. Unfortunately, I've been unable to figure out how the relay class works and all of the examples of the relay class that I've been able to find are all in Java. Where can I find a good example of this class so I can go find and figure it out?
Thanks!
#include "WPILib.h"
class RobotDemo : public SimpleRobot
{
RobotDrive myRobot;
Joystick stick;
// This declares the Relay
Relay Elevator;
public:
RobotDemo(void):
myRobot(1, 2),
stick(1),
// This sets up the Relay
Elevator(3)
{
myRobot.SetExpiration(0.1);
}
void Autonomous(void)
{
myRobot.SetSafetyEnabled(false);
myRobot.Drive(0.5, 0.0);
Wait(2.0);
myRobot.Drive(0.0, 0.0);
}
void OperatorControl(void)
{
myRobot.SetSafetyEnabled(true);
while (IsOperatorControl())
{
myRobot.ArcadeDrive(stick);
// This sets the relay
// if stick (USB 1), Trigger (Button 1) == pressed
if(stick.GetRawButton(1) == true)
// set Elevator (PWM 3) to forward
Elevator.Set(Relay::kForward);
else
// if stick (USB 1), Button 2 == pressed
if(stick.GetRawButton(2) == true)
// set Elevator (PWM 3) Reverse
Elevator.Set(Relay::kReverse);
else
// if stick (USB 1), Button 3 == pressed
if(stick.GetRawButton(3) == true)
// set Elevator (PWM 3) to Off
Elevator.Set(Relay::kOff);
Wait(0.005);
}
}
};
START_ROBOT_CLASS(RobotDemo);
This uses the Relay on PWM 3 and triggered by Buttons 1, 2, and 3 to run Forward, Reverse, and Off (respectively).
This is the Simple Robot code just modified to have a Relay too.
vBulletin® v3.6.4, Copyright ©2000-2017, Jelsoft Enterprises Ltd.