Go to Post We are all insane aren't we? I just want to build a robot now. :P - Lowfategg [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-03-2015, 14:36
SirGibbs SirGibbs is offline
Registered User
FRC #5676 (Hornets)
Team Role: Programmer
 
Join Date: Feb 2015
Rookie Year: 2015
Location: USA
Posts: 11
SirGibbs is an unknown quantity at this point
arcade drive

Hey guys I am from team 5676 and we have a little or big problem with our arcade drive and the java program. We are using talon motor controllers with the kop andymark motors and pneumatic's. But we don't get it running. The robot is just turning around the y and at the x axes at option 1 but the pneumatic's are working. At option 2 is it not driving and the pneumatic's aren't working also but I thought that it would be he exact copy of the example but the code is getting permanently deployed at the roborio. Because an other problem is that at option 1 is the code stopping and getting periodically erased from the roborio at around 1;50 until I restart it. My first thought was that it's maybe running out of ram but that doesn't seem to be the problem.
Every help or input would be highly appreciated. I thank all of you in advance for your time and help.

option 1:
Code:
package org.usfirst.frc.team5676.robot;

import edu.wpi.first.wpilibj.IterativeRobot;
import edu.wpi.first.wpilibj.Joystick;
import edu.wpi.first.wpilibj.DoubleSolenoid;
import edu.wpi.first.wpilibj.RobotDrive; 



public class Robot extends IterativeRobot {
    RobotDrive myRobot;
    Joystick stick;
    DoubleSolenoid Piston;
    
    public void robotInit() {
    	myRobot = new RobotDrive (0, 1, 2, 3);
    	stick = new Joystick(0);
    			
    }
    
    
    public void autonomousPeriodic() {

    }

  public void teleopPeriodic() {
        	
	  myRobot.arcadeDrive(stick);
          
    	Piston = new DoubleSolenoid (0,1);
    	   		
    	   		if(stick.getRawButton(5)) {
    	   			
    	   			Piston.set(DoubleSolenoid.Value.kForward);	
    	   		
    	   			System.out.println("'A' button is pressed: Piston moves forward");
    	   		}
    	   	  else if(stick.getRawButton(6))
    	   		{
    	   			Piston.set(DoubleSolenoid.Value.kReverse); 
    	   	
    	   			System.out.println("'B' button is pressed: Piston moves backward");
    	   		}
    	   		else
    	   		{
    	   			Piston.set(DoubleSolenoid.Value.kOff);		
    	   		}
    	   	
    
    	
    Piston = new DoubleSolenoid(2,3 );
		
		if(stick.getRawButton(3)) {
			
			Piston.set(DoubleSolenoid.Value.kForward);	
		
			System.out.println("'A' button is pressed: Piston moves forward");
		}
	  else if(stick.getRawButton(4))
		{
			Piston.set(DoubleSolenoid.Value.kReverse); 
	
			System.out.println("'B' button is pressed: Piston moves backward");
		}
		else
		{
			Piston.set(DoubleSolenoid.Value.kOff);		
		}
 
    	
 
Piston = new DoubleSolenoid(4,5 );
	
	if(stick.getRawButton(1)) {
		
		Piston.set(DoubleSolenoid.Value.kForward);	
	
		System.out.println("'A' button is pressed: Piston moves forward");
	}
 else if(stick.getRawButton(2))
	{
		Piston.set(DoubleSolenoid.Value.kReverse); 

		System.out.println("'B' button is pressed: Piston moves backward");
	}
	else
	{
		Piston.set(DoubleSolenoid.Value.kOff); }
	
	}

    /**
     * This function is called periodically during test mode
     */

    public void testPeriodic() {
    
    }
    
}


option 2:

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

import edu.wpi.first.wpilibj.IterativeRobot;
import edu.wpi.first.wpilibj.Joystick;
import edu.wpi.first.wpilibj.DoubleSolenoid;
import edu.wpi.first.wpilibj.RobotDrive; 
import edu.wpi.first.wpilibj.Timer;


public class Robot extends IterativeRobot {
    RobotDrive myRobot;
    Joystick stick;
    DoubleSolenoid Piston;
    
    public void robotInit() {
    	myRobot = new RobotDrive (0, 1, 2, 3);
    	stick = new Joystick(0);
    			
    }
    
    
    public void autonomousPeriodic() {

    }

  public void teleopPeriodic() {
        	
	  while (isOperatorControl() && isEnabled()) {
        	myRobot.arcadeDrive(stick);
            Timer.delay(0.01);		
        }
	  
    	Piston = new DoubleSolenoid (0,1);
    	   		
    	   		if(stick.getRawButton(5)) {
    	   			
    	   			Piston.set(DoubleSolenoid.Value.kForward);	
    	   		
    	   			System.out.println("'A' button is pressed: Piston moves forward");
    	   		}
    	   	  else if(stick.getRawButton(6))
    	   		{
    	   			Piston.set(DoubleSolenoid.Value.kReverse); 
    	   	
    	   			System.out.println("'B' button is pressed: Piston moves backward");
    	   		}
    	   		else
    	   		{
    	   			Piston.set(DoubleSolenoid.Value.kOff);		
    	   		}
    	   	
    
    	
    Piston = new DoubleSolenoid(2,3 );
		
		if(stick.getRawButton(3)) {
			
			Piston.set(DoubleSolenoid.Value.kForward);	
		
			System.out.println("'A' button is pressed: Piston moves forward");
		}
	  else if(stick.getRawButton(4))
		{
			Piston.set(DoubleSolenoid.Value.kReverse); 
	
			System.out.println("'B' button is pressed: Piston moves backward");
		}
		else
		{
			Piston.set(DoubleSolenoid.Value.kOff);		
		}
 
    	
 
Piston = new DoubleSolenoid(4,5 );
	
	if(stick.getRawButton(1)) {
		
		Piston.set(DoubleSolenoid.Value.kForward);	
	
		System.out.println("'A' button is pressed: Piston moves forward");
	}
 else if(stick.getRawButton(2))
	{
		Piston.set(DoubleSolenoid.Value.kReverse); 

		System.out.println("'B' button is pressed: Piston moves backward");
	}
	else
	{
		Piston.set(DoubleSolenoid.Value.kOff); }
	
	}

    /**
     * This function is called periodically during test mode
     */

    public void testPeriodic() {
    
    }
    
}

Last edited by SirGibbs : 13-03-2015 at 14:39.
Reply With Quote
  #2   Spotlight this post!  
Unread 13-03-2015, 15:12
notmattlythgoe's Avatar
notmattlythgoe notmattlythgoe is offline
Flywheel Police
AKA: Matthew Lythgoe
FRC #2363 (Triple Helix)
Team Role: Mentor
 
Join Date: Feb 2010
Rookie Year: 2009
Location: Newport News, VA
Posts: 1,715
notmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond repute
Re: arcade drive

Q1. Do you have 3 different pistons that are supposed to move when different buttons are pressed?

Q2. Which motors on your drive train are plugged into each port?

Last edited by notmattlythgoe : 13-03-2015 at 15:26.
Reply With Quote
  #3   Spotlight this post!  
Unread 13-03-2015, 16:00
notmattlythgoe's Avatar
notmattlythgoe notmattlythgoe is offline
Flywheel Police
AKA: Matthew Lythgoe
FRC #2363 (Triple Helix)
Team Role: Mentor
 
Join Date: Feb 2010
Rookie Year: 2009
Location: Newport News, VA
Posts: 1,715
notmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond repute
Re: arcade drive

I cleaned your code up a bit. One issue you had was that you were creating new references to your pistons every ~20ms which is a bad thing to do. You were also sharing the same reference for ever single piston, also a bad thing to do. You can see that I moved the created 2 more pistons and created their references in robotInit().

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

import edu.wpi.first.wpilibj.IterativeRobot;
import edu.wpi.first.wpilibj.Joystick;
import edu.wpi.first.wpilibj.DoubleSolenoid;
import edu.wpi.first.wpilibj.RobotDrive; 



public class Robot extends IterativeRobot {
    RobotDrive myRobot;
    Joystick stick;
    DoubleSolenoid piston1;
	DoubleSolenoid piston2;
	DoubleSolenoid piston3;
    
    public void robotInit() {
    	myRobot = new RobotDrive (0, 1, 2, 3);
    	stick = new Joystick(0);
    	piston1 = new DoubleSolenoid(0, 1)
		piston2 = new DoubleSolenoid(2, 3);
		piston3 = new DoubleSolenoid(4, 5);
    }
    
    public void autonomousPeriodic() {

    }

	public void teleopPeriodic() {
        	
		myRobot.arcadeDrive(stick);
			  
					
		if (stick.getRawButton(5)) {
			piston1.set(DoubleSolenoid.Value.kForward);	
			ystem.out.println("'A' button is pressed: Piston moves forward");
		} else if (stick.getRawButton(6)) {
			piston1.set(DoubleSolenoid.Value.kReverse); 
			System.out.println("'B' button is pressed: Piston moves backward");
		} else {
			piston1.set(DoubleSolenoid.Value.kOff);		
		}
			
		if (stick.getRawButton(3)) {
			Ppiston2.set(DoubleSolenoid.Value.kForward);	
			System.out.println("'A' button is pressed: Piston moves forward");
		} else if (stick.getRawButton(4)) m{
			piston2.set(DoubleSolenoid.Value.kReverse); 
			System.out.println("'B' button is pressed: Piston moves backward");
		} else {
			piston2.set(DoubleSolenoid.Value.kOff);		
		}
		
		if (stick.getRawButton(1)) {
			piston3.set(DoubleSolenoid.Value.kForward);	
			System.out.println("'A' button is pressed: Piston moves forward");
		} else if (stick.getRawButton(2)) {
			piston3.set(DoubleSolenoid.Value.kReverse); 
			System.out.println("'B' button is pressed: Piston moves backward");
		} else {
			piston3.set(DoubleSolenoid.Value.kOff); 
		}
	}

    /**
     * This function is called periodically during test mode
     */

    public void testPeriodic() {
    
    }  
}
Reply With Quote
  #4   Spotlight this post!  
Unread 13-03-2015, 17:31
SirGibbs SirGibbs is offline
Registered User
FRC #5676 (Hornets)
Team Role: Programmer
 
Join Date: Feb 2015
Rookie Year: 2015
Location: USA
Posts: 11
SirGibbs is an unknown quantity at this point
Re: arcade drive

At first thank you very much!!!

Question 1: Yes we do.

Question 2: I am sorry, I am not sure I am already home. Do you think that it could be just wired wrong? I tried the default labview code just for fun and it worked perfectly with the arcade drive. So shouldn't it also work with the java code with the "default example"?
Reply With Quote
  #5   Spotlight this post!  
Unread 13-03-2015, 17:37
notmattlythgoe's Avatar
notmattlythgoe notmattlythgoe is offline
Flywheel Police
AKA: Matthew Lythgoe
FRC #2363 (Triple Helix)
Team Role: Mentor
 
Join Date: Feb 2010
Rookie Year: 2009
Location: Newport News, VA
Posts: 1,715
notmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond reputenotmattlythgoe has a reputation beyond repute
Re: arcade drive

Quote:
Originally Posted by SirGibbs View Post
At first thank you very much!!!

Question 1: Yes we do.

Question 2: I am sorry, I am not sure I am already home. Do you think that it could be just wired wrong? I tried the default labview code just for fun and it worked perfectly with the arcade drive. So shouldn't it also work with the java code with the "default example"?
The way you have the ports in your RobotDrive constructor call they should be plugged in like this:
Left Front = 0
Left Rear = 1
Right Front = 2
Right Rear = 3

The constructor call has this order for the parameters:

Code:
RobotDrive(int leftFront, int leftRear, int rightFront, int rightRear)
If they are not in the right order the drivetrain will act funny.
Reply With Quote
  #6   Spotlight this post!  
Unread 14-03-2015, 20:59
cstelter cstelter is offline
Programming Mentor
AKA: Craig Stelter
FRC #3018 (Nordic Storm)
Team Role: Mentor
 
Join Date: Apr 2012
Rookie Year: 2012
Location: Mankato, MN
Posts: 77
cstelter will become famous soon enough
Re: arcade drive

Quote:
Originally Posted by SirGibbs View Post
At option 2 is it not driving and the pneumatic's aren't working also but I thought that it would be he exact copy of the example but the code is getting permanently deployed at the roborio.


option 2:

Code:
  public void teleopPeriodic() {
        	
	  while (isOperatorControl() && isEnabled()) {
        	myRobot.arcadeDrive(stick);
            Timer.delay(0.01);		
        }
	  
    	Piston = new DoubleSolenoid (0,1);
        ...
The reason you see the symptom of your pneumatics not running is that telopPeriodic is *only* called when isOperatorControl() and isEnabled() are both true. So the first time through telopPeriodic() (which is supposed to be called every 20ms), you enter the while loop that is always true until you disable. You never leave the first call to teleopPeriodic() with this method.

You are mixing two paradigms-- this construct you would use for SampleRobot:

Code:
public class Robot extends SampleRobot {
    . . .
    void operatorControl() {
	  while (isOperatorControl() && isEnabled()) {
        	myRobot.arcadeDrive(stick);
            Timer.delay(0.01);		
        }
    }
In SampleRobot operatorControl is called only once when the Teleop begins.

This is the style to use in IterativeRobot:

Code:
public class Robot extends IterativeRobot {
     ...
     public void teleopPeriodic() {
        	myRobot.arcadeDrive(stick);
        }
Up higher in the IterativeRobot base class there is something similar to

Code:
    	  while (isOperatorControl() && isEnabled()) {

        	teleopPeriodic()

            Timer.delay(0.02);		
        }
It's actually much different, but the effect is the same-- Iterative robot will call teleopPeriodic() every 20ms as long as we're enabled in Teleop mode.

The net effect is in your option 2, your piston code will only be called once (maybe) only when isOperatorControl() goes false or isEnabled() goes false. I say maybe because it wouldn't surprise me if the teleopPeriodic call was on a thread that is terminated when either of these values go false.

But this explains the symptom you found.

Stick with Option 1 and take Matt's advice and you should get up and running quickly
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 10:26.

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