To LUGNET HomepageTo LUGNET News HomepageTo LUGNET Guide Homepage
 Help on Searching
 
Post new message to lugnet.robotics.rcx.nqcOpen lugnet.robotics.rcx.nqc in your NNTP NewsreaderTo LUGNET News Traffic PageSign In (Members)
 Robotics / RCX / NQC / 1808
1807  |  1809
Subject: 
RE: time sampling under the rcx standard OS
Newsgroups: 
lugnet.robotics.rcx.nqc
Date: 
Sat, 17 Sep 2005 14:21:40 GMT
Viewed: 
5847 times
  
Here are some comments on how to improve your code for
real-time performance.

1. Move the "SetUserDisplay" out of the loop and put it just
before the loop.

2. I think the "OnFwd" macro is actually two instructions:
"Fwd" and then "On". Replace this with a "Fwd" instruction
before the loop and then just use an "On" instruction in
your loop.

3. These two changes will improve the cycle time (assuming
no waiting) through your loop by 25%.

4. You should have a range check on "actif" to ensure it is
0 to 10. If it's more than 10 then you could be getting
funny results. The firmware treats the delay count as
"unsigned' value so if the code "Wait(10-actif)" results in
a negative wait time value you could be waiting a long time.

You really want to use the faster firmware mentioned in the
other reply to your post. The version on the web should give
you the ability to get 50+ loops per second. The standard
firmware has an underlying clock running at 10-milliseconds.
So a "Wait(40)" will actually wait from 40 to 50
milliseconds. Faster firmware uses 1-millisecond basic clock
so the wait would only be 40 to 41 milliseconds.

Of course, if you use the faster firmware you also get the
128 power level capability. So you eliminate your loop and
simply set the motor power to:
     128 * SENSOR_2 /  10
This will let the firmware do all the work for you!



-----Original Message-----
From: news-gateway@lugnet.com
[mailto:news-gateway@lugnet.com]On Behalf Of Francois Bardet
Sent: Saturday, September 17, 2005 2:59 AM
To: lugnet.robotics.rcx.nqc@lugnet.com
Subject: time sampling under the rcx standard OS

Hi list,

I'm trying to implement a position regulation (using a motor
and a rotation
sensor), using for instance a PID
(Proportional-Integral-Derivative) regulation.
I tried to code it in NQC, using the standard OS, but it
seems that the RCX
loops at very low and unreliable frequency (few Hertz).
Please see example at
the end of this post.
I heard that BrickOS might allow a more reliable time
control, but I'd
appreciate a solution to keep me using the standard OS and
NQC !

- Can the standard RCX OS sample a sensor value at a known
and constant rate ?

- Can this rate be higher (at least 50Hz) in order to get a
good regulation?

- Or should I get better results using BrickOS ?

As example below is a code for a PWM (Pule Width
Modulation), in which a
rotation sensor allows 10 pulse rates to the motor, looping
at 0.1 seconds :

task main()
{
SetSensor(SENSOR_2,SENSOR_ROTATION);
SetPower(OUT_A,1);
while(true)
{
int actif=SENSOR_2;
int passif=10-actif;
OnFwd(OUT_A);
Wait(actif);
Off(OUT_A);
Wait(passif);
SetUserDisplay(actif,0);
}
}

The problem is that it doesn't loop at 0.1 seconds, but much
slower (~0.5
second)... while I'd like to control time at few ms
accuracy.
Any advice to help me keep using the standard OS and NQC ?



Message has 1 Reply:
  Re: time sampling under the rcx standard OS
 
Thank you Dick, for advicing me to switch to the faster firmware, I’m sure I need both a 1-millisecond basic clock, and the 128 power level capability. So I tried to download it from (URL) but it just appears as a text file, which I don’t know how (...) (19 years ago, 18-Sep-05, to lugnet.robotics.rcx.nqc)

Message is in Reply To:
  Re: time sampling under the rcx standard OS
 
(...) Francois, I think you should be able to get much faster sampling. I can easily get 10-20 Hz, and others have claimed to get down to 3 ms. Whether it can be done at a constant rate, I'm not sure, and think it probably depends on what else is in (...) (19 years ago, 17-Sep-05, to lugnet.robotics.rcx.nqc)

10 Messages in This Thread:



Entire Thread on One Page:
Nested:  All | Brief | Compact | Dots
Linear:  All | Brief | Compact

This Message and its Replies on One Page:
Nested:  All | Brief | Compact | Dots
Linear:  All | Brief | Compact
    

Custom Search

©2005 LUGNET. All rights reserved. - hosted by steinbruch.info GbR