Go to the documentation of this file.00001
00002
00003 """
00004 Example 1: Read values from a number of analog and digital sensors and control
00005 one or more servos.
00006
00007 The Pi Robot Project: http://www.pirobot.org
00008 Copyright (c) 2010 Patrick Goebel. All right reserved.
00009
00010 This program is free software; you can redistribute it and/or modify
00011 it under the terms of the GNU General Public License as published by
00012 the Free Software Foundation; either version 2 of the License, or
00013 (at your option) any later version.
00014
00015 This program is distributed in the hope that it will be useful,
00016 but WITHOUT ANY WARRANTY; without even the implied warranty of
00017 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00018 GNU General Public License for more details at:
00019
00020 http://www.gnu.org/licenses/gpl.html
00021
00022 NOTE: See the offical ElementTM manual at:
00023 http://www.roboticsconnection.com/multimedia/docs/Element_3.0_UserGuide.pdf
00024 """
00025
00026 from element_driver import Element
00027 import time, os
00028
00029 if os.name == "posix":
00030 portName = "/dev/ttyUSB0"
00031
00032
00033
00034 else:
00035 portName = "COM12"
00036
00037 baudRate = 57600
00038
00039 myElement = Element(port=portName, baudrate=baudRate, timeout=0.5, units=0)
00040 myElement.connect()
00041
00042 print "Firmware Version", myElement.fw()
00043 print "Units", myElement.get_units()
00044 print "Baudrate", myElement.get_baud()
00045
00046
00047
00048
00049 samples = 1
00050
00051 for i in range(samples):
00052 print "All raw analog sensor values:", myElement.get_all_analog()
00053 print "Raw analog values from the cache:", myElement.analog_sensor_cache
00054 print "Element voltage from the cache", myElement.voltage(cached=True)
00055 print "Ping sonar reading on digital pin 0:", myElement.get_Ping(0)
00056 print "Ping reading from the cache:", myElement.get_Ping(0, cached=True)
00057 print "Sharp IR reading using on analog pin 0:", myElement.get_GP2D12(0)
00058 print "Sharp IR reading from cache:", myElement.get_GP2D12(0, cached=True)
00059
00060 time.sleep(0.05)
00061
00062 print "\nTesting completed, shutting down."
00063
00064 myElement.stop()
00065 myElement.close()
00066