Exemple #1
0
    def __init__(self,
                 service_port,
                 host_ip,
                 spots_available,
                 data_log_mode=False):
        '''
        This will create a ParKingClient
        :param service_port:
        :param host_ip:
        :param data_log_mode:
        :return:
        '''
        self.data_log_mode = data_log_mode
        if self.data_log_mode:
            self.log_file = self.create_logs()
            self.data_file = self.create_data_file()
        else:
            self.log_file = None
            self.data_file = None
        self.index_for_csv = 1
        self.host_ip = host_ip
        self.service_port = service_port
        self.running = False

        self.sock = socket(AF_INET, SOCK_STREAM)
        self.connect()
        self.send_init_packet(spots_available)

        alive_thread = Thread(target=self.keep_alive, args=())
        alive_thread.daemon = True
        alive_thread.start()

        GPIO.setmode(GPIO.BCM)
        self.write_to_log('creating sensor 1')
        self.sensor_1 = i2c_hmc5883l.i2c_hmc5883l(1)
        self.sensor_1.setContinuousMode()
        self.sensor_1.setDeclination(0, 6)
        self.write_to_log('sensor one created')

        if not config.ONE_SENSOR:
            self.write_to_log('creating sensor 2')
            self.sensor_2 = i2c_hmc5883l.i2c_hmc5883l(0)
            self.sensor_2.setContinuousMode()
            self.sensor_2.setDeclination(0, 6)
            self.write_to_log('sensor two created')

        sleep(2)

        (x, y, z) = self.read_from_sensor_1()
        self.z_base_line_1 = z
        self.last_z_signal_1 = 0

        if not config.ONE_SENSOR:
            (x, y, z) = self.read_from_sensor_2()
            self.z_base_line_2 = z
            self.last_z_signal_2 = 0
Exemple #2
0
    def __init__(self, service_port, host_ip, spots_available, data_log_mode=False):
        '''
        This will create a ParKingClient
        :param service_port:
        :param host_ip:
        :param data_log_mode:
        :return:
        '''
        self.data_log_mode = data_log_mode
        if self.data_log_mode:
            self.log_file = self.create_logs()
            self.data_file = self.create_data_file()
        else:
            self.log_file = None
            self.data_file = None
        self.index_for_csv = 1
        self.host_ip = host_ip
        self.service_port = service_port
        self.running = False

        self.sock = socket(AF_INET, SOCK_STREAM)
        self.connect()
        self.send_init_packet(spots_available)


        alive_thread = Thread(target=self.keep_alive, args=())
        alive_thread.daemon = True
        alive_thread.start()

        GPIO.setmode(GPIO.BCM)
        self.write_to_log('creating sensor 1')
        self.sensor_1 = i2c_hmc5883l.i2c_hmc5883l(1)
        self.sensor_1.setContinuousMode()
        self.sensor_1.setDeclination(0,6)
        self.write_to_log('sensor one created')

        if not config.ONE_SENSOR:
            self.write_to_log('creating sensor 2')
            self.sensor_2 = i2c_hmc5883l.i2c_hmc5883l(0)
            self.sensor_2.setContinuousMode()
            self.sensor_2.setDeclination(0,6)
            self.write_to_log('sensor two created')

        sleep(2)

        (x, y, z) = self.read_from_sensor_1()
        self.z_base_line_1 = z
        self.last_z_signal_1 = 0

        if not config.ONE_SENSOR:
            (x, y, z) = self.read_from_sensor_2()
            self.z_base_line_2 = z
            self.last_z_signal_2 = 0
    def __init__(self):

        self.hmc5883l = i2c_hmc5883l.i2c_hmc5883l(
            1)  #wenn nicht das erste I2C Gerät muss die Eins geändert werden

        self.hmc5883l.setContinuousMode()
        self.hmc5883l.setDeclination(2, 15)
Exemple #4
0
    def __init__(self, service_port, host_ip, spots_available, data_log_mode=False):
        '''
        This will create a ParKingClient
        :param service_port:
        :param host
        :ip:
        :param data_log_mode:
        :return:
        '''
        self.data_log_mode = data_log_mode
        if self.data_log_mode:
            self.log_file = self.create_logs()
        else:
            self.log_file = None
        self.host_ip = host_ip
        self.service_port = service_port
        self.running = False

        self.sock = socket(AF_INET, SOCK_STREAM)

        GPIO.setwarnings(False)
        GPIO.setmode(GPIO.BOARD)
        self.write_to_log('creating sensor 1')
        self.sensor_1 = i2c_hmc5883l.i2c_hmc5883l(1)
        self.sensor_1.setContinuousMode()
        self.sensor_1.setDeclination(0,6)
        self.write_to_log('sensor one created')

        sleep(2)

        (x, y, z) = self.read_from_sensor_1()
        self.z_base_line_1 = z
        self.last_z_signal_1 = 0
Exemple #5
0
def writeCalibratedSamples(num, freq, infile, outfile):

    # Calculate calibration constants
    xc, yc, zc = calculateCalibration(infile)
    print(xc)
    print(yc)
    print(zc)

    # Instantiate I2C communication and set HMC5883L to continuous mode
    hmc5883l = i2c_hmc5883l.i2c_hmc5883l(1)
    hmc5883l.setContinuousMode()

    # Store and return sample lists
    xs = []
    ys = []
    zs = []

    sleep_time = 1 / freq
    # Take num samples of x, y, and z magnitudes
    for i in list(range(num)):
        x, y, z = hmc5883l.getAxes()
        print(x)
        print(y)
        print(z)
        x -= xc
        y -= yc
        z -= zc
        outfile.write('%.2f,%.2f,%.2f\n' % (x, y, z))
        xs.append(x)
        ys.append(y)
        zs.append(z)
        time.sleep(sleep_time)

    return xs, ys, zs
Exemple #6
0
def main():
	compass = i2c_hmc5883l.i2c_hmc5883l(4)	# 4 is because /dev/i2c-4 is the GPIO I2C bus on the odroid
	compass.setContinuousMode()
	compass.setDeclination(0, 6)
	
	# Get data from compass 10 times and print
	for i in range(10):
		print(compass)
		time.delay(1)
 def __init__(self, pin, i2c_port=1):
     """
     Configures the GPIO pin powering the magnetometer.
     Initializes I2C communication to HMC5883L magnetometer. 
     """
     self.gpio = OutputDevice(pin)
     logger.info("Configured GPIO pin %d for magnetometer power" % pin)
     self.hmc = i2c_hmc5883l(i2c_port, gauss=self.lower_bound)
     logger.info("Initialized I2C communication at port %d" % i2c_port)
Exemple #8
0
	def __init__(self):
		from i2clibraries import i2c_hmc5883l
		from i2clibraries import i2c_adxl345
		from i2clibraries import i2c_itg3205
		i2c_port = 0  # different versions of the pi use different ports
		self.accelerometer = i2c_adxl345.i2c_adxl345(i2c_port)
		self.accelerometer.setScale(2)
		self.gyroscope = i2c_itg3205.i2c_itg3205(i2c_port, addr=0x68)
		self.magnetometer = i2c_hmc5883l.i2c_hmc5883l(i2c_port)
		self.magnetometer.setContinuousMode()
		self.magnetometer.setDeclination(1,43)  # magnetic declination in degrees west (degrees, minute)
		print("SEN10724 IMU initialised")
Exemple #9
0
def compass():
    # Create an object for the electronic compass, should be moved to the objects file
    compass = i2c_hmc5883l.i2c_hmc5883l(1)
    # Set the compass to measure continuously
    compass.setContinuousMode()
    # This is where it gets tricky. The setDeclination function is to set the magnetic declination for the place you want to use the compass
    # For The Netherlands the magnetic Declination is 0,5 degrees per 7 radialdegrees
    compass.setDeclination(0.5, 7)
    while True:
        # Break when a shutdown is requested
        if ShutdownRequested:
            break
        # Else update the heading variables of the droid
        else:
            (CompassHeadingDegrees, CompassHeadingMinutes) = compass.getHeading()
Exemple #10
0
def comp_heading():
	from i2clibraries import i2c_hmc5883l
	import time

	# select i2c port
	hmc5883l = i2c_hmc5883l.i2c_hmc5883l(1)

	hmc5883l.setContinuousMode()

	# set magnetic declination
	hmc5883l.setDeclination(8,22)

	heading_list = hmc5883l.getHeading()
	minutes = heading_list[1]/60
	heading = heading_list[0] + minutes
	return (heading)
Exemple #11
0
def writeSamples(num, freq, outfile):

    # Instantiate I2C communication and set HMC5883L to continuous mode
    hmc5883l = i2c_hmc5883l.i2c_hmc5883l(1)
    hmc5883l.setContinuousMode()

    sleep_time = 1 / freq
    # Take num samples of x, y, and z magnitudes
    for i in list(range(num)):
        x, y, z = hmc5883l.getAxes(
        )  # returns float('nan') if register overflow
        print(x)
        print(y)
        print(z)
        #if all([x!=None, y!=None, z!=None]):
        outfile.write('%.2f,%.2f,%.2f\n' % (x, y, z))
        time.sleep(sleep_time)
Exemple #12
0
	def __init__(self, compass_stack, compass_n, compass_s):
		# Call Thread initializer
		super(Compass, self).__init__()
		
		# Get IGVC logger
		self.logger = logging.getLogger("IGVC")
		
		# Save stack and semaphores
		self.compass_stack = compass_stack
		self.compass_n = compass_n
		self.compass_s = compass_s
		self.stopped = False
		
		# Instantiates compass
		self.compass = i2c_hmc5883l.i2c_hmc5883l(4)	# 4 is because /dev/i2c-4 is the GPIO I2C bus on the odroid
		self.compass.setContinuousMode()
		self.compass.setDeclination(0, 6)
Exemple #13
0
    def __init__(self,
                 service_port,
                 host_ip,
                 spots_available,
                 data_log_mode=False):
        '''
        This will create a ParKingClient
        :param service_port:
        :param host
        :ip:
        :param data_log_mode:
        :return:
        '''
        self.data_log_mode = data_log_mode
        if self.data_log_mode:
            self.log_file = self.create_logs()
        else:
            self.log_file = None
        self.host_ip = host_ip
        self.service_port = service_port
        self.running = False

        self.sock = socket(AF_INET, SOCK_STREAM)

        GPIO.setwarnings(False)
        GPIO.setmode(GPIO.BOARD)
        self.write_to_log('creating sensor 1')
        self.sensor_1 = i2c_hmc5883l.i2c_hmc5883l(1)
        self.sensor_1.setContinuousMode()
        self.sensor_1.setDeclination(0, 6)
        self.write_to_log('sensor one created')

        sleep(2)

        (x, y, z) = self.read_from_sensor_1()
        self.z_base_line_1 = z
        self.last_z_signal_1 = 0
Exemple #14
0
from i2clibraries import i2c_hmc5883l
import time

hmc5883l = i2c_hmc5883l.i2c_hmc5883l(
    1)  #choosing which i2c port to use, RPi2 model B uses port 1
hmc5883l.setContinuousMode()
hmc5883l.setDeclination(0, 6)  #in brakets (degrees, minute)
#hmc5883l.getHeading()
for i in range(1, 10):
    i = hmc5883l
    print(i)
    time.sleep(0.5)
#print(hmc5883l)
Exemple #15
0
                                  self.bct_POWER)
        sleep(1)


# -----------------------------------------------------------------------------------------------

# test_main
if __name__ == "__main__":
    test = Beacon_tx()
    test.beacon_TX_config("up", "leadv 3", "noscan")
    test.beacon_TX_cmd_format(test.bct_OCF_format, test.bct_IBEACONPROFIX,
                              test.bct_UUID, test.bct_MAJOR, test.bct_MINOR,
                              test.bct_POWER)
    test.beacon_TX_cmd_setting(test.bct_OCF_setting, 100)
    test.beacon_TX_cmd_operate(test.bct_OCF_operate, test.bct_start)
    test_compass = compass.i2c_hmc5883l(1)
    test_compass.setContinuousMode()
    test_compass.setDeclination(0, 6)
    test_gps = gps_module.gps()

    print("Receiving GPS data")
    print("BLE EMIT START")

    ser = gps_module.serial.Serial(test_gps.port, baudrate=9600)
    while True:
        try:
            test.beacon_TX_DevTrigger(test.formation, test_gps.beacon_lat,
                                      test_gps.beacon_lon,
                                      test_compass.getHeadingString())
            print(test_compass)
            for i in range(1, 17):
import bluetooth
import RPi.GPIO as GPIO  #calling for header file which helps in using GPIOs of PI
import time
from i2clibraries import i2c_hmc5883l
MOTOR = 18

GPIO.setmode(
    GPIO.BCM)  #programming the GPIO by BCM pin numbers. (like PIN40 as GPIO21)
GPIO.setwarnings(False)
GPIO.setup(MOTOR, GPIO.OUT)  #initialize GPIO18 (MOTOR) as an output Pin
p = GPIO.PWM(MOTOR, 50)  #set up PWM on the MOTOR pin
hmctest = i2c_hmc5883l.i2c_hmc5883l(1)
hmctest.setContinuousMode()
hmctest.setDeclination(0, 13)  #sets up pins for I2C module

while 1:  # runs forever
    server_socket = bluetooth.BluetoothSocket(bluetooth.RFCOMM)
    port = 1
    server_socket.bind(("", port))
    client_socket = 0  #setting up the bluetooth module to get ready for a connection
    print("Awaiting SPP bluetooth connection")
    server_socket.listen(
        1)  #waits for an incoming connection before moving on.

    client_socket, address = server_socket.accept(
    )  #accepts incoming connection.
    print("Accepted connection from ", address)
    p.start(2.5)  #start PWM on MOTOR pin
    while client_socket != 0:  #runs only when there is a connected device.
        try:  #checks to see if there is still a connection.
            data = client_socket.recv(
Exemple #17
0
from i2clibraries import i2c_hmc5883l
import time

compass = i2c_hmc5883l.i2c_hmc5883l(1)


def main():
    global compass
    compass.setContinuousMode()
    compass.setDeclination(16, 0)

    while 1:
        heading = compass.getHeading()
        print("Heading: " + str(heading[0]) + ", " + str(heading[1]))
        time.sleep(1)


if __name__ == "__main__":
    main()
Exemple #18
0
 def __init__(self, config: Config):
     self.compass = i2c_hmc5883l.i2c_hmc5883l(config.compass.pin)
     self.compass.setContinuousMode()
     self.compass.setDeclination(*config.compass.declination)
     self.calibrateCompass()
     threading.Thread(target=self.getRelativeHeadingThread)
	def connectCompass(self):
		try:
			self.hm = i2c_hmc5883l.i2c_hmc5883l(1) #i2c channel 1
			self.hm.setContinuousMode()
		except Exception as e:
			raise e
Exemple #20
0
    if newHeading_Kart > 180:
        newHeadingAdjusted_Kart = newHeading_Kart - 360
    elif newHeading_Kart < -180:
        newHeadingAdjusted_Kart = newHeading_Kart + 360
    else:
        newHeadingAdjusted_Kart = newHeading_Kart

    return newHeadingAdjusted_Kart


#- Main code -#
#Interface with the GPS
gps_connection = gps3.GPSDSocket(host='127.0.0.1')
gps_fix = gps3.Fix()
#Interface with the Compass
hmc5883l = i2c_hmc5883l.i2c_hmc5883l(1)
hmc5883l.setContinuousMode()
hmc5883l.setDeclination(7, 52)

#Get the heading updates from the Arduino

#arduino=serial.Serial('/dev/ttyACM0',baudrate=9600, timeout = 3.0)
#arduino.isOpen()
compassHeading = None
while True:
    time.sleep(0.1)
    #compassHeading = arduino.readline().decode('UTF-8')
    #compassHeading = compassHeading.rstrip()
    compassHeading = get_KartHeading(hmc5883l)
    print("== Compass ==")
    print(compassHeading)
""" 
Prints compass bearing every second.
Must be run with python3. Will not work if moved out of ~/summer2015/Compass/quick2wire-python-api
Attempt to use a i2clibraries code
source: http://think-bowl.com/raspberry-pi/i2c-python-library-3-axis-digital-compass-hmc5883l-with-the-raspberry-pi/ 
"""

import time
import os
#sets environment variables
os.system("export QUICK2WIRE_API_HOME=~/summer2015/Compass/quick2wire-python-api")
os.system("export PYTHONPATH=$PYTHONPATH:$QUICK2WIRE_API_HOME")

from i2clibraries import i2c_hmc5883l

hmc5883l = i2c_hmc5883l.i2c_hmc5883l(1, 0x1e, 0.88)  #changed to 1
hmc5883l.setContinuousMode()
hmc5883l.setDeclination(-14, 42)


while True:
    time.sleep(1)
    print(hmc5883l)


# To get degrees and minutes into variables
#(degrees, minutes) = hmc5883l.getDeclination()
#(degress, minutes) = hmc5883l.getHeading()

# To get string of degrees and minutes
#declination = hmc5883l.getDeclinationString()
Exemple #22
0
from envirophat import motion, analog, leds
import time
from i2clibraries import i2c_hmc5883l

# INITIALISATION START

compass = i2c_hmc5883l.i2c_hmc5883l(1)
compass.setContinuousMode()
compass.setDeclination(1, 47)

# INITIALISATION DONE

try:
    print('started compass')
    while True:
        (heading, minutes) = compass.getHeading()
        compareHeading = motion.heading()
        print(heading, compareHeading)
        time.sleep(.2)

except KeyboardInterrupt:
    leds.off()
#- Main code -#

#File to write the data
archivo = open("coordenadas.txt","a")
archivo.write("Inicio\n")

#Interface with the controller
gamepad = InputDevice("/dev/input/event0")
print(gamepad)

#Interface with the GPS
gps_connection = gps3.GPSDSocket(host='127.0.0.1')
gps_fix = gps3.Fix()

#Interface with the Compass
hmc5883l = i2c_hmc5883l.i2c_hmc5883l(1)
hmc5883l.setContinuousMode()
hmc5883l.setDeclination(8,0)

adxl345 = i2c_adxl345.i2c_adxl345(1)

direccionFinal = 1

#Instance of the API
api = Api("carroV1")

compassHeading = None
velocity = 0
manual = True

while True:    
Exemple #24
0
 def __init__(self):
     self.hmc5883l = i2c_hmc5883l.i2c_hmc5883l(1)
     self.hmc5883l.setContinuousMode()
     self.hmc5883l.setDeclination(-20, 54)
     threading.Thread.__init__(self)