Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   Java (http://www.chiefdelphi.com/forums/forumdisplay.php?f=184)
-   -   Need help programming double solenoids! (http://www.chiefdelphi.com/forums/showthread.php?t=134130)

Zalmay 07-02-2015 14:11

Need help programming double solenoids!
 
I am a member of team 4528, the Automatons. I need help figuring out why my pneumatics code for double solenoids won't work.

Code:

package org.usfirst.frc.team4528.robot;

import edu.wpi.first.wpilibj.Compressor;                //Pneumatics
import edu.wpi.first.wpilibj.Joystick;                        //DriveTrain
import edu.wpi.first.wpilibj.RobotDrive;                //DriveTrain
import edu.wpi.first.wpilibj.SampleRobot;               
import edu.wpi.first.wpilibj.DoubleSolenoid;                //Pneumatics
import edu.wpi.first.wpilibj.Timer;                               
import edu.wpi.first.wpilibj.Victor;                        //Motors

public class Robot15 extends SampleRobot
{
        Victor frontLeft;
        Victor rearLeft;
        Victor frontRight;
        Victor rearRight;
        Victor pully;

        RobotDrive myRobot;
        XBoxJoystick gamestick;

        DoubleSolenoid pistonArm;
        Compressor compressor;

        public void Robot()
        {
               
                frontLeft = new Victor(1);        //Set to appropriate PWM port
                rearLeft = new Victor(2);        //Set to appropriate PWM port
                frontRight = new Victor(3);        //Set to appropriate PWM port
                rearRight = new Victor(4);        //Set to appropriate PWM port
                pully = new Victor(5);                //Set to appropriate PWM port

                pistonArm = new DoubleSolenoid(7, 6);
                compressor = new Compressor();        //Set to null

                gamestick = new XBoxJoystick(0);        //Set to appropriate victors
                myRobot = new RobotDrive(frontLeft, rearLeft, frontRight, rearRight);
        }

        public void useElavator()
        {
                if(gamestick.getRightZ() > 0)
                {
                        pully.set(gamestick.getRightZ());        //Sets value of trigger to speed of motor
                }
                else if(gamestick.getLeftZ() > 0)
                {
                        pully.set(-gamestick.getLeftZ());        //Sets value of trigger to speed of motor
                }
                else
                {
                        pully.set(0.0);                                //Doesn't run if trigger not pressed
                }
        }
       
        public void moveArm()
        {
                compressor.start();
                compressor.setClosedLoopControl(true);        //Lets PCM handle the automatic turning on and off of compressor once pressure hits 120 psi
               
                if(gamestick.getAButton() == true)
                {
                        pistonArm.set(DoubleSolenoid.Value.kForward);        //Pushes piston whenever 'A' button is pressed
                        System.out.println("'A' button is pressed: Piston moves forward");
                }
                else if(gamestick.getBButton() == true)
                {
                        pistonArm.set(DoubleSolenoid.Value.kReverse); //Reverses piston  whenever 'B' button is pressed
       
                        System.out.println("'B' button is pressed: Piston moves backward");
                }
                else
                {
                        pistonArm.set(DoubleSolenoid.Value.kOff);                //Disables piston
                }
        }

        public void operatorControl()
        {
                myRobot.setSafetyEnabled(false);
                while(isOperatorControl() && isEnabled())
                {
                        //squaredInputs help to lower speed value of analog sticks at lower values
                        myRobot.tankDrive(gamestick.getLeftY(), gamestick.getRightY(), true);
                        Timer.delay(0.005);
                        useElavator();
                        Timer.delay(0.005);
                        moveArm();
                }
        }
}

We know that the problem is not with the hardware itself since we are able to use the pistons manually via the solenoid. It is most likely a problem with the code, specifically the moveArm() method.

Team3266Spencer 07-02-2015 16:48

Re: Need help programming double solenoids!
 
Please explain what you mean by "won't work."

CreativeName55 07-02-2015 18:30

Re: Need help programming double solenoids!
 
The two possibilities I see are the setting it to off, as I have no idea what that does (we've always set it to a position and left it there until we set it the other way), or if the solenoid's not receiving the right voltage. Some solenoid's are meant to receive 12V, some 24V. If they're wired wrong, they don't work

GeeTwo 07-02-2015 20:41

Re: Need help programming double solenoids!
 
We're not using pneumatics this year, and I was not programming last year, so maybe this won't make sense with the 2015 setup. However, I remember that our lead programmer last year spoke of "strobing" the double solenoids when the buttons were pressed rather than "setting" them. I believe that this is because (physical) double solenoid valves only need to be supplied with current for a fraction of a second; when no voltage is applied to either side, they physically maintain their state through the position of the internal piston.


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

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