def __init__(self, target_name,default_update_rate=50):#, target_addr, port, default_update_rate=50.0): self.update_rate = default_update_rate self.sampling_divisor = int(400/self.update_rate) self.is_connected = False self._init_pubsub() self._init_params() self.robot = BB8_driver.Sphero(target_name) # if target_name: # if target_addr: # if port: # self.robot = BB8_driver.Sphero(target_name, target_addr, port) # else: # self.robot = BB8_driver.Sphero(target_name, target_addr) # else: # self.robot = BB8_driver.Sphero(target_name) # else: # self.robot = BB8_driver.Sphero() self.imu = Imu() self.imu.orientation_covariance = [1e-6, 0, 0, 0, 1e-6, 0, 0, 0, 1e-6] self.imu.angular_velocity_covariance = [1e-6, 0, 0, 0, 1e-6, 0, 0, 0, 1e-6] self.imu.linear_acceleration_covariance = [1e-6, 0, 0, 0, 1e-6, 0, 0, 0, 1e-6] self.last_cmd_vel_time = rospy.Time.now() self.last_diagnostics_time = rospy.Time.now() self.cmd_heading = 0 self.cmd_speed = 0 self.power_state_msg = "No Battery Info" self.power_state = 0 self.prev_ODOM_X = None self.prev_ODOM_Y = None
def __init__(self, irc, server, channel, nick, password, debug=False): self.irc = irc self.server = server self.channel = channel self.nick = nick self.password = password self.debug = debug self.sphero = BB8_driver.Sphero() self.bt = False
def __init__(self): pygame.mixer.init() #pygame.mixer.music.load('sounds/connect.mp3') #pygame.mixer.music.play() self.bb8 = BB8_driver.Sphero() self.bb8.connect() self.bb8.start() time.sleep(2) self.flash_green(ntimes=2)
def do_connect(self, line): if self.sp: print "Already connected!" return False print "Connecting ..." self.sp = BB8_driver.Sphero() try: self.sp.connect() except btle.BTLEException, e: print "BT FAIL:", e self.sp = None return
def alarm(): speed = 20 bb8 = BB8_driver.Sphero() bb8.connect() bb8.start() #bb8.roll(speed, 40, 1, False) bb8.set_rgb_led(255, 0, 0, 0, False) time.sleep(1) bb8.set_rgb_led(0, 255, 0, 0, False) time.sleep(1) #bb8.roll(speed, 320, 1, False) bb8.set_rgb_led(0, 255, 255, 0, False) time.sleep(1) bb8.set_rgb_led(255, 0, 0, 0, False) time.sleep(1) bb8.set_rgb_led(0, 255, 0, 0, False) #bb8.roll(speed, 0, 1, False) time.sleep(1) bb8.join() bb8.disconnect()
import cwiid import time import BB8_driver import matplotlib.pyplot as pyplot import numpy import sys modes = ["tank"] print("Please connect the Wiimote now.") wm = cwiid.Wiimote() print("Wiimote successfully connected") wm.rpt_mode = cwiid.RPT_BTN | cwiid.RPT_ACC bb8 = BB8_driver.Sphero() a = None print("Connecting to BB-8") try: bb8.connect() except: print("Connection failed. Escaping script.") sys.exit(1) bb8.ping(True) print("Connection Successful") bb8.start() print("Hold Wiimote in horizontal equillibrium for calibration.") time.sleep(3)
#!/usr/bin/python # -*- coding: utf-8 -*- from bluepy import btle import struct import time import BB8_driver import sys bb8 = BB8_driver.Sphero('F5:6B:10:17:17:17') #bb = BB8('F5:6B:10:17:17:17') bb8.connect() bb8.start() time.sleep(2) bb8.set_rgb_led(255, 0, 0, 0, False) time.sleep(1) bb8.set_rgb_led(0, 255, 0, 0, False) time.sleep(1) bb8.set_rgb_led(0, 0, 255, 0, False) time.sleep(3) bb8.join() bb8.disconnect() sys.exit(1)
class Server(): def __init__(self, Adress=('', 5000), MaxClient=1): self.s = socket.socket() self.s.bind(Adress) self.s.listen(MaxClient) def WaitForConnection(self): print('Waiting for connection from client...') self.Client, self.Adr = (self.s.accept()) print('Got a connection from: ' + str(self.Client) + '.') print('Waiting for connection to Sphero...') robot = BB8_driver.Sphero() robot.connect() robot.start() time.sleep(2) robot.set_rgb_led(0, 255, 0, 0, False) robot.set_back_led(255, False) s = Server() s.WaitForConnection() print('Waiting for command... ') #time.sleep(5) #robot.set_back_led(0, False) #robot.disconnect() while 1 == 1: