help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Running octave script on interrupt


From: Przemek Klosowski
Subject: Re: Running octave script on interrupt
Date: Fri, 3 Oct 2014 18:11:26 -0400
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.1.1

On 10/03/2014 11:30 AM, Grzegorz Ficht wrote:
I am running octave on a raspberry pi (later it might be a beaglebone or odroid), equipped with a couple of basic libraries (instrument-control being one of them). My idea is to run an m-file that operates with a frequency of 100Hz, get some i2c data, do the calculations and send back some i2c data. The application being a control system, execution at constant frequency is crucial. On a microcontroller, one would normally set up an interrupt to run at 100Hz and execute the code. But as I've seen in the documentation, Octave doesn't allow for "timed execution" (the only thing remotely close to that is waiting for time to elapse with a >= operator, but that makes the frequency fluctuate). So one of my options is running octave scripts from an outside shell script. But the problem then is that after I run the script, Octave closes and each time i want to run the script it needs to initialize itself. Is there any way to ommit this (minimze octave instead of closing it?). Or is there an entirely other solution I am not aware of? I am working on the newest raspbian build, without lxde.

Looks like a cool project. You need to specify few things to get a meaningful help, though. What do you mean by 'timed execution'?
Octave sleep(n) function is accurate to seconds, so it won't work for you, but time() on my Linux is in miliseconds, so you could busy-loop, and that would be accurate to a combination of the OS latency and Octave interpreter execution jitter. If that's acceptable, then a code like this would work:

next=time;
k=5000;
while (k--)
    next+=.01
    while(time()<next); endwhile 
    a(k)=time
endwhile

which on my system seems to run at  100Hz +-  1Hz judging from hist(diff(a),1000). You seem to need to run the loop forever, so just replace the outer loop with while(true).

How precisely do you need to control the frequency? If you need a better frequency accuracy and/or can't afford to run a busy loop, you probably would need to run the data acquisition in a realtime process (either RT_LINUX or Xenomai), and write the data to a pipe, and have Octave read that pipe.

Curiously to Octave developers, I noticed a problem with the above code. After running it in different configurations for a while, the time() function got stuck and started returning a constant value. I restarted Octave and it behaved fine, but I definitely saw it choke although I couldn't replicate this.

reply via email to

[Prev in Thread] Current Thread [Next in Thread]