Skip to content

Commit 112e2c3

Browse files
authored
Bring Develop into Master (#174)
* Update C++ drivers for FW version 1.0.0 * Feature/split easy libraries (#149) * add vscode to gitignore * split easygopigo3 into 2 files: easygopigo3 and easy_sensors * Bit of linting * split easygopigo3 library * change print statement to a cleaner one * remove I2C_mutex * typo * Split easygopigo3.py and create easysensors.py * Feature/overall mutex (#152) * add vscode to gitignore * split easygopigo3 into 2 files: easygopigo3 and easy_sensors * Bit of linting * split easygopigo3 library * change print statement to a cleaner one * remove I2C_mutex * typo * Split easygopigo3.py and create easysensors.py * upping version number to 1.2 * add a check for overall mutex need * Add comments about overall_mutex support * Notebooks for Mouse Controller project. Change turn_degrees blocking default (#153) * removing i2c_mutex which will be found in script_tools instead (#148) * Revert "removing i2c_mutex which will be found in script_tools instead (#148)" This reverts commit 1e9ba8f. * Revert the removal of mock packages in the docs * add 2 notebooks in Mouse Control Project * change blocking default in turn_degrees to be consistent * adjust documentation for turn_degrees blocking parameter * better handling of mutex checking (#155) * Bug/line follower (#156) * better handling of mutex checking * re-add Line Follower * Fix/overallmutex (#157) * add 2 notebooks in Mouse Control Project * change blocking default in turn_degrees to be consistent * adjust documentation for turn_degrees blocking parameter * Check overall_mutex flag each time. * Add reset method Add reset_motor_encoder as a simpler way to reset one or both motors' encoders to 0. * Fix/trickle down use mutex value (#162) * Trickle down use_mutex values when sensors are instantiated from easygopigo3 * new reconfig_bus() method (#167) * add 2 notebooks in Mouse Control Project * change blocking default in turn_degrees to be consistent * adjust documentation for turn_degrees blocking parameter * Trickle down use_mutex values when sensors are instantiated from easygopigo3 * new reconfig_bus method * remove errant print * feature - updated documentation for all the things we did (#168) * feature - first major things to modify * feature - use conda instead of pip * feature - disable deb checker * feature - being explicit is safer than being sorry * feature - clean things up * feature - more on autosummary stuff * feature - create a new index for basic API * feature - add cross-reference to disensors * feature - lots of changes * remove version support on RTD as we don't have a release system * make EasyGoPiGo3 class's documentation up-to-date * feature - small improvement to a sentence * feature - further work on easygopigo3.py docstrings * feature - add list of soon to be deprecated API * feature - improve the "deprecated api" page * feature - split the documentation into sections * feature - add note to class graphic * feature - fix description alignments * feature - split functions/classes list into multiple lists * feature - fix the tutorials section * feature - make docs more pretty * Fix/distance sensor (#169) * add 2 notebooks in Mouse Control Project * change blocking default in turn_degrees to be consistent * adjust documentation for turn_degrees blocking parameter * change the call to easyDistanceSensor
1 parent 4fe818f commit 112e2c3

31 files changed

+3176
-2462
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -104,3 +104,4 @@ sftp-config-alt6.json
104104
.json
105105

106106
.ftpconfig
107+
.vscode/sftp.json

Projects/MouseControl/README.ipynb

+58
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "markdown",
5+
"metadata": {},
6+
"source": [
7+
"# Mouse Control Project\n",
8+
"\n",
9+
"In this project, you'll be able to control your `GoPiGo3` robot with a ``wireless mouse``.\n",
10+
"Make sure you connect a `wireless mouse` to your `Raspberry Pi` and then launch the script (preferably with SSH).\n",
11+
"\n",
12+
"![GoPiGo3 with Mouse](http://i.imgur.com/Rat5EQN.jpg)\n",
13+
"\n",
14+
"When the ``mouse_control_robot`` script is launched (with either Python 2 or 3), the user\n",
15+
"is prompted to input a value which represents the mode of operation:\n",
16+
"\n",
17+
"* When the input value is `choice = 1`, the robot gets to be controlled by the mouse's buttons. Here's a list on what each combination of buttons does:\n",
18+
" * The `left` button of the mouse - moves the `GoPiGo3` to the left.\n",
19+
" * The `right` button of the mouse - moves the `GoPiGo3` to the right.\n",
20+
" * The `middle` button of the mouse - moves the `GoPiGo3` backward.\n",
21+
" * Both the `left` & the `right` buttons of the mouse - moves the `GoPiGo3` forward.\n",
22+
" * Not pressing any button keeps the robot stationary.\n",
23+
"\n",
24+
"* When the input value is `choice = 2`, the robot gets to be controlled by the mouse's movements.\n",
25+
" * Moving the mouse `forward`, makes the `GoPiGo3` to move forward.\n",
26+
" * Moving the mouse `backward`, makes the `GoPiGo3` to move backward.\n",
27+
" * Moving the mouse to the `left`, makes the `GoPiGo3` to move to the left.\n",
28+
" * Moving the mouse to the `right`, makes the `GoPiGo3` to move to the right.\n",
29+
" * Not moving the mouse in any direction keeps the robot stationary.\n",
30+
"\n",
31+
"When closing the app, press the `CTRL-C` combination of keys and move the mouse around just a little bit, so that the process stops. That's because the script uses blocking methods and while the mouse is stationary (and no buttons are pressed), the script is in a state of *\"waiting\"*. \n",
32+
"\n",
33+
"![](http://i.imgur.com/K5ZK8fj.gif)\n"
34+
]
35+
}
36+
],
37+
"metadata": {
38+
"kernelspec": {
39+
"display_name": "Python 3",
40+
"language": "python",
41+
"name": "python3"
42+
},
43+
"language_info": {
44+
"codemirror_mode": {
45+
"name": "ipython",
46+
"version": 3
47+
},
48+
"file_extension": ".py",
49+
"mimetype": "text/x-python",
50+
"name": "python",
51+
"nbconvert_exporter": "python",
52+
"pygments_lexer": "ipython3",
53+
"version": "3.4.3"
54+
}
55+
},
56+
"nbformat": 4,
57+
"nbformat_minor": 2
58+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,253 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "markdown",
5+
"metadata": {},
6+
"source": [
7+
"## License\n",
8+
" GoPiGo for the Raspberry Pi: an open source robotics platform for the Raspberry Pi.\n",
9+
" Copyright (C) 2017 Dexter Industries\n",
10+
"This program is free software: you can redistribute it and/or modify\n",
11+
"it under the terms of the GNU General Public License as published by\n",
12+
"the Free Software Foundation, either version 3 of the License, or\n",
13+
"(at your option) any later version.\n",
14+
"This program is distributed in the hope that it will be useful,\n",
15+
"but WITHOUT ANY WARRANTY; without even the implied warranty of\n",
16+
"MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n",
17+
"GNU General Public License for more details.\n",
18+
"You should have received a copy of the GNU General Public License\n",
19+
"along with this program. If not, see <http://www.gnu.org/licenses/gpl-3.0.txt>."
20+
]
21+
},
22+
{
23+
"cell_type": "code",
24+
"execution_count": null,
25+
"metadata": {},
26+
"outputs": [],
27+
"source": [
28+
"import struct\n",
29+
"import sys\n",
30+
"import signal\n",
31+
"from time import sleep\n",
32+
"from easygopigo3 import EasyGoPiGo3\n",
33+
"from builtins import input\n",
34+
"import threading\n",
35+
"import gopigo3\n",
36+
"import atexit\n",
37+
"\n",
38+
"debug = False # Print raw values when debugging\n",
39+
"signal_not_called = True # used to stop reading values from the mouse\n",
40+
"\n",
41+
"MOUSE_THRESH = 20 # the mouse's sensitivity - the bigger the number, the less sensible the mouse. Idem vice-versa.\n",
42+
"\n",
43+
"# ensure that upon exit the robot stops moving\n",
44+
"def cleanup_func(gopigo3):\n",
45+
" print(\"stopping GoPiGo3\")\n",
46+
" gopigo3.stop()\n",
47+
"\n",
48+
"# upon exit, stop reading values from the mouse\n",
49+
"# used in conjunction with signal_not_called var\n",
50+
"def signal_handler(signal, frame):\n",
51+
" print(\"stop reading mouse values\")\n",
52+
" global signal_not_called\n",
53+
" signal_not_called = False\n",
54+
"\n",
55+
"# bLeft is 1 if the left mouse button is pressed and 0 if it isn't\n",
56+
"# bMiddle is 1 if the middle mouse button is pressed and 0 if it isn't\n",
57+
"# bRight is 1 if the right mouse button is pressed and 0 if it isn't\n",
58+
"# x is the position of the mouse on the x axis\n",
59+
"# y is the position of the mouse on the y axis\n",
60+
"def getMouseValues(file_input):\n",
61+
"\n",
62+
" buf = file_input.read(3)\n",
63+
"\n",
64+
" # if ran with Python 3\n",
65+
" # ord function will throw an exception, since\n",
66+
" # buf[0] already is an integer, as opposed in Python 2\n",
67+
" # where buf[0] is a string\n",
68+
" try:\n",
69+
" button = ord(buf[0])\n",
70+
" except TypeError as msg:\n",
71+
" button = buf[0]\n",
72+
" if debug is True:\n",
73+
" print(str(msg))\n",
74+
"\n",
75+
" print(button)\n",
76+
" left_button = (button & 0x1) > 0\n",
77+
" middle_button = (button & 0x4) > 0\n",
78+
" right_button = (button & 0x2) > 0\n",
79+
" x_axis, y_axis = struct.unpack(\"bb\", buf[1:])\n",
80+
"\n",
81+
" if debug is True:\n",
82+
" print(\"Left but: {}, Middle but: {}, Right but: {}, x pos: {}, y pos: {}\".format(left_button, middle_button, right_button, x_axis, y_axis))\n",
83+
"\n",
84+
" return (left_button, middle_button, right_button, x_axis, y_axis)\n",
85+
"\n",
86+
"\n",
87+
"def Main():\n",
88+
"\n",
89+
" print(\" _____ _____ _ _____ ____ \")\n",
90+
" print(\" / ____| | __ (_)/ ____| |___ \\ \")\n",
91+
" print(\" | | __ ___ | |__) || | __ ___ __) |\")\n",
92+
" print(\" | | |_ |/ _ \\| ___/ | | |_ |/ _ \\ |__ < \")\n",
93+
" print(\" | |__| | (_) | | | | |__| | (_) | ___) |\")\n",
94+
" print(\" \\_____|\\___/|_| |_|\\_____|\\___/ |____/ \")\n",
95+
" print(\" \")\n",
96+
"\n",
97+
" print(\"To move the robot around using the mouse buttons press 1 and enter.\")\n",
98+
" print(\"To move the robot around using the movements of the mouse press 2 and enter.\")\n",
99+
"\n",
100+
" # read data from the keyboard\n",
101+
" # if it fails reading the right values, then the script exits\n",
102+
" try:\n",
103+
" choice = int(input(\"choice (1/2) = \"))\n",
104+
" except ValueError:\n",
105+
" print(\"Invalid number read\")\n",
106+
" sys.exit(1)\n",
107+
"\n",
108+
" if not (choice == 1 or choice == 2):\n",
109+
" print(\"Invalid number entered\")\n",
110+
" sys.exit(1)\n",
111+
"\n",
112+
" # now the choice var can either be 1 or 2\n",
113+
" # show different menus depending on the choice var\n",
114+
" print(\"\\nWith this script you can control your GoPiGo3 robot with a wireless mouse.\")\n",
115+
" if choice == 1:\n",
116+
" print(\"1. Left + Right buttons of the mouse - move the GoPiGo3 forward\")\n",
117+
" print(\"2. Left button of the mouse - move the GoPiGo3 to the left\")\n",
118+
" print(\"3. Right button of the mouse - move the GoPiGo3 to the right\")\n",
119+
" print(\"4. Middle button of the mouse - move the GoPiGo3 backward\")\n",
120+
" else:\n",
121+
" print(\"1. Move the mouse forward - for moving the GoPiGo3 forward\")\n",
122+
" print(\"2. Move the mouse backward - for moving the GoPiGo3 backward\")\n",
123+
" print(\"3. Move the mouse to the left - for rotating the GoPiGo3 to the left\")\n",
124+
" print(\"4. Move the mouse to the right - for rotating the GoPiGo3 to the right\")\n",
125+
"\n",
126+
" # Wait for an input to start\n",
127+
" input(\"\\nPress Enter to start\")\n",
128+
"\n",
129+
" # create an instance of the EasyGoPiGo3 class\n",
130+
" # if it fails instantiating the object, then the scripts exits\n",
131+
" try:\n",
132+
" robot = EasyGoPiGo3()\n",
133+
"\n",
134+
" except IOError:\n",
135+
" print(\"GoPiGo3 not detected\")\n",
136+
" sys.exit(1)\n",
137+
"\n",
138+
" except gopigo3.FirmwareVersionError:\n",
139+
" print(\"Please update your GoPiGo3 firmware\")\n",
140+
" sys.exit(1)\n",
141+
"\n",
142+
" except Exception:\n",
143+
" print(\"Something went wrong\")\n",
144+
" sys.exit(1)\n",
145+
"\n",
146+
" # stops the robot from moving when exiting the script\n",
147+
" # the cleanup_func is called after the signal_handler function\n",
148+
" atexit.register(cleanup_func, gopigo3 = robot)\n",
149+
"\n",
150+
" print(\"\\nIn order to stop the script, press CTRL-C and move your mouse a little bit\")\n",
151+
"\n",
152+
" # open file for reading the continuous stream of data from the mouse\n",
153+
" with open(\"/dev/input/mice\", \"rb\") as mouse_input:\n",
154+
"\n",
155+
" left_button = 0\n",
156+
" middle_button = 0\n",
157+
" right_button = 0\n",
158+
" x_axis = 0\n",
159+
" y_axis = 0\n",
160+
"\n",
161+
" # as long as CTRL-C hasn't been pressed\n",
162+
" while signal_not_called:\n",
163+
"\n",
164+
" # read the mouse's values\n",
165+
" # this is a blocking function\n",
166+
" (left_button, middle_button, right_button, x_axis, y_axis) = getMouseValues(mouse_input)\n",
167+
"\n",
168+
" # if we have the first choice (see the menu)\n",
169+
" if choice == 1:\n",
170+
"\n",
171+
" # when both the mouse's buttons are pressed\n",
172+
" # move forward\n",
173+
" if left_button == True and right_button == True:\n",
174+
" robot.forward()\n",
175+
" # when just the left button is pressed\n",
176+
" # move to the left\n",
177+
" elif left_button == True and right_button == False:\n",
178+
" robot.left()\n",
179+
" # when just the right button is pressed\n",
180+
" # move to the right\n",
181+
" elif left_button == False and right_button == True:\n",
182+
" robot.right()\n",
183+
" # when the middle button is pressed\n",
184+
" # move backward\n",
185+
" elif middle_button == True:\n",
186+
" robot.backward()\n",
187+
" # when no button is pressed\n",
188+
" # stop the robot from moving\n",
189+
" elif middle_button == False or (left_button == False and right_button == False):\n",
190+
" robot.stop()\n",
191+
"\n",
192+
" # if we have the second choice (see the menu)\n",
193+
" else:\n",
194+
"\n",
195+
" # if the mouse is moved to the left\n",
196+
" # then move the robot to the left\n",
197+
" if x_axis < -MOUSE_THRESH:\n",
198+
" robot.left()\n",
199+
" # if the mouse is moved to the right\n",
200+
" # then move the robot to the right\n",
201+
" elif x_axis > MOUSE_THRESH:\n",
202+
" robot.right()\n",
203+
" # if the mouse is moved backward\n",
204+
" # then move the robot backward\n",
205+
" elif y_axis < -MOUSE_THRESH:\n",
206+
" robot.backward()\n",
207+
" # if the mouse is moved forward\n",
208+
" # then move the robot forward\n",
209+
" elif y_axis > MOUSE_THRESH:\n",
210+
" robot.forward()\n",
211+
" # if the mouse is not moving in any direction\n",
212+
" # then stop the robot from moving\n",
213+
" else:\n",
214+
" robot.stop()\n",
215+
"\n",
216+
" sleep(0.10)\n",
217+
"\n",
218+
"if __name__ == \"__main__\":\n",
219+
" # when CTRL-C is pressed, this is will ensure signal_handler is called\n",
220+
" signal.signal(signal.SIGINT, signal_handler)\n",
221+
" Main()\n"
222+
]
223+
},
224+
{
225+
"cell_type": "code",
226+
"execution_count": null,
227+
"metadata": {},
228+
"outputs": [],
229+
"source": []
230+
}
231+
],
232+
"metadata": {
233+
"kernelspec": {
234+
"display_name": "Python 3",
235+
"language": "python",
236+
"name": "python3"
237+
},
238+
"language_info": {
239+
"codemirror_mode": {
240+
"name": "ipython",
241+
"version": 3
242+
},
243+
"file_extension": ".py",
244+
"mimetype": "text/x-python",
245+
"name": "python",
246+
"nbconvert_exporter": "python",
247+
"pygments_lexer": "ipython3",
248+
"version": "3.4.3"
249+
}
250+
},
251+
"nbformat": 4,
252+
"nbformat_minor": 2
253+
}

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ In order to quick install the `GoPiGo3` repository, open up a terminal and type
2727

2828
1. For installing the python packages of the `GoPiGo3` with root privileges (except any other settings that can come with), use the following command:
2929
```
30-
sudo sh -c "curl -kL dexterindustries.com/update_gopigo3 | bash"
30+
curl -kL dexterindustries.com/update_gopigo3 | sudo bash
3131
```
3232

3333
2. For installing the python packages of the `GoPiGo3` without root privileges (except any other settings that can come with), use the following command:

Software/C/GoPiGo3.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ int GoPiGo3::get_version_hardware(char *str){
163163
if(int error = spi_read_32(GPGSPI_MESSAGE_GET_HARDWARE_VERSION, value)){
164164
return error;
165165
}
166-
sprintf(str, "%d.%d.%d", (value / 1000000), ((value / 1000) % 1000), (value % 1000));
166+
sprintf(str, "%d.x.x", (value / 1000000));
167167
}
168168

169169
int GoPiGo3::get_version_firmware(char *str){

Software/C/GoPiGo3.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@
1212
#ifndef GoPiGo3_h_
1313
#define GoPiGo3_h_
1414

15-
#define FIRMWARE_VERSION_REQUIRED "0.3." // Firmware version needs to start with this
15+
#define FIRMWARE_VERSION_REQUIRED "1.0." // Firmware version needs to start with this
1616

17-
#define LONGEST_I2C_TRANSFER 16 // longest possible I2C read/write
18-
#define LONGEST_SPI_TRANSFER 24 // spi_read_string 20 chars (LONGEST_I2C_TRANSFER + 6) // longest possible message for configuring for an I2C sensor
17+
#define LONGEST_I2C_TRANSFER 32 // longest possible I2C read/write
18+
#define LONGEST_SPI_TRANSFER (LONGEST_I2C_TRANSFER + 6) // at least 24 for spi_read_string 20 chars, and at least LONGEST_I2C_TRANSFER + 6 for I2C transactions
1919

2020
#define SPI_TARGET_SPEED 500000 // SPI target speed of 500kbps
2121

0 commit comments

Comments
 (0)