-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
fafd70e
commit 3521c23
Showing
48 changed files
with
4,754 additions
and
0 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
FROM ros:melodic | ||
|
||
RUN apt-get update -y && apt-get install -y ros-melodic-compressed-image-transport | ||
RUN apt-get update -y && apt-get install -y python-pip | ||
RUN pip install tensorflow keras | ||
WORKDIR /root/projects/ | ||
RUN echo 'catkin_make install && source /root/projects/devel/setup.bash' >> /root/.bashrc |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
# ROS ROBOBO FOR LEARNING MACHINES | ||
|
||
Note, if you feel like not using this path but installing directly on your system, you are free to do it, but you are on your own. | ||
|
||
## Download/Install requirements | ||
Here are the instructions to have the simulation system running. | ||
|
||
- Download VREP from [here](http://coppeliarobotics.com/previousVersions), V-REP PRO EDU V3.5.0 rev4 | ||
- extract folder anywhere, where you preferer | ||
- make sure you have the the version 3.5, other versions may not work properly | ||
|
||
- Download `Robobo_Scene.ttt` and `Robobo_Model.ttm` files and place them inside your VREP folder | ||
- place `Robobo_Scene.ttt` file in `VREP/scenes` | ||
- place `Robobo_Model.ttm` file in `VREP/models/robots/mobile` | ||
|
||
- Download docker | ||
- Linux: download from your package manager | ||
- OsX: register and download from [here](https://hub.docker.com/editions/community/docker-ce-desktop-mac) | ||
- Windows PRO: register and download from [here](https://hub.docker.com/editions/community/docker-ce-desktop-windows) | ||
- Windows HOME: register and download from [here](https://docs.docker.com/toolbox/toolbox_install_windows/) | ||
|
||
- Download git + Editor | ||
|
||
- Download [repository](https://github.com/ci-group/learning_machines_robobo) | ||
``` | ||
git clone https://github.com/ci-group/learning_machines_robobo.git | ||
``` | ||
|
||
## Running | ||
Now you downloaded everything, you can start the environment | ||
|
||
- Start docker | ||
- Linux/systemd: start docker daemon | ||
- OsX/Windows: open docker app | ||
|
||
- Start docker container (this will open a terminal with python and all required libraries installed). This step could take a while, since first your computer will download the docker image from the internet, secondly will compile some stuff from your project folder. | ||
- Linux/OsX, open a terminal in the **learning_machines_robobo** project folder and type: | ||
``` | ||
./start-docker.sh | ||
``` | ||
- Windows, open CMD and change directory to the <strong>learning_machines_robobo</strong> project folder, and type: | ||
``` | ||
start-docker.bat | ||
``` | ||
- Start VREP | ||
- open the program | ||
- open the scene file that you downloaded before: Robobo_Scene.ttt | ||
- enable Real Time button (optional) | ||
- start the simulation with the play button | ||
- Fix the script: inside the project folder, open the file `src/send_commands.py` and | ||
- ~~remove the line in which I create a connection to an hardware robot~~ | ||
- fix the line of the connection to the simulated robot to have your local machine ip (localhost or 127.0.0.1 will not work because of docker. Connect to your home network and use the IP that the router will give you) | ||
- Run the script | ||
- inside the docker container running, type | ||
``` | ||
./src/send_commands.py | ||
``` | ||
- Change the script, experiment and HAVE FUN :D | ||
# Windows HOME + Docker Toolbox | ||
If you are having problems with Windows HOME, follow this guide it may fix your issues | ||
You need to change the file `start-docker.bat` changing from | ||
```bat | ||
SET project_folder=%~dp0 | ||
docker run --rm -it -v %project_folder%:/root/projects cigroup/learning-machines bash | ||
``` | ||
to | ||
```bat | ||
SET project_folder=/c/Users/YourUser/path/to/learning_machines_robobo | ||
docker run --rm -it -v %project_folder%:/root/projects cigroup/learning-machines bash | ||
``` | ||
where your project is in the folder `C:\Users\YourUser\path\to\learning_machines_robobo`. Change this variable accordingly to your own username and path to the project folder. You cannot use folders outside `C:\Users\` and remember to change all backslasesh (`\`) to forward slashes (`/`). | ||
|
||
# Informations to run this project alternatevely | ||
|
||
## Setup (with ros image) | ||
|
||
- start docker with `docker run --rm -it -v "${PROJECT_FOLDER}:/root/projects/" cigroup/learning-machines bash` | ||
- change folder to `/root/projects/` (inside docker) | ||
- run `catkin_make install` (only run for the first setup, it's not needed even across different docker containers) | ||
- run `source devel/setup.bash` | ||
- run `src/send_commands.py` command to test the connection | ||
|
||
### Important Notes | ||
|
||
The environment variable `ROS_MASTER_URI` idendifies where the ROS MASTER NODE is running. Verify that your phone is in "Local ROS Master" and adjust the IP of the `ROS_MASTER_URI` variable with the address of the phone (visible at the first page of the application). | ||
|
||
The library we provide is already taking care of this enviroment variable, but in case you encouter any problems you know where to look for. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from .prey_controller import Prey |
Binary file added
BIN
+206 Bytes
learning_machines_robobo-master/src/prey/__pycache__/__init__.cpython-37.pyc
Binary file not shown.
Binary file added
BIN
+3.84 KB
learning_machines_robobo-master/src/prey/__pycache__/prey_controller.cpython-37.pyc
Binary file not shown.
129 changes: 129 additions & 0 deletions
129
learning_machines_robobo-master/src/prey/prey_controller.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
import random | ||
import threading | ||
|
||
|
||
class StoppableThread(threading.Thread): | ||
"""Thread class with a stop() method. The thread itself has to check | ||
regularly for the stopped() condition.""" | ||
|
||
def __init__(self): | ||
super(StoppableThread, self).__init__() | ||
self._stop_event = threading.Event() | ||
|
||
def stop(self): | ||
self._stop_event.set() | ||
|
||
def stopped(self): | ||
return self._stop_event.is_set() | ||
|
||
|
||
class Prey(StoppableThread): | ||
def __init__(self, robot, seed=42, log=None, level=2): | ||
super(Prey, self).__init__() | ||
self._log = log | ||
self._robot = robot | ||
# seed for the random function -> make reproducible the experiment | ||
self._seed = seed | ||
# default level is 2 -> medium | ||
self._level = level | ||
|
||
def _sensor_better_reading(self, sensors_values): | ||
""" | ||
Normalising simulation sensor reading due to reuse old code | ||
:param sensors_values: | ||
:return: | ||
""" | ||
old_min = 0 | ||
old_max = 0.20 | ||
new_min = 20000 | ||
new_max = 0 | ||
return [0 if value is False else (((value - old_min) * (new_max - new_min)) / (old_max - old_min)) + new_min for value in sensors_values] | ||
|
||
def run(self): | ||
""" | ||
Method that moves the robot. | ||
It avoids obstacles and with a predefined probability it changes direction | ||
:return: | ||
""" | ||
if self._log is not None: | ||
self._log.info("The robot prey is moving") | ||
else: | ||
print("The robot prey is moving") | ||
if self._level == 0: | ||
if self._log is not None: | ||
self._log.info("Level {} selected -> super easy option".format(self._level)) | ||
else: | ||
print("Level {} selected -> super easy option".format(self._level)) | ||
maximum_speed = 5.0 | ||
turning_speed = 5.0 | ||
epsilon = 0.02 | ||
elif self._level == 1: | ||
if self._log is not None: | ||
self._log.info("Level {} selected -> easy option".format(self._level)) | ||
else: | ||
print("Level {} selected -> easy option".format(self._level)) | ||
maximum_speed = 10.0 | ||
turning_speed = 10.0 | ||
epsilon = 0.03 | ||
elif self._level == 2: | ||
if self._log is not None: | ||
self._log.info("Level {} selected -> medium option".format(self._level)) | ||
else: | ||
print("Level {} selected -> medium option".format(self._level)) | ||
maximum_speed = 20.0 | ||
turning_speed = 10.0 | ||
epsilon = 0.06 | ||
elif self._level == 3: | ||
if self._log is not None: | ||
self._log.info("Level {} selected -> hard option".format(self._level)) | ||
else: | ||
print("Level {} selected -> hard option".format(self._level)) | ||
maximum_speed = 40.0 | ||
turning_speed = 20.0 | ||
epsilon = 0.08 | ||
elif self._level == 4: | ||
if self._log is not None: | ||
self._log.info("Level {} selected -> insane (Good luck Catching Me)".format(self._level)) | ||
else: | ||
print("Level {} selected -> insane (Good luck Catching Me)".format(self._level)) | ||
maximum_speed = 70.0 | ||
turning_speed = 30.0 | ||
epsilon = 0.1 | ||
else: | ||
raise Exception("Level Value not correct, try from 0 to 4.") | ||
|
||
random.seed = self._seed | ||
|
||
while not self.stopped(): | ||
speed_right = speed_left = maximum_speed | ||
if random.random() <= epsilon: | ||
speed_right = random.uniform(-turning_speed, turning_speed) | ||
speed_left = random.uniform(-turning_speed, turning_speed) | ||
for i in range(3): | ||
self._robot.move(left=speed_right, right=speed_left, millis=200) | ||
self._robot.move(left=speed_right, right=speed_left, millis=200) | ||
sensors = self._sensor_better_reading(self._robot.read_irs()) | ||
# self.log.debug(sensors) | ||
# print(sensors) | ||
if sum(sensors) != 0: | ||
index_max_value = sensors.index(max(sensors)) | ||
if index_max_value == 5: | ||
# central -> turn | ||
if random.random() <= 0.5: | ||
while sum(sensors[3:5]) > 500: | ||
self._robot.move(left=-10.0, right=20.0, millis=500) | ||
sensors = self._sensor_better_reading(self._robot.read_irs()) | ||
else: | ||
while sum(sensors[6:8]) > 500: | ||
self._robot.move(left=20.0, right=-10, millis=500) | ||
sensors = self._sensor_better_reading(self._robot.read_irs()) | ||
elif index_max_value == 3 or index_max_value == 4: | ||
# front right right -> go left | ||
while sum(sensors[3:5]) > 500: | ||
self._robot.move(left=-10.0, right=20.0, millis=200) | ||
sensors = self._sensor_better_reading(self._robot.read_irs()) | ||
elif index_max_value == 7 or index_max_value == 6: | ||
# front left left -> go right | ||
while sum(sensors[6:8]) > 500: | ||
self._robot.move(left=20.0, right=-10.0, millis=200) | ||
sensors = self._sensor_better_reading(self._robot.read_irs()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# from base import Robobo | ||
from __future__ import absolute_import, print_function | ||
from .simulation import SimulationRobobo | ||
from .simulation_prey import SimulationRoboboPrey | ||
|
||
import sys | ||
if sys.version_info < (3,0): | ||
from .hardware import HardwareRobobo | ||
else: | ||
print("Hardware Connection not available in python3 :(", file=sys.stderr) |
Binary file added
BIN
+545 Bytes
learning_machines_robobo-master/src/robobo/__pycache__/__init__.cpython-37.pyc
Binary file not shown.
Binary file added
BIN
+2.86 KB
learning_machines_robobo-master/src/robobo/__pycache__/base.cpython-37.pyc
Binary file not shown.
Binary file added
BIN
+12.1 KB
learning_machines_robobo-master/src/robobo/__pycache__/simulation.cpython-37.pyc
Binary file not shown.
Binary file added
BIN
+1.83 KB
learning_machines_robobo-master/src/robobo/__pycache__/simulation_prey.cpython-37.pyc
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
from __future__ import unicode_literals, print_function, absolute_import, division, generators, nested_scopes | ||
import time | ||
|
||
class Robobo(object): | ||
def __init__(self): | ||
pass | ||
|
||
def connect(self, uri=None): | ||
raise NotImplementedError("Not implemented") | ||
|
||
def spin(self): | ||
raise NotImplementedError("Not implemented") | ||
|
||
def set_emotion(self, emotion): | ||
raise NotImplementedError("Not implemented") | ||
|
||
def move(self, left, right, millis): | ||
raise NotImplementedError("Not implemented") | ||
|
||
def talk(self, message): | ||
raise NotImplementedError("Not implemented") | ||
|
||
def set_led(self, selector, color): | ||
raise NotImplementedError("Not implemented") | ||
|
||
def read_irs(self): | ||
raise NotImplementedError("Not implemented") | ||
|
||
def get_image_front(self): | ||
raise NotImplementedError("Not implemented") | ||
|
||
def set_phone_orientation(self, a, b, c, d, e, f): | ||
raise NotImplementedError("Not implemented") | ||
|
||
def set_phone_pan(self, pan_position, pan_speed): | ||
""" | ||
Command the robot to move the smartphone holder in the horizontal (pan) axis. | ||
Arguments | ||
pan_position: Angle to position the pan at. | ||
pan_speed: Movement speed for the pan mechanism. | ||
""" | ||
raise NotImplementedError("Not implemented") | ||
|
||
def set_phone_tilt(self, tilt_position, tilt_speed): | ||
""" | ||
Command the robot to move the smartphone holder in the vertical (tilt) axis. | ||
Arguments | ||
tilt_position: Angle to position the tilt at. | ||
tilt_speed: Movement speed for the tilt mechanism. | ||
""" | ||
raise NotImplementedError("Not implemented") | ||
|
||
def sleep(self, seconds): | ||
time.sleep(seconds) |
Oops, something went wrong.