Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   Programming (http://www.chiefdelphi.com/forums/forumdisplay.php?f=51)
-   -   no control of bot when kicker is operating (http://www.chiefdelphi.com/forums/showthread.php?t=86070)

isaacdl 11-06-2010 12:30

no control of bot when kicker is operating
 
We are working on learning Java as a precursor to next years season by programming this years bot in Java. We have tank drive working just fine, and the pneumatic kicker works just fine. The one problem we have is that one kick (out and in) takes about a second to complete. (Half second delay each way is programmed in to provide time for the cylinder to fully extend and retract). During that second, the we have no control over the bot. If it was driving (ie the joystick was moved forward or backwards) when the kicker is activated, the bot will *continue* to move at that speed and direction until the kicker cycle is done, even if we release the stick or change directions. How should we solve that?

Robototes2412 11-06-2010 12:31

Re: no control of bot when kicker is operating
 
Use Timers

isaacdl 11-06-2010 12:33

Re: no control of bot when kicker is operating
 
You're going to have to give us more than that. How?

Chris is me 11-06-2010 12:42

Re: no control of bot when kicker is operating
 
We got stuck in a goal in Connecticut, twice, because of this very issue. We stopped kicking while moving for the rest of the event to correct it. Hope you find a solution.

Andrew Schreiber 11-06-2010 12:46

Re: no control of bot when kicker is operating
 
I assume you are using Wait or some similar statement (for some odd reason I can never remember what the thing is called) just like you would in Auton?

Robototes2412 is correct if that is your problem and that using Timers is your problem. I am not familiar enough with Java to know exactly how but a quick bit of research should show you the solution.

Sorry I couldn't be more help.

isaacdl 11-06-2010 12:49

Re: no control of bot when kicker is operating
 
We're using Timer.delay(xnumberofseconds). Is that what you mean?

Ether 11-06-2010 12:55

Re: no control of bot when kicker is operating
 
It sounds like your "driving" code has to wait for your "kicking" code to complete.

If this is the case, there are two (at least) different ways to solve this:

1) put your kicking code and driving code into separate tasks so that the OS can multitask them for you,

or

2) use a state machine for your kicker code, so that it doesn't bring everything to a halt while it's waiting for the delay

ATannahill 11-06-2010 12:56

Re: no control of bot when kicker is operating
 
What is happening is that your code is stopping there and is not checking for new values for the joystick.

I don't know much about java but what will probably work is assigning the time at the beginning of the kick to a variable. When the time is equal to or greater than the variable plus .5 move on with the kick.

This will let your code loop and read the joysticks.

Andrew Schreiber 11-06-2010 12:59

Re: no control of bot when kicker is operating
 
Quote:

Originally Posted by isaacdl (Post 966277)
We're using Timer.delay(xnumberofseconds). Is that what you mean?

I believe so... There should be a way of setting a timer to go off in X period of time. In C++ these would be the Timer.Start Timer.Stop and Timer.HasPeriodPassed (Referenced http://www.virtualroadside.com/WPILib/class_timer.html) Java should have an equivalent. This should not delay the loop you are in which is your problem. (If I am assuming your problem correctly)

isaacdl 11-06-2010 13:01

Re: no control of bot when kicker is operating
 
Quote:

Originally Posted by Ether (Post 966278)
It sounds like your "driving" code has to wait for your "kicking" code to complete.

If this is the case, there are two (at least) different ways to solve this:

1) put your kicking code and driving code into separate tasks so that the OS can multitask them for you,

or

2) use a state machine for your kicker code, so that it doesn't bring everything to a halt while it's waiting for the delay


We're trying option one right now, but having never had to program multiple threads, could you explain how to do it? We're trying various things we're finding on the internet, but none of it is exactly what we need.
If it matters, we're using SimpleRobotTemplate (so like Independent from LabView :P ) as opposed to IterativeRobot.

isaacdl 11-06-2010 13:04

Re: no control of bot when kicker is operating
 
Quote:

Originally Posted by Andrew Schreiber (Post 966280)
I believe so... There should be a way of setting a timer to go off in X period of time. In C++ these would be the Timer.Start Timer.Stop and Timer.HasPeriodPassed (Referenced http://www.virtualroadside.com/WPILib/class_timer.html) Java should have an equivalent. This should not delay the loop you are in which is your problem. (If I am assuming your problem correctly)

As far as I can tell, it's literally a delay; if you set a state for something (ie motor 1 forward 50%) and then use that delay method for 2 seconds, motor 1 will continue to operate at 50% until the timer is done and you send a command to change the state.

Ether 11-06-2010 13:19

Re: no control of bot when kicker is operating
 
Quote:

Originally Posted by isaacdl (Post 966281)
We're trying option one right now, but having never had to program multiple threads, could you explain how to do it?

I wish I could give you more specific help, but I am unfamiliar with Java. I'm sure there's a way to do it. There are lots of good Java programmers on CD. One fellow is even currently writing a Java programming manual for FIRST:

http://www.chiefdelphi.com/forums/sh...ad.php?t=85836

maybe you could ask him.


~

buildmaster5000 11-06-2010 21:34

Re: no control of bot when kicker is operating
 
Another option is to create a kickerLoops variable, and allow a certain loops to go by before operating your cylinders. We did this for our kicker and it worked great, but getting the initial setup/timing down might take a while.

synth3tk 11-06-2010 21:50

Re: no control of bot when kicker is operating
 
Give me a few minutes, and I can pull up our code, which an on-hand programming helper at the regional assisted us with. We had that exact same issue.

synth3tk 11-06-2010 22:03

Re: no control of bot when kicker is operating
 
Notes:

This is setup so that a button on a USB gamepad triggers the kicker.

Replace the sFire/sLatch/etc parts with your actual kicking code.

Depending on how your kicker works, you may need more or less "sections".

kickTime.start in the first block is required, and kickTimer.stop(); and kickTimer.reset();.

Code:

        // Set kicking loop to start when button 7 on gamepad is pressed and not in loop already
        Watchdog.getInstance().feed();
        if(gamePad.getRawButton(7) == true && kickTimer.get() == 0.0)
        {
            kickTimer.start();
            sFire.set(true);
            sLatch.set(false);

            sExt.set(true);
            sRet.set(false);
        }
        if (kickTimer.get() > 0.75 && kickTimer.get() < 1.05)
        {
            sFire.set(true);
            sLatch.set(false);

            sExt.set(false);
            sRet.set(true);
        }
        if (kickTimer.get() > 1.05 && kickTimer.get() < 1.35)
        {
            sFire.set(false);
            sLatch.set(true);

            sExt.set(false);
            sRet.set(true);
        }
        if (kickTimer.get() > 1.35)
        {
            sFire.set(false);
            sLatch.set(true);

            sExt.set(true);
            sRet.set(false);
            kickTimer.stop();
            kickTimer.reset();
        }



All times are GMT -5. The time now is 03:45.

Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi