![]() |
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?
|
Re: no control of bot when kicker is operating
Use Timers
|
Re: no control of bot when kicker is operating
You're going to have to give us more than that. How?
|
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.
|
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. |
Re: no control of bot when kicker is operating
We're using Timer.delay(xnumberofseconds). Is that what you mean?
|
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 |
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. |
Re: no control of bot when kicker is operating
Quote:
|
Re: no control of bot when kicker is operating
Quote:
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. |
Re: no control of bot when kicker is operating
Quote:
|
Re: no control of bot when kicker is operating
Quote:
http://www.chiefdelphi.com/forums/sh...ad.php?t=85836 maybe you could ask him. ~ |
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.
|
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.
|
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 |
Re: no control of bot when kicker is operating
What you've posted is essentially a state machine, where the state variable is the value of kickTimer.
A generic state machine might look like this: Quote:
The above has the advantage that it's a little easier to see how to use events (like limit switches etc) to change states, instead of being strictly timer-based. ~ |
Re: no control of bot when kicker is operating
Thanks for the suggestions. I should have also stated:
I'm a non-student member (I guess a mentor, in some ways), and our team is extremely small. I couldn't even coerce any students to learn programming, so I had to learn Java with some small help from the team mentor (who knew very little more about Java than I did) and the internet starting 2 days from Kick-Off. We were just getting the bare minimum working. But I'll keep that in mind for the future, if/when we teach the new programmers. |
Re: no control of bot when kicker is operating
One solution for solving this in Java is threads. Team 997’s kicker this year takes 4.5 seconds to reload. It was extremely important for us to make sure the driver maintained control during this time. I’ve copied in some of our code below and removed most of the extra stuff it for you to see how we did threading on our robot.
A couple things to keep in mind. 1. It is vital your each thread of execution have either a Thread.yield() and/or a Timer.delay(). These are required to ensure each thread gets time on the CPU. Otherwise one thread could starve (not get any time on the CPU). 2. Put things like kicking that take a long time in separate threads, but keep quick things in the main thread. I accidentally put our gear shift in the kicker thread and the driver couldn’t shift while the kicker was reloading. :o We fixed this after regionals. Main thread that starts kicker thread: Code:
public class RobotMain extends SimpleRobot {Code:
public class KickerThread extends Thread { |
Re: no control of bot when kicker is operating
One point of clarification, since multithreading can be a confusing topic for some. Event though the performKick() method is located in the RobotMain class, the call to performKick() located in the KickerThread class' run() method still executes on the second thread. Any methods called during the While loop in the operatorControl() method are executing on the main thread.
|
Re: no control of bot when kicker is operating
Hey, welcome aboard frasnow. Check your Private Message inbox, I had a question about your post. :-)
|
Re: no control of bot when kicker is operating
1 Attachment(s)
I'm not sure if Java has the same thing, but in C++ another easy way to do something like this (without having to worry about yielding, since it does it for you automatically) in a different thread is via the Notifier class. It calls a function every N seconds (we specified 0.0025 seconds) on a different thread. Then you just have your state machine in a single function and have it do the right thing (ie, operate the right switches and such) every time the function gets called. And as the other poster said, you have a different function that gets called by the main thread that touches the state variables.
Of course, a key thing when dealing with multiple threads is to make sure you deal with potential synchronization problems, by using the appropriate locking mechanisms. In C++, you can use the Synchronized class to do that. I've attached our Kicker code in C++. The full version of our 2010 code is at http://www.virtualroadside.com/FRC/ |
Re: no control of bot when kicker is operating
Some thoughts for discussion:
Threads in C++ can be preemptive, regardless of whether or not they are created by the Notifier class. In any case, using cooperative multitasking techniques like releasing the CPU to service other tasks while waiting for an event or timer (block waiting) is good programming practice. It makes your code more responsive and avoids wasting CPU resources. If the kicker code is properly implemented as a state machine, you don't need concurrency, and you don't need to worry about synchronization. ~ |
Re: no control of bot when kicker is operating
I've seen the following kicker approach successfully implemented in LabVIEW. The same approach could be used in Java or C++.
put the following code in a separate concurrent periodic task using your language of choice. for a kicker, 20Hz is probably plenty fast enough. Code:
/*"kickRequested" is a global boolean that is used by your code in Autononmous and/or TeleOp to request that a kick be performed. "kicking" is a local boolean to control reentrancy: If a kick is presently in progress when the request is made, the request will be ignored (so as not to interrupt the ongoing kick cycle) |
Re: no control of bot when kicker is operating
One thing I liked doing for the kicker code was making sure you couldn't violate the timing rules (2 seconds between extensions out of the main robot body), and tossing in a few extra threads made it fit together nicely. Obviously reload time can make this unneeded, so it might not even be needed, depending.
Example code here. |
| All times are GMT -5. The time now is 23:19. |
Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi