Go to Post FIRST Championships event is not about winning, its about the experience, the atmosphere, the people and the sites, there are a lot of amazing things to see at The Championships. - Mike Schroeder [more]
Home
Go Back   Chief Delphi > Technical > Programming
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
 
 
Thread Tools Rate Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Spotlight this post!  
Unread 14-02-2015, 00:20
Zalmay's Avatar
Zalmay Zalmay is offline
Registered User
FRC #4528
 
Join Date: Feb 2015
Location: United States
Posts: 11
Zalmay is an unknown quantity at this point
Need help programming Double Solenoids!

Hello again, I know I have posted this before but I have made slight modifications to the code and wondered if anyone could take a look at it to see if it has any errors. I ask this because when we tested it, it did not work. The A and B buttons were pressed, it just wasn't moving the piston. I have checked the CAN ID and made sure it is the same as the value I initialized it in the code, so that's not likely to be an issue. Thanks for the help in advance guys.

Robot.java:
Code:
package org.usfirst.frc.team4528.robot;

import edu.wpi.first.wpilibj.Compressor;
import edu.wpi.first.wpilibj.DoubleSolenoid;
import edu.wpi.first.wpilibj.SampleRobot;
import edu.wpi.first.wpilibj.RobotDrive;
import edu.wpi.first.wpilibj.Timer;
import edu.wpi.first.wpilibj.Victor;

public class Robot extends SampleRobot 
{
	Victor frontLeft;
	Victor rearLeft;
	Victor frontRight;
	Victor rearRight;
	Victor motor;	//add-on
    RobotDrive myRobot;
    XBoxJoystick stick;
    Compressor compressor;
    DoubleSolenoid piston;
    
    public Robot() 
    {
    	frontLeft = new Victor(2);
    	rearLeft = new Victor(3);
    	frontRight = new Victor(0);
    	rearRight = new Victor(1);
    	motor = new Victor(4);		//add-on
        myRobot = new RobotDrive(frontLeft, rearLeft, frontRight, rearRight);
        stick = new XBoxJoystick(0);
        compressor = new Compressor();	//null parameter
        piston = new DoubleSolenoid(0, 4, 5);	
        //CAN ID is first parameter(null if 0), second parameter is forward port and
        //third parameter is reverse port
    }
    
  //add-on
    

  	public void runMotor()
  	{
          	if(stick.getLeftZ() > 0 && stick.getRightZ() == 0)		//Changed so not functional if both pressed
          	{
          		motor.set(stick.getLeftZ());
          	}
          	else if(stick.getRightZ() > 0 && stick.getLeftZ() == 0)	//Changed so not functional if both pressed
          	{
          		motor.set(-stick.getRightZ());
          	}
          	else
          	{
          		motor.set(0.0);
          	}
  	}

  	public void moveArm()
  	{
  		compressor.start();
  		compressor.setClosedLoopControl(true);
  		
  		if(stick.getAButton() == true && stick.getBButton() != true)
  		{
  			piston.set(DoubleSolenoid.Value.kForward);
  		}
  		else if(stick.getBButton() == true && stick.getAButton() != true)
  		{
  			piston.set(DoubleSolenoid.Value.kReverse);
  		}
  		else
  		{
  			piston.set(DoubleSolenoid.Value.kOff);
  		}
  	}

    /**
     * Drive left & right motors for 2 seconds then stop
     */
    public void autonomous() 
    {
    	while(isAutonomous() && isEnabled())
    	{
    		//Drives full forward for 5 seconds then stops
    		myRobot.drive(1.0, 0.0);
    		Timer.delay(5.0);
    		myRobot.drive(0.0, 0.0);
    	}
    }
    
    /**
     * Runs the motors with arcade steering.
     */
    public void operatorControl() 
    {
        myRobot.setSafetyEnabled(false);
        while (isOperatorControl() && isEnabled()) 
        {
            myRobot.arcadeDrive(0.6*stick.getLeftY(), -0.6*stick.getRightX(), true);
            Timer.delay(0.005);		// wait for a motor update time
            runMotor();
        }
    }

    /**
     * Runs during test mode
     */
    public void test() 
    {
    	
    }
}
XBoxJoystick.java:
Code:
package org.usfirst.frc.team4528.robot;

import edu.wpi.first.wpilibj.Joystick;

public class XBoxJoystick 
{
	private Joystick joystick;
    private int port;

    private final double DEAD_ZONE = 0.08; // Chief Delphi said 0.05;

    public XBoxJoystick(int port) 
    {
            this.port = port;
            this.joystick = new Joystick(port);
    }

    public double getLeftX() 
    {
            return correctDeadSpot(joystick.getRawAxis(0));
    }

    public double getLeftY() 
    {
            return correctDeadSpot(joystick.getRawAxis(1));
    }

    public double getLeftZ() 
    {
        return joystick.getRawAxis(2);
    }
    
    public double getRightZ() 
    {
        return joystick.getRawAxis(3);
    }

    public double getRightX() 
    {
            return correctDeadSpot(joystick.getRawAxis(4));
    }

    public double getRightY() {
            return correctDeadSpot(joystick.getRawAxis(5));
    }

    public double getDpadX() 
    {
            return joystick.getRawAxis(6);
    }

    // WARNING this doesn't work with vanilla driver station
    public double getDpadY() 
    {
            return joystick.getRawAxis(7);
    }

    public boolean getAButton() 
    {
            return getButton(1);
    }

    public boolean getBButton() 
    {
            return getButton(2);
    }

    public boolean getXButton() 
    {
            return getButton(3);
    }

    public boolean getYButton() 
    {
            return getButton(4);
    }

    public boolean getLBButton() 
    {
            return getButton(5);
    }

    public boolean getRBButton() 
    {
            return getButton(6);
    }

    public boolean getBackButton() 
    {
            return getButton(7);
    }

    public boolean getStartButton() 
    {
            return getButton(8);
    }

    public boolean getLSButton() 
    {
            return getButton(9);
    }

    public boolean getRSButton() 
    {
            return getButton(10);
    }

    private double correctDeadSpot(double value) 
    {
            if (Math.abs(value) < DEAD_ZONE)
                    return 0;
            return value;
    }

    private boolean getButton(int buttonNumber) 
    {
            return joystick.getRawButton(buttonNumber);
    }
}
 


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 01:50.

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