mirror of
https://github.com/eclipse/upm.git
synced 2025-07-27 14:11:15 +03:00
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:
96
examples/python/lsm303.py
Normal file → Executable file
96
examples/python/lsm303.py
Normal file → Executable file
@ -26,62 +26,64 @@
|
||||
import time, sys, signal, atexit
|
||||
import pyupm_lsm303 as lsm303
|
||||
|
||||
# Instantiate LSM303 compass on I2C
|
||||
myAccelrCompass = lsm303.LSM303(0)
|
||||
def main():
|
||||
# Instantiate LSM303 compass on I2C
|
||||
myAccelrCompass = lsm303.LSM303(0)
|
||||
|
||||
## 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 myAccelrCompass
|
||||
def exitHandler():
|
||||
print "Exiting"
|
||||
sys.exit(0)
|
||||
|
||||
# This lets you run code on exit,
|
||||
# including functions from myAccelrCompass
|
||||
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)
|
||||
while(1):
|
||||
# Load coordinates into LSM303 object
|
||||
successFail = myAccelrCompass.getCoordinates()
|
||||
# in XYZ order. The sensor returns XZY,
|
||||
# but the driver compensates and makes it XYZ
|
||||
coords = myAccelrCompass.getRawCoorData()
|
||||
|
||||
# Print out the X, Y, and Z coordinate data
|
||||
# using two different methods
|
||||
outputStr = "coor: rX {0} - rY {1} - rZ {2}".format(
|
||||
coords.__getitem__(0), coords.__getitem__(1),
|
||||
coords.__getitem__(2))
|
||||
print outputStr
|
||||
|
||||
while(1):
|
||||
# Load coordinates into LSM303 object
|
||||
successFail = myAccelrCompass.getCoordinates()
|
||||
# in XYZ order. The sensor returns XZY,
|
||||
# but the driver compensates and makes it XYZ
|
||||
coords = myAccelrCompass.getRawCoorData()
|
||||
outputStr = "coor: gX {0} - gY {1} - gZ {2}".format(
|
||||
myAccelrCompass.getCoorX(), myAccelrCompass.getCoorY(),
|
||||
myAccelrCompass.getCoorZ())
|
||||
print outputStr
|
||||
|
||||
# Print out the X, Y, and Z coordinate data
|
||||
# using two different methods
|
||||
outputStr = "coor: rX {0} - rY {1} - rZ {2}".format(
|
||||
coords.__getitem__(0), coords.__getitem__(1),
|
||||
coords.__getitem__(2))
|
||||
print outputStr
|
||||
# Get and print out the heading
|
||||
print "heading:", myAccelrCompass.getHeading()
|
||||
|
||||
outputStr = "coor: gX {0} - gY {1} - gZ {2}".format(
|
||||
myAccelrCompass.getCoorX(), myAccelrCompass.getCoorY(),
|
||||
myAccelrCompass.getCoorZ())
|
||||
print outputStr
|
||||
# Get the acceleration
|
||||
myAccelrCompass.getAcceleration();
|
||||
accel = myAccelrCompass.getRawAccelData();
|
||||
|
||||
# Get and print out the heading
|
||||
print "heading:", myAccelrCompass.getHeading()
|
||||
# Print out the X, Y, and Z acceleration data
|
||||
# using two different methods
|
||||
outputStr = "acc: rX {0} - rY {1} - Z {2}".format(
|
||||
accel.__getitem__(0), accel.__getitem__(1), accel.__getitem__(2))
|
||||
print outputStr
|
||||
|
||||
# Get the acceleration
|
||||
myAccelrCompass.getAcceleration();
|
||||
accel = myAccelrCompass.getRawAccelData();
|
||||
outputStr = "acc: gX {0} - gY {1} - gZ {2}".format(
|
||||
myAccelrCompass.getAccelX(), myAccelrCompass.getAccelY(),
|
||||
myAccelrCompass.getAccelZ())
|
||||
print outputStr
|
||||
|
||||
# Print out the X, Y, and Z acceleration data
|
||||
# using two different methods
|
||||
outputStr = "acc: rX {0} - rY {1} - Z {2}".format(
|
||||
accel.__getitem__(0), accel.__getitem__(1), accel.__getitem__(2))
|
||||
print outputStr
|
||||
print " "
|
||||
time.sleep(1)
|
||||
|
||||
outputStr = "acc: gX {0} - gY {1} - gZ {2}".format(
|
||||
myAccelrCompass.getAccelX(), myAccelrCompass.getAccelY(),
|
||||
myAccelrCompass.getAccelZ())
|
||||
print outputStr
|
||||
|
||||
print " "
|
||||
time.sleep(1)
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
Reference in New Issue
Block a user