Subject:
|
Re: Light Sensor help
|
Newsgroups:
|
lugnet.robotics
|
Date:
|
Tue, 9 Apr 2002 20:38:03 GMT
|
Original-From:
|
ROLS@nospamROLS.ORG
|
Viewed:
|
575 times
|
| |
| |
Interesting this is being discussed now. I wrote
a chunk of code at the weekend (NQC) to allow me
fine control over the motors. Basically, you give
each one a number from 0-100, call it N. The drive
task counts ticks from 0-99 and ensures the motor
is on for exactly N of those ticks. A little integer
division ensures that the 'on' bursts are evenly
spread over the 100 ticks.
Anyway - the code was pretty short, read a couple
of variables, did a multiplication and division,
case statement to pick the output and store the
variables back again for next time. That's all the
task did.
When I ran it, I was horrified at how slow it was.
Basically it managed to do that loop, and nothing
else, about 60 times in 10 seconds, which made for
very jerky movement. That's 167ms per loop.
So I stripped out all the generic stuff from the
function, removed the case statement and basically
made the whole thing as short as possible. I got it
up to about 15 iterations a second, which was enough
to ensure smooth movement. Even so, I was very surprised
to find it operating SO slowly, with nothing else going
on, the processor should fairly rip through this tiny
piece of code.
I stopped at that point, but I guess I ought to go back
and take a look at the compiled code and see how many
instructions make up one loop. With a timing of about
3ms per bytecode instruction (from the information below),
it makes a little more sense. 15 iterations/second is
67ms/iteration, which would be 22 instructions, which is
probably about right.
That all seems rather slow though doesn't it? How fast
is the clock speed on the onboard processor?
Roland
On Tue, 09 April 2002, "T. Alexander Popiel" wrote:
>
> In message: <GuB96o.CKA@lugnet.com>
> "John Barnes" <barnes@sensors.com> writes:
> >
> > The purpose of this post however, is to ask if anyone has done any timing
> > tests to find out what the byte code execution speeds are recently. Easy
> > enough to do, set up an empty loop that goes round say 10,000 times and time
> > it with a stop watch, and then insert different instructions into the loop
> > and check out how much longer the overall time increases by.
>
> Yes, I just recently did some timing tests, using that exact method.
> Each bytecode takes 2.9 +/- .2 ms to execute, as near as I can tell.
> This appears to be independent of which bytecode it is (though I did
> not test any that I really expected to be expensive (the multiply and
> divide codes, that is)). I specifically tested jmp, jmpl, chk, chkl,
> setv, addv, subv, out, and dir (using the NQC disassemble nomenclature).
> For setv and chkl, I tested sources 0 (variable), 2 (immediate), and
> 9 (cooked sensor). I did _not_ test source 36 (indirect).
>
> Also, calling a subroutine takes that same 2.9 +/- .2 ms for each of
> the call instruction and the return instruction (in addition to whatever
> else is in the subroutine).
>
> > I'd like to think that someone has already done this before, but I can't
> > seem to find a post anywhere and if it's that old, it probably wasn't on
> > vers 2.0 firmware.
>
> I did this on both 1.5 and 2.0, with no detectable difference.
>
> > It might be very insightful to know just how slow the interpreter is. I have
> > a nasty feeling that the effective code execution speed of NQC programs is
> > really slow.
>
> Actually, it's not too horrible... particularly if you drive your
> motors in a separate task from the sensor readings, and use one of
> the global variables to communicate between the tasks. You can get
> worst case response from sensor change to motor output in under 30ms
> without half trying.
>
> - Alex
|
|
Message has 1 Reply: | | Re: Light Sensor help
|
| (...) 16 MHz AFAIK, and I bet it could go much faster, at the price of a less reproducible timing. leJOS executes some tens of Java bytecodes per millisecond, an empty 10000 iterations loop containing four relatively simple byte codes runs in 1.4 (...) (23 years ago, 10-Apr-02, to lugnet.robotics)
|
2 Messages in This Thread:
- Entire Thread on One Page:
- Nested:
All | Brief | Compact | Dots
Linear:
All | Brief | Compact
|
|
|
|