Go to Post Does that mean that the Ultimate Question of Life, the Universe, and Everything is, "How many total tubes will be available to score for the FRC 2011 game, LogoMotion? - EricH [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

 
 
 
Thread Tools Rate Thread Display Modes
Prev Previous Post   Next Post Next
  #4   Spotlight this post!  
Unread 26-01-2012, 23:38
ianonavy ianonavy is offline
Programming Mentor/Alumnus
AKA: Ian Adam Naval
FRC #3120 (RoboKnights)
Team Role: Mentor
 
Join Date: Dec 2010
Rookie Year: 2008
Location: Sherman Oaks
Posts: 32
ianonavy is an unknown quantity at this point
Re: A good time based way to program

Quote:
Originally Posted by neal View Post
I can't test that either until Saturday, but wouldn't that delay the whole main operatorControl() while loop?
Oh, I see. You're using the SimpleRobot class. I recommend that you really look into the command-based robot implementation. It makes everything a lot more object-oriented, and it's really nice. There should be a sample project called GearsBot if you've updated your NetBeans FRC plugins for this year's competition.

If you are going to stick with that style, you could try something like this

Code:
// Buttons
        final int MOVE_ARM = 1;
        
        // Constants
        final int ARM_PWM = 1;
        final double ARM_SPEED = 1.0;
        final int ARM_TIME = 1.0; // seconds
        
        // Should be instance fields
        Timer armTimer = new Timer();
        Jaguar arm = new Jaguar(ARM_PWM);
        Joystick joystick = new Joystick(1);
        
        armTimer.reset();
        armTimer.stop();
        while (isOperatorControl() && isEnabled()) {
            if (joystick.rawButton(MOVE_ARM)) {
                armTimer.start();
            }
            if (armTimer.get() / 1e6 < ARM_TIME) {
                arm.set(ARM_SPEED);
            } else {
                arm.set(0);
                armTimer.stop(); 
                armTimer.reset();
            }
        }
I don't know that it's the best way of approaching it. There's probably some better way of putting them into separate functions. Essentially, you're going to have separate Timer objects for each motor. You could extend the Jaguar class and make something like a TimedJaguar.

Undocumented and untested quick example:

Code:
public class TimedJaguar extends Jaguar{
    Timer timer;

    public TimedJaguar() {
        timer = new Timer();
        timer.reset();
    }

    public void setForTime(double power, double time) {
        // Implement here.
    }
}
Reply With Quote
 


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 13:13.

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