Compressor programming please help

Ok so i was reading the rule book and the pressure switch is supposed to start working at 115 PSI and turn back on at 95. The rule books says the cRIO must be programmed to react to the GPIO port that is connected to the pressure switch… The question is… what is a GPIO port???

This is also my program for the compressor please tell me why this dosnt work please! i have no clue why.

#include “Compressor.h”

Relay compressor;
DigitalInput compressor_switch;

compressor(5),
compressor_switch(1),

if(compressor_switch.Get() == 1) {
compressor.Set(Relay::kOn);
sprintf(m_compressor, “Comressors is Off;”);
lcd->Printf(DriverStationLCD::kUser_Line2, 1, m_compressor);
lcd->UpdateLCD();
} else {
compressor.Set(Relay::kOff);
sprintf(m_compressor, “Comressors is On.”);
lcd->Printf(DriverStationLCD::kUser_Line2, 1, m_compressor);
lcd->UpdateLCD();
}

also, what PWM wires have to connected to the compressor pressure switch? Black & Red or Red & white or Black & White and does it matter which side of the pressure switch is each wire supposed to be on or it doesn’t matter?

The Compressor class takes care of all the logic for you. All you need to do is create a Compressor object with the proper Relay and Digital I/O pins specified, and tell it to start.


Compressor *myCompressor = new Compressor(1, 5); 
myCompressor->Start();

It will turn on and off all by itself after that.

The pressure switch is a simple SPST switch. It does not matter which side of the connection is which. One side goes to a black “ground” wire on a Digital I/O, and the other side goes to a white “signal” wire. The red “+5” wire should not be connected, and for safety the end of it should be wrapped in electrical tape to prevent it from touching anything.

ok this is my whole code…

#include “WPILib.h”
#include “Vision/AxisCamera.h”
#include “Vision/HSLImage.h”
#include “DriverStationLCD.h”
//#include “AxisCamera.h”
//#include “FrcError.h”
#include “Vision/PCVideoServer.h”
#include “Compressor.h”
/* * This is a demo program showing the use of the RobotBase class.

  • The SimpleRobot class is the base of a robot application that will automatically call your
  • Autonomous and OperatorControl methods at the right time as controlled by the switches on
  • the driver station or the field controls.
    /
    class RobotDemo : public SimpleRobot
    {
    RobotDrive myRobot; // robot drive system
    Joystick leftjoy;
    Joystick rightjoy;
    Joystick armjoy;
    Jaguar arm;
    Relay piston;
    Relay compressor;
    DigitalInput compressor_switch;
    DigitalInput limitswitch_foward;
    DigitalInput limitswitch_reverse;
    Servo x_axis;
    Servo y_axis;
    public:
    RobotDemo(void):
    myRobot(1, 2),
    leftjoy(1),
    rightjoy(2),
    armjoy(3),
    arm(3),
    piston(4),
    compressor(5),
    compressor_switch(1),
    limitswitch_foward(2),
    limitswitch_reverse(3),
    x_axis(10),
    y_axis(9)
    {
    GetWatchdog().SetExpiration(1.00);
    }
    /
  • Drive left & right motors for 3 seconds then stop
    /
    void Autonomous(void)
    {
    /PCVideoServer * pyrocam = new PCVideoServer();
    pyrocam->Start();
    /
    //AxisCamera &camera = AxisCamera::GetInstance(); // Creates an instance of the camera
    // camera.
    //AxisCamera &camera = AxisCamera::getInstance();
    /

    x_axis.SetAngle(90);
    y_axis.SetAngle(90);*/
    GetWatchdog().SetEnabled(false);
    }
    /**
  • Runs the motors with arcade steering.
    /
    void OperatorControl(void)
    {
    GetWatchdog().SetEnabled(true);
    while (IsOperatorControl())
    {
    GetWatchdog().Feed();
    DriverStationLCD * lcd = DriverStationLCD::GetInstance();
    // drive with arcade style (use right stick)
    int clawclosebutton = 2;
    float speedModifier = 1.00;
    float armModifier = 0.75;
    char m_motor[22];
    char m_compressor[22];
    char m_lim_switch[22];
    char m_piston[22];
    //LMV = Left Motor Value; RMV = Right Motor Value
    sprintf(m_motor, “LMV: %f; RMV: %f;”, leftjoy.GetY() * speedModifier, rightjoy.GetY() * speedModifier);
    lcd->Printf(DriverStationLCD::kUser_Line1, 1, m_motor);
    myRobot.TankDrive(leftjoy.GetY() * speedModifier, rightjoy.GetY() * speedModifier);
    //myRobot.SetLeftRightMotorSpeeds(leftjoy.GetY() * speedModifier, rightjoy.GetY() * speedModifier);
    //Compressor Operation
    /
    if(compressor_switch.Get() == 1) {
    compressor.Set(Relay::kOff);
    sprintf(m_compressor, “Comressors is Off;”);
    lcd->Printf(DriverStationLCD::kUser_Line2, 1, m_compressor);
    lcd->UpdateLCD();
    } else {
    compressor.Set(Relay::kOn);
    sprintf(m_compressor, “Comressors is On.”);
    lcd->Printf(DriverStationLCD::kUser_Line2, 1, m_compressor);
    lcd->UpdateLCD();
    }
    /
    //if (rightjoy.GetRawButton(compressoronbutton) == 1) {
    /
    if(leftjoy.GetTrigger() == 1) {
    //compressor.Set(Relay::slight_smile:
    compressor.Set(Relay::kOff);
    compressor.SetDirection(Relay::kForwardOnly);
    sprintf(m_compressor, “Comressors is On.”);
    lcd->Printf(DriverStationLCD::kUser_Line2, 1, m_compressor);
    } else {
    compressor.Set(Relay::kOn);
    sprintf(m_compressor, “Comressors is Off.”);
    lcd->Printf(DriverStationLCD::kUser_Line2, 1, m_compressor);
    }
    /
    compressor.Set(Relay::kOn);
    //Arm operation
    //Do not forget to include sensors,
    //The following program is temporary.
    /if ((limitswitch_foward.Get() ==1) && (armjoy.GetY() > 0)) {
    sprintf(m_lim_switch, “Front Switch Triggered.”);
    lcd->Printf(DriverStationLCD::kUser_Line3, 1, m_lim_switch);
    arm.Set(0.0);
    } else if ((limitswitch_reverse.Get() ==1) && (armjoy.GetY()< 0)) {
    sprintf(m_lim_switch, “Rear Switch Triggered.”);
    lcd->Printf(DriverStationLCD::kUser_Line3, 1, m_lim_switch);
    arm.Set(0.0);
    } else{
    /
    sprintf(m_lim_switch, “Arm Y-Axis: %f”, armjoy.GetY());
    lcd->Printf(DriverStationLCD::kUser_Line3, 1, m_lim_switch);
    arm.Set(armjoy.GetY() * armModifier);
    //}
    //Piston operation
    if (armjoy.GetTrigger() == 1) {
    sprintf(m_piston, “Arm: Clamped”);
    lcd->Printf(DriverStationLCD::kUser_Line4, 1, m_piston);
    piston.SetDirection(Relay::kForwardOnly);
    piston.Set(Relay::kOn);
    } else if (armjoy.GetRawButton(clawclosebutton) == 1) {
    sprintf(m_piston, “Arm: Opened”);
    lcd->Printf(DriverStationLCD::kUser_Line4, 1, m_piston);
    piston.SetDirection(Relay::kReverseOnly);
    piston.Set(Relay::kOn);
    } else {
    sprintf(m_piston, “Arm: Off”);
    lcd->Printf(DriverStationLCD::kUser_Line4, 1, m_piston);
    piston.Set(Relay::kOff);
    }
    lcd->UpdateLCD();
    /
    HSLImage image; // Creates an image
    AxisCamera &camera = AxisCamera::GetInstance(); // Creates an instance of the camera
    camera.WriteResolution(AxisCameraParams::kResolution_160x120);
    camera.WriteBrightness(0);
    camera.GetImage(image.GetImaqImage()); // Gets the image from the camera
    Wait(5.00); // wait for a motor update time {
    */
    }
    }
    };
    START_ROBOT_CLASS(RobotDemo);

Its not turning on the compressor for some reason by it self =/ any problems you can see in my code?

this is is more relevant… not as messy

#include “WPILib.h”
#include “Vision/AxisCamera.h”
#include “Vision/HSLImage.h”
#include “DriverStationLCD.h”
//#include “AxisCamera.h”
//#include “FrcError.h”
#include “Vision/PCVideoServer.h”
#include “Compressor.h”

class RobotDemo : public SimpleRobot
{

RobotDrive myRobot; // robot drive system
Joystick leftjoy;
Joystick rightjoy;
Joystick armjoy;
Jaguar arm;
Relay piston;
Relay compressor;
DigitalInput compressor_switch;
DigitalInput limitswitch_foward;
DigitalInput limitswitch_reverse;
Servo x_axis;
Servo y_axis;

myRobot(1, 2),
leftjoy(1),
rightjoy(2),
armjoy(3),
arm(3),
piston(4),
compressor(5),
compressor_switch(1),
limitswitch_foward(2),
limitswitch_reverse(3),
x_axis(10),
y_axis(9)
{
GetWatchdog().SetExpiration(1.00);
}

void OperatorControl(void)

compressor.Set(Relay::kOn);

your constructor does not look the same as Alan’s.

Thge compressor has its own class in wpi lib, so you don’t have to create a relay for it. Instead you make it a compressor object and construct it with the pressure switch port and the relay port.

so…

 
 
**[size=2]class[/size]**
[LEFT]RobotDemo : **[size=2]public[/size]** SimpleRobot

{
 
[LEFT]RobotDrive myRobot; [size=2]// robot drive system[/size]
Joystick leftjoy;
Joystick rightjoy;
Joystick armjoy;
Jaguar arm;
Relay piston;[/LEFT]
 
[LEFT]Compressor robot_compressor; [size=2]// This will handle the compressor[/size][/LEFT]
 
[LEFT]DigitalInput limitswitch_foward;
DigitalInput limitswitch_reverse;
Servo x_axis;
Servo y_axis;[/LEFT]
 
[LEFT]myRobot(1, 2),
leftjoy(1),
rightjoy(2),
armjoy(3),
arm(3),
piston(4),[/LEFT]
 
[LEFT]robot_compressor(pressure **[size=2]switch[/size]** channel, relay channel);[size=2]//obviously sub in the ports that you are using[/size][/LEFT]
 
[LEFT] 
 
 
**[size=2]void[/size]** OperatorControl(**[size=2]void[/size]**)
{
GetWatchdog().SetExpiration(1.00);
robot_compressor.start();[size=2]// to start the compressor[/size][/LEFT]
 
[LEFT]robot_compressor.stop();[size=2]//to stop the compressor [/size]
}[/LEFT]
 
 

[/LEFT]

[LEFT]

I also moved where the GetWatchdog.SetExperation I think it just got pasted into the wrong spot (it was above the operator control function)

[/LEFT]

soo i dont put anything in between
"
robot_compressor.start();

robot_compressor.stop();
}
"
it will just start and stop on its own using the pressure switch?

Yes you do, put your loops between the start and stop.

You use start when you want the compressor to start controlling itself… it will automatically turn on or off based on if the max pressure is realized.

If for some part of the match you don’t want the compressor running no matter what (even if it isn’t at max pressure yet) you use stop.

For example if you only wanted to use pneumatics during autonomous you would use start before your autonomous loop, and then after the loop you would tell it to stop so it wouldn’t continue to run during teleop.

The start and stop commands don’t literally tell the compressor to turn on or turn off, they tell the compressor whether it should be controlling itself or not. I hope this helps.

ok so how would i write the code to just control it self for all of operator control period no matter what to just shut off at 115 like the pressure switch makes it and to turn back on at 95 and to never shut off completely … so that it would always turn back on when we need more pressure

Do you not understand what I wrote in my first response to you? It should be exactly what you need.

i dont actually, im sorry… Its because i am fairly new to programming and I know what I am doing most of the time but I don’t understand how to insert your program into mine since i tried and it could not build

To control the compressor, you just use the Compressor class. You instantiate a single Compressor object, telling it which relay port is connected to the compressor and which Digital I/O port is connected to the pressure switch. You then call its Start() method.

That’s it. Nothing more. You do not create a Relay object for it. You do not create a DigitalInput for it.

Take out everything in your code that you have put in to try to make the compressor work, and replace it with two lines in your initialization code:

Compressor *myCompressor = new Compressor(1, 5); 
myCompressor->Start();

“1” is the Digital Input with the pressure switch. “5” is the Relay powering the compressor.

You could also make myCompressor a regular variable instead of a pointer and call the object’s constructor as part of the RobotDemo constructor, but I’m not as comfortable as some people are with the requirements for what order things have to be specified.

oh ok thank you, i will try to make this work properly next time i get a change to build on my robot thank you so much