Go to Post "Everything is possible. Just depends on how much it costs and how much physics you have to apply..." - Kimmeh [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

 
Closed Thread
Thread Tools Rate Thread Display Modes
  #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);
    }
}
  #2   Spotlight this post!  
Unread 14-02-2015, 00:43
Christopher149 Christopher149 is offline
Registered User
FRC #0857 (Superior Roboworks) FTC 10723 (SnowBots)
Team Role: Mentor
 
Join Date: Jan 2011
Rookie Year: 2007
Location: Houghton, MI
Posts: 1,104
Christopher149 has a reputation beyond reputeChristopher149 has a reputation beyond reputeChristopher149 has a reputation beyond reputeChristopher149 has a reputation beyond reputeChristopher149 has a reputation beyond reputeChristopher149 has a reputation beyond reputeChristopher149 has a reputation beyond reputeChristopher149 has a reputation beyond reputeChristopher149 has a reputation beyond reputeChristopher149 has a reputation beyond reputeChristopher149 has a reputation beyond repute
Re: Need help programming Double Solenoids!

You never call moveArm() in operatorControl(), which appears (to my tired brain) to be at least some of your issue.
__________________
2015-present: FTC 10723 mentor
2012-present: 857 mentor
2008-2011: 857 student

2015: Industrial Design, Excellence in Engineering, District Finalist, Archimedes Division (#6 alliance captain)
2014: Judges Award, District Engineering Inspiration, District Finalist, Galileo Division

  #3   Spotlight this post!  
Unread 14-02-2015, 09:08
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
Re: Need help programming Double Solenoids!

How silly of me to forget. Thank you for pointing it out to me. One more question however. When I did build the code and test it the compressor still ran despite the command for it to start and stay in a closed loop being inside the moveArm() method I did not call, does anyone know why that it?
Thanks in advance.
  #4   Spotlight this post!  
Unread 14-02-2015, 09:19
Mark McLeod's Avatar
Mark McLeod Mark McLeod is offline
Just Itinerant
AKA: Hey dad...Father...MARK
FRC #0358 (Robotic Eagles)
Team Role: Engineer
 
Join Date: Mar 2003
Rookie Year: 2002
Location: Hauppauge, Long Island, NY
Posts: 8,855
Mark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond repute
Re: Need help programming Double Solenoids!

The compressor is automatically engaged whenever you have instantiated a solenoid.
You don't need to instantiate the compressor and your Start is redundant.
__________________
"Rationality is our distinguishing characteristic - it's what sets us apart from the beasts." - Aristotle
Closed Thread


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 21:17.

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