[Phission-cvs] phission/brains X11DisplayTest.py,NONE,1.1 X11DisplayTest.sh,NONE,1.1
Brought to you by:
pthoren
From: <pt...@us...> - 2004-01-12 20:03:01
|
Update of /cvsroot/phission/phission/brains In directory sc8-pr-cvs1:/tmp/cvs-serv5600 Added Files: X11DisplayTest.py X11DisplayTest.sh Log Message: Used to test out the X11 display with a single window --- NEW FILE: X11DisplayTest.py --- #----------------------------------------------------------------------------- # (c) 2003 Philip D.S. Thoren (pt...@cs...) # # This is used to test the X11Display class # #----------------------------------------------------------------------------- import sys #----------------------------------------------------------------------------- # Make 'phission' an importable object name extension sys.path.append("../../"); #----------------------------------------------------------------------------- # Load brain stuff from pyro.brain.behaviors.core import * # Stop # MUST BE AFTER ANY OTHER brain imports from phission.brains import Brain #----------------------------------------------------------------------------- # import the modules from the phission directory. # (1) X11Display from phission.display.X11 import * # (2) V4LCapture from phission.capture.v4l import * # (3) CSafeImage from phission.base import * #----------------------------------------------------------------------------- class PhissionTest(Brain): #------------------------------------------------------------------------- # The __init__ method is the first method called ( When the PhissionTest # brain is first created. __init__ is called from the INIT def at the # bottom of this source file . #------------------------------------------------------------------------- def __init__(self, name, robot): self.name = name self.robot = robot Brain.__init__(self, self.name, self.getRobot()) # Don't let the robot sleep when it's actively running self.setSleepTime(0) # Create the X11 display window self.display = X11Display(); # Capture device self.capture = V4LCapture(); self.capture.set(320,240); self.capture.setChannel(1); self.display.setLiveSourceInput(self.capture.getLiveSourceOutput()) #----------------------------------------------------------------------------- # The setup function is called right after the module is __init__'d #----------------------------------------------------------------------------- def setup(self): pass #----------------------------------------------------------------------------- # The 'begin' method is called once at the beginning # of a run session right before the first step call. #----------------------------------------------------------------------------- # It's called 'begin' because the Brain inherits from a Threading class # that uses the start() method spawn a thread. #----------------------------------------------------------------------------- # 'begin' can return an error code to stop a robot run session from begining # in the case a fatal error occurs #----------------------------------------------------------------------------- def begin(self): print >> sys.__stderr__, "begin called" # If the display window isn't open, open it if self.display.isVisible() == 0: if self.display.openWindow(320,240) == FAIL: print >> sys.__stderr__, "Error opening display window" return -1 # make sure the capture device is open if self.capture.isDeviceOpen() == 0: if self.capture.openDevice("/dev/video0") == FAIL: print >> sys.__stderr__, "Error opening device" return -1 # Start capturing if there is no capture in progress if self.capture.isCapturing() == 0: if self.capture.startCapture() == FAIL: print >> sys.__stderr__, "Error starting capture" return -1 if self.display.isLiveSourceOn() == 0: if self.display.liveSourceOn() == FAIL: print >> sys.__stderr__, "Error starting live source" return -1 return 0 #----------------------------------------------------------------------------- # The step method is called serially when the robot is running #----------------------------------------------------------------------------- def step(self): robot = self.getRobot(); return #----------------------------------------------------------------------------- def stop(self): print >> sys.__stderr__, "stop called" # Start capturing if there is no capture in progress if self.capture.isCapturing() == 1: self.capture.stopCapture(); if self.display.isLiveSourceOn() == 1: self.display.liveSourceOff(); #----------------------------------------------------------------------------- def destroy(self): print >> sys.__stderr__, "destroy called" if self.display.isLiveSourceOn() == 1: self.display.liveSourceOff(); # make sure the capture device is closed before quitting if self.capture.isDeviceOpen() == 1: self.capture.closeDevice(); # If the display window is open, close it !!! if self.display.isVisible() == 1: self.display.closeWindow() #----------------------------------------------------------------------------- def INIT(robot): return PhissionTest('PhissionTest', robot) --- NEW FILE: X11DisplayTest.sh --- pyro -r SimpleRobot.py -b X11DisplayTest.py |