2 ##############################################################################
5 # @author The LibrePilot Project, http://www.librepilot.org Copyright (C) 2017.
6 # The OpenPilot Team, http://www.openpilot.org Copyright (C) 2011.
7 # @brief Base classes for python UAVObject
9 # @see The GNU Public License (GPL) Version 3
11 #############################################################################/
13 # This program is free software; you can redistribute it and/or modify
14 # it under the terms of the GNU General Public License as published by
15 # the Free Software Foundation; either version 3 of the License, or
16 # (at your option) any later version.
18 # This program is distributed in the hope that it will be useful, but
19 # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
20 # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
23 # You should have received a copy of the GNU General Public License along
24 # with this program; if not, write to the Free Software Foundation, Inc.,
25 # 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
35 from librepilot
.uavtalk
.uavobject
import *
36 from librepilot
.uavtalk
.uavtalk
import *
37 from librepilot
.uavtalk
.objectManager
import *
38 from librepilot
.uavtalk
.connectionManager
import *
43 appName
= os
.path
.basename(sys
.argv
[0])
46 print " %s port " % appName
47 print " for example: %s COM30 " % appName
50 if __name__
== '__main__':
52 if len(sys
.argv
) != 2:
53 print "ERROR: Incorrect number of arguments"
59 if port
[:3].upper() == "COM":
60 _port
= int(port
[3:])-1
64 serPort
= serial
.Serial(_port
, 57600, timeout
=.5)
65 uavTalk
= UavTalk(serPort
, None)
67 print "Starting ObjectManager"
68 objMan
= ObjManager(uavTalk
)
69 objMan
.importDefinitions()
71 print "Starting UavTalk"
75 print "Getting Current Settings:"
76 for _
in range(2): # Try only twice to get the settings
79 objMan
.StabilizationSettingsBank1
.getUpdate()
80 except TimeoutException
:
83 except KeyboardInterrupt:
91 print "s. Save settings"
93 print "1. Tune Roll Rate %2.4f %2.4f %2.4f %2.4f" % tuple(objMan
.StabilizationSettingsBank1
.RollRatePID
.value
)
94 print "2. Tune Pitch Rate %2.4f %2.4f %2.4f %2.4f" % tuple(objMan
.StabilizationSettingsBank1
.PitchRatePID
.value
)
95 print "3. Tune Yaw Rate %2.4f %2.4f %2.4f %2.4f" % tuple(objMan
.StabilizationSettingsBank1
.YawRatePID
.value
)
97 print "4. Tune Roll Attitude %2.4f %2.4f %2.4f" % tuple(objMan
.StabilizationSettingsBank1
.RollPI
.value
)
98 print "5. Tune Pitch Attitude %2.4f %2.4f %2.4f" % tuple(objMan
.StabilizationSettingsBank1
.PitchPI
.value
)
99 print "6. Tune Yaw Attitude %2.4f %2.4f %2.4f" % tuple(objMan
.StabilizationSettingsBank1
.YawPI
.value
)
108 objMan
.ObjectPersistence
.Operation
.value
= objectpersistence
.OperationField
.SAVE
109 objMan
.ObjectPersistence
.Selection
.value
= objectpersistence
.SelectionField
.SINGLEOBJECT
110 objMan
.ObjectPersistence
.ObjectID
.value
= objMan
.StabilizationSettingsBank1
.objId
111 objMan
.ObjectPersistence
.InstanceID
.value
= objMan
.StabilizationSettingsBank1
.instId
112 objMan
.ObjectPersistence
.updated()
115 objMan
.ObjectPersistence
.getUpdate(timeout
=1)
116 if objMan
.ObjectPersistence
.Operation
.value
== objectpersistence
.OperationField
.COMPLETED
:
121 PI
= objMan
.StabilizationSettingsBank1
.RollRatePID
.value
124 PI
= objMan
.StabilizationSettingsBank1
.PitchRatePI
.value
127 PI
= objMan
.StabilizationSettingsBank1
.YawRatePI
.value
130 PI
= objMan
.StabilizationSettingsBank1
.RollPI
.value
133 PI
= objMan
.StabilizationSettingsBank1
.PitchPI
.value
136 PI
= objMan
.StabilizationSettingsBank1
.YawPI
.value
144 print "1. tune K %2.4f" % PI
[0]
145 print "2. tune I %2.4f" % PI
[1]
146 print "3. tune I Limit %2.4f" % PI
[2]
166 print "Current value: %2.4f" % PI
[PIIndex
]
167 print "Tune-range from",
168 tuneFrom
= float(raw_input())
169 print "Tune-range to",
170 tuneTo
= float(raw_input())
180 # get update of AccessoryDesired
181 objMan
.AccessoryDesired
.getUpdate(timeout
=.5)
183 # calculate value out of Accessory0 input (-1 ... +1)
184 txControl
= objMan
.AccessoryDesired
.AccessoryVal
.value
185 value
= tuneFrom
+ ((txControl
+1)/2)*(tuneTo
-tuneFrom
)
187 objMan
.StabilizationSettingsBank1
.updated()
189 print "\r%-1.2f => %2.4f" % (txControl
, value
),
192 except TimeoutException
:
197 print "An error occured: ", e
199 traceback
.print_exc()