Ejemplo n.º 1
0
UID = "rkQ"  # Change XYZ to the UID of your Temperature Bricklet
UID1 = "j6b"
UID2 = "maf"

from ip_connection import IPConnection
from bricklet_temperature import BrickletTemperature
from bricklet_dual_button import BrickletDualButton
from bricklet_ambient_light import BrickletAmbientLight

if __name__ == "__main__":
    ipcon = IPConnection()  # Create IP connection
    t = BrickletTemperature(UID, ipcon)  # Create device object
    db = BrickletDualButton(UID1, ipcon)
    al = BrickletAmbientLight(UID2, ipcon)

    ipcon.connect(HOST, PORT)  # Connect to brickd
    # Don't use device before ipcon is connected

    while True:
        # Get current temperature (unit is °C/100)
        temperature = t.get_temperature()
        illuminance = al.get_illuminance()

        print("Temperature: " + str(temperature / 100.0) + " °C")
        print("Illuminance: " + str(illuminance / 10.0) + " Lux")

        if ((illuminance / 10.0) > 250):
            y = 2
        else:
            y = 3
Ejemplo n.º 2
0
    def __init__(self):
        ipcon = IPConnection()
        ipcon.connect(HOST, PORT)
            
        ipcon.register_callback(IPConnection.CALLBACK_ENUMERATE, self.cb_enumerate)

        ipcon.enumerate()
        i = 0
        while self.imu_uid == None:
            time.sleep(0.1)
            i += 1
            if i == 20:
                print "Didn't find IMU, exiting"
                return
        
        self.s = Servo('9TZyPftcTLE', ipcon)
        self.i = IMU(self.imu_uid, ipcon)
    
        self.s.set_output_voltage(self.SERVO_VOLTAGE)
        for servo in self.servos.values():
            self.s.set_pulse_width(servo[0], servo[1][0], servo[1][1])
            self.s.set_degree(servo[0], servo[2][0], servo[2][1])
            self.s.set_velocity(servo[0], 0xFFFF) 
            self.s.set_acceleration(servo[0], 0xFFFF) 
            self.s.set_position(servo[0], 0)
            self.s.enable(servo[0])
    
        time.sleep(1)
        
        self.write_gyr_bias()
        time.sleep(0.2)
        self.calibrate_gyr_bias()
        self.write_gyr_bias()

        self.write_gyr_gain()
        time.sleep(0.2)
        self.calibrate_gyr_gain()
        self.write_gyr_gain()
        
        self.write_acc() # default
        time.sleep(0.2)
        self.calibrate_acc()
        self.write_acc() # new calibration
        
        text = """# Each line starts with "calibration type:"
# followed by the x, y and z calibration, separated by a comma.
# Multiplier and Divider are written as "mul/div"

"""
        
        c = []
        for num in range(6):
            c.append(self.i.get_calibration(num))
            
            
        text += '0: ' + str(c[0][0]) + '/' + str(c[0][3]) + ', ' + str(c[0][1]) + '/' + str(c[0][4]) + ', ' + str(c[0][2]) + '/' + str(c[0][5])
        text += '\n'
        text += '1: ' + str(c[1][0]) + ', ' + str(c[1][1]) + ', ' + str(c[1][2])
        text += '\n'
        text += '2: ' + str(c[2][0]) + '/' + str(c[2][3]) + ', ' + str(c[2][1]) + '/' + str(c[2][4]) + ', ' + str(c[2][2]) + '/' + str(c[2][5])
        text += '\n'
        text += '3: ' + str(c[3][0]) + ', ' + str(c[3][1]) + ', ' + str(c[3][2])
        text += '\n'
        text += '4: ' + str(c[4][0]) + '/' + str(c[4][3]) + ', ' + str(c[4][1]) + '/' + str(c[4][4]) + ', ' + str(c[4][2]) + '/' + str(c[4][5])
        text += '\n'
        text += '5: ' + str(c[5][0]) + ', ' + str(c[5][1]) + ', ' + str(c[5][2]) + ', ' + str(c[5][3]) + ', ' + str(c[5][4]) + ', ' + str(c[5][5]) + ', ' + str(c[5][6]) + ', ' + str(c[5][7])
        
        f = file(self.imu_uid + '.txt', 'w')
        f.write(text)
        f.close()
Ejemplo n.º 3
0
    def __init__(self):
        ipcon = IPConnection()
        ipcon.connect(HOST, PORT)

        ipcon.register_callback(IPConnection.CALLBACK_ENUMERATE,
                                self.cb_enumerate)

        ipcon.enumerate()
        i = 0
        while self.imu_uid == None:
            time.sleep(0.1)
            i += 1
            if i == 20:
                print "Didn't find IMU, exiting"
                return

        self.s = Servo('9TZyPftcTLE', ipcon)
        self.i = IMU(self.imu_uid, ipcon)

        self.s.set_output_voltage(self.SERVO_VOLTAGE)
        for servo in self.servos.values():
            self.s.set_pulse_width(servo[0], servo[1][0], servo[1][1])
            self.s.set_degree(servo[0], servo[2][0], servo[2][1])
            self.s.set_velocity(servo[0], 0xFFFF)
            self.s.set_acceleration(servo[0], 0xFFFF)
            self.s.set_position(servo[0], 0)
            self.s.enable(servo[0])

        time.sleep(1)

        self.write_gyr_bias()
        time.sleep(0.2)
        self.calibrate_gyr_bias()
        self.write_gyr_bias()

        self.write_gyr_gain()
        time.sleep(0.2)
        self.calibrate_gyr_gain()
        self.write_gyr_gain()

        self.write_acc()  # default
        time.sleep(0.2)
        self.calibrate_acc()
        self.write_acc()  # new calibration

        text = """# Each line starts with "calibration type:"
# followed by the x, y and z calibration, separated by a comma.
# Multiplier and Divider are written as "mul/div"

"""

        c = []
        for num in range(6):
            c.append(self.i.get_calibration(num))

        text += '0: ' + str(c[0][0]) + '/' + str(c[0][3]) + ', ' + str(
            c[0][1]) + '/' + str(c[0][4]) + ', ' + str(c[0][2]) + '/' + str(
                c[0][5])
        text += '\n'
        text += '1: ' + str(c[1][0]) + ', ' + str(c[1][1]) + ', ' + str(
            c[1][2])
        text += '\n'
        text += '2: ' + str(c[2][0]) + '/' + str(c[2][3]) + ', ' + str(
            c[2][1]) + '/' + str(c[2][4]) + ', ' + str(c[2][2]) + '/' + str(
                c[2][5])
        text += '\n'
        text += '3: ' + str(c[3][0]) + ', ' + str(c[3][1]) + ', ' + str(
            c[3][2])
        text += '\n'
        text += '4: ' + str(c[4][0]) + '/' + str(c[4][3]) + ', ' + str(
            c[4][1]) + '/' + str(c[4][4]) + ', ' + str(c[4][2]) + '/' + str(
                c[4][5])
        text += '\n'
        text += '5: ' + str(c[5][0]) + ', ' + str(c[5][1]) + ', ' + str(
            c[5][2]) + ', ' + str(c[5][3]) + ', ' + str(c[5][4]) + ', ' + str(
                c[5][5]) + ', ' + str(c[5][6]) + ', ' + str(c[5][7])

        f = file(self.imu_uid + '.txt', 'w')
        f.write(text)
        f.close()
import os, json, datetime, time, csv
from ip_connection import IPConnection
from bricklet_temperature import Temperature

HOST = "10.50.3.253"
PORT = 4223
UID = "ns2"
UID2 = "nNJ"

ipcon = IPConnection()
ipcon.connect(HOST, PORT)
temp1 = Temperature(UID,ipcon)
temp2 = Temperature(UID2,ipcon)


def write_csv_log(dict):
    os.getcwd()
    print "Writing file!"
    with open('temp_data.csv', 'wb') as f:
        w = csv.writer(f, delimiter=',')
        w.writerow([1])
        f.flush()
        f.close()
    return 0

def read_sensor(sensor_alias):
    value = None
    try:
        value = sensor_alias.get_temperature()/100.0
    except:
        print "Some Error!"
Ejemplo n.º 5
0
#!/usr/bin/env python
# -*- coding: utf-8 -*-

HOST = "localhost"
PORT = 4223
UID = "5551"

from ip_connection import IPConnection
from bricklet_can import BrickletCAN

# Callback function for frame read callback
def cb_frame_read(can, frame_type, identifier, data, length):
    can.write_frame(frame_type, identifier, data, length)

if __name__ == "__main__":
    ipcon = IPConnection() # Create IP connection
    can = BrickletCAN(UID, ipcon) # Create device object

    ipcon.connect(HOST, PORT) # Connect to brickd
    # Don't use device before ipcon is connected

    # Register frame read callback to function cb_frame_read
    can.register_callback(can.CALLBACK_FRAME_READ, lambda *args: cb_frame_read(can, *args))

    # Enable frame read callback
    can.enable_frame_read_callback()

    raw_input("Press key to exit\n") # Use input() in Python 3
    can.disable_frame_read_callback()
    ipcon.disconnect()