def connect(): ipcon = IPConnection() # Create IP connection gps = GPS(UID, ipcon) # Create device object ipcon.connect(HOST, PORT) # Connect to brickd # Don't use device before ipcon is connected print('GPS Bricklet connected...') return gps, ipcon
def cb_enumerate(uid, connected_uid, position, hardware_version, firmware_version, device_identifier, enumeration_type): if connected_uid == '0': print 'Master Brick UID: \t%s' % (uid) #print 'UID: %s' % uid #print 'connected_uid: %s' % connected_uid #print 'position: %s' % position #print 'hardware_version: %i.%i.%i' % hardware_version #print 'firmware_version: %i.%i.%i' % firmware_version #print 'device_identifier: %d' % device_identifier #print 'enumeration_type: %d' % enumeration_type if enumeration_type == IPConnection.ENUMERATION_TYPE_CONNECTED or \ enumeration_type == IPConnection.ENUMERATION_TYPE_AVAILABLE: # Enumeration is for IMU Brick if device_identifier == IMU.DEVICE_IDENTIFIER: print 'IMU Brick UID: \t\t%s' % (uid) # Create imu device object imu = IMU(uid, ipcon) imu.set_all_data_period(100) imu.register_callback(imu.CALLBACK_ALL_DATA, cb_imudynamic) # Enumeration is for GPS Bricklet if device_identifier == GPS.DEVICE_IDENTIFIER: print 'GPS Bricklet UID: \t%s' % (uid) # Create imu device object gps = GPS(uid, ipcon) gps.set_coordinates_callback_period(100) gps.register_callback(gps.CALLBACK_COORDINATES, cb_coordinates)
PORT = 4223 UID = "ABC" # Change to your UID from tinkerforge.ip_connection import IPConnection from tinkerforge.bricklet_gps import GPS # Callback function for coordinates def cb_coordinates(latitude, ns, longitude, ew, pdop, hdop, vdop, epe): print('Latitude: ' + str(latitude / 1000000.0) + '° ' + ns) print('Longitude: ' + str(longitude / 1000000.0) + '° ' + ew) if __name__ == "__main__": ipcon = IPConnection() # Create IP connection gps = GPS(UID, ipcon) # Create device object ipcon.connect(HOST, PORT) # Connect to brickd # Don't use device before ipcon is connected # Set Period for coordinates callback to 1s (1000ms) # Note: The callback is only called every second if the # coordinates have changed since the last call! gps.set_coordinates_callback_period(1000) # Register coordinates callback to function cb_coordinates gps.register_callback(gps.CALLBACK_COORDINATES, cb_coordinates) raw_input('Press key to exit\n') # Use input() in Python 3 ipcon.disconnect()
HOST = "localhost" PORT = 4223 UID = "ABC" # Change to your UID from tinkerforge.ip_connection import IPConnection from tinkerforge.bricklet_gps import GPS # Callback function for coordinates def cb_coordinates(latitude, ns, longitude, ew, pdop, hdop, vdop, epe): print('Latitude: ' + str(latitude/1000000.0) + '° ' + ns) print('Longitude: ' + str(longitude/1000000.0) + '° ' + ew) if __name__ == "__main__": ipcon = IPConnection() # Create IP connection gps = GPS(UID, ipcon) # Create device object ipcon.connect(HOST, PORT) # Connect to brickd # Don't use device before ipcon is connected # Set Period for coordinates callback to 1s (1000ms) # Note: The callback is only called every second if the # coordinates have changed since the last call! gps.set_coordinates_callback_period(1000) # Register coordinates callback to function cb_coordinates gps.register_callback(gps.CALLBACK_COORDINATES, cb_coordinates) raw_input('Press key to exit\n') # Use input() in Python 3 ipcon.disconnect()
if msg_header[0] == msg_index - 1: sms_reply_to = msg_header[2] break except: print 'ERROR: Failed to process received SMS' return try: modem.sms_send(sms_reply_to, msg_body_send) except: # Ignore exceptions pass time.sleep(2) mm = ModemManager( sys.argv[1], PIN_SIM) # You can keep the PIN as empty string if PIN is disabled mm.register_new_sms_callback( cb_new_sms) # Register a callback for new SMS arrival event ipcon = IPConnection() # Create IP connection gps = GPS(UID, ipcon) # Create device object ipcon.connect(HOST, PORT) # Connect to brickd # Don't use device before ipcon is connected raw_input('Press any key to exit...\n') # Use input() in Python 3 mm.stop_prober() ipcon.disconnect()
#!/usr/bin/env python # -*- coding: utf-8 -*- from tinkerforge.ip_connection import IPConnection from tinkerforge.bricklet_gps import GPS from settings import HOST, PORT, GPSUID from array import array ipcon = IPConnection(HOST, PORT) # Create ip connection to brickd gps = GPS(GPSUID) # Create device object ipcon.add_device(gps) # Add device to ip connection coords = gps.get_coordinates() lon = coords.longitude/1000000.0 lat = coords.latitude/1000000.0 print('Latitude: ' + str(lat) + '° ' + coords.ns) print('Longitude: ' + str(lon/1000000.0) + '° ' + coords.ew) if coords.ns == "S": lat = 0 - lat if coords.ew == "W": lon = 0 - lon arr = array(lat, lon) try: # This will create a new file or **overwrite an existing file**. f = open("location.txt", "w") try: arr.tofile(f) finally:
if fix == 3 or fix == 2: enable = True else: enable = False print("stop!!!1") servo.set_position(steeringsrv, mid) servo.set_position(motor, stop) if __name__ == "__main__": enable = False ipcon = IPConnection(HOST, PORT) # Create ip connection to brickd gps = GPS(GPSUID) # Create device object ipcon.add_device(gps) # Add device to ip connection servo = Servo(SERVOUID) # Create device object ipcon.add_device(servo) # Add device to IP connection # Don't use device before it is added to a connection servo.set_degree(motor, -9000, 9000) servo.set_pulse_width(motor, 950, 1950) servo.set_period(motor, 20000) servo.set_acceleration(motor, 7000) servo.set_velocity(motor, 0xFFFF) # Full speed servo.set_degree(steeringsrv, -3600, 3600) servo.set_pulse_width(steeringsrv, 955, 2000) servo.set_period(steeringsrv, 20000) servo.set_acceleration(steeringsrv, 7000) # Full acceleration 0xFFFF servo.set_velocity(steeringsrv, 0xFFFF) # Full speed