From 34d45deae59976e933faa9a6b79fc74d705d30c1 Mon Sep 17 00:00:00 2001 From: Miclain Keffeler Date: Thu, 6 Apr 2017 11:42:24 -0500 Subject: [PATCH 1/6] Fix raw_motor_values function --- Ollie_driver.py | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) mode change 100644 => 100755 Ollie_driver.py diff --git a/Ollie_driver.py b/Ollie_driver.py old mode 100644 new mode 100755 index a56dec5..c75a34c --- a/Ollie_driver.py +++ b/Ollie_driver.py @@ -2,7 +2,7 @@ from bluepy import btle -# import bluetooth +#import bluetooth import sys import struct import time @@ -149,11 +149,11 @@ def __init__(self, deviceAddress): # This startup sequence is also identical to the one for Ollie. # It even uses the same unlock code. - print 'Sending antidos' + print ('Sending antidos') self.antidos.write('011i3', withResponse=True) - print 'Sending txpower' + print ('Sending txpower') self.txpower.write('\x0007', withResponse=True) - print 'Sending wakecpu' + print ('Sending wakecpu') self.wakecpu.write('\x01', withResponse=True) def getSpheroCharacteristic(self, fragment): @@ -161,9 +161,9 @@ def getSpheroCharacteristic(self, fragment): def dumpCharacteristics(self): for s in self.peripheral.getServices(): - print s + print (s) for c in s.getCharacteristics(): - print c, hex(c.handle) + print (c, hex(c.handle)) def cmd(self, did, cid, data=[], answer=True, resetTimeout=True): # Commands are as specified in Sphero API 1.50 PDF. @@ -178,7 +178,7 @@ def cmd(self, did, cid, data=[], answer=True, resetTimeout=True): chk ^= 255 msg = [0xff, sop2, did, cid, seq, dlen] + data + [chk] - print 'cmd:', ' '.join([chr(c).encode('hex') for c in msg]) + print ('cmd:', ' '.join([chr(c).encode('hex') for c in msg])) # Note: withResponse is very important. Most commands won't work without it. self.roll.write(''.join([chr(c) for c in msg]), withResponse=True) @@ -240,8 +240,8 @@ def __init__(self, target_name='Sphero'): threading.Thread.__init__(self) self.target_name = target_name self.bt = None - # Use "sudo hcitool lescan" to find Ollie's MAC address input it at deviceAddress = - self.deviceAddress = 'DF:79:DD:9C:B6:1D' + # Use "sudo hcitool lescan" to find Ollie's MAC address input it at deviceAddress = 'EC:61:42:58:09:41' + self.deviceAddress = 'EC:61:42:58:09:41' self.shutdown = False self.is_connected = False self.mask_list = None @@ -575,7 +575,7 @@ def set_data_strm(self, sample_div, sample_frames, sample_mask1, pcnt, sample_ma self.create_mask_list(sample_mask1, sample_mask2) self.stream_mask1 = sample_mask1 self.stream_mask2 = sample_mask2 - print data + print (data) self.send(data, response) def set_filtered_data_strm(self, sample_div, sample_frames, pcnt, response): @@ -738,7 +738,7 @@ def set_raw_motor_values(self, l_mode, l_power, r_mode, r_power, response): brake, 0x04 - ignored. :param power: 0-255 scalar value (units?). """ - self.send(self.pack_cmd(REQ['CMD_RAW_MOTORS'], [l_mode, l_power, r_mode, r_power]), response) + self.send(self.pack_cmd(REQ['CMD_SET_RAW_MOTORS'], [l_mode, l_power, r_mode, r_power]), response) def send(self, data, response): """ @@ -829,7 +829,7 @@ def recv(self, num_bytes): data = self.raw_data_buf while len(data) > 5: if data[:2] == RECV['SYNC']: - print "got response packet" + print ("got response packet") # response packet data_length = ord(data[4]) if data_length + 5 <= len(data): @@ -857,7 +857,7 @@ def recv(self, num_bytes): IDCODE['PWR_NOTIFY']): self._async_callback_dict[IDCODE['PWR_NOTIFY']](self.parse_pwr_notify(data_packet, data_length)) else: - print "got a packet that isn't streaming" + print ("got a packet that isn't streaming") else: raise RuntimeError("Bad SOF : " + self.data2hexstr(data)) self.raw_data_buf = data @@ -918,8 +918,8 @@ def parse_data_strm(self, data, data_length): for i in range((data_length - 1) / 2): unpack = struct.unpack_from('>h', ''.join(data[5 + 2 * i:])) output[self.mask_list[i]] = unpack[0] - print self.mask_list - print output + print (self.mask_list) + print (output) return output From 5273c1f4896f19af8576e1fb32ef0c2567b726c3 Mon Sep 17 00:00:00 2001 From: Miclain Keffeler Date: Thu, 6 Apr 2017 11:43:51 -0500 Subject: [PATCH 2/6] Add ability to turn via i,j,k and l to Ollietest --- Ollietest.py | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) mode change 100644 => 100755 Ollietest.py diff --git a/Ollietest.py b/Ollietest.py old mode 100644 new mode 100755 index 57cdb96..2aac77b --- a/Ollietest.py +++ b/Ollietest.py @@ -1,5 +1,4 @@ #!/usr/bin/python -from bluepy import btle import struct import time import Ollie_driver @@ -16,7 +15,20 @@ time.sleep(1) ollie.set_rgb_led(0,0,255,0,False) time.sleep(3) +ollie.set_stablization(False,'False') +while 1: + key = raw_input("what is your character") + if(key == "l"): + ollie.set_raw_motor_values(1,60,1,40,'01h') + if(key== "j"): + ollie.set_raw_motor_values(1,40,1,60,'01h') + if(key== "i"): + ollie.set_raw_motor_values(1,60,1,60,'01h') + if(key == "k"): + ollie.set_raw_motor_values(2,60,2,60,'01h') + if(key=='g'): + break +time.sleep(5) ollie.join() -ollie.disconnect() sys.exit(1) From ef87f3199b9215f66c643dd38818e18e714a9ed2 Mon Sep 17 00:00:00 2001 From: Miclain K Keffeler Date: Sun, 9 Apr 2017 17:36:38 -0500 Subject: [PATCH 3/6] Update README.md Describe Installation and Setup --- README.md | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index bc257ac..dcc85fe 100644 --- a/README.md +++ b/README.md @@ -1,15 +1,22 @@ # SpheroOllie-python -**Sphero's Ollie** +A library of functions to be used with the Sphero Ollie! -Now even better with a python API library! +#Setup +Run the following commands in your terminal. You must be running this on a computer that has Bluetooth LE (Different from standard bluetooth) +'sudo apt-get install python-pip libglib2.0-dev build-essential git' +'sudo pip install bluepy' +'git clone https://github.com/mkkeffeler/SpheroOllie-python' +'git checkout patch_branch' -Use "sudo hcitool lescan" to find Ollie's MAC address -input it at "`deviceAddress =`" (line 244) in the Sphero class in Ollie_driver.py +#Getting Ready +Use 'sudo hcitool lescan' to find Ollie's MAC address -** +input this device address "`deviceAddress =`" (line 244) in the Sphero class in Ollie_driver.py -***Included Scripts:*** +Currently, Ollietest.py allows you to direct your Ollie where to go using the I J K and L keys. The G key is used to end the program. + +***Included Scripts:*** ** **OllieTest.py** A simple program that connects to Ollie and flashes the internal RGB LED red to green to blue. You can take it a step further and add `ollie.roll` commands to make him move using the API. @@ -17,7 +24,7 @@ A simple program that connects to Ollie and flashes the internal RGB LED red to **OlliejoyDrive.py** *requires PyGame library* -Allow you to drive Ollie with a joystick/gamepad. +Allows you to drive Ollie with a joystick/gamepad. Shows on screen feedback of analog stick as well as speed and heading Currently setup for a Xbox 360 controller. From 7ffd91201d341cd1a7a02a5a8192288ab1ef74f4 Mon Sep 17 00:00:00 2001 From: Miclain K Keffeler Date: Sun, 9 Apr 2017 17:46:33 -0500 Subject: [PATCH 4/6] UPDATE README.md Update README --- README.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index dcc85fe..645feb3 100644 --- a/README.md +++ b/README.md @@ -3,13 +3,13 @@ A library of functions to be used with the Sphero Ollie! #Setup Run the following commands in your terminal. You must be running this on a computer that has Bluetooth LE (Different from standard bluetooth) -'sudo apt-get install python-pip libglib2.0-dev build-essential git' -'sudo pip install bluepy' -'git clone https://github.com/mkkeffeler/SpheroOllie-python' -'git checkout patch_branch' +`sudo apt-get install python-pip libglib2.0-dev build-essential git` +`sudo pip install bluepy` +`git clone https://github.com/mkkeffeler/SpheroOllie-python` +`git checkout patch_branch` #Getting Ready -Use 'sudo hcitool lescan' to find Ollie's MAC address +Use `sudo hcitool lescan` to find Ollie's MAC address input this device address "`deviceAddress =`" (line 244) in the Sphero class in Ollie_driver.py From 81b2900bb2d43b9c3e8a7971826f45874f370378 Mon Sep 17 00:00:00 2001 From: Miclain K Keffeler Date: Sun, 9 Apr 2017 17:47:29 -0500 Subject: [PATCH 5/6] Update README.md --- README.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 645feb3..1e829ea 100644 --- a/README.md +++ b/README.md @@ -2,11 +2,11 @@ A library of functions to be used with the Sphero Ollie! #Setup -Run the following commands in your terminal. You must be running this on a computer that has Bluetooth LE (Different from standard bluetooth) -`sudo apt-get install python-pip libglib2.0-dev build-essential git` -`sudo pip install bluepy` -`git clone https://github.com/mkkeffeler/SpheroOllie-python` -`git checkout patch_branch` +Run the following commands in your terminal. You must be running this on a computer that has Bluetooth LE (Different from standard bluetooth)
+`sudo apt-get install python-pip libglib2.0-dev build-essential git`
+`sudo pip install bluepy`
+`git clone https://github.com/mkkeffeler/SpheroOllie-python`
+`git checkout patch_branch`

#Getting Ready Use `sudo hcitool lescan` to find Ollie's MAC address From d2bc21b5c344f508b2f39353e440c99cc395c382 Mon Sep 17 00:00:00 2001 From: Miclain K Keffeler Date: Tue, 11 Apr 2017 14:38:49 -0500 Subject: [PATCH 6/6] Update README.md --- README.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/README.md b/README.md index 1e829ea..e823e93 100644 --- a/README.md +++ b/README.md @@ -45,3 +45,11 @@ Tie in the btle handleNotifcations to Sphero response API - getting sensor info, command responses, etc. back from Ollie +#Common Errors +If `sudo hcitool lescan` throws an error involving 'input/output error' perform the following commands and try again + +`sudo systemctl daemon-reload`

+`sudo hciconfig hci0 down`

+`sudo hciconfig hci0 up`

+ +If that doesn't work please open an issue with details.