This file explains how to setup the software for the robots. It assumes that you already assembled your robot according to the instructions in [1_ASSEMBLY.md](https://imaginaerraum.de/git/Telos4/RoboRally/src/branch/master/docs/1_ASSEMBLY.md) and that you updated the firmware of the motor shield as described in [2_MOTOR_SHIELD_FIX.md](https://imaginaerraum.de/git/Telos4/RoboRally/src/branch/master/docs/2_MOTOR_SHIELD_FIX.md).
You can download the latest micropython firmware for the ESP8266 from [here](http://micropython.org/download#esp8266). I used version _esp8266-20190125-v1.10.bin_ but you can also use a more recent version.
Join the same WiFi network with your PC (either the access point or the local network) and connect to the D1 mini via the [online WebREPL](http://micropython.org/webrepl):
In order to avoid having to set up the WebREPL and the WiFi everytime we reboot the robot we can upload a file called boot.py which runs each time the robot restarts:
- Find the file `boot.py` in the `micropython_firmware/` subfolder and edit the lines indicated with `# TODO`. In particular, set the wifi network, password and IP addresses. You should choose a unique IP address for each robot
```
# TODO: edit these lines
network_name = 'Your WiFi network' # existing wifi network to connect to (leave empty if unused)
password = 'Your password' # password for the network
desired_ip = '192.168.1.101' # the robot will be reachable by this IP in the network
Next, upload the motor controller script to the microcontroller. At the moment the firmware consists of the following three files located in `micropython_firmware/`:
-`main.py` Main script handling network communication and control
-`d1motor.py` Interface for the Wemos D1 mini motor shield
-`l293dmotor.py`Interface for alternative motor driver using L293D (no longer used)
You can upload these files the same way you did before with the WebREPL. After uploading all the files reboot the microcontroller by pressing the reset button or by pressing `Ctrl+D` in the WebREPL prompt.
- If everything worked, connect to the robot via WebREPL as before. Don't worry if the prompt does not appear to be working. The robot is running a program waiting for incoming connections for remote control.
We can connect to the robot via a socket on port `1234`. There is a simple demo program which illustrates how to control the robot remotely via keyboard. The program uses `pygame` for input handling so make sure to install it using
```
$ sudo pip install pygame
```
The program is located in the `remote_control/`. Run it using
You can control the robot by sending commands to the robot as a string containing `'(u1, u2)\n'`, where `u1` and `u2` are floats in the range `[-1.0, 1.0]`, e.g. `'(0.3, -0.6)\n'`.
Since the mounting plates of the robot are made of metal it is a good idea to put some isolation around the electronics. You can use some isolation tape to cover the exposed pins:
The next step is to setup the position detection using ROS. For this see the [4_ROS_SETUP.md](https://imaginaerraum.de/git/Telos4/RoboRally/src/branch/master/docs/4_ROS_SETUP.md)