From d1e3d745659172e6983b2f7499c3146eaee33d00 Mon Sep 17 00:00:00 2001 From: "Stuckey, William M" Date: Mon, 10 Sep 2018 17:22:20 -0400 Subject: [PATCH] nix matplotlib partial fix and warning, run script, documentation --- .gitignore | 6 +++++ README.md | 10 ++++++++ rps/examples/formation_control.py | 2 +- run_sim.py | 41 +++++++++++++++++++++++++++++++ 4 files changed, 58 insertions(+), 1 deletion(-) create mode 100755 run_sim.py diff --git a/.gitignore b/.gitignore index 7bbc71c..4df4e17 100644 --- a/.gitignore +++ b/.gitignore @@ -3,6 +3,12 @@ __pycache__/ *.py[cod] *$py.class +# vim files +*.swp + +# ignore generated datafile +*.npy + # C extensions *.so diff --git a/README.md b/README.md index e9db014..5e75986 100644 --- a/README.md +++ b/README.md @@ -29,5 +29,15 @@ Though, these are included in the setup.py file. For the absolutely correct lis There are a variety of examples in the 'examples' folder. Check these out before starting your simulation! +You can run the examples with +``` +./run_sim.py rps/examples/.py +``` + +You can also run the examples without the wrapper, but it won't perform any dependnecy sanity checks. +``` +python3 rps/examples/.py +``` + # Submission Instructions When your simulation is complete, go the the Robotarium [website](https://www.robotarium.org), follow the instructions there, and see your code run on real robots! diff --git a/rps/examples/formation_control.py b/rps/examples/formation_control.py index 4a4facf..1d0edce 100644 --- a/rps/examples/formation_control.py +++ b/rps/examples/formation_control.py @@ -33,7 +33,7 @@ iterations = 2000 N = 6 -r = robotarium.Robotairum(number_of_agents=N, number_of_agents=10, show_figure=True, save_data=True, update_time=1) +r = robotarium.Robotarium(number_of_agents=N, show_figure=True, save_data=True, update_time=1) si_barrier_cert = create_single_integrator_barrier_certificate(N) diff --git a/run_sim.py b/run_sim.py new file mode 100755 index 0000000..40287e0 --- /dev/null +++ b/run_sim.py @@ -0,0 +1,41 @@ +#!/usr/bin/env python3 + +import os +import sys + +# PyQt4 still has a bug where it fails to yeild interactive control +# back to the starting terminal on some operating systems. This is +# at least observed on Linux and may affect OSX as well. Manually +# setting Qt4 return hooks didn't work. The only apparent fix +# is to move to Qt5 if able. This method check if the required +# PyQt5 modules and backend are present. If they are, we move the +# renderer forward to PyQt5. Otherwise, we fallback to the default. +# +# Backend *MUST* be set before any subpackages are imported. +def select_pyplot_renderer(): + try: + from PyQt5 import QtCore, QtGui, QtWidgets + import matplotlib + matplotlib.use('Qt5Agg') + except ImportError: + if sys.platform == "linux" or sys.platform == "linux2": + print('*** could not set sim renderer to Qt5Agg') + print('*** canvas may fail to yield interactive control on close') + print('*** please install PyQt5 if you experience issues') + print('\tDebian Package: python3-pyqt5') + print('\tFedora Core: python3-qt5') + print('') + print('') + + # fallback renderer + import matplotlib + matplotlib.use('TkAgg') + + +select_pyplot_renderer() + +print('launching sim program: ' + sys.argv[1]) +print('') +os.system('python3 ' + sys.argv[1]) +exit(0) +