mirror of
https://github.com/paparazzi/paparazzi.git
synced 2026-06-05 15:12:09 +08:00
[ardrone] pep8 for python script
This commit is contained in:
@@ -1,4 +1,6 @@
|
|||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
|
|
||||||
|
from __future__ import print_function
|
||||||
import re
|
import re
|
||||||
import argparse
|
import argparse
|
||||||
import socket
|
import socket
|
||||||
@@ -18,15 +20,15 @@ def is_ip(address):
|
|||||||
|
|
||||||
# Execute a command
|
# Execute a command
|
||||||
def execute_command(command):
|
def execute_command(command):
|
||||||
tn.write(command+'\n')
|
tn.write(command + '\n')
|
||||||
return tn.read_until('# ')[len(command)+2:-4]
|
return tn.read_until('# ')[len(command) + 2:-4]
|
||||||
|
|
||||||
# Read from config.ini
|
# Read from config.ini
|
||||||
def read_from_config(name, config = ''):
|
def read_from_config(name, config=''):
|
||||||
if config == '':
|
if config == '':
|
||||||
config = execute_command('cat /data/config.ini')
|
config = execute_command('cat /data/config.ini')
|
||||||
search = re.search(name+'[^=]+=[\r\n\t ]([^\r\n\t ]+)', config)
|
search = re.search(name + '[^=]+=[\r\n\t ]([^\r\n\t ]+)', config)
|
||||||
if search == None:
|
if search is None:
|
||||||
return ''
|
return ''
|
||||||
else:
|
else:
|
||||||
return search.group(1)
|
return search.group(1)
|
||||||
@@ -34,9 +36,9 @@ def read_from_config(name, config = ''):
|
|||||||
# Write to config
|
# Write to config
|
||||||
def write_to_config(name, value):
|
def write_to_config(name, value):
|
||||||
if read_from_config(name) == '':
|
if read_from_config(name) == '':
|
||||||
execute_command('echo "'+name+' = '+value+'\" >> /data/config.ini')
|
execute_command('echo "' + name + ' = ' + value + '\" >> /data/config.ini')
|
||||||
else:
|
else:
|
||||||
execute_command('sed -i "s/\('+name+' *= *\).*/\\1'+value+'/g" /data/config.ini')
|
execute_command('sed -i "s/\(' + name + ' *= *\).*/\\1' + value + '/g" /data/config.ini')
|
||||||
|
|
||||||
# Check the version
|
# Check the version
|
||||||
def check_version():
|
def check_version():
|
||||||
@@ -84,11 +86,11 @@ def ardrone2_reboot():
|
|||||||
|
|
||||||
# Install the vision framework
|
# Install the vision framework
|
||||||
def ardrone2_install_vision():
|
def ardrone2_install_vision():
|
||||||
print 'Uploading GST'
|
print('Uploading GST')
|
||||||
ftp.storbinary("STOR arm_light.tgz",file("bin/arm_light.tgz","rb"))
|
ftp.storbinary("STOR arm_light.tgz", file("bin/arm_light.tgz", "rb"))
|
||||||
print execute_command("cd /data/video && tar -xzf arm_light.tgz")
|
print(execute_command("cd /data/video && tar -xzf arm_light.tgz"))
|
||||||
print execute_command("rm -rf /data/video/arm_light.tgz")
|
print(execute_command("rm -rf /data/video/arm_light.tgz"))
|
||||||
print 'Now Starting Vision'
|
print('Now Starting Vision')
|
||||||
ardrone2_start_vision()
|
ardrone2_start_vision()
|
||||||
|
|
||||||
# Remove the vision framework
|
# Remove the vision framework
|
||||||
@@ -114,27 +116,29 @@ def ardrone2_start_vision():
|
|||||||
# Show result
|
# Show result
|
||||||
execute_command("ls -altr /opt/arm/gst/bin")
|
execute_command("ls -altr /opt/arm/gst/bin")
|
||||||
|
|
||||||
|
|
||||||
def ardrone2_status():
|
def ardrone2_status():
|
||||||
config_ini = execute_command('cat /data/config.ini')
|
config_ini = execute_command('cat /data/config.ini')
|
||||||
|
|
||||||
print '======================== ARDrone 2 Status ========================'
|
print('======================== ARDrone 2 Status ========================')
|
||||||
print 'Version:\t\t'+check_version()
|
print('Version:\t\t' + check_version())
|
||||||
print 'Host:\t\t\t'+args.host+' ('+read_from_config('static_ip_address_base', config_ini)+read_from_config('static_ip_address_probe', config_ini)+' after boot)'
|
print('Host:\t\t\t' + args.host + ' (' + read_from_config('static_ip_address_base', config_ini) +
|
||||||
print 'Currently running:\t'+check_running()
|
read_from_config('static_ip_address_probe', config_ini) + ' after boot)')
|
||||||
print 'Serial number:\t\t' + read_from_config('drone_serial', config_ini)
|
print('Currently running:\t' + check_running())
|
||||||
print 'Network id:\t\t' + read_from_config('ssid_single_player', config_ini)
|
print('Serial number:\t\t' + read_from_config('drone_serial', config_ini))
|
||||||
print 'Motor software:\t\t' \
|
print('Network id:\t\t' + read_from_config('ssid_single_player', config_ini))
|
||||||
+read_from_config('motor1_soft', config_ini)+'\t'+read_from_config('motor2_soft', config_ini)+'\t' \
|
print('Motor software:\t\t' +
|
||||||
+read_from_config('motor3_soft', config_ini)+'\t'+read_from_config('motor4_soft', config_ini)
|
read_from_config('motor1_soft', config_ini) + '\t' + read_from_config('motor2_soft', config_ini) + '\t' +
|
||||||
print 'Motor hardware:\t\t' \
|
read_from_config('motor3_soft', config_ini) + '\t' + read_from_config('motor4_soft', config_ini))
|
||||||
+read_from_config('motor1_hard', config_ini)+'\t'+read_from_config('motor2_hard', config_ini)+'\t' \
|
print('Motor hardware:\t\t' +
|
||||||
+read_from_config('motor3_hard', config_ini)+'\t'+read_from_config('motor4_hard', config_ini)
|
read_from_config('motor1_hard', config_ini) + '\t' + read_from_config('motor2_hard', config_ini) + '\t' +
|
||||||
|
read_from_config('motor3_hard', config_ini) + '\t' + read_from_config('motor4_hard', config_ini))
|
||||||
|
|
||||||
autorun = {'': 'Native','0': 'Native','1': 'Paparazzi RAW','2': 'Paparazzi SDK'}
|
autorun = {'': 'Native', '0': 'Native', '1': 'Paparazzi RAW', '2': 'Paparazzi SDK'}
|
||||||
if check_autoboot():
|
if check_autoboot():
|
||||||
print 'Autorun at start:\tInstalled booting ' + autorun[read_from_config('start_paparazzi', config_ini)]
|
print('Autorun at start:\tInstalled booting ' + autorun[read_from_config('start_paparazzi', config_ini)])
|
||||||
else:
|
else:
|
||||||
print 'Autorun at start:\tNot installed'
|
print('Autorun at start:\tNot installed')
|
||||||
|
|
||||||
# Check if the vision framework is installed and running
|
# Check if the vision framework is installed and running
|
||||||
vision_framework = ""
|
vision_framework = ""
|
||||||
@@ -142,15 +146,11 @@ def ardrone2_status():
|
|||||||
vision_framework += "Installed"
|
vision_framework += "Installed"
|
||||||
if check_vision_running:
|
if check_vision_running:
|
||||||
vision_framework += " and running"
|
vision_framework += " and running"
|
||||||
print 'Vision framework:\t'+vision_framework
|
print('Vision framework:\t' + vision_framework)
|
||||||
|
|
||||||
# Request the filesystem status
|
# Request the filesystem status
|
||||||
print '\n======================== Filesystem Status ========================'
|
print('\n======================== Filesystem Status ========================')
|
||||||
print check_filesystem()
|
print(check_filesystem())
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# Parse the arguments
|
# Parse the arguments
|
||||||
@@ -163,7 +163,8 @@ subparsers = parser.add_subparsers(title='Command to execute', metavar='command'
|
|||||||
subparsers.add_parser('status', help='Request the status of the ARDrone 2')
|
subparsers.add_parser('status', help='Request the status of the ARDrone 2')
|
||||||
subparsers.add_parser('reboot', help='Reboot the ARDrone 2')
|
subparsers.add_parser('reboot', help='Reboot the ARDrone 2')
|
||||||
subparsers.add_parser('installvision', help='Install the vision framework')
|
subparsers.add_parser('installvision', help='Install the vision framework')
|
||||||
subparser_upload = subparsers.add_parser('upload_gst_module', help='Upload, configure and move a gstreamer0.10 module libXXX.so')
|
subparser_upload = subparsers.add_parser('upload_gst_module',
|
||||||
|
help='Upload, configure and move a gstreamer0.10 module libXXX.so')
|
||||||
subparser_upload.add_argument('file', help='Filename of *.so module')
|
subparser_upload.add_argument('file', help='Filename of *.so module')
|
||||||
subparser_paparazzi = subparsers.add_parser('upload_paparazzi', help='Upload paparazzi autopilot software')
|
subparser_paparazzi = subparsers.add_parser('upload_paparazzi', help='Upload paparazzi autopilot software')
|
||||||
subparser_paparazzi.add_argument('file', help='Filename of *.elf executable')
|
subparser_paparazzi.add_argument('file', help='Filename of *.elf executable')
|
||||||
@@ -180,7 +181,8 @@ subparser_networkid.add_argument('name', help='the new network ID(SSID)')
|
|||||||
subparser_ipaddress = subparsers.add_parser('ipaddress', help='Set the IP address of the ARDrone 2')
|
subparser_ipaddress = subparsers.add_parser('ipaddress', help='Set the IP address of the ARDrone 2')
|
||||||
subparser_ipaddress.add_argument('address', help='the new IP address')
|
subparser_ipaddress.add_argument('address', help='the new IP address')
|
||||||
subparser_autostart = subparsers.add_parser('autostart', help='Set what to start on boot for the ARDrone 2')
|
subparser_autostart = subparsers.add_parser('autostart', help='Set what to start on boot for the ARDrone 2')
|
||||||
subparser_autostart.add_argument('type', choices=['native','paparazzi_raw','paparazzi_sdk'], help='what to start on boot')
|
subparser_autostart.add_argument('type', choices=['native', 'paparazzi_raw', 'paparazzi_sdk'],
|
||||||
|
help='what to start on boot')
|
||||||
|
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
@@ -190,7 +192,7 @@ try:
|
|||||||
ftp = FTP(args.host)
|
ftp = FTP(args.host)
|
||||||
ftp.login()
|
ftp.login()
|
||||||
except:
|
except:
|
||||||
print 'Could not connect to ARDrone 2 (host: '+args.host+')'
|
print('Could not connect to ARDrone 2 (host: ' + args.host + ')')
|
||||||
exit(2)
|
exit(2)
|
||||||
|
|
||||||
# Read until after login
|
# Read until after login
|
||||||
@@ -203,102 +205,102 @@ if args.command == 'status':
|
|||||||
# Reboot the drone
|
# Reboot the drone
|
||||||
elif args.command == 'reboot':
|
elif args.command == 'reboot':
|
||||||
ardrone2_reboot()
|
ardrone2_reboot()
|
||||||
print 'The ARDrone 2 is rebooting...'
|
print('The ARDrone 2 is rebooting...')
|
||||||
|
|
||||||
# Kill a program
|
# Kill a program
|
||||||
elif args.command == 'kill':
|
elif args.command == 'kill':
|
||||||
execute_command('killall -9 '+args.program)
|
execute_command('killall -9 ' + args.program)
|
||||||
print 'Program "'+args.program+'" is now killed'
|
print('Program "' + args.program + '" is now killed')
|
||||||
|
|
||||||
# Start a program
|
# Start a program
|
||||||
elif args.command == 'start':
|
elif args.command == 'start':
|
||||||
execute_command(args.start+' &')
|
execute_command(args.start + ' &')
|
||||||
print 'Program "'+args.start+'" is now started'
|
print('Program "' + args.start + '" is now started')
|
||||||
|
|
||||||
# Change the network ID
|
# Change the network ID
|
||||||
elif args.command == 'networkid':
|
elif args.command == 'networkid':
|
||||||
write_to_config('ssid_single_player', args.name)
|
write_to_config('ssid_single_player', args.name)
|
||||||
print 'The network ID (SSID) of the ARDrone 2 is changed to '+args.name
|
print('The network ID (SSID) of the ARDrone 2 is changed to ' + args.name)
|
||||||
|
|
||||||
if raw_input("Shall I restart the ARDrone 2? (y/N) ").lower() == 'y':
|
if input("Shall I restart the ARDrone 2? (y/N) ").lower() == 'y':
|
||||||
ardrone2_reboot()
|
ardrone2_reboot()
|
||||||
|
|
||||||
# Change the IP address
|
# Change the IP address
|
||||||
elif args.command == 'ipaddress':
|
elif args.command == 'ipaddress':
|
||||||
splitted_ip = args.address.split(".")
|
splitted_ip = args.address.split(".")
|
||||||
write_to_config('static_ip_address_base', splitted_ip[0]+'.'+splitted_ip[1]+'.'+splitted_ip[2]+'.')
|
write_to_config('static_ip_address_base', splitted_ip[0] + '.' + splitted_ip[1] + '.' + splitted_ip[2] + '.')
|
||||||
write_to_config('static_ip_address_probe', splitted_ip[3])
|
write_to_config('static_ip_address_probe', splitted_ip[3])
|
||||||
print 'The IP Address of the ARDrone 2 is changed to '+args.address
|
print('The IP Address of the ARDrone 2 is changed to ' + args.address)
|
||||||
|
|
||||||
if raw_input("Shall I restart the ARDrone 2? (y/N) ").lower() == 'y':
|
if input("Shall I restart the ARDrone 2? (y/N) ").lower() == 'y':
|
||||||
ardrone2_reboot()
|
ardrone2_reboot()
|
||||||
|
|
||||||
# Change the autostart
|
# Change the autostart
|
||||||
elif args.command == 'autostart':
|
elif args.command == 'autostart':
|
||||||
autorun = {'native': '0','paparazzi_raw': '1','paparazzi_sdk': '2'}
|
autorun = {'native': '0', 'paparazzi_raw': '1', 'paparazzi_sdk': '2'}
|
||||||
write_to_config('start_paparazzi', autorun[args.type])
|
write_to_config('start_paparazzi', autorun[args.type])
|
||||||
print 'The autostart on boot is changed to '+args.type
|
print('The autostart on boot is changed to ' + args.type)
|
||||||
|
|
||||||
# Install Vision framework
|
# Install Vision framework
|
||||||
elif args.command == 'installvision':
|
elif args.command == 'installvision':
|
||||||
if check_vision_installed():
|
if check_vision_installed():
|
||||||
print 'Vision framework already installed'
|
print('Vision framework already installed')
|
||||||
if raw_input("Shall I reinstall the vision framework? (y/N) ").lower() == 'y':
|
if input("Shall I reinstall the vision framework? (y/N) ").lower() == 'y':
|
||||||
ardrone2_remove_vision()
|
ardrone2_remove_vision()
|
||||||
ardrone2_install_vision()
|
ardrone2_install_vision()
|
||||||
|
|
||||||
ardrone2_install_vision()
|
ardrone2_install_vision()
|
||||||
print 'Vision framework installed'
|
print('Vision framework installed')
|
||||||
|
|
||||||
# Start Vision framework
|
# Start Vision framework
|
||||||
elif args.command == 'startvision':
|
elif args.command == 'startvision':
|
||||||
if check_vision_running():
|
if check_vision_running():
|
||||||
print 'Vision framework already started'
|
print('Vision framework already started')
|
||||||
else:
|
else:
|
||||||
if not check_vision_installed():
|
if not check_vision_installed():
|
||||||
print 'No vision framework installed'
|
print('No vision framework installed')
|
||||||
if raw_input("Shall I install the vision framework? (y/N) ").lower() == 'y':
|
if input("Shall I install the vision framework? (y/N) ").lower() == 'y':
|
||||||
ardrone2_install_vision()
|
ardrone2_install_vision()
|
||||||
|
|
||||||
if check_vision_installed():
|
if check_vision_installed():
|
||||||
ardrone2_start_vision()
|
ardrone2_start_vision()
|
||||||
print 'Vision framework started'
|
print('Vision framework started')
|
||||||
|
|
||||||
elif args.command == 'upload_gst_module':
|
elif args.command == 'upload_gst_module':
|
||||||
print 'Uploading ...' + args.file
|
print('Uploading ...' + args.file)
|
||||||
ftp.storbinary("STOR " + args.file,file(args.file,"rb"))
|
ftp.storbinary("STOR " + args.file, file(args.file, "rb"))
|
||||||
execute_command("chmod 777 /data/video/" + args.file)
|
execute_command("chmod 777 /data/video/" + args.file)
|
||||||
print execute_command("mv /data/video/" + args.file + " /data/video/opt/arm/gst/lib/gstreamer-0.10")
|
print(execute_command("mv /data/video/" + args.file + " /data/video/opt/arm/gst/lib/gstreamer-0.10"))
|
||||||
if check_vision_running():
|
if check_vision_running():
|
||||||
print 'Info: Vision framework already started'
|
print('Info: Vision framework already started')
|
||||||
else:
|
else:
|
||||||
if not check_vision_installed():
|
if not check_vision_installed():
|
||||||
print 'Warning: No vision framework installed'
|
print('Warning: No vision framework installed')
|
||||||
if raw_input("Warning: Shall I install the vision framework? (y/N) ").lower() == 'y':
|
if input("Warning: Shall I install the vision framework? (y/N) ").lower() == 'y':
|
||||||
ardrone2_install_vision()
|
ardrone2_install_vision()
|
||||||
|
|
||||||
if check_vision_installed():
|
if check_vision_installed():
|
||||||
ardrone2_start_vision()
|
ardrone2_start_vision()
|
||||||
print '#pragma message: Vision framework started'
|
print('#pragma message: Vision framework started')
|
||||||
print '#pragma message: Vision Plugin Uploaded and DSP Started.'
|
print('#pragma message: Vision Plugin Uploaded and DSP Started.')
|
||||||
|
|
||||||
|
|
||||||
elif args.command == 'insmod':
|
elif args.command == 'insmod':
|
||||||
modfile = args.file.rsplit('/',1)
|
modfile = args.file.rsplit('/', 1)
|
||||||
print 'Uploading \'' + modfile[1]
|
print('Uploading \'' + modfile[1])
|
||||||
ftp.storbinary("STOR " + modfile[1], file(args.file,"rb"))
|
ftp.storbinary("STOR " + modfile[1], file(args.file, "rb"))
|
||||||
print execute_command("insmod /data/video/"+modfile[1])
|
print(execute_command("insmod /data/video/" + modfile[1]))
|
||||||
|
|
||||||
elif args.command == 'upload_paparazzi':
|
elif args.command == 'upload_paparazzi':
|
||||||
# Split filename and path
|
# Split filename and path
|
||||||
f = args.file.rsplit('/', 1)
|
f = args.file.rsplit('/', 1)
|
||||||
|
|
||||||
print "Kill running ap.elf and make folder " + args.folder
|
print("Kill running ap.elf and make folder " + args.folder)
|
||||||
execute_command("killall " + f[1])
|
execute_command("killall " + f[1])
|
||||||
sleep(1)
|
sleep(1)
|
||||||
execute_command("mkdir -p " + args.folder)
|
execute_command("mkdir -p " + args.folder)
|
||||||
print 'Uploading \'' + f[1] + "\' from " + f[0] + " to " + args.folder
|
print('Uploading \'' + f[1] + "\' from " + f[0] + " to " + args.folder)
|
||||||
ftp.storbinary("STOR " + args.folder + "/" + f[1], file(args.file,"rb"))
|
ftp.storbinary("STOR " + args.folder + "/" + f[1], file(args.file, "rb"))
|
||||||
sleep(0.5)
|
sleep(0.5)
|
||||||
execute_command("chmod 777 /data/video/" + args.folder + "/" + f[1])
|
execute_command("chmod 777 /data/video/" + args.folder + "/" + f[1])
|
||||||
execute_command("/data/video/" + args.folder + "/" + f[1] + " > /dev/null 2>&1 &")
|
execute_command("/data/video/" + args.folder + "/" + f[1] + " > /dev/null 2>&1 &")
|
||||||
@@ -307,6 +309,6 @@ elif args.command == 'upload_paparazzi':
|
|||||||
|
|
||||||
|
|
||||||
# Close the telnet and python script
|
# Close the telnet and python script
|
||||||
tn.close();
|
tn.close()
|
||||||
ftp.close();
|
ftp.close()
|
||||||
exit(0)
|
exit(0)
|
||||||
|
|||||||
Reference in New Issue
Block a user