Skip to content

Commit

Permalink
Bring Develop into Master (#174)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
CleoQc authored Apr 26, 2018
1 parent 4fe818f commit 112e2c3
Show file tree
Hide file tree
Showing 31 changed files with 3,176 additions and 2,462 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -104,3 +104,4 @@ sftp-config-alt6.json
.json

.ftpconfig
.vscode/sftp.json
58 changes: 58 additions & 0 deletions Projects/MouseControl/README.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Mouse Control Project\n",
"\n",
"In this project, you'll be able to control your `GoPiGo3` robot with a ``wireless mouse``.\n",
"Make sure you connect a `wireless mouse` to your `Raspberry Pi` and then launch the script (preferably with SSH).\n",
"\n",
"![GoPiGo3 with Mouse](http://i.imgur.com/Rat5EQN.jpg)\n",
"\n",
"When the ``mouse_control_robot`` script is launched (with either Python 2 or 3), the user\n",
"is prompted to input a value which represents the mode of operation:\n",
"\n",
"* 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",
" * The `left` button of the mouse - moves the `GoPiGo3` to the left.\n",
" * The `right` button of the mouse - moves the `GoPiGo3` to the right.\n",
" * The `middle` button of the mouse - moves the `GoPiGo3` backward.\n",
" * Both the `left` & the `right` buttons of the mouse - moves the `GoPiGo3` forward.\n",
" * Not pressing any button keeps the robot stationary.\n",
"\n",
"* When the input value is `choice = 2`, the robot gets to be controlled by the mouse's movements.\n",
" * Moving the mouse `forward`, makes the `GoPiGo3` to move forward.\n",
" * Moving the mouse `backward`, makes the `GoPiGo3` to move backward.\n",
" * Moving the mouse to the `left`, makes the `GoPiGo3` to move to the left.\n",
" * Moving the mouse to the `right`, makes the `GoPiGo3` to move to the right.\n",
" * Not moving the mouse in any direction keeps the robot stationary.\n",
"\n",
"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",
"\n",
"![](http://i.imgur.com/K5ZK8fj.gif)\n"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.4.3"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
253 changes: 253 additions & 0 deletions Projects/MouseControl/mouse_control_robot.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,253 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## License\n",
" GoPiGo for the Raspberry Pi: an open source robotics platform for the Raspberry Pi.\n",
" Copyright (C) 2017 Dexter Industries\n",
"This program is free software: you can redistribute it and/or modify\n",
"it under the terms of the GNU General Public License as published by\n",
"the Free Software Foundation, either version 3 of the License, or\n",
"(at your option) any later version.\n",
"This program is distributed in the hope that it will be useful,\n",
"but WITHOUT ANY WARRANTY; without even the implied warranty of\n",
"MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n",
"GNU General Public License for more details.\n",
"You should have received a copy of the GNU General Public License\n",
"along with this program. If not, see <http://www.gnu.org/licenses/gpl-3.0.txt>."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import struct\n",
"import sys\n",
"import signal\n",
"from time import sleep\n",
"from easygopigo3 import EasyGoPiGo3\n",
"from builtins import input\n",
"import threading\n",
"import gopigo3\n",
"import atexit\n",
"\n",
"debug = False # Print raw values when debugging\n",
"signal_not_called = True # used to stop reading values from the mouse\n",
"\n",
"MOUSE_THRESH = 20 # the mouse's sensitivity - the bigger the number, the less sensible the mouse. Idem vice-versa.\n",
"\n",
"# ensure that upon exit the robot stops moving\n",
"def cleanup_func(gopigo3):\n",
" print(\"stopping GoPiGo3\")\n",
" gopigo3.stop()\n",
"\n",
"# upon exit, stop reading values from the mouse\n",
"# used in conjunction with signal_not_called var\n",
"def signal_handler(signal, frame):\n",
" print(\"stop reading mouse values\")\n",
" global signal_not_called\n",
" signal_not_called = False\n",
"\n",
"# bLeft is 1 if the left mouse button is pressed and 0 if it isn't\n",
"# bMiddle is 1 if the middle mouse button is pressed and 0 if it isn't\n",
"# bRight is 1 if the right mouse button is pressed and 0 if it isn't\n",
"# x is the position of the mouse on the x axis\n",
"# y is the position of the mouse on the y axis\n",
"def getMouseValues(file_input):\n",
"\n",
" buf = file_input.read(3)\n",
"\n",
" # if ran with Python 3\n",
" # ord function will throw an exception, since\n",
" # buf[0] already is an integer, as opposed in Python 2\n",
" # where buf[0] is a string\n",
" try:\n",
" button = ord(buf[0])\n",
" except TypeError as msg:\n",
" button = buf[0]\n",
" if debug is True:\n",
" print(str(msg))\n",
"\n",
" print(button)\n",
" left_button = (button & 0x1) > 0\n",
" middle_button = (button & 0x4) > 0\n",
" right_button = (button & 0x2) > 0\n",
" x_axis, y_axis = struct.unpack(\"bb\", buf[1:])\n",
"\n",
" if debug is True:\n",
" print(\"Left but: {}, Middle but: {}, Right but: {}, x pos: {}, y pos: {}\".format(left_button, middle_button, right_button, x_axis, y_axis))\n",
"\n",
" return (left_button, middle_button, right_button, x_axis, y_axis)\n",
"\n",
"\n",
"def Main():\n",
"\n",
" print(\" _____ _____ _ _____ ____ \")\n",
" print(\" / ____| | __ (_)/ ____| |___ \\ \")\n",
" print(\" | | __ ___ | |__) || | __ ___ __) |\")\n",
" print(\" | | |_ |/ _ \\| ___/ | | |_ |/ _ \\ |__ < \")\n",
" print(\" | |__| | (_) | | | | |__| | (_) | ___) |\")\n",
" print(\" \\_____|\\___/|_| |_|\\_____|\\___/ |____/ \")\n",
" print(\" \")\n",
"\n",
" print(\"To move the robot around using the mouse buttons press 1 and enter.\")\n",
" print(\"To move the robot around using the movements of the mouse press 2 and enter.\")\n",
"\n",
" # read data from the keyboard\n",
" # if it fails reading the right values, then the script exits\n",
" try:\n",
" choice = int(input(\"choice (1/2) = \"))\n",
" except ValueError:\n",
" print(\"Invalid number read\")\n",
" sys.exit(1)\n",
"\n",
" if not (choice == 1 or choice == 2):\n",
" print(\"Invalid number entered\")\n",
" sys.exit(1)\n",
"\n",
" # now the choice var can either be 1 or 2\n",
" # show different menus depending on the choice var\n",
" print(\"\\nWith this script you can control your GoPiGo3 robot with a wireless mouse.\")\n",
" if choice == 1:\n",
" print(\"1. Left + Right buttons of the mouse - move the GoPiGo3 forward\")\n",
" print(\"2. Left button of the mouse - move the GoPiGo3 to the left\")\n",
" print(\"3. Right button of the mouse - move the GoPiGo3 to the right\")\n",
" print(\"4. Middle button of the mouse - move the GoPiGo3 backward\")\n",
" else:\n",
" print(\"1. Move the mouse forward - for moving the GoPiGo3 forward\")\n",
" print(\"2. Move the mouse backward - for moving the GoPiGo3 backward\")\n",
" print(\"3. Move the mouse to the left - for rotating the GoPiGo3 to the left\")\n",
" print(\"4. Move the mouse to the right - for rotating the GoPiGo3 to the right\")\n",
"\n",
" # Wait for an input to start\n",
" input(\"\\nPress Enter to start\")\n",
"\n",
" # create an instance of the EasyGoPiGo3 class\n",
" # if it fails instantiating the object, then the scripts exits\n",
" try:\n",
" robot = EasyGoPiGo3()\n",
"\n",
" except IOError:\n",
" print(\"GoPiGo3 not detected\")\n",
" sys.exit(1)\n",
"\n",
" except gopigo3.FirmwareVersionError:\n",
" print(\"Please update your GoPiGo3 firmware\")\n",
" sys.exit(1)\n",
"\n",
" except Exception:\n",
" print(\"Something went wrong\")\n",
" sys.exit(1)\n",
"\n",
" # stops the robot from moving when exiting the script\n",
" # the cleanup_func is called after the signal_handler function\n",
" atexit.register(cleanup_func, gopigo3 = robot)\n",
"\n",
" print(\"\\nIn order to stop the script, press CTRL-C and move your mouse a little bit\")\n",
"\n",
" # open file for reading the continuous stream of data from the mouse\n",
" with open(\"/dev/input/mice\", \"rb\") as mouse_input:\n",
"\n",
" left_button = 0\n",
" middle_button = 0\n",
" right_button = 0\n",
" x_axis = 0\n",
" y_axis = 0\n",
"\n",
" # as long as CTRL-C hasn't been pressed\n",
" while signal_not_called:\n",
"\n",
" # read the mouse's values\n",
" # this is a blocking function\n",
" (left_button, middle_button, right_button, x_axis, y_axis) = getMouseValues(mouse_input)\n",
"\n",
" # if we have the first choice (see the menu)\n",
" if choice == 1:\n",
"\n",
" # when both the mouse's buttons are pressed\n",
" # move forward\n",
" if left_button == True and right_button == True:\n",
" robot.forward()\n",
" # when just the left button is pressed\n",
" # move to the left\n",
" elif left_button == True and right_button == False:\n",
" robot.left()\n",
" # when just the right button is pressed\n",
" # move to the right\n",
" elif left_button == False and right_button == True:\n",
" robot.right()\n",
" # when the middle button is pressed\n",
" # move backward\n",
" elif middle_button == True:\n",
" robot.backward()\n",
" # when no button is pressed\n",
" # stop the robot from moving\n",
" elif middle_button == False or (left_button == False and right_button == False):\n",
" robot.stop()\n",
"\n",
" # if we have the second choice (see the menu)\n",
" else:\n",
"\n",
" # if the mouse is moved to the left\n",
" # then move the robot to the left\n",
" if x_axis < -MOUSE_THRESH:\n",
" robot.left()\n",
" # if the mouse is moved to the right\n",
" # then move the robot to the right\n",
" elif x_axis > MOUSE_THRESH:\n",
" robot.right()\n",
" # if the mouse is moved backward\n",
" # then move the robot backward\n",
" elif y_axis < -MOUSE_THRESH:\n",
" robot.backward()\n",
" # if the mouse is moved forward\n",
" # then move the robot forward\n",
" elif y_axis > MOUSE_THRESH:\n",
" robot.forward()\n",
" # if the mouse is not moving in any direction\n",
" # then stop the robot from moving\n",
" else:\n",
" robot.stop()\n",
"\n",
" sleep(0.10)\n",
"\n",
"if __name__ == \"__main__\":\n",
" # when CTRL-C is pressed, this is will ensure signal_handler is called\n",
" signal.signal(signal.SIGINT, signal_handler)\n",
" Main()\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.4.3"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ In order to quick install the `GoPiGo3` repository, open up a terminal and type

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

2. For installing the python packages of the `GoPiGo3` without root privileges (except any other settings that can come with), use the following command:
Expand Down
2 changes: 1 addition & 1 deletion Software/C/GoPiGo3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ int GoPiGo3::get_version_hardware(char *str){
if(int error = spi_read_32(GPGSPI_MESSAGE_GET_HARDWARE_VERSION, value)){
return error;
}
sprintf(str, "%d.%d.%d", (value / 1000000), ((value / 1000) % 1000), (value % 1000));
sprintf(str, "%d.x.x", (value / 1000000));
}

int GoPiGo3::get_version_firmware(char *str){
Expand Down
6 changes: 3 additions & 3 deletions Software/C/GoPiGo3.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@
#ifndef GoPiGo3_h_
#define GoPiGo3_h_

#define FIRMWARE_VERSION_REQUIRED "0.3." // Firmware version needs to start with this
#define FIRMWARE_VERSION_REQUIRED "1.0." // Firmware version needs to start with this

#define LONGEST_I2C_TRANSFER 16 // longest possible I2C read/write
#define LONGEST_SPI_TRANSFER 24 // spi_read_string 20 chars (LONGEST_I2C_TRANSFER + 6) // longest possible message for configuring for an I2C sensor
#define LONGEST_I2C_TRANSFER 32 // longest possible I2C read/write
#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

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

Expand Down
Loading

0 comments on commit 112e2c3

Please sign in to comment.