Skip to content

Commit 2d1fdcf

Browse files
committed
Scripts: Modernize Python 2 code to get ready for Python 3
1 parent a5a0068 commit 2d1fdcf

18 files changed

+123
-106
lines changed

Scripts/PARACHUTE LANDING APPROACH.py

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
approach_azimuth = 180
1+
from __future__ import print_function
2+
approach_azimuth = 180
23

34
parachute_deploy_altitude = 40
45

@@ -40,34 +41,34 @@
4041
hdop = cs.gpshdop
4142

4243
if satellites < 6:
43-
print'GPS FAILED. NO MISSION CREATED. WAIT FOR BETTER GPS'
44-
print ''
44+
print('GPS FAILED. NO MISSION CREATED. WAIT FOR BETTER GPS')
45+
print('')
4546
elif hdop > 4:
46-
print'GPS FAILED. NO MISSION CREATED. WAIT FOR BETTER GPS.'
47-
print ''
47+
print('GPS FAILED. NO MISSION CREATED. WAIT FOR BETTER GPS.')
48+
print('')
4849
else:
49-
print'GPS PASSED.'
50-
print ''
50+
print('GPS PASSED.')
51+
print('')
5152

5253
if descent_delta < 0:
5354

54-
print 'CURRENT ALTITUDE BELOW PARACHUTE DEPLOY ALTITUDE'
55-
print 'NO MISSION CREATED'
55+
print('CURRENT ALTITUDE BELOW PARACHUTE DEPLOY ALTITUDE')
56+
print('NO MISSION CREATED')
5657

5758
elif parachute_deploy_altitude < 20:
5859

59-
print 'PARACHUTE DEPLOY ALTITUDE LESS THAN 20 METERS'
60-
print 'NO MISSION CREATED'
60+
print('PARACHUTE DEPLOY ALTITUDE LESS THAN 20 METERS')
61+
print('NO MISSION CREATED')
6162

6263
elif parachute_deploy_altitude > 100:
6364

64-
print 'PARACHUTE DEPLOY ALTITUDE MORE THAN 100 METERS'
65-
print 'NO MISSION CREATED'
65+
print('PARACHUTE DEPLOY ALTITUDE MORE THAN 100 METERS')
66+
print('NO MISSION CREATED')
6667

6768
elif parachute_deploy_distance_from_home > 100:
6869

69-
print 'PARACHUTE DEPLOY DISTANCE IS MORE THAN 100 FROM HOME'
70-
print 'NO MISSION CREATED'
70+
print('PARACHUTE DEPLOY DISTANCE IS MORE THAN 100 FROM HOME')
71+
print('NO MISSION CREATED')
7172

7273
else:
7374

@@ -113,7 +114,7 @@
113114
Script.Sleep(1000)
114115
MAV.setWPACK(); #final ack
115116
Script.Sleep(1000)
116-
print 'AUTOGENERATED LANDING APPROACH MISSION'
117+
print('AUTOGENERATED LANDING APPROACH MISSION')
117118

118119

119120

Scripts/TAKEOFF.py

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
launch_altitude = 100
1+
from __future__ import print_function
2+
launch_altitude = 100
23

34
cruise_altitude = 200
45

@@ -40,29 +41,29 @@
4041
hdop = cs.gpshdop
4142

4243
if satellites < 6:
43-
print'GPS FAILED. NO MISSION CREATED. WAIT FOR BETTER GPS'
44-
print ''
44+
print('GPS FAILED. NO MISSION CREATED. WAIT FOR BETTER GPS')
45+
print('')
4546
elif hdop > 4:
46-
print'GPS FAILED. NO MISSION CREATED. WAIT FOR BETTER GPS.'
47-
print ''
47+
print('GPS FAILED. NO MISSION CREATED. WAIT FOR BETTER GPS.')
48+
print('')
4849
else:
49-
print'GPS PASSED.'
50-
print ''
50+
print('GPS PASSED.')
51+
print('')
5152

5253
if launch_altitude < 50:
5354

54-
print 'LAUNCH ALTITUDE LESS THAN 50 METERS'
55-
print 'NO MISSION CREATED'
55+
print('LAUNCH ALTITUDE LESS THAN 50 METERS')
56+
print('NO MISSION CREATED')
5657

5758
elif launch_altitude >100:
5859

59-
print 'LAUNCH ALTITUDE GREATER THAN 100 METERS'
60-
print 'NO MISSION CREATED'
60+
print('LAUNCH ALTITUDE GREATER THAN 100 METERS')
61+
print('NO MISSION CREATED')
6162

6263
elif cruise_altitude < launch_altitude:
6364

64-
print 'CRUISE ALTITUDE LESS THAN LAUNCH ALTITUDE'
65-
print 'NO MISSION CREATED'
65+
print('CRUISE ALTITUDE LESS THAN LAUNCH ALTITUDE')
66+
print('NO MISSION CREATED')
6667

6768
else:
6869

@@ -119,4 +120,4 @@
119120
MAV.setWP(wp4,5,MAVLink.MAV_FRAME.GLOBAL_RELATIVE_ALT); #upload wp4
120121
MAV.setWPCurrent(1); #restart mission to waypoint 0
121122
MAV.setWPACK(); #final ack
122-
print 'AUTOGENERATED TAKEOFF MISSION'
123+
print('AUTOGENERATED TAKEOFF MISSION')

Scripts/cubeorange.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-

1+
from __future__ import print_function
2+
23
import clr
34
import MissionPlanner
45
clr.AddReference("MAVLink")
@@ -9,7 +10,7 @@
910

1011
import MAVLink
1112

12-
print 'Start Script'
13+
print('Start Script')
1314

1415
MAV.setParam("INS_ACC_ID", 0, True);
1516
MAV.setParam("INS_ACC2_ID", 0, True);
@@ -19,4 +20,4 @@
1920
MAV.setParam("INS_ACC2_ID", 2883874, True);
2021
MAV.setParam("INS_ACC3_ID", 3015690, True);
2122

22-
print 'Done'
23+
print('Done')

Scripts/datetime.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1+
from __future__ import print_function
12
c#
23
import System
34
c#
45
dt = System.DateTime.Now
56
st = dt.ToString("yyyy-MM-ddTHH:mm:ss.fff") + ' setting wp 1'
67

78
# python
8-
print st
9+
print(st)
910
# c#
1011
System.Console.WriteLine(st)

Scripts/example1.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
# cs.???? = currentstate, any variable on the status tab in the planner can be used.
1+
from __future__ import print_function
2+
# cs.???? = currentstate, any variable on the status tab in the planner can be used.
23
# Script = options are
34
# Script.Sleep(ms)
45
# Script.ChangeParam(name,value)
@@ -8,24 +9,24 @@
89
# Script.SendRC(channel,pwm,sendnow)
910
#
1011

11-
print 'Start Script'
12+
print('Start Script')
1213
for chan in range(1,9):
1314
Script.SendRC(chan,1500,False)
1415
Script.SendRC(3,Script.GetParam('RC3_MIN'),True)
1516

1617
Script.Sleep(5000)
1718
while cs.lat == 0:
18-
print 'Waiting for GPS'
19+
print('Waiting for GPS')
1920
Script.Sleep(1000)
20-
print 'Got GPS'
21+
print('Got GPS')
2122
jo = 10 * 13
22-
print jo
23+
print(jo)
2324
Script.SendRC(3,1000,False)
2425
Script.SendRC(4,2000,True)
2526
cs.messages.Clear()
2627
Script.WaitFor('ARMING MOTORS',30000)
2728
Script.SendRC(4,1500,True)
28-
print 'Motors Armed!'
29+
print('Motors Armed!')
2930

3031
Script.SendRC(3,1700,True)
3132
while cs.alt < 50:
@@ -55,4 +56,4 @@
5556
Script.WaitFor('DISARMING MOTORS',30000)
5657
Script.SendRC(4,1500,True)
5758

58-
print 'Roll complete'
59+
print('Roll complete')

Scripts/example10.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1-
import clr
1+
from __future__ import print_function
2+
import clr
23
import MissionPlanner
34
clr.AddReference("MAVLink")
45
from System import Func, Action
56
import MAVLink
67

78
def OtherMethod(message):
8-
print "got HB";
9+
print("got HB");
910
return True
1011

1112
def MyMethod(message):
@@ -16,11 +17,11 @@ def MyMethod(message):
1617
def MyPacketHandler(o, message):
1718
try:
1819
if message.msgid == MAVLink.MAVLINK_MSG_ID.STATUSTEXT.value__:
19-
print "STATUSTEXT from MyPacketHandler " + str(message.sysid) + " " + str(message.compid)
20-
print dir(message)
20+
print("STATUSTEXT from MyPacketHandler " + str(message.sysid) + " " + str(message.compid))
21+
print(dir(message))
2122
print(bytes(message.data.text))
2223
except Exception as inst:
23-
print inst
24+
print(inst)
2425

2526
sub = MAV.SubscribeToPacketType(MAVLink.MAVLINK_MSG_ID.HEARTBEAT.value__, Func[MAVLink.MAVLinkMessage, bool] (OtherMethod))
2627
sub2 = MAV.SubscribeToPacketType(MAVLink.MAVLINK_MSG_ID.STATUSTEXT, Func[MAVLink.MAVLinkMessage,

Scripts/example2.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-

1+
from __future__ import print_function
2+
23
import clr
34
import MissionPlanner
45
clr.AddReference("MAVLink")
@@ -9,11 +10,11 @@
910

1011
import MAVLink
1112

12-
print 'Start Script'
13+
print('Start Script')
1314

1415
def OtherMethod(message):
15-
print "got HB";
16-
print dir(message.data)
16+
print("got HB");
17+
print(dir(message.data))
1718
return True
1819

1920
sub = MAV.SubscribeToPacketType(MAVLink.MAVLINK_MSG_ID.HEARTBEAT.value__, Func[MAVLink.MAVLinkMessage, bool] (OtherMethod))

Scripts/example3.py

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import sys
1+
from __future__ import print_function
2+
import sys
23
import math
34
import clr
45
import time
@@ -25,10 +26,10 @@ def gps_distance(lat1, lon1, lat2, lon2):
2526
c = 2.0 * atan2(sqrt(a), sqrt(1.0-a))
2627
return radius_of_earth * c
2728

28-
print __name__
29+
print(__name__)
2930

3031
# main program
31-
print "Start script"
32+
print("Start script")
3233
######Mission variables######
3334
dist_tolerance = 15 #(m)
3435
ber_tolerance = 45 #heading tolerance
@@ -43,23 +44,23 @@ def gps_distance(lat1, lon1, lat2, lon2):
4344
target = (-35, 117.98) # gps pos of target in degrees
4445

4546
time.sleep(5) # wait 10 seconds before starting
46-
print 'Starting Mission'
47+
print('Starting Mission')
4748
Script.ChangeMode("Guided") # changes mode to "Guided"
4849
item = MissionPlanner.Utilities.Locationwp() # creating waypoint
4950

5051
alt = 60.000000 # altitude value
5152
Locationwp.lat.SetValue(item,target[0]) # sets latitude
5253
Locationwp.lng.SetValue(item,target[1]) # sets longitude
5354
Locationwp.alt.SetValue(item,alt) # sets altitude
54-
print 'Drop zone set'
55+
print('Drop zone set')
5556
MAV.setGuidedModeWP(item) # tells UAV "go to" the set lat/long @ alt
56-
print 'Going to DZ'
57+
print('Going to DZ')
5758
Good = True
5859
while Good == True:
5960
ground_speed = cs.groundspeed
6061
alt = cs.alt
6162
wp_dist = gps_distance(cs.lat ,cs.lng, math.radians(target[0]), math.radians(target[1]))
62-
print wp_dist
63+
print(wp_dist)
6364
ber_error = cs.ber_error
6465
fall_time = ((2 * alt) / gravity) ** (0.5)
6566
fall_dist = ground_speed * fall_time
@@ -69,12 +70,12 @@ def gps_distance(lat1, lon1, lat2, lon2):
6970
if (math.fabs(ber_error) <= ber_tolerance):
7071
######Payload Release######
7172
Script.SendRC(payload_servo,1900,True)
72-
print 'Bombs away!'
73+
print('Bombs away!')
7374
else:
74-
print 'Heading outside of threshold, go around!'
75+
print('Heading outside of threshold, go around!')
7576
Good = False
7677
else:
77-
print 'Outside of threshold!'
78+
print('Outside of threshold!')
7879
time.sleep (1.0) #sleep for a second
7980
#Broken out of the loop as Bearing was not right
80-
print 'Bearing was out of tolerance for the Drop - Start run again'
81+
print('Bearing was out of tolerance for the Drop - Start run again')

Scripts/example4 wp.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import sys
1+
from __future__ import print_function
2+
import sys
23
import math
34
import clr
45
import time
@@ -24,22 +25,22 @@
2425
wp2 = Locationwp().Set(-35,117.89,50, id)
2526
wp3 = Locationwp().Set(-35,117.85,20, id)
2627

27-
print "set wp total"
28+
print("set wp total")
2829
MAV.setWPTotal(5)
29-
print "upload home - reset on arm"
30+
print("upload home - reset on arm")
3031
MAV.setWP(home,0,MAVLink.MAV_FRAME.GLOBAL_RELATIVE_ALT);
31-
print "upload to"
32+
print("upload to")
3233
MAV.setWP(to,1,MAVLink.MAV_FRAME.GLOBAL_RELATIVE_ALT);
33-
print "upload wp1"
34+
print("upload wp1")
3435
MAV.setWP(wp1,2,MAVLink.MAV_FRAME.GLOBAL_RELATIVE_ALT);
35-
print "upload wp2"
36+
print("upload wp2")
3637
MAV.setWP(wp2,3,MAVLink.MAV_FRAME.GLOBAL_RELATIVE_ALT);
37-
print "upload wp3"
38+
print("upload wp3")
3839
MAV.setWP(wp3,4,MAVLink.MAV_FRAME.GLOBAL_RELATIVE_ALT);
39-
print "final ack"
40+
print("final ack")
4041
MAV.setWPACK();
4142

42-
print "done"
43+
print("done")
4344

4445

4546

Scripts/example5 inject data.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
1-

1+
from __future__ import print_function
2+
23
import clr
34
import MissionPlanner
45
clr.AddReference("MAVLink")
56
from System import Byte
67
from System import Array
78
import MAVLink
89

9-
print 'Start Script'
10+
print('Start Script')
1011

1112
key = Array[Byte]([0x13, 0x00, 0x00, 0x00, 0x08, 0x00])
1213

0 commit comments

Comments
 (0)