python_examples: Reformatted, self-checking, executable

* Moved body of each python example to main.  This allows for basic
      load module testing for CI
    * General cleanup of python modules (crlf/tabs/prints/etc)
    * Chmod'ed to 755 to allow running examples without specifying the
      python interpreter
    * Added ctest for loading python2/3 modules
    * Added jniclasscode pragma for java swig interface files.
    * Updated check_examplenames.py module to check all languages vs. a
      cxx example name
    * Added tests for checking python module and test loading
    * Added 'make test' to travis-ci run (run ctests)
    * Print a more meaningful message when not building cxx docs into
      python modules
    * Updated check_clean.py to only check java wrapper files
    * ENABLED ctests for UPM
    * Deleted using_carrays.py python example - this is covered by other
      examples

Signed-off-by: Noel Eck <noel.eck@intel.com>
This commit is contained in:
Noel Eck
2016-09-29 18:24:19 -07:00
parent 62718daf0b
commit 2f78d9f62b
203 changed files with 5890 additions and 5216 deletions

63
examples/python/l298-stepper.py Normal file → Executable file
View File

@ -21,47 +21,48 @@
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
import time, sys, signal, atexit
import pyupm_l298 as upmL298
# Instantiate a Stepper motor on a L298 Dual H-Bridge.
# This was tested with the NEMA-17 12V, 350mA, with 200 steps per rev.
myHBridge = upmL298.L298(200, 3, 4, 7, 8, 9)
def main():
# Instantiate a Stepper motor on a L298 Dual H-Bridge.
# This was tested with the NEMA-17 12V, 350mA, with 200 steps per rev.
myHBridge = upmL298.L298(200, 3, 4, 7, 8, 9)
## Exit handlers ##
# This stops python from printing a stacktrace when you hit control-C
def SIGINTHandler(signum, frame):
raise SystemExit
## Exit handlers ##
# This stops python from printing a stacktrace when you hit control-C
def SIGINTHandler(signum, frame):
raise SystemExit
# This lets you run code on exit,
# including functions from myHBridge
def exitHandler():
print "Exiting"
sys.exit(0)
# This lets you run code on exit,
# including functions from myHBridge
def exitHandler():
print "Exiting"
sys.exit(0)
# Register exit handlers
atexit.register(exitHandler)
signal.signal(signal.SIGINT, SIGINTHandler)
# Register exit handlers
atexit.register(exitHandler)
signal.signal(signal.SIGINT, SIGINTHandler)
myHBridge.setSpeed(10) # 10 RPMs
myHBridge.setDirection(upmL298.L298.DIR_CW)
myHBridge.enable(True)
print "Rotating 1 full revolution at 10 RPM speed."
# move 200 steps, a full rev
myHBridge.stepperSteps(200)
myHBridge.setSpeed(10) # 10 RPMs
myHBridge.setDirection(upmL298.L298.DIR_CW)
myHBridge.enable(True)
print "Sleeping for 2 seconds..."
time.sleep(2)
print "Rotating 1 full revolution at 10 RPM speed."
# move 200 steps, a full rev
myHBridge.stepperSteps(200)
print "Rotating 1/2 revolution in opposite direction at 10 RPM speed."
myHBridge.setDirection(upmL298.L298.DIR_CCW)
myHBridge.stepperSteps(100)
print "Sleeping for 2 seconds..."
time.sleep(2)
# release
myHBridge.enable(False)
print "Rotating 1/2 revolution in opposite direction at 10 RPM speed."
myHBridge.setDirection(upmL298.L298.DIR_CCW)
myHBridge.stepperSteps(100)
# exitHandler is called automatically
# release
myHBridge.enable(False)
# exitHandler is called automatically
if __name__ == '__main__':
main()