[visionegg] Re: stimulus code outputs
- From: Christophe Pallier <pallier@xxxxxxxxxxxxx>
- To: visionegg@xxxxxxxxxxxxx
- Date: Mon, 28 Mar 2005 17:52:41 +0200
Hi Andrew,
Thanks for pointing out RTAI Linux. I should have a look a it.
However, as you say, it does not solve the latency problem for video
drivers (or in my case, for audio drivers).
In the best of the world, we would like to be able to send a bit on a
port, start an audio stream and show a picture
at the same millisecond (sync on the video vsync). The low latency
patches for Linux is another possiblity to reduce latencies (see, e.g.
jackit.sourceforge.net). The pity is that it is difficult to distribute
a program that relies on a patched kernel.
Regarding SDL_GetTicks, it uses gettimeofday as far as I remember and so
it has as good accuracy as you can get under Linux (optionaly, one can
choose to use the Pentium TSC when recompiling SDL, but this is not a
good idea for some systems (SMP & processor with throttling frequency).
I imagine python time.time also use gettimeofday but I should check.
I thought that the latencies were not due to python/pygame, so I wrote a
few lines of C to do about the same thing as the prvious pyhon code (see
below), and it turned out that the worse latencies I get are better
(typically 30~50 msec, with kernel 2.6.8 and a Pentium 4-2Ghz) than with
the previous python/pygame (~200 msec). Maybe pygame.time.delay does
not use nanosleep. Again I should check the source.
Cheers, and thanks for the VisionEgg!
Christophe
#include <stdio.h>
#include <sys/time.h>
#include <time.h>
int main()
{
struct timeval tv0,tv1;
struct timezone tz0,tz1;
struct timespec delay,rem;
long latency,max;
delay.tv_sec=0;
delay.tv_nsec=5000000L; /* 5 msec */
while(1) {
gettimeofday(&tv0, &tz0);
nanosleep(&delay,&rem);
gettimeofday(&tv1, &tz1);
latency = (tv1.tv_sec-tv0.tv_sec)*1000000L+tv1.tv_usec-tv0.tv_usec;
if (latency>max) { max=latency; printf("%ld\n",max/1000); };
}
}
Finally, a question about your code -- I always read those notes about
the resolution of "ticks" in SDL/pygame and got scared away from using
them. Thus, the Vision Egg generally uses Python standard library
calls. I see you are using pygame's get_ticks(). Does this perform
differently than time.time() on linux? Also, by using a "busy wait" [I
think pygame.time.delay() is], does the kernel scheduler penalize your
process? If not, I would agree this is probably more accurate than a
time.sleep(). I'll try to test this soon myself.
Cheers!
Andrew
On Mar 24, 2005, at 1:23 AM, Christophe Pallier wrote:
Hello Darren,
Expy is an attempt to re-implement with pygame an old, (venerable
;-), DOS experimental stimulator (EXPE: www.lscp.net/expe) which I
wrote 15 years ago (and is still used nowdays in some labs, for its
"perfect" timing). Expy is extremely preliminary and we should not
have put the web page in my opinion, because the program is not
really usable. Emmanuel Dupoux and I hope to be able to recruit a
programmer to pursue this project, but we are still looking for
funding. Still if you can steal any ideas from the project, it would
not have been entirely useless.
I would really like to use python/pygame and maybe VisionEgg to
program experiments. Actually, a colleague, Mark Welxer, and I, have
experimented with python a bit and encouraged students to use it: see
http://cim.risc.cnrs.fr/cours/exphum/projects/projects.shtml), but I
need to convinced myself that I can solve some latencies problems
(not specific to python) for some experiments (I work under Linux;
the situation may be better with Windows). Just try the following
very simple minded program to see the latencies you can get:
import pygame
a= pygame.time.get_ticks()
max=-1
for i in range (1,1000):
b = pygame.time.get_ticks()
c = b-a
if c>max:
max=c
a = b
t.delay(10)
print max
(I just got max=140 msec on my system).
I know VisionEgg offers to swith to 'real-time' mode (SCHED_FIFO in
Linux), but I have had bad experience in the past with real-time
processes slowing down other threads (e.g. sound output was choppy).
But I have not tested VisionEgg enough yet.
Anyway, maybe a good idea would be to set up some repository of real
experiments programmed in python, using whatever packages (visionegg,
pygame or other). This would encourage people to try and test these
packages.
Christophe Pallier
www.pallier.org
Darren Weber wrote:
I notice that pyserial and pyparallel are used by expy - seems there
is more than one development effort in python for psychology
experiments; I wonder if some sort of integration of efforts might be
possible/useful?
http://www.ehess.fr/centres/lscp/expy/expy.html
On Wed, 23 Mar 2005 09:58:25 -0800, Darren Weber
<darrenleeweber@xxxxxxxxx> wrote:
http://pyserial.sourceforge.net/
On Wed, 23 Mar 2005 09:47:58 -0800, Darren Weber
<darrenleeweber@xxxxxxxxx> wrote:
The visionegg provides display capabilities, but what about output of
a stimulus code event to an external device. For example, lets
say we
present an image every 2 sec and there are 5 different categories of
image. Each category is given a code, a number between 0-255. Now,
we want to send this code to an EEG | MEG | fMRI system that will
record the timing of this event code during the acquisition of
another
data timeseries. It is simple enough to save a stimulus/event log to
a file, but it would be nice to interact with the serial/parallel
port
also. Is there a command like:
eventCode = 128 # or eventID (maybe event.id)
event.send.parallelport(eventCode)
event.send.serialport(eventCode)
I don't have any experience with sending codes to the serial/parallel
port. Any tips or reading material would be really useful.
Best, Darren
======================================
The Vision Egg mailing list
Archives: http://www.freelists.org/archives/visionegg
Website: http://www.visionegg.org/mailinglist.html
======================================
The Vision Egg mailing list
Archives: http://www.freelists.org/archives/visionegg
Website: http://www.visionegg.org/mailinglist.html
======================================
The Vision Egg mailing list
Archives: http://www.freelists.org/archives/visionegg
Website: http://www.visionegg.org/mailinglist.html
======================================
The Vision Egg mailing list
Archives: http://www.freelists.org/archives/visionegg
Website: http://www.visionegg.org/mailinglist.html
- Follow-Ups:
- [visionegg] time and OS es
- From: John Christie
- References:
- [visionegg] stimulus code outputs
- From: Darren Weber
- [visionegg] Re: stimulus code outputs
- From: Darren Weber
- [visionegg] Re: stimulus code outputs
- From: Darren Weber
- [visionegg] Re: stimulus code outputs
- From: Christophe Pallier
- [visionegg] Re: stimulus code outputs
- From: Andrew Straw
Other related posts:
- » [visionegg] stimulus code outputs
- » [visionegg] Re: stimulus code outputs
- » [visionegg] Re: stimulus code outputs
- » [visionegg] Re: stimulus code outputs
- » [visionegg] Re: stimulus code outputs
- » [visionegg] Re: stimulus code outputs
- » [visionegg] Re: stimulus code outputs
- » [visionegg] Re: stimulus code outputs
- » [visionegg] Re: stimulus code outputs
#include <stdio.h> #include <sys/time.h> #include <time.h>
delay.tv_sec=0; delay.tv_nsec=5000000L; /* 5 msec */
Finally, a question about your code -- I always read those notes about the resolution of "ticks" in SDL/pygame and got scared away from using them. Thus, the Vision Egg generally uses Python standard library calls. I see you are using pygame's get_ticks(). Does this perform differently than time.time() on linux? Also, by using a "busy wait" [I think pygame.time.delay() is], does the kernel scheduler penalize your process? If not, I would agree this is probably more accurate than a time.sleep(). I'll try to test this soon myself.
Cheers! Andrew
On Mar 24, 2005, at 1:23 AM, Christophe Pallier wrote:
Hello Darren,
Expy is an attempt to re-implement with pygame an old, (venerable ;-), DOS experimental stimulator (EXPE: www.lscp.net/expe) which I wrote 15 years ago (and is still used nowdays in some labs, for its "perfect" timing). Expy is extremely preliminary and we should not have put the web page in my opinion, because the program is not really usable. Emmanuel Dupoux and I hope to be able to recruit a programmer to pursue this project, but we are still looking for funding. Still if you can steal any ideas from the project, it would not have been entirely useless.
I would really like to use python/pygame and maybe VisionEgg to program experiments. Actually, a colleague, Mark Welxer, and I, have experimented with python a bit and encouraged students to use it: see http://cim.risc.cnrs.fr/cours/exphum/projects/projects.shtml), but I need to convinced myself that I can solve some latencies problems (not specific to python) for some experiments (I work under Linux; the situation may be better with Windows). Just try the following very simple minded program to see the latencies you can get:
import pygame a= pygame.time.get_ticks() max=-1 for i in range (1,1000): b = pygame.time.get_ticks() c = b-a if c>max: max=c a = b t.delay(10) print max
(I just got max=140 msec on my system).
I know VisionEgg offers to swith to 'real-time' mode (SCHED_FIFO in Linux), but I have had bad experience in the past with real-time processes slowing down other threads (e.g. sound output was choppy). But I have not tested VisionEgg enough yet.
Anyway, maybe a good idea would be to set up some repository of real experiments programmed in python, using whatever packages (visionegg, pygame or other). This would encourage people to try and test these packages.
Christophe Pallier www.pallier.org
Darren Weber wrote:
I notice that pyserial and pyparallel are used by expy - seems there is more than one development effort in python for psychology experiments; I wonder if some sort of integration of efforts might be possible/useful?
http://www.ehess.fr/centres/lscp/expy/expy.html
On Wed, 23 Mar 2005 09:58:25 -0800, Darren Weber <darrenleeweber@xxxxxxxxx> wrote:
http://pyserial.sourceforge.net/
On Wed, 23 Mar 2005 09:47:58 -0800, Darren Weber <darrenleeweber@xxxxxxxxx> wrote:
The visionegg provides display capabilities, but what about output of
a stimulus code event to an external device. For example, lets say we
present an image every 2 sec and there are 5 different categories of
image. Each category is given a code, a number between 0-255. Now,
we want to send this code to an EEG | MEG | fMRI system that will
record the timing of this event code during the acquisition of another
data timeseries. It is simple enough to save a stimulus/event log to
a file, but it would be nice to interact with the serial/parallel port
also. Is there a command like:
eventCode = 128 # or eventID (maybe event.id) event.send.parallelport(eventCode) event.send.serialport(eventCode)
I don't have any experience with sending codes to the serial/parallel port. Any tips or reading material would be really useful.
Best, Darren
====================================== The Vision Egg mailing list Archives: http://www.freelists.org/archives/visionegg Website: http://www.visionegg.org/mailinglist.html
====================================== The Vision Egg mailing list Archives: http://www.freelists.org/archives/visionegg Website: http://www.visionegg.org/mailinglist.html
====================================== The Vision Egg mailing list Archives: http://www.freelists.org/archives/visionegg Website: http://www.visionegg.org/mailinglist.html
====================================== The Vision Egg mailing list Archives: http://www.freelists.org/archives/visionegg Website: http://www.visionegg.org/mailinglist.html
- [visionegg] time and OS es
- From: John Christie
- [visionegg] stimulus code outputs
- From: Darren Weber
- [visionegg] Re: stimulus code outputs
- From: Darren Weber
- [visionegg] Re: stimulus code outputs
- From: Darren Weber
- [visionegg] Re: stimulus code outputs
- From: Christophe Pallier
- [visionegg] Re: stimulus code outputs
- From: Andrew Straw