浏览代码

*** empty log message ***

Samir Naik 24 年之前
父节点
当前提交
b941cade0e
共有 2 个文件被更改,包括 160 次插入0 次删除
  1. 68 0
      direct/src/directdevices/DirectFastrak.py
  2. 92 0
      direct/src/directdevices/DirectRadamec.py

+ 68 - 0
direct/src/directdevices/DirectFastrak.py

@@ -0,0 +1,68 @@
+""" Class used to create and control radamec device """
+from math import *
+from PandaObject import *
+from DirectDeviceManager import *
+
+import DirectNotifyGlobal
+
+"""
+TODO:
+Handle interaction between widget, followSelectedTask and updateTask
+"""
+
+# ANALOGS
+NULL_AXIS = -1
+FAST_X = 0
+FAST_Y = 1
+FAST_Z = 2
+
+class DirectFastrak(PandaObject):
+    fastrakCount = 0
+    notify = DirectNotifyGlobal.directNotify.newCategory('DirectFastrak')
+
+    def __init__(self, device = 'Tracker0', nodePath = direct.camera):
+        # See if device manager has been initialized
+        if direct.deviceManager == None:
+            direct.deviceManager = DirectDeviceManager()
+
+        # Set name
+        self.name = 'Fastrak-' + `DirectFastrak.fastrakCount`
+        self.deviceNo = DirectFastrak.fastrakCount
+        DirectFastrak.fastrakCount += 1
+
+        # Get analogs
+        self.device = device
+        self.tracker = None
+        self.trackerPos = None
+
+        # Spawn update task
+        self.updateFunc = self.fastrakUpdate
+        self.enable()
+        
+    def enable(self):
+        # Kill existing task
+        self.disable()
+        # Initialize tracker
+        self.tracker = direct.deviceManager.createTracker(self.device)
+        # Update task
+        taskMgr.spawnMethodNamed(self.updateTask, self.name + '-updateTask')
+    
+    def disable(self):
+        taskMgr.removeTasksNamed(self.name + '-updateTask')
+
+    def destroy(self):
+        self.disable()
+        self.tempCS.removeNode()
+
+    def updateTask(self, state):
+        self.updateFunc()
+        return Task.cont
+
+    def fastrakUpdate(self):
+        # Get tracker position in feet.  Flip x,z axes.
+        pos = direct.fastrak[self.deviceNo].tracker.getPos()
+        self.trackerPos = Vec3(3.280839895013123 * pos[2],
+                               3.280839895013123 * pos[1],
+                               3.280839895013123 * pos[0])
+        self.notify.debug("Tracker(%d) Pos = %s" % (self.deviceNo, `self.trackerPos`))
+    

+ 92 - 0
direct/src/directdevices/DirectRadamec.py

@@ -0,0 +1,92 @@
+""" Class used to create and control radamec device """
+from math import *
+from PandaObject import *
+from DirectDeviceManager import *
+
+import DirectNotifyGlobal
+import OnscreenText
+
+
+"""
+TODO:
+Handle interaction between widget, followSelectedTask and updateTask
+"""
+
+# ANALOGS
+NULL_AXIS = -1
+RAD_PAN = 0
+RAD_TILT = 1
+RAD_ZOOM = 2
+RAD_FOCUS = 3
+
+class DirectRadamec(PandaObject):
+    radamecCount = 0
+    notify = DirectNotifyGlobal.directNotify.newCategory('DirectRadamec')
+    
+    def __init__(self, device = 'Analog0', nodePath = direct.camera):
+        # See if device manager has been initialized
+        if direct.deviceManager == None:
+            direct.deviceManager = DirectDeviceManager()
+        # Set name
+        DirectRadamec.radamecCount += 1
+        self.name = 'Radamec-' + `DirectRadamec.radamecCount`
+        # Get analogs
+        self.device = device
+        self.analogs = direct.deviceManager.createAnalogs(self.device)
+        self.aList = [0,0,0,0,0,0,0,0]
+        # Radamec device max/mins - measured on 7/31/2001 - Samir
+        # Note:  These values change quite often, i.e. everytime
+        #        you unplug the radamec cords, or jostle them too
+        #        much.  For best results, re-record these values often.
+        self.minRange = [-180.0, -90, 524290.0, 520315.0]
+        self.maxRange = [180.0, 90, 542700.0, 559518.0]
+        # Pick initial mode
+        self.updateFunc = self.radamecUpdate
+        # Spawn update task
+        self.enable()
+        
+    def enable(self):
+        # Kill existing task
+        self.disable()
+        # Update task
+        taskMgr.spawnMethodNamed(self.updateTask, self.name + '-updateTask')
+    
+    def disable(self):
+        taskMgr.removeTasksNamed(self.name + '-updateTask')
+
+    def destroy(self):
+        self.disable()
+
+    def updateTask(self, state):
+        self.updateVals()
+        self.updateFunc()
+        return Task.cont
+    
+    def updateVals(self):
+        numControls = self.analogs.__len__()
+        self.notify.debug("We have %s analog controls." % numControls)
+        # Update analogs
+        for i in range(len(self.analogs)):
+            self.aList[i] = self.analogs[i]
+
+    def radamecUpdate(self):
+        panVal = self.normalizeChannel(RAD_PAN,-180,180)
+        tiltVal = self.normalizeChannel(RAD_TILT,-90,90)
+
+        self.notify.debug("PAN = %s" % self.aList[RAD_PAN])
+        self.notify.debug("TILT = %s" % self.aList[RAD_TILT])
+        self.notify.debug("ZOOM = %s" % self.aList[RAD_ZOOM])
+        self.notify.debug("FOCUS = %s" % self.aList[RAD_FOCUS])
+        self.notify.debug("Normalized: panVal: %s  tiltVal: %s" % (panVal, tiltVal))
+
+    # Normalize to the range [-minVal,maxVal] based on some hard-coded
+    # max/min numbers of the Radamec device
+    def normalizeChannel(self, chan, minVal = -1, maxVal = 1):
+        try:
+            maxRange = self.maxRange[chan]
+            minRange = self.minRange[chan]
+        except IndexError:
+            raise RuntimeError, "can't normalize this channel (chanel %d)" % chan
+        range = maxRange - minRange
+        clampedVal = CLAMP(self.aList[chan], minRange, maxRange)
+        return ((maxVal - minVal) * (clampedVal - minRange) / range) + minVal