View Single Post
  #2   Spotlight this post!  
Unread 18-02-2012, 10:29
DavisC DavisC is offline
Registered User
FRC #0539 (Titans)
Team Role: College Student
 
Join Date: Jul 2011
Rookie Year: 2010
Location: Virginia
Posts: 200
DavisC is just really niceDavisC is just really niceDavisC is just really niceDavisC is just really nice
Re: Spike Relay Help!!!

Code:
#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.
__________________
FRC Team 539
Student Member: 2010 Breakaway - 2014 Aerial Assist
Mentor: 2015 Recycle Rush - present
Reply With Quote