Go to Post po-nos, cancans, and totes ma goats - dubiousSwain [more]
Home
Go Back   Chief Delphi > Technical > Programming > Java
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Reply
 
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 18-01-2014, 10:19
anthonygraff24 anthonygraff24 is offline
Registered User
FRC #2872 (CyberCats)
Team Role: Programmer
 
Join Date: Jan 2013
Rookie Year: 2012
Location: Long Island
Posts: 38
anthonygraff24 is an unknown quantity at this point
Pneumatics Coding

Hi. I'm the new lead programmer on our team and we want to use pneumatics on our bot. We've never done pneumatics before, so I don't know how to code it AT ALL! If anyone could give me any resources on how to code the Pneumatics or even some sample code it would be much appreciated!
Reply With Quote
  #2   Spotlight this post!  
Unread 18-01-2014, 10:34
Bennett Bennett is offline
Registered User
FRC #2977 (Sir Lancer Bots)
Team Role: Mentor
 
Join Date: Jan 2012
Rookie Year: 2012
Location: Minnesota
Posts: 26
Bennett is an unknown quantity at this point
Re: Pneumatics Coding

Here's some code to run a spike relay to control your compressor, and it uses a pressure sensor to turn it off.
Code:
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package edu.wpi.first.wpilibj.templates.commands;

import edu.wpi.first.wpilibj.Relay;
import edu.wpi.first.wpilibj.RobotBase;
import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard;
import edu.wpi.first.wpilibj.templates.RobotTemplate;

/**
 *
 */
public class ManualRunSpikes extends CommandBase {
    Relay ms1 = compressor.compressorOne();
    boolean thatBoolean = false;
    boolean isFlipped;
    
    public ManualRunSpikes() {
        // Use requires() here to declare subsystem dependencies
        // eg. requires(chassis);
        requires(compressor);
    }

    // Called just before this Command runs the first time
    protected void initialize() {
    }

    // Called repeatedly when this Command is scheduled to run
    protected void execute() {
        if (oi.getB() == false) {
            isFlipped = false;
        }
        
        if (oi.getB() == true & isFlipped == false) {
            thatBoolean = !thatBoolean;
            isFlipped = true;
        }
        
        if (compressor.getCompressorSwitch() == false & thatBoolean == true) {
            ms1.set(Relay.Value.kForward);
        }
        
        if (compressor.getCompressorSwitch() == false & thatBoolean == false) {
            ms1.set(Relay.Value.kOff);
        }
        
        if (compressor.getCompressorSwitch() == true) {
            ms1.set(Relay.Value.kOff);
        }
        
        SmartDashboard.putBoolean("asdf", thatBoolean);
        SmartDashboard.putBoolean("switch", compressor.getCompressorSwitch());
    }

    // Make this return true when this Command no longer needs to run execute()
    protected boolean isFinished() {
        return false;
    }

    // Called once after isFinished returns true
    protected void end() {
            ms1.set(Relay.Value.kOff);
            thatBoolean = false;
    }

    // Called when another command which requires one or more of the same
    // subsystems is scheduled to run
    protected void interrupted() {
            ms1.set(Relay.Value.kOff);
    }
}
Here is our compressor subsystem:
Code:
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package edu.wpi.first.wpilibj.templates.subsystems;

import edu.wpi.first.wpilibj.DigitalInput;
import edu.wpi.first.wpilibj.Relay;
import edu.wpi.first.wpilibj.command.Subsystem;
import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard;
import edu.wpi.first.wpilibj.templates.commands.ManualRunSpikes;
import edu.wpi.first.wpilibj.templates.commands.RunSpikes;

/**
 *
 */
public class Compressor extends Subsystem {
    // Put methods for controlling this subsystem
    // here. Call these from Commands.
    Relay s1 = new Relay(1);
    DigitalInput comSwitch = new DigitalInput(1);

    public void initDefaultCommand() {
        // Set the default command for a subsystem here.
        //setDefaultCommand(new RunSpikes());
        setDefaultCommand(new ManualRunSpikes());
    }
    
    public Relay compressorOne() {
        return s1;
    }
    
    public boolean getCompressorSwitch() {
        return comSwitch.get(); 
    }
}
You use Solenoids to control pneumatic cylinders, and here is some code for them:
Code:
/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package edu.wpi.first.wpilibj.templates.subsystems;

import edu.wpi.first.wpilibj.Solenoid;
import edu.wpi.first.wpilibj.Talon;
import edu.wpi.first.wpilibj.command.Subsystem;
import edu.wpi.first.wpilibj.templates.RobotMap;


/**
 *
 */
public class Intake extends Subsystem {
    // Put methods for controlling this subsystem
    // here. Call these from Commands.
    
    
    Solenoid shoe = new Solenoid(1, RobotMap.sole); // creates Solenoid
    Solenoid spirit = new Solenoid(1, RobotMap.soul); // creates Solenoid


    public void initDefaultCommand() {
        // Set the default command for a subsystem here.
        //setDefaultCommand(new MySpecialCommand());
    }
    
    
    public void push () {
        shoe.set(true);
        spirit.set(false);
    }
    
    public void pull () {
        shoe.set(false);
        spirit.set(true);
    }
    

}
Hopefully that isn't too confusing, feel free to ask if you need any more help.
__________________
2013 Lake Superior Regional SemiFinalists
2013 Team Spirit Award Winners
2013 MSHSL State Competition SemiFinalists / Third Place
Reply With Quote
  #3   Spotlight this post!  
Unread 18-01-2014, 11:49
fsilberberg fsilberberg is offline
WPILib Developer
AKA: Fred Silberberg
FRC #0190
Team Role: Alumni
 
Join Date: Jan 2010
Rookie Year: 2010
Location: Redmond
Posts: 146
fsilberberg has a spectacular aura aboutfsilberberg has a spectacular aura aboutfsilberberg has a spectacular aura about
Re: Pneumatics Coding

While you certainly can go with a fully manual method like Bennett has suggested, WPILib will take care of most of that for you. This is all that you really need to do for the compressor.

Code:
Compressor compressor = new Compressor(1, 2);
// 1, 2 are locations of your limit switch and compressor relay, respectively 
compressor.start();
This will start the compressor and run it until the pressure switch has been hit. It will start back up again once the switch turns off again.

I recommend putting this in your main Robot class, where the compressor is declared as a class variable and you initialize and start in your robotInit() method. You can also create a pneumatics subsystem, and have its default command run the compressor.start() method in the initialize() method.

For operating solenoids, the WPILib documentation has an example, you can find that here:
http://wpilib.screenstepslive.com/s/...ders-solenoids.
If you have any more questions, feel free to ask.
Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -5. The time now is 11:45.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


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