-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMAVLinkClientPython.py
112 lines (89 loc) · 4.73 KB
/
MAVLinkClientPython.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
from __future__ import print_function
from vicon_dssdk import ViconDataStream
import argparse
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument('host', nargs='?',
help="Host name, in the format of server:port",
default = "localhost:801")
args = parser.parse_args()
client = ViconDataStream.Client()
while True:
print('NEW POSITION')
try:
client.Connect( args.host )
# Check setting the buffer size works
client.SetBufferSize( 1 )
#Enable all the data types
client.EnableSegmentData()
client.EnableMarkerData()
client.EnableUnlabeledMarkerData()
client.EnableMarkerRayData()
client.EnableDeviceData()
client.EnableCentroidData()
HasFrame = False
while not HasFrame:
try:
client.GetFrame()
HasFrame = True
except ViconDataStream.DataStreamException as e:
client.GetFrame()
# Try setting the different stream modes
client.SetStreamMode( ViconDataStream.Client.StreamMode.EClientPull )
print( 'Get Frame Pull', client.GetFrame(), client.GetFrameNumber() )
client.SetStreamMode( ViconDataStream.Client.StreamMode.EClientPullPreFetch )
print( 'Get Frame PreFetch', client.GetFrame(), client.GetFrameNumber() )
client.SetStreamMode( ViconDataStream.Client.StreamMode.EServerPush )
print( 'Get Frame Push', client.GetFrame(), client.GetFrameNumber() )
print( 'Frame Rate', client.GetFrameRate() )
try:
client.SetApexDeviceFeedback( 'BogusDevice', True )
except ViconDataStream.DataStreamException as e:
print( 'No Apex Devices connected' )
client.SetAxisMapping( ViconDataStream.Client.AxisMapping.EForward,
ViconDataStream.Client.AxisMapping.ELeft,
ViconDataStream.Client.AxisMapping.EUp )
xAxis, yAxis, zAxis = client.GetAxisMapping()
print( 'X Axis', xAxis, 'Y Axis', yAxis, 'Z Axis', zAxis )
try:
client.SetTimingLog( '', '' )
except ViconDataStream.DataStreamException as e:
print( 'Failed to set timing log' )
try:
client.ConfigureWireless()
except ViconDataStream.DataStreamException as e:
print( 'Failed to configure wireless', e )
subjectNames = client.GetSubjectNames()
for subjectName in subjectNames:
segmentNames = client.GetSegmentNames( subjectName )
for segmentName in segmentNames:
segmentChildren = client.GetSegmentChildren( subjectName, segmentName )
try:
print( segmentName, 'has static scale',
client.GetSegmentStaticScale(subjectName
, segmentName))
except ViconDataStream.DataStreamException as e:
print( 'Scale Error', e )
print( segmentName, 'has global translation',
client.GetSegmentGlobalTranslation(subjectName,
segmentName))
print( segmentName, 'has global rotation( helical )',
client.GetSegmentGlobalRotationHelical(subjectName,
segmentName ) )
print( segmentName, 'has global rotation( EulerXYZ )',
client.GetSegmentGlobalRotationEulerXYZ( subjectName,
segmentName ) )
print( segmentName, 'has global rotation( Quaternion )',
client.GetSegmentGlobalRotationQuaternion( subjectName,
segmentName ) )
print( segmentName, 'has global rotation( Matrix )',
client.GetSegmentGlobalRotationMatrix( subjectName,
segmentName ) )
# TODO: Send this data to the PX4 autopilot
# software as a MAVLink Odometry message
try:
print( 'Object Quality', client.GetObjectQuality( subjectName ) )
except ViconDataStream.DataStreamException as e:
print( 'Not present', e )
except ViconDataStream.DataStreamException as e:
print( 'Handled data stream error', e )
print()