Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   Pneumatics (http://www.chiefdelphi.com/forums/forumdisplay.php?f=54)
-   -   Pneumatics system code (http://www.chiefdelphi.com/forums/showthread.php?t=129776)

Team 4939 12-06-2014 23:57

Pneumatics system code
 
From all of us here at Team 4939, hopefully everybody had a good time. As a rookie team I know we did.

During the off-season we decided to incorporate a very basic pneumatics system into our robot, so that we would be more experienced for next. We were able to figure out where to connect everything (or so we think) according to the instructions, but when it comes to the code, we are just feeling very lost.

As a rookie team most of out programmers including myself, have no clue where to go from here. We found a couple resources online, but are just feeling very confused. We believe we have all the parts we just have to get them to work. The system works manually, but when doing it automatically with the joystick we have no clue where to go. Here is our current code

Code:

package edu.wpi.first.wpilibj.templates;
 
import edu.wpi.first.wpilibj.Jaguar;
import edu.wpi.first.wpilibj.Joystick;
import edu.wpi.first.wpilibj.RobotDrive;
import edu.wpi.first.wpilibj.SimpleRobot;
import edu.wpi.first.wpilibj.Timer;
 
public class RobotTemplate extends SimpleRobot {
   
    RobotDrive chassis = new RobotDrive(1,2);
    Joystick mainStick = new Joystick(1);
    Jaguar jaguar = new Jaguar(3);
    Jaguar jag = new Jaguar(4);

   
    public void autonomous(){
        chassis.setSafetyEnabled(false);
        chassis.drive (-0.5, 0.08);
        Timer.delay(2.0);
        chassis.drive (0, 0.0);
    }
   
    public void operatorControl() {
        chassis.setSafetyEnabled(true);
        while (isOperatorControl() && isEnabled()) {
            double speed;
            double rot;
            speed = mainStick.getY();
            rot = -mainStick.getX();
            chassis.arcadeDrive (speed, rot);
            if (mainStick.getRawButton(3)){
                jag.set(1);
                jaguar.set(-1);
            }
            else if (mainStick.getRawButton(4)){
                jaguar.set(-1);
                jag.set(1);
            }
            else{
                jaguar.set(0);
                jag.set(0);
            }
    }
    }
   
    public void test() {
     
    }
}

All help is greatly appreciated since it is the end of the FRC season.

I will try and upload a picture of how we have the system set up tomorrow.

Thanks in Advance

Domenic Rodriguez 13-06-2014 00:29

Re: Pneumatics system code
 
The compressor is controlled automatically through the Compressor class. Simply pass the Pressure Switch and Relay channels to the constructor and call Compressor#start() in robotInit() and you should be good to go. If desired, it can be disabled with Compressor#stop().

Solenoids come in two varieties: Solenoids and DoubleSolenoids. Single solenoids can be set true or false, while double solenoids are typically set to DoubleSolenoid.Value.kForward, DoubleSolenoid.Value.kReverse, or DoubleSolenoid.Value.kOff.

A simple example incorporating your code:
Code:

package edu.wpi.first.wpilibj.templates;
 
import edu.wpi.first.wpilibj.Jaguar;
import edu.wpi.first.wpilibj.Joystick;
import edu.wpi.first.wpilibj.RobotDrive;
import edu.wpi.first.wpilibj.SimpleRobot;
import edu.wpi.first.wpilibj.Timer;
 
public class RobotTemplate extends SimpleRobot {
   
    RobotDrive chassis = new RobotDrive(1,2);
    Joystick mainStick = new Joystick(1);
    Jaguar jaguar = new Jaguar(3);
    Jaguar jag = new Jaguar(4);

    // Pneumatics
    Compressor compressor = new Compressor(1, 1);
    Solenoid solenoid = new Solenoid(1);
    DoubleSolenoid doubleSolenoid = new DoubleSolenoid(2, 3);
   
    public void robotInit() {
        compressor.start();
    }

    public void autonomous(){
        chassis.setSafetyEnabled(false);
        chassis.drive (-0.5, 0.08);
        Timer.delay(2.0);
        chassis.drive (0, 0.0);
    }
   
    public void operatorControl() {
        chassis.setSafetyEnabled(true);
        while (isOperatorControl() && isEnabled()) {
            double speed;
            double rot;
            speed = mainStick.getY();
            rot = -mainStick.getX();
            chassis.arcadeDrive (speed, rot);
            if (mainStick.getRawButton(3)){
                jag.set(1);
                jaguar.set(-1);
            }
            else if (mainStick.getRawButton(4)){
                jaguar.set(-1);
                jag.set(1);
            }
            else{
                jaguar.set(0);
                jag.set(0);
            }

            // Solenoid
            solenoid.set(mainStick.getRawButton(1);
            if (mainStick.getRawButton(2))
                doubleSolenoid.set(DoubleSolnoid.Value.kForward);
            else
                doubleSolenoid.set(DoubleSolenoid.Value.kOff);
        }
    }
   
    public void test() {
     
    }
}


Also, you might want to check out these articles from the WPILib docs at ScreenSteps Live:
http://wpilib.screenstepslive.com/s/...for-pneumatics
http://wpilib.screenstepslive.com/s/...ders-solenoids

SoftwareBug2.0 13-06-2014 00:32

Re: Pneumatics system code
 
I would start by making a list of what all the connected pneumatic components are and what joystick inputs they're supposed to be controlled by. This will make it easier to help you.

By the way, the following two code snipets are identical:
Code:

int x;
x=4;

Code:

int x=4;

mmaunu 13-06-2014 20:44

Re: Pneumatics system code
 
Since you are just starting out, I want to point out a tiny error in Domenic Rodriguez ' s code. He named a variable "double" since it represents a double solenoid. However, you can't name a variable "double" in Java as it is a reserved word. Change the name to doubleSol or something else and you will be fine. Be sure to only change the name of the variable and not other occurrences of "double".

Sorry...on mobile or I would repost the code with the fixes in place.

Domenic Rodriguez 13-06-2014 21:40

Re: Pneumatics system code
 
Quote:

Originally Posted by mmaunu (Post 1389793)
Since you are just starting out, I want to point out a tiny error in Domenic Rodriguez ' s code. He named a variable "double" since it represents a double solenoid. However, you can't name a variable "double" in Java as it is a reserved word. Change the name to doubleSol or something else and you will be fine. Be sure to only change the name of the variable and not other occurrences of "double".

Sorry...on mobile or I would repost the code with the fixes in place.

Fixed, my bad. Now I feel silly; I guess that's what I get for writing code at 12:30 AM :rolleyes:

Team 4939 16-06-2014 17:32

Re: Pneumatics system code
 
Sorry for not replying earlier, but I just haven't been able to test the code that you all helped out with yet, due to exams and such. I should be able to test the system out tomorrow and I will post a reply letting you know how it worked out. I was able to get a picture: http://postimg.org/image/wvu8lykol/ . If that makes a difference to the code.

Also I was wondering something about where to plug the spike in, I pluged one end to the solenoid, and the other end into port 5 on my Digital side car.

I noticed in the code that Domenic Rodriguez posted :

Code:

// Pneumatics
    Compressor compressor = new Compressor(1, 1);
    Solenoid solenoid = new Solenoid(1);
    DoubleSolenoid doubleSolenoid = new DoubleSolenoid(2, 3);


Ports 1, 2, and 3 are labeled.

Where should I plug my Spike into?

Thank You to all that helped me get this far, just a little more help is needed.

Domenic Rodriguez 16-06-2014 18:35

Re: Pneumatics system code
 
Quote:

Originally Posted by Team 4939 (Post 1390101)
Sorry for not replying earlier, but I just haven't been able to test the code that you all helped out with yet, due to exams and such. I should be able to test the system out tomorrow and I will post a reply letting you know how it worked out. I was able to get a picture: http://postimg.org/image/wvu8lykol/ . If that makes a difference to the code.

Also I was wondering something about where to plug the spike in, I pluged one end to the solenoid, and the other end into port 5 on my Digital side car.

I noticed in the code that Domenic Rodriguez posted :

Code:

// Pneumatics
    Compressor compressor = new Compressor(1, 1);
    Solenoid solenoid = new Solenoid(1);
    DoubleSolenoid doubleSolenoid = new DoubleSolenoid(2, 3);


Ports 1, 2, and 3 are labeled.

Where should I plug my Spike into?

Thank You to all that helped me get this far, just a little more help is needed.

To clarify, are you planning on controlling your solenoid with a Spike Relay, or with the solenoid module on the cRIO?

The Solenoid and DoubleSolenoid classes only work for controlling solenoids through the solenoid module. If you are controlling your solenoid through a relay, you will need to use the Relay class instead.

Judging by your picture, it looks like you are using a double solenoid. I've never controlled a solenoid through Spikes before, but I believe you will need two Spikes, one for each side. Edit: Nope, see Mark McLeod's post below.

Updated code:
Code:

package edu.wpi.first.wpilibj.templates;
 
import edu.wpi.first.wpilibj.Jaguar;
import edu.wpi.first.wpilibj.Joystick;
import edu.wpi.first.wpilibj.RobotDrive;
import edu.wpi.first.wpilibj.SimpleRobot;
import edu.wpi.first.wpilibj.Timer;
import edu.wpi.first.wpilibj.Compressor;
import edu.wpi.first.wpilibj.Relay;
 
public class RobotTemplate extends SimpleRobot {
   
    RobotDrive chassis = new RobotDrive(1,2);
    Joystick mainStick = new Joystick(1);
    Jaguar jaguar = new Jaguar(3);
    Jaguar jag = new Jaguar(4);

    // Pneumatics
    Compressor compressor = new Compressor(1, 1);
    Relay spike = new Relay(2);
   
    public void robotInit() {
        compressor.start();
    }

    public void autonomous(){
        chassis.setSafetyEnabled(false);
        chassis.drive (-0.5, 0.08);
        Timer.delay(2.0);
        chassis.drive (0, 0.0);
    }
   
    public void operatorControl() {
        chassis.setSafetyEnabled(true);
        while (isOperatorControl() && isEnabled()) {
            double speed = mainStick.getY();
            double rot = -mainStick.getX();
            chassis.arcadeDrive (speed, rot);
            if (mainStick.getRawButton(3)){
                jag.set(1);
                jaguar.set(-1);
            }
            else if (mainStick.getRawButton(4)){
                jaguar.set(-1);
                jag.set(1);
            }
            else{
                jaguar.set(0);
                jag.set(0);
            }

            // Solenoid
            if (mainStick.getRawButton(1))
                spike.set(Relay.Value.kForward);
            else if (mainStick.getRawButton(2))
                spike.set(Relay.Value.kReverse);
        }
    }
}


Mark McLeod 16-06-2014 19:23

Re: Pneumatics system code
 
Quote:

Originally Posted by Domenic Rodriguez (Post 1390105)
Judging by your picture, it looks like you are using a double solenoid. I've never controlled a solenoid through Spikes before, but I believe you will need two Spikes, one for each side.

Only one spike per double solenoid.
The code for a double would use kForward for one direction and kReverse for the other direction. Don't use kOff for this purpose.
Wiring a spike to control a 12v-only solenoid via a Relay output on the Digital Sidecar looks like this:


24v solenoids are usable only through the cRIO Solenoid Module/Breakout, not a 12v Spike relay.

Team 4939 16-06-2014 19:42

Re: Pneumatics system code
 
Quote:

Originally Posted by Mark McLeod (Post 1390110)
Only one spike per double solenoid.
The code for a double would use kForward for one direction and kReverse for the other direction. Don't use kOff for this purpose.
Wiring a spike to control a 12v-only solenoid via a Relay output on the Digital Sidecar looks like this:


24v solenoids are usable only through the cRIO Solenoid Module/Breakout, not a 12v Spike relay.

By the picture that I posted earlier this evening could you tell me if it is a 24v solenoid or a 12v solenoid. If not I will just ask my electrical team members.

Mark McLeod 16-06-2014 19:57

Re: Pneumatics system code
 
I suspect from your photo that it is a 24v solenoid just because that's what has been offered in the KOP, but that style can be either voltage rating. The black end caps will have a voltage printed on them.

If it is a 24v solenoid, then it gets wired to two sets of pins on the Solenoid Breakout and the Solenoid Breakout must get 24v power from the empty connectors of the Power Distribution's special 24v output.

Team 4939 17-06-2014 14:06

Re: Pneumatics system code
 
Quote:

Originally Posted by Mark McLeod (Post 1390116)
I suspect from your photo that it is a 24v solenoid just because that's what has been offered in the KOP, but that style can be either voltage rating. The black end caps will have a voltage printed on them.

If it is a 24v solenoid, then it gets wired to two sets of pins on the Solenoid Breakout and the Solenoid Breakout must get 24v power from the empty connectors of the Power Distribution's special 24v output.

Yes you were right it was a 24v solenoid, but I was able to find a different 12v double solenoid in a couple of spare parts sitting around, but unfortunately due to exams and such our team will not be able to switch the solenoids out until next week this time. So I would just like to thank you for all the help you have offered.

I should be able to use the code above posted by Domenic Rodriguez correct?

Mark McLeod 17-06-2014 14:59

Re: Pneumatics system code
 
Quote:

Originally Posted by Team 4939 (Post 1390219)
I should be able to use the code above posted by Domenic Rodriguez correct?

Correct, that code looks good.

Team 4939 24-06-2014 10:25

Re: Pneumatics system code
 
I tried out the code but it did not work out.

If I am right the spike has a light that is supposed to flash when I pressed the assigned button on my joystick. Also on my driver station when a activate any of the other functions such as (movement, or intake motors) the voltage spikes, is that not supposed to happen when a press the button assigned to the pneumatics spike.

None of the things is happening, so I don't know what to exactly do.

I am sitting here with my team so any immediate help would be greatly appreciated.

adciv 24-06-2014 10:33

Re: Pneumatics system code
 
Please provide a copy of your code for this.

Also, what is the LED on the spike doing? (Blink Status & Color)

Team 4939 24-06-2014 10:36

Re: Pneumatics system code
 
I am using the code that Domenic Rodriguez posted:

Quote:

Originally Posted by Domenic Rodriguez (Post 1390105)
Updated code:
Code:

package edu.wpi.first.wpilibj.templates;
 
import edu.wpi.first.wpilibj.Jaguar;
import edu.wpi.first.wpilibj.Joystick;
import edu.wpi.first.wpilibj.RobotDrive;
import edu.wpi.first.wpilibj.SimpleRobot;
import edu.wpi.first.wpilibj.Timer;
import edu.wpi.first.wpilibj.Compressor;
import edu.wpi.first.wpilibj.Relay;
 
public class RobotTemplate extends SimpleRobot {
   
    RobotDrive chassis = new RobotDrive(1,2);
    Joystick mainStick = new Joystick(1);
    Jaguar jaguar = new Jaguar(3);
    Jaguar jag = new Jaguar(4);

    // Pneumatics
    Compressor compressor = new Compressor(1, 1);
    Relay spike = new Relay(2);
   
    public void robotInit() {
        compressor.start();
    }

    public void autonomous(){
        chassis.setSafetyEnabled(false);
        chassis.drive (-0.5, 0.08);
        Timer.delay(2.0);
        chassis.drive (0, 0.0);
    }
   
    public void operatorControl() {
        chassis.setSafetyEnabled(true);
        while (isOperatorControl() && isEnabled()) {
            double speed = mainStick.getY();
            double rot = -mainStick.getX();
            chassis.arcadeDrive (speed, rot);
            if (mainStick.getRawButton(3)){
                jag.set(1);
                jaguar.set(-1);
            }
            else if (mainStick.getRawButton(4)){
                jaguar.set(-1);
                jag.set(1);
            }
            else{
                jaguar.set(0);
                jag.set(0);
            }

            // Solenoid
            if (mainStick.getRawButton(1))
                spike.set(Relay.Value.kForward);
            else if (mainStick.getRawButton(2))
                spike.set(Relay.Value.kReverse);
        }
    }
}


The light of the spike is red-ish/orange and it is steady.

Here are some pics of the wiring at the moment:

http://tinypic.com/view.php?pic=11qp...8#.U6m8OyWmfIU

http://i61.tinypic.com/2qkjmuh.jpg

Any solutions would be appreciated


All times are GMT -5. The time now is 12:23.

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