README.md 3.6 KB
Newer Older
Cédric Bonhomme's avatar
Cédric Bonhomme committed
1 2 3 4 5
EV3WebController
================

# Presentation

6 7
[EV3WebController](https://bitbucket.org/cedricbonhomme/ev3webcontroller)
provides a Web interface in order to control the Lego Mindstorms EV3 robot.
Cédric Bonhomme's avatar
Cédric Bonhomme committed
8 9 10

Tested with Python 3.4 and Python 2.7.

11 12 13 14 15 16
# Installation

First, install [ev3dev](http://www.ev3dev.org) on your
Lego Mindstorms EV3 brick.

For the network I recommend the Wireless Nano Adapter *Edimax EW-7811Un* which
17
is working perfectly out of the box.
18 19 20 21 22 23

Then on the robot:

    $ ssh root@192.168.1.16
    $ wget https://bootstrap.pypa.io/get-pip.py
    $ python get-pip.py
Cédric Bonhomme's avatar
Cédric Bonhomme committed
24 25 26 27
    $ wget https://bitbucket.org/cedricbonhomme/ev3webcontroller/get/master.tar.gz
    $ tar -xzvf master.tar.gz
    $ rm master.tar.gz
    $ mv cedricbonhomme-ev3webcontroller-* EV3WebController
Cédric Bonhomme's avatar
Cédric Bonhomme committed
28
    $ cd EV3WebController/
29
    $ pip install -r requirements.txt
30 31 32 33 34 35 36
    $ wget https://github.com/topikachu/python-ev3/archive/master.tar.gz
    $ tar -xzvf master.tar.gz
    $ rm master.tar.gz
    $ cd python-ev3-master/
    $ python setup.py install
    $ cd ..
    $ rm -Rf python-ev3-master/
Cédric Bonhomme's avatar
Cédric Bonhomme committed
37
    $ cp conf/conf.cfg-sample conf/conf.cfg
38 39 40 41

Launch the web server:

    $ python runserver.py
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
    * Running on http://0.0.0.0:5000/ (Press CTRL+C to quit)
    * Restarting with stat

# Launch EV3WebController at boot

In order to get EV3WebController start at boot, just create a new systemd
service.

First create the file */etc/systemd/system/brickrc.service*:

    [Unit]
    Description=EV3WebController
    After=multi-user.target

    [Install]
    WantedBy=multi-user.target

    [Service]
    Type=oneshot
    RemainAfterExit=yes
    ExecStart=/root/EV3WebController/run.sh

Then enable the new service:

    $ systemctl daemon-reload
    $ systemctl enable brickrc.service
    $ systemctl restart brickrc.service

70

71
# How to use the interface
Cédric Bonhomme's avatar
Cédric Bonhomme committed
72

73 74
## Move the robot

Cédric Bonhomme's avatar
Cédric Bonhomme committed
75
    $ GET http://192.168.1.16:5000/move/<direction>/<speed=800>
76

Cédric Bonhomme's avatar
Cédric Bonhomme committed
77
The value of *speed* is optional. Default is 800.
78 79 80 81 82 83 84 85 86 87 88

Acceptable values for *direction*:

* forward;
* backward;
* left;
* right;
* stop.

### Examples

89 90
#### Action successfully completed

Cédric Bonhomme's avatar
Cédric Bonhomme committed
91 92
    $ GET http://192.168.1.16:5000/move/forward
    {"action": "move", "direction": "forward", "message": "OK"}
93 94 95

In this case the HTTP status code returned is 200.

96 97
#### Unable to understand the request

Cédric Bonhomme's avatar
Cédric Bonhomme committed
98
    $ GET http://192.168.1.16:5000/move/nowhere
99 100 101 102
    {"message": "Unknown direction", "direction": "nowhere", "action": "move"}

In this case the HTTP status code returned is 400.

103 104 105 106
#### Hit a wall

    $ GET http://192.168.1.16:5000/move/forward?blocks=25
    {"action": "move", "direction": "forward", "message": "hit_wall"}
107

Cédric Bonhomme's avatar
Cédric Bonhomme committed
108 109 110
If a wall is detected the current action is stopped and the server
will return the message "hit_wall".

Cédric Bonhomme's avatar
Typo.  
Cédric Bonhomme committed
111
#### End of the labyrinth
Cédric Bonhomme's avatar
Cédric Bonhomme committed
112 113 114 115

    $ GET http://192.168.1.16:5000/move/forward?blocks=20
    {"action": "move", "direction": "forward", "message": "in_target"}

Cédric Bonhomme's avatar
Cédric Bonhomme committed
116 117 118
If the red color is detected the current action is stopped and the server
will return the message "in_target".

119
## Retrieve values from sensors (not yet implemented)
120

Cédric Bonhomme's avatar
Cédric Bonhomme committed
121
    $ GET http://192.168.1.16:5000/sensor/<sensor_name>
122 123 124 125 126 127 128 129

Acceptable values for *sensor_name*:

* button;
* ir_sensor.

### Examples

Cédric Bonhomme's avatar
Cédric Bonhomme committed
130
    $ GET http://192.168.1.16:5000/sensor/ir_sensor
131 132
    {"distance": 12}

133 134 135 136 137
# Donation

If you wish and if you like *EV3WebController*, you can donate via bitcoin
[1GVmhR9fbBeEh7rP1qNq76jWArDdDQ3otZ](https://blockexplorer.com/address/1GVmhR9fbBeEh7rP1qNq76jWArDdDQ3otZ).
Thank you!
138 139 140

# License

Cédric Bonhomme's avatar
typo.  
Cédric Bonhomme committed
141
EV3WebController is free software released under the "Modified BSD license"
142

143
Copyright (c) 2014-2015 Cédric Bonhomme - https://www.cedricbonhomme.org
Cédric Bonhomme's avatar
Cédric Bonhomme committed
144 145 146

# Contact

147
[Cédric Bonhomme](https://www.cedricbonhomme.org).