|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
| Thread Tools | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
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!
![]() |
|
#2
|
|||
|
|||
|
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);
}
}
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();
}
}
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);
}
}
|
|
#3
|
|||
|
|||
|
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(); 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. |
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|