certi-cvs
[Top][All Lists]
Advanced

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

[certi-cvs] applications/PyHLA/examples/updateAttributeValu...


From: certi-cvs
Subject: [certi-cvs] applications/PyHLA/examples/updateAttributeValu...
Date: Thu, 09 Jul 2009 15:47:25 +0000

CVSROOT:        /sources/certi
Module name:    applications
Changes by:     Petr Gotthard <gotthardp>       09/07/09 15:47:25

Added files:
        PyHLA/examples/updateAttributeValues: uav-receive.py uav-send.py 
                                              uav.fed 

Log message:
        Simple example for UAV in Python.

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/applications/PyHLA/examples/updateAttributeValues/uav-receive.py?cvsroot=certi&rev=1.1
http://cvs.savannah.gnu.org/viewcvs/applications/PyHLA/examples/updateAttributeValues/uav-send.py?cvsroot=certi&rev=1.1
http://cvs.savannah.gnu.org/viewcvs/applications/PyHLA/examples/updateAttributeValues/uav.fed?cvsroot=certi&rev=1.1

Patches:
Index: uav-receive.py
===================================================================
RCS file: uav-receive.py
diff -N uav-receive.py
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ uav-receive.py      9 Jul 2009 15:47:25 -0000       1.1
@@ -0,0 +1,59 @@
+#!/usr/bin/env python
+# Requires PyHLA, see http://www.nongnu.org/certi/PyHLA
+import hla.rti
+import hla.omt as fom
+
+import struct
+
+class MyAmbassador(hla.rti.FederateAmbassador):
+    def initialize(self):
+        self.classHandle = rtia.getObjectClassHandle("SampleClass")
+
+        self.textAttributeHandle = rtia.getAttributeHandle("TextAttribute", 
self.classHandle)
+        self.structAttributeHandle = 
rtia.getAttributeHandle("StructAttribute", self.classHandle)
+        self.fomAttributeHandle = rtia.getAttributeHandle("FOMAttribute", 
self.classHandle)
+
+        rtia.subscribeObjectClassAttributes(self.classHandle,
+            [self.textAttributeHandle, self.structAttributeHandle, 
self.fomAttributeHandle])
+
+    # RTI callbacks
+    def discoverObjectInstance(self, object, objectclass, name):
+        print "DISCOVER", name
+        rtia.requestObjectAttributeValueUpdate(object,
+            [self.textAttributeHandle, self.structAttributeHandle, 
self.fomAttributeHandle])
+
+    def reflectAttributeValues(self, object, attributes, tag, order, 
transport, time=None, retraction=None):
+        if self.textAttributeHandle in attributes:
+            print "REFLECT", attributes[self.textAttributeHandle]
+
+        if self.structAttributeHandle in attributes:
+            structValue = struct.unpack('hhl', 
attributes[self.structAttributeHandle])
+            print "REFLECT", structValue
+
+        if self.fomAttributeHandle in attributes:
+            fomValue, size = 
fom.HLAfloat32BE.unpack(attributes[self.fomAttributeHandle])
+            print "REFLECT", fomValue
+
+print "Create ambassador"
+rtia = hla.rti.RTIAmbassador()
+
+try:
+    rtia.createFederationExecution("uav", "uav.fed")
+    print "Federation created."
+except hla.rti.FederationExecutionAlreadyExists:
+    print "Federation already exists."
+
+mya = MyAmbassador()
+rtia.joinFederationExecution("uav-receive", "uav", mya)
+
+mya.initialize()
+
+try:
+    while(1):
+        rtia.tick(1.0, 1.0)
+except KeyboardInterrupt:
+    pass
+
+rtia.resignFederationExecution(hla.rti.ResignAction.DeleteObjectsAndReleaseAttributes)
+
+print "Done."

Index: uav-send.py
===================================================================
RCS file: uav-send.py
diff -N uav-send.py
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ uav-send.py 9 Jul 2009 15:47:25 -0000       1.1
@@ -0,0 +1,55 @@
+#!/usr/bin/env python
+# Requires PyHLA, see http://www.nongnu.org/certi/PyHLA
+import hla.rti
+import hla.omt as fom
+
+import struct
+
+class MyAmbassador(hla.rti.FederateAmbassador):
+    def initialize(self):
+        self.classHandle = rtia.getObjectClassHandle("SampleClass")
+
+        self.textAttributeHandle = rtia.getAttributeHandle("TextAttribute", 
self.classHandle)
+        self.structAttributeHandle = 
rtia.getAttributeHandle("StructAttribute", self.classHandle)
+        self.fomAttributeHandle = rtia.getAttributeHandle("FOMAttribute", 
self.classHandle)
+
+        rtia.publishObjectClass(self.classHandle,
+            [self.textAttributeHandle, self.structAttributeHandle, 
self.fomAttributeHandle])
+        self.myObject = rtia.registerObjectInstance(self.classHandle, "HAF")
+
+    # RTI callbacks
+    def startRegistrationForObjectClass(*params):
+        print "START", params
+
+    def provideAttributeValueUpdate(*params):
+        print "PROVIDE UAV", params
+
+print "Create ambassador"
+rtia = hla.rti.RTIAmbassador()
+print rtia
+
+try:
+    rtia.createFederationExecution("uav", "uav.fed")
+    print "Federation created."
+except hla.rti.FederationExecutionAlreadyExists:
+    print "Federation already exists."
+
+mya = MyAmbassador()
+rtia.joinFederationExecution("uav-send", "uav", mya)
+
+mya.initialize()
+
+try:
+    while(1):
+        rtia.updateAttributeValues(mya.myObject,
+            {mya.textAttributeHandle:"text",
+            mya.structAttributeHandle:struct.pack('hhl', 1, 2, 3),
+            mya.fomAttributeHandle:fom.HLAfloat32BE.pack(3.14)},
+            "update")
+        rtia.tick(1.0, 1.0)
+except KeyboardInterrupt:
+    pass
+
+rtia.resignFederationExecution(hla.rti.ResignAction.DeleteObjectsAndReleaseAttributes)
+
+print "Done."

Index: uav.fed
===================================================================
RCS file: uav.fed
diff -N uav.fed
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ uav.fed     9 Jul 2009 15:47:25 -0000       1.1
@@ -0,0 +1,19 @@
+(FED
+  (Federation TestFed)
+  (FEDversion v1.3)
+  (spaces
+  )
+  (objects
+    (class ObjectRoot
+      (attribute privilegeToDelete reliable timestamp)
+      (class RTIprivate)
+      (class SampleClass
+        (attribute TextAttribute reliable timestamp)
+        (attribute StructAttribute reliable timestamp)
+        (attribute FOMAttribute reliable timestamp)
+      )
+    )
+  )
+  (interactions
+  )
+)




reply via email to

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