Go to Post I guess it's true, 'There is no replacement for displacement'. - Andy A. [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 13-02-2015, 10:09
Team 4939 Team 4939 is offline
Registered User
AKA: Anshul Shah
FRC #4939 (All spark 9)
Team Role: Programmer
 
Join Date: Jan 2014
Rookie Year: 2014
Location: Brampton
Posts: 52
Team 4939 is an unknown quantity at this point
Pneumatics Programming

Hello,

I was just adding the pneumatics code required, and being the rookie I am , I came up with an error. The thing is that I used the code from http://wpilib.screenstepslive.com/s/...for-pneumatics exactly(or so I think) and there seems to be an error. The error message is: Syntax error, insert "AssignmentOperator Expression" to complete Expression. I have posted the code below:

Code:
package org.usfirst.frc.team4939.robot;

import edu.wpi.first.wpilibj.Compressor;
import edu.wpi.first.wpilibj.IterativeRobot;
import edu.wpi.first.wpilibj.Joystick;
import edu.wpi.first.wpilibj.RobotDrive;
import edu.wpi.first.wpilibj.Solenoid;
import edu.wpi.first.wpilibj.Victor;
import edu.wpi.first.wpilibj.livewindow.LiveWindow;

/**
 * The VM is configured to automatically run this class, and to call the
 * functions corresponding to each mode, as described in the IterativeRobot
 * documentation. If you change the name of this class or the package after
 * creating this project, you must also update the manifest file in the resource
 * directory.
 */
public class Robot extends IterativeRobot {
	RobotDrive myRobot;
	Joystick stick;
	int autoLoopCounter;
	Victor victor;
	Compressor c;
	
    /**
     * This function is run when the robot is first started up and should be
     * used for any initialization code.
     */
    public void robotInit() {
    	myRobot = new RobotDrive(0,1,2,3);
    	stick = new Joystick(0);
    	victor = new Victor(4);
    	c = new Compressor(0);
    	c->SetClosedLoopControl(true); // THIS SEEMS TO BE THE PROBLEM
    	}
    
    /**
     * This function is run once each time the robot enters autonomous mode
     */
    public void autonomousInit() {
    	autoLoopCounter = 0;
    }

    /**
     * This function is called periodically during autonomous
     */
    public void autonomousPeriodic() {
    	if(autoLoopCounter < 100) //Check if we've completed 100 loops (approximately 2 seconds)
		{
			myRobot.drive(-0.5, 0.0); 	// drive forwards half speed
			autoLoopCounter++;
			} else {
			myRobot.drive(0.0, 0.0); 	// stop robot
		}
    }
    
    /**
     * This function is called once each time the robot enters tele-operated mode
     */
    public void teleopInit(){
    }

    /**
     * This function is called periodically during operator control
     */
    public void teleopPeriodic() {
    	double rot = -stick.getX();
    	double speed = -stick.getY();
        myRobot.arcadeDrive(speed,rot);
        if(stick.getRawButton(3)){
        	victor.set(1);
        }
        else if(stick.getRawButton(2)){
        	victor.set(-1);
        }
        else{
        	victor.set(0);
        }
        ArmsDouble= new DoubleSolenoid(1, 2);
        ArmsDouble= new DoubleSolenoid(1, 1, 2);
        if(stick.getRawButton(4)){
        	ArmsDouble.set(DoubleSolenid.Value.kForward);
        	
        }
        else if(stick.getRawButton(5)){
        	ArmsDouble.set(DoubleSolenoid.Value.kReverse);
        	
        }
    }
    /**
     * This function is called periodically during test mode
     */
    public void testPeriodic() {
    	LiveWindow.run();
    }
    
}
Thanks to all in advance.
Reply With Quote
  #2   Spotlight this post!  
Unread 13-02-2015, 10:29
Oromus's Avatar
Oromus Oromus is offline
Lead Programmer, Community Liaison
AKA: Ryan
FRC #1902 (Exploding Bacon)
Team Role: Programmer
 
Join Date: Jan 2015
Rookie Year: 2013
Location: Florida
Posts: 83
Oromus is a splendid one to beholdOromus is a splendid one to beholdOromus is a splendid one to beholdOromus is a splendid one to beholdOromus is a splendid one to beholdOromus is a splendid one to behold
Re: Pneumatics Programming

Change this...
Code:
c->SetClosedLoopControl(true);
...to this...
Code:
c.setClosedLoopControl(true);
The "->" needs to be a "." and "Set" needs to become "set". That WPILib example is not showing the code in Java syntax. Also, for future reference, starting this year you don't have to create a Compressor object or do anything with it; if you make any pnuematics-related classes (i.e. Solenoids), the compressor turns on and regulates itself without any code needed. Also, that link appears to be a 2014 code example; you may want to look at 2015 code examples here instead. Good luck with programming!

Last edited by Oromus : 13-02-2015 at 10:36.
Reply With Quote
  #3   Spotlight this post!  
Unread 13-02-2015, 10:50
Ozuru's Avatar
Ozuru Ozuru is offline
It's always the programmer's fault.
no team
 
Join Date: May 2013
Rookie Year: 2010
Location: Earth
Posts: 268
Ozuru is a splendid one to beholdOzuru is a splendid one to beholdOzuru is a splendid one to beholdOzuru is a splendid one to beholdOzuru is a splendid one to beholdOzuru is a splendid one to beholdOzuru is a splendid one to behold
Re: Pneumatics Programming

As Oromus said, that example is in C++. All you're doing is calling a function -- inside the Compressor object there is a function called setClosedLoopControl that takes a boolean as an argument. In Java, that would be articulated as...

Code:
c.setClosedLoopControl(true);
...while in C++ that would be:

Code:
c->SetClosedLoopControl(true);
They both do the same thing; they're just differences between languages. It's like comparing apples to oranges -- they both can achieve the same thing (making you less hungry) but the means of doing so is relatively different.

that was a horrible example imsosorry
Reply With Quote
  #4   Spotlight this post!  
Unread 13-02-2015, 15:20
Team 4939 Team 4939 is offline
Registered User
AKA: Anshul Shah
FRC #4939 (All spark 9)
Team Role: Programmer
 
Join Date: Jan 2014
Rookie Year: 2014
Location: Brampton
Posts: 52
Team 4939 is an unknown quantity at this point
Re: Pneumatics Programming

Quote:
Originally Posted by Ozuru View Post
As Oromus said, that example is in C++. All you're doing is calling a function -- inside the Compressor object there is a function called setClosedLoopControl that takes a boolean as an argument. In Java, that would be articulated as...

Code:
c.setClosedLoopControl(true);
...while in C++ that would be:

Code:
c->SetClosedLoopControl(true);
They both do the same thing; they're just differences between languages. It's like comparing apples to oranges -- they both can achieve the same thing (making you less hungry) but the means of doing so is relatively different.

that was a horrible example imsosorry
Quote:
Originally Posted by Oromus View Post
Change this...
Code:
c->SetClosedLoopControl(true);
...to this...
Code:
c.setClosedLoopControl(true);
The "->" needs to be a "." and "Set" needs to become "set". That WPILib example is not showing the code in Java syntax. Also, for future reference, starting this year you don't have to create a Compressor object or do anything with it; if you make any pnuematics-related classes (i.e. Solenoids), the compressor turns on and regulates itself without any code needed. Also, that link appears to be a 2014 code example; you may want to look at 2015 code examples here instead. Good luck with programming!

Thank You, very much that seems to have fixed my problem.
Reply With Quote
  #5   Spotlight this post!  
Unread 13-02-2015, 15:22
Team 4939 Team 4939 is offline
Registered User
AKA: Anshul Shah
FRC #4939 (All spark 9)
Team Role: Programmer
 
Join Date: Jan 2014
Rookie Year: 2014
Location: Brampton
Posts: 52
Team 4939 is an unknown quantity at this point
Re: Pneumatics Programming

Code:
package org.usfirst.frc.team4939.robot;

import edu.wpi.first.wpilibj.Compressor;
import edu.wpi.first.wpilibj.IterativeRobot;
import edu.wpi.first.wpilibj.Joystick;
import edu.wpi.first.wpilibj.RobotDrive;
import edu.wpi.first.wpilibj.DoubleSolenoid;
import edu.wpi.first.wpilibj.Victor;
import edu.wpi.first.wpilibj.livewindow.LiveWindow;

/**
 * The VM is configured to automatically run this class, and to call the
 * functions corresponding to each mode, as described in the IterativeRobot
 * documentation. If you change the name of this class or the package after
 * creating this project, you must also update the manifest file in the resource
 * directory.
 */
public class Robot extends IterativeRobot {
	RobotDrive myRobot;
	Joystick stick;
	int autoLoopCounter;
	Victor victor;
	Compressor c;
	
    /**
     * This function is run when the robot is first started up and should be
     * used for any initialization code.
     */
    public void robotInit() {
    	myRobot = new RobotDrive(0,1,2,3);
    	stick = new Joystick(0);
    	victor = new Victor(4);
    	}
    
    /**
     * This function is run once each time the robot enters autonomous mode
     */
    public void autonomousInit() {
    	autoLoopCounter = 0;
    }

    /**
     * This function is called periodically during autonomous
     */
    public void autonomousPeriodic() {
    	if(autoLoopCounter < 100) //Check if we've completed 100 loops (approximately 2 seconds)
		{
			myRobot.drive(-0.5, 0.0); 	// drive forwards half speed
			autoLoopCounter++;
			} else {
			myRobot.drive(0.0, 0.0); 	// stop robot
		}
    }
    
    /**
     * This function is called once each time the robot enters tele-operated mode
     */
    public void teleopInit(){
    }

    /**
     * This function is called periodically during operator control
     */
    public void teleopPeriodic() {
    	double rot = -stick.getX();
    	double speed = -stick.getY();
        myRobot.arcadeDrive(speed,rot);
        if(stick.getRawButton(3)){
        	victor.set(1);
        }
        else if(stick.getRawButton(2)){
        	victor.set(-1);
        }
        else{
        	victor.set(0);
        }
        ArmsDouble= new DoubleSolenoid(1, 2); // THATS SEEMS TO BE THE PROBLEM
        ArmsDouble= new DoubleSolenoid(1, 1, 2);// THAT SEEMS TO BE THE PROBLEM
        if(stick.getRawButton(4)){
        	ArmsDouble.set(DoubleSolenoid.Value.kForward);
        	
        }
        else if(stick.getRawButton(5)){
        	ArmsDouble.set(DoubleSolenoid.Value.kReverse);
        	
        }
    }
    /**
     * This function is called periodically during test mode
     */
    public void testPeriodic() {
    	LiveWindow.run();
    }
    
}
I seem to have a different problem now.

The error code that shows up is: Multiple markers at this line
- DoubleSolenoid cannot be resolved
to a type
- ArmsDouble cannot be resolved to a
variable

Thank You
Reply With Quote
  #6   Spotlight this post!  
Unread 13-02-2015, 15:34
Rakusan2 Rakusan2 is offline
Registered User
AKA: Tomas Rakusan
FRC #3571 (Milton Mustangs)
Team Role: Programmer
 
Join Date: May 2014
Rookie Year: 2011
Location: Milton, ON, Canada
Posts: 22
Rakusan2 is an unknown quantity at this point
Re: Pneumatics Programming

Quote:
Originally Posted by Team 4939 View Post
Code:
package org.usfirst.frc.team4939.robot;

import edu.wpi.first.wpilibj.Compressor;
import edu.wpi.first.wpilibj.IterativeRobot;
import edu.wpi.first.wpilibj.Joystick;
import edu.wpi.first.wpilibj.RobotDrive;
import edu.wpi.first.wpilibj.DoubleSolenoid;
import edu.wpi.first.wpilibj.Victor;
import edu.wpi.first.wpilibj.livewindow.LiveWindow;

/**
 * The VM is configured to automatically run this class, and to call the
 * functions corresponding to each mode, as described in the IterativeRobot
 * documentation. If you change the name of this class or the package after
 * creating this project, you must also update the manifest file in the resource
 * directory.
 */
public class Robot extends IterativeRobot {
	RobotDrive myRobot;
	Joystick stick;
	int autoLoopCounter;
	Victor victor;
	Compressor c;
	
    /**
     * This function is run when the robot is first started up and should be
     * used for any initialization code.
     */
    public void robotInit() {
    	myRobot = new RobotDrive(0,1,2,3);
    	stick = new Joystick(0);
    	victor = new Victor(4);
    	}
    
    /**
     * This function is run once each time the robot enters autonomous mode
     */
    public void autonomousInit() {
    	autoLoopCounter = 0;
    }

    /**
     * This function is called periodically during autonomous
     */
    public void autonomousPeriodic() {
    	if(autoLoopCounter < 100) //Check if we've completed 100 loops (approximately 2 seconds)
		{
			myRobot.drive(-0.5, 0.0); 	// drive forwards half speed
			autoLoopCounter++;
			} else {
			myRobot.drive(0.0, 0.0); 	// stop robot
		}
    }
    
    /**
     * This function is called once each time the robot enters tele-operated mode
     */
    public void teleopInit(){
    }

    /**
     * This function is called periodically during operator control
     */
    public void teleopPeriodic() {
    	double rot = -stick.getX();
    	double speed = -stick.getY();
        myRobot.arcadeDrive(speed,rot);
        if(stick.getRawButton(3)){
        	victor.set(1);
        }
        else if(stick.getRawButton(2)){
        	victor.set(-1);
        }
        else{
        	victor.set(0);
        }
        ArmsDouble= new DoubleSolenoid(1, 2); // THATS SEEMS TO BE THE PROBLEM
        ArmsDouble= new DoubleSolenoid(1, 1, 2);// THAT SEEMS TO BE THE PROBLEM
        if(stick.getRawButton(4)){
        	ArmsDouble.set(DoubleSolenoid.Value.kForward);
        	
        }
        else if(stick.getRawButton(5)){
        	ArmsDouble.set(DoubleSolenoid.Value.kReverse);
        	
        }
    }
    /**
     * This function is called periodically during test mode
     */
    public void testPeriodic() {
    	LiveWindow.run();
    }
    
}
I seem to have a different problem now.

The error code that shows up is: Multiple markers at this line
- DoubleSolenoid cannot be resolved
to a type
- ArmsDouble cannot be resolved to a
variable

Thank You
You need a declaration for ArmsDouble
Code:
DoubleSolenoid ArmsDouble;
also why are you initializing ArmsDouble twice?
Reply With Quote
  #7   Spotlight this post!  
Unread 13-02-2015, 15:39
Oromus's Avatar
Oromus Oromus is offline
Lead Programmer, Community Liaison
AKA: Ryan
FRC #1902 (Exploding Bacon)
Team Role: Programmer
 
Join Date: Jan 2015
Rookie Year: 2013
Location: Florida
Posts: 83
Oromus is a splendid one to beholdOromus is a splendid one to beholdOromus is a splendid one to beholdOromus is a splendid one to beholdOromus is a splendid one to beholdOromus is a splendid one to behold
Re: Pneumatics Programming

As Rakusan2 said, you need to declare ArmsDouble somewhere, i.e. "DoubleSolenoid ArmsDouble = new DoubleSolenoid(1, 2)". DoubleSolenoid not being able to resolved may be fixed by that as well.
Reply With Quote
  #8   Spotlight this post!  
Unread 13-02-2015, 15:42
Team 4939 Team 4939 is offline
Registered User
AKA: Anshul Shah
FRC #4939 (All spark 9)
Team Role: Programmer
 
Join Date: Jan 2014
Rookie Year: 2014
Location: Brampton
Posts: 52
Team 4939 is an unknown quantity at this point
Re: Pneumatics Programming

Quote:
Originally Posted by Rakusan2 View Post
You need a declaration for ArmsDouble
Code:
DoubleSolenoid ArmsDouble;
also why are you initializing ArmsDouble twice?
If I am using a Double Solenoid do I not need to initialize it twice for both the In and Out feature?

That's the impression this gave me: http://wpilib.screenstepslive.com/s/...ders-solenoids
Reply With Quote
  #9   Spotlight this post!  
Unread 13-02-2015, 15:46
Rakusan2 Rakusan2 is offline
Registered User
AKA: Tomas Rakusan
FRC #3571 (Milton Mustangs)
Team Role: Programmer
 
Join Date: May 2014
Rookie Year: 2011
Location: Milton, ON, Canada
Posts: 22
Rakusan2 is an unknown quantity at this point
Re: Pneumatics Programming

Quote:
Originally Posted by Team 4939 View Post
If I am using a Double Solenoid do I not need to initialize it twice for both the In and Out feature?

That's the impression this gave me: http://wpilib.screenstepslive.com/s/...ders-solenoids
No, a single declaration and initialization of DoubleSolenoid takes care of both solenoids
Reply With Quote
  #10   Spotlight this post!  
Unread 13-02-2015, 15:46
Oromus's Avatar
Oromus Oromus is offline
Lead Programmer, Community Liaison
AKA: Ryan
FRC #1902 (Exploding Bacon)
Team Role: Programmer
 
Join Date: Jan 2015
Rookie Year: 2013
Location: Florida
Posts: 83
Oromus is a splendid one to beholdOromus is a splendid one to beholdOromus is a splendid one to beholdOromus is a splendid one to beholdOromus is a splendid one to beholdOromus is a splendid one to behold
Re: Pneumatics Programming

That example was just showing the different ways you can initialize your DoubleSolenoid; you do one constructor or the other.
Reply With Quote
  #11   Spotlight this post!  
Unread 15-02-2015, 00:38
viggy96 viggy96 is offline
Registered User
FRC #3331
Team Role: College Student
 
Join Date: Jan 2015
Rookie Year: 2010
Location: Charlotte
Posts: 55
viggy96 is infamous around these partsviggy96 is infamous around these parts
DoubleSolenoid(in channel, out channel). Also, the compressor does not need to be instantiated. The compressor is on a closed loop controlled by the PCM. You just need to instantiate the DoubleSolenoid once, and and set the position on button values.
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 18:06.

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