Thread: arcade drive
View Single Post
  #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