def get_direction(): c=grove_compass_lib.compass() declinationAngle = -0.6907 PI = math.pi heading = c.heading + declinationAngle #Correct for when signs are reversed. if(heading < 0): heading += 2.0*PI # Check for wrap due to addition of declination. if(heading > 2.0*PI): heading -= 2.0*PI; headingDegrees = heading * 180.0 / math.pi #print ("X:",c.x,"Y:",c.y,"X:",c.z,"Heading:",heading , " Radians:", headingDegrees) c.update() #show_direction(headingDegrees) # print c.headingDegrees time.sleep(.1) return headingDegrees
The MIT License (MIT) GrovePi for the Raspberry Pi: an open source platform for connecting Grove Sensors to the Raspberry Pi. Copyright (C) 2015 Dexter Industries Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 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 grove_compass_lib c=grove_compass_lib.compass() while True: print ("X:",c.x,"Y:",c.y,"X:",c.z,"Heading:",c.headingDegrees) c.update() time.sleep(.1)
import grove_compass_lib import time c=grove_compass_lib.compass() while True: print "X:",c.x,"Y:",c.y,"X:",c.z,"Heading:",c.headingDegrees c.update() time.sleep(.1)
def read_sensor(): c = grove_compass_lib.compass() print("X:", c.x, "Y:", c.y, "X:", c.z, "Heading:", c.headingDegrees) c.update() time.sleep(0.1) return [c.x, c.y, c.z, c.headingDegrees]