Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   C/C++ (http://www.chiefdelphi.com/forums/forumdisplay.php?f=183)
-   -   Spike Relay Help!!! (http://www.chiefdelphi.com/forums/showthread.php?t=103155)

blazingswrd 18-02-2012 10:08

Spike Relay Help!!!
 
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!

DavisC 18-02-2012 10:29

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.


All times are GMT -5. The time now is 13:31.

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