|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
| Thread Tools | Rate Thread | Display Modes |
|
#1
|
||||
|
||||
|
Configure Timers
We're trying out JAVA this year on our Robot after using Labview the last few seasons (not ask)...
In Labview we use the Configure Timer VI's to set the number of samples for averaging when using encoders or counters for speed control. We can't seem to find the equivilent Method Call in JAVA. Anyone know if this exists or do we have to write our own averaging? |
|
#2
|
||||
|
||||
|
Re: Configure Timers
Never Mind. Found my answer. Not available in C++ and JAVA.
http://www.chiefdelphi.com/forums/sh...7&postcount=24 |
|
#3
|
||||
|
||||
|
Re: Configure Timers
Quote:
http://www.chiefdelphi.com/forums/sh...3&postcount=29 It's not hard to do. A fairly simple change to the WPILib source code. Last edited by Ether : 01-30-2013 at 07:29 PM. |
|
#4
|
||||
|
||||
|
Re: Configure Timers
Thanks Ether. We'll look into modifying the encoder and/or counter class(s).
|
|
#5
|
|||
|
|||
|
Re: Configure Timers
You can use the TimerTask and Timer class, like we are doing. It will fire off a TimerTask's run() method every x milliseconds.
|
|
#6
|
||||
|
||||
|
Re: Configure Timers
Quote:
|
|
#7
|
|||
|
|||
|
Re: Configure Timers
Quote:
So for example, if I was running something with a 40ms period, It would actually run between 38 - 42 ms, but for the most part the cRIO was pretty good about keeping it constant 40. All of the threads I run on the robot use the TimerTask class. The timer task does not preempt the running thread, if they are at the same priority so keep that in mind, it will affect your thread execution. Last edited by NotInControl : 02-02-2013 at 01:30 AM. |
|
#8
|
||||
|
||||
|
Re: Configure Timers
Quote:
1) Do you put code in each of your threads to monitor throughput margin and re-entrancy ? 2) Are there other scheduling options in FRC Java which will provide concurrent processing of same-priority threads ? |
|
#9
|
|||
|
|||
|
Re: Configure Timers
Quote:
Especially when I run embedded code on an operating system that doesn't guarantee timing, I always put code in in there to monitor the execution of each state. Unfortunately, the SwawkOS doesn't support : Code:
System.nanoTime() Code:
System.currentTimeMillis(); Quote:
Something like: Code:
this.executor = new java.util.Timer(); this.executor.schedule(new MyTimedTask(this), 0L, this.period); Code:
while(true)
system.out.println("Hello World");
However, for JavaFRC you can use other properties of the Timer Task to control your concurrancy. For example you could use the scheduleAtFixedRate method of the TimerTask, which i believe does preempt the running thread to try and guarantee execution. (I never tested it however). The better way to do it in a normal J2ME project would be to set the priority of all of your threads. Using the Thread.setPriority() and Thread.getPriority() functions and the Thread.xxPRIORITY static fields. You can have up to 10 levels of priorities. Where Higher priorities will pre-empt lower ones. However these methods are not supported by Squawk JVM for FRC, and all threads in FRC Java are created with the same NORMAL priority. The best way to do it JavaFRC would be to avoid the need for preemption and try to ensure your code is optimized and runs in a period that is reasonable so that the CPU can be shared between all normal priority tasks. If all of your JavaFRC threads have relatively small execution times compared to its period, (and they should), then all your threads should have enough access to the CPU to run within its within its periodicity. Java VM in general is not a real time OS, so timing is never truly guaranteed, no matter what we do. Most of the inconsistencies arise when you have threads that are relying on preemptive behavior, instead of cooperatively giving up CPU time. Hope that helps, - Kev Last edited by NotInControl : 02-04-2013 at 02:47 AM. |
|
#10
|
||||
|
||||
|
Re: Configure Timers
Quote:
It's not good enough for accurately measuring the speed of a frisbee-shooting wheel using the counts/time method. It's not good enough to measure the linear speed of a frisbee as it exits the shooter on your robot. |
|
#11
|
|||
|
|||
|
Re: Configure Timers
Quote:
Quote:
I come from the defense world where if timing is inaccurate people could loose their lives. We obviously don't have that problem in FIRST was my point and I believe our problems in FIRST can afford less accuracy in our software timers, which was the point I was making. I have never observed good performance from the default encoder rate method but I have written my own encoder Rate codes with performance of +/- 3 rpm without averaging samples, where loop times were ~200ms, and that is way better than I need it for anything I need to do with a shooter wheel. What is your desired accuracy that calculating the speed of a wheel using time measured in milliseconds is not allowing you to achieve? What is driving this accuracy? Here is some psuedocode from my 2013 robot giving the performance I stated above with a 500PPR encoder @ 2300 wheel speed. It is a class which extends the encoder, which is why it uses Super. Code:
public double getRPM()
{
//getRate
timeNow = System.currentTimeMillis();
countNow = super.get(); //calls encoder.get method
rate=(countNow-countBefore)/(timeNow-oldTime); //counts per millisecond
oldTime=timeNow;
countBefore=countNow;
//return average
return rate*1000*60/PPR; //... rpm
}
Quote:
System.currentTimeMillis() is a software timer. To measure linear speed of the disc you need something which can provide you external readings first. If you had for example two IR line sensors in the path of the disc a set distance apart. Saved the time each IR sensor was crossed by the disc and then calculated the Velocity using distance over time, your saying the accuracy you would get from that wouldn't be good enough because the time measured was in Milliseconds? Not good enough to accomplish what exactly? Last edited by NotInControl : 02-04-2013 at 04:04 AM. Reason: changed 1 to 3 (typo) |
|
#12
|
||||
|
||||
|
Re: Configure Timers
Quote:
|
|
#13
|
|||
|
|||
|
Re: Configure Timers
That response didn't really answer my questions above. But to answer yours information on the encoder in question can be found here:
http://www.robotshop.com/productinfo...-38&lang=en-US It is an encoder I like to use on my personal projects. It won't be the final encoder we use on our Robot this year. The final encoders we use this year will be a GreyHill 256 PPR. Hope this helps, Kev |
|
#14
|
||||
|
||||
|
Re: Configure Timers
In order to prepare a thoughtful analytical response, I needed to gather some technical information to clear up some ambiguities in your post.
But since you're in a hurry, I'll just ask you for clarification instead of taking the time to research it myself. When you use the term PPR, what do you mean by that? Do you mean the same thing that US Digital does (see attachment)? Or do you use the term PPR to mean what US Digital calls CPR? GrayHill specs their encoders in CPR, not PPR, and they define CPR the same way that US Digital does. So is your "256 PPR" GrayHill encoder 256 CPR or 64 CPR? And is your "500 PPR" Cytron encoder 500 CPR or 125 CPR? If you don't have this info, I will respond to your post without it, but my response will be in generalities and therefor less useful I would think. |
|
#15
|
|||
|
|||
|
Re: Configure Timers
Quote:
I believe I have all bases covered but I won't know for sure until you share your perspective and reasoning. But I do appreciate you taking the time to formulate a complete answer... so thank you. Quote:
When I use the Term PPR, as in Pulses per revolution, I mean it in terms of the square wave being generated. A Pulse in my definition is a complete rising edge, width, and falling edge. Therefore, if you are counting all rising and falling edges, a single pulse produces 2 counts. If the encoder is quadrature, there are two digital outputs each generating its own pulse. Therefore if you were to count all rising and falling edges from a quadrature encoder, each pulse would return 2 counts but you have 2 pulses to deal with so the total is 4 counts. So in my definition, a quadrature 500PPR, can produce 2000 counts per revolution when counting all rising and falling edges on both channels. I believe GreyHill defines this as Cycles Per Revolution (CPR) which is another term used in industry but means the exact same thing as my PPR. I avoid using CPR because unless you are intimately familiar with the definitions you may confuse CPR to mean "Count Per Revolution" (or at least I would, and that is completely wrong). So the GreyHill 256 Cycles Per Rotation encoder I mentioned would produce 1000 counts per rev if you were counting the rising and falling edge of each signal. or as I call it 256 Pulses per revolution (On a Single Channel). Does that clarify things and answers your question? Hope that helps, Kev |
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|