|
@@ -3,6 +3,9 @@
|
|
|
from ShowBaseGlobal import *
|
|
from ShowBaseGlobal import *
|
|
|
import NodePath
|
|
import NodePath
|
|
|
import DistributedObject
|
|
import DistributedObject
|
|
|
|
|
+import Correction
|
|
|
|
|
+import Prediction
|
|
|
|
|
+import Task
|
|
|
|
|
|
|
|
class DistributedNode(DistributedObject.DistributedObject, NodePath.NodePath):
|
|
class DistributedNode(DistributedObject.DistributedObject, NodePath.NodePath):
|
|
|
"""Distributed Node class:"""
|
|
"""Distributed Node class:"""
|
|
@@ -12,6 +15,7 @@ class DistributedNode(DistributedObject.DistributedObject, NodePath.NodePath):
|
|
|
self.DistributedNode_initialized
|
|
self.DistributedNode_initialized
|
|
|
except:
|
|
except:
|
|
|
self.DistributedNode_initialized = 1
|
|
self.DistributedNode_initialized = 1
|
|
|
|
|
+ self.DeadReconing = None
|
|
|
DistributedObject.DistributedObject.__init__(self, cr)
|
|
DistributedObject.DistributedObject.__init__(self, cr)
|
|
|
return None
|
|
return None
|
|
|
|
|
|
|
@@ -23,6 +27,43 @@ class DistributedNode(DistributedObject.DistributedObject, NodePath.NodePath):
|
|
|
self.reparentTo(hidden)
|
|
self.reparentTo(hidden)
|
|
|
DistributedObject.DistributedObject.delete(self)
|
|
DistributedObject.DistributedObject.delete(self)
|
|
|
|
|
|
|
|
|
|
+ def setDeadReconing(self, state):
|
|
|
|
|
+ self.DeadReconing = state
|
|
|
|
|
+ if state:
|
|
|
|
|
+ self.Predictor = NullPrediction(Point3(self.getX(), self.getY(),
|
|
|
|
|
+ self.getZ()))
|
|
|
|
|
+ self.Corrector = SplineCorrection(Point3(self.getX(), self.getY(),
|
|
|
|
|
+ self.getZ()), Vec3(0))
|
|
|
|
|
+ taskName = self.taskName("correctionPos")
|
|
|
|
|
+ # remove any old tasks
|
|
|
|
|
+ taskMgr.removeTasksNamed(taskName)
|
|
|
|
|
+ # spawn new task
|
|
|
|
|
+ task = Task.Task(self.correctPos)
|
|
|
|
|
+ taskMgr.spawnTaskNamed(task, taskName)
|
|
|
|
|
+ else:
|
|
|
|
|
+ self.Predictor = None
|
|
|
|
|
+ self.Corrector = None
|
|
|
|
|
+ taskName = self.taskName("correctionPos")
|
|
|
|
|
+ taskMgr.removeTasksNamed(taskName)
|
|
|
|
|
+
|
|
|
|
|
+ def setPos(self, x, y, z):
|
|
|
|
|
+ if self.DeadReconing:
|
|
|
|
|
+ self.Predictor.newTelemetry(Point3(x, y, z))
|
|
|
|
|
+ else:
|
|
|
|
|
+ NodePath.NodePath.setPos(self, x, y, z)
|
|
|
|
|
+
|
|
|
|
|
+ def setHpr(self, h, p, r):
|
|
|
|
|
+ NodePath.NodePath.setHpr(self, h, p, r)
|
|
|
|
|
+
|
|
|
|
|
+ def setPosHpr(self, x, y, z, h, p, r):
|
|
|
|
|
+ if self.DeadReconing:
|
|
|
|
|
+ self.Predictor.newTelemetry(Point3(x, y, z))
|
|
|
|
|
+ else:
|
|
|
|
|
+ NodePath.NodePath.setPosHpr(self, x, y, z, h, p, r)
|
|
|
|
|
+
|
|
|
|
|
+ def d_setDeadReconing(self, state):
|
|
|
|
|
+ self.sendUpdate("setDeadReconing", [state])
|
|
|
|
|
+
|
|
|
def d_setPos(self, x, y, z):
|
|
def d_setPos(self, x, y, z):
|
|
|
self.sendUpdate("setPos", [x, y, z])
|
|
self.sendUpdate("setPos", [x, y, z])
|
|
|
|
|
|
|
@@ -36,3 +77,10 @@ class DistributedNode(DistributedObject.DistributedObject, NodePath.NodePath):
|
|
|
|
|
|
|
|
def d_setPosHpr(self, x, y, z, h, p, r):
|
|
def d_setPosHpr(self, x, y, z, h, p, r):
|
|
|
self.sendUpdate("setPosHpr", [x, y, z, h, p, r])
|
|
self.sendUpdate("setPosHpr", [x, y, z, h, p, r])
|
|
|
|
|
+
|
|
|
|
|
+ def correctPos(self, task):
|
|
|
|
|
+ self.Corrector.newTarget(self.Predictor.getPos(),
|
|
|
|
|
+ self.Predictor.getVel())
|
|
|
|
|
+ self.Corrector.step()
|
|
|
|
|
+ NodePath.NodePath.setPos(self, self.Corrector.getPos())
|
|
|
|
|
+ return Task.cont
|