Skip to content

Commit ec8f23c

Browse files
committed
cleanup
1 parent ec7261f commit ec8f23c

7 files changed

Lines changed: 223 additions & 136 deletions

File tree

_includes/head.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
<link rel="stylesheet" href="/stylesheets/infrastructure-utils.css" />
1515

1616
<!-- Python code highlighting -->
17-
<link rel="stylesheet" href="{{ site.github.url }}/stylesheets/pygments/monokai.css" />
17+
<link rel="stylesheet" href="/stylesheets/pygments/monokai.css" />
1818

1919
<!-- 3rd-party libraries -->
2020
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js"></script>

docs/getting-started.md

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ First, here are the things you need before starting:
2121
For the EV3, this can be one of the following:
2222

2323
* USB cable (the one that comes with the EV3)
24-
* USB WiFi dongle
24+
* USB Wi-Fi dongle
2525
* USB Ethernet (wired) dongle
2626
* Bluetooth
2727

@@ -143,12 +143,15 @@ you want to use and on the OS of your host computer, so pick the one that applie
143143
* [Connecting to the Internet](../tutorials/connecting-to-the-internet-via-usb) tutorial
144144
* __USB Ethernet dongle__ (as in the kind with an RJ45 connector)
145145
* If your network has a DHCP server, this will "just work".
146-
* __USB WiFi Dongle__
147-
* Hopefully you can figure it out. I'm putting off writing detailed docs
148-
until brickman is a bit more stable.
146+
* __USB Wi-Fi Dongle__
147+
* Setting up Wi-Fi Via the Brickman User Interface (hopefully you can figure
148+
this out, but it would be nice if someone made a tutorial)
149+
* [Setting Up Wi-Fi Using the Command Line](../tutorials/setting-up-wifi-using-the-command-line)
150+
(requires another connection type first to get to the command line, but way
151+
easier to enter you passphrase this way)
149152
* __Bluetooth__
150153
* Note: Bluetooth may not work on the first boot. Please reboot if you see "???"
151-
after you power on Bluetooth.
154+
after you power on Bluetooth.
152155
* [Connecting to the Internet](../tutorials/connecting-to-the-internet-via-bluetooth) tutorial
153156

154157
{% include icon.html type="info" %}

docs/tutorials/python-development-environment.md

Lines changed: 0 additions & 126 deletions
This file was deleted.
Lines changed: 199 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,199 @@
1+
---
2+
title: Setting Up a Python Development Environment with PyCharm
3+
subject: Software - Python
4+
author: Anton Vanhoucke
5+
---
6+
7+
* Table of Contents
8+
{:toc}
9+
10+
This tutorial shows how to set up a nice working environment for developing
11+
Python on Ev3dev. The platform used is a BrickPi, but most of it is usable
12+
for regular LEGO EV3 bricks.
13+
{:.lead}
14+
15+
Ev3dev is a lean and modern system to run on the Raspberry Pi that powers the
16+
BrickPi. It's got multiple languages that work in a pretty similar way and
17+
make switching easy. Moreover, if you code in ev3dev on the BrickPi, people
18+
with a regular EV3 and Ev3dev will be able to run your code! Alas, it doesn't
19+
work the other way around as the BrickPi has a more limited set of motor
20+
commands.
21+
22+
For this tutorial, I will suppose you have burned an SD disk, connected your
23+
RPi and BrickPi to an ethernet cable and booted it. If you have an EV3 brick
24+
without ethernet, [set up another networking connection first][network].
25+
26+
[network]: /docs/tutorials
27+
28+
## Log in to ev3dev ##
29+
30+
Now you can either attach a screen and keyboard to it for the setup, or
31+
connect to it via ssh. I prefer the latter. My router has a DNS that registers
32+
hostnames. It allows me to start a Terminal (on Mac) or Putty (on Windows) and
33+
simply do:
34+
35+
`ssh robot@ev3dev`
36+
37+
If you don't have a DNS try: `robot@ev3dev.local` or connect to it's IP
38+
address directly. eg. `robot@192.168.0.2`
39+
40+
The password is `maker` by default. If you used screen and keyboard, you're
41+
automatically logged in.
42+
43+
##Configure the right BrickPi##
44+
45+
You're logged in to the command line. Cool! This step will activate the
46+
BrickPi. Skip it if you have a normal EV3. Now several Mindstorms shields
47+
are available for the RPi, we have to setup the right one first. That is,
48+
if you haven't done so already after burning the image. For this go:
49+
50+
`sudo nano /boot/flash/config.txt` (the password is still `maker`)
51+
Scroll down and uncomment the appropriate lines for your hardware.
52+
53+
{% include icon.html type="info" %}
54+
I have multiple Raspberry Pis and Mindstorms brains. I like to keep
55+
them apart on the network by giving them separate names. I renamed mine like
56+
this:<br />`sudo hostnamectl set-hostname ev3dev-rpi`
57+
{:.alert .alert-info}
58+
59+
Finally do `sudo reboot`.
60+
61+
## Set up development environment ##
62+
63+
I prefer to have a passwordless ssh to the robot. For this I [add a user with
64+
the same login name as on my development computer.][users] Remember to give
65+
yourself sudo rights as explained on that same page. After adding that user,
66+
you can [set up passwordless ssh][passwordless].
67+
68+
{% include icon.html type="danger" %}
69+
This doesn't matter on BrickPi, but on robots with a screen, you will *not* be
70+
able to launch programs using the Brickman interface. For this, you *must* use
71+
the `robot` user! Only set up your own user account if you really know what you
72+
are doing.
73+
{:.alert .alert-danger}
74+
75+
[users]: https://www.raspberrypi.org/documentation/linux/usage/users.md
76+
[passwordless]: https://www.raspberrypi.org/documentation/remote-access/ssh/passwordless.md
77+
78+
With passwordless ssh and the same username on the ev3dev machine, you can go
79+
`ssh ev3dev` and you're in!
80+
81+
Next we need a versioning system. That's a tool for tracking changes you made
82+
to your code. Coincidentally the same tool is also very handy for transferring
83+
code between computers or sharing it on the web. There are several, but I
84+
prefer git. It's not installed by default so you have to do:
85+
86+
sudo apt-get update
87+
sudo apt-get install git
88+
git config --global user.email "you@example.com"
89+
git config --global user.name "Your Name"
90+
91+
Now let's make a new project using our versioning system. Just type:
92+
93+
mkdir pyproject.git
94+
git init --bare myproject.git
95+
96+
Yay! Git is initialised in the new folder we created. We have a new project
97+
repository. Now we can clone this repository on our development machine, but
98+
first we need to do a little more configuring, to automatically deploy our
99+
code when we push it back to the ev3dev brick.
100+
101+
nano myproject.git/hooks/post-receive
102+
103+
add these lines. If you created a user with your own name, replace `robot`
104+
with that name:
105+
106+
#!/bin/sh
107+
git --work-tree=/home/robot/myproject --git-dir=/home/robot/myproject.git checkout -f
108+
109+
and finally do:
110+
111+
chmod +x myproject.git/hooks/post-receive
112+
113+
## On to PyCharm ##
114+
115+
Now typing code in nano is fine, but it's much nicer to do it inside a real
116+
IDE (Integrated Development Environment). There are many, like Visual Studio,
117+
Eclipse and PyCharm. My favourite is [PyCharm Community Edition][pycharm].
118+
So go grab a copy of that one and start it on your development machine.
119+
120+
[pycharm]: https://www.jetbrains.com/pycharm/
121+
122+
{% include screenshot.html source="/images/osx/PyCharm/welcome.png" %}
123+
124+
What we are going to do now is make a clone of our project on the ev3dev
125+
machine to start working on it on the development machine.
126+
In the Welcome dialog choose: 'Checkout from version control' > 'Git'
127+
Now type the hostname of the ev3dev machine, followed by a semicolon the
128+
projectname. In the other fields choose a nice parent and project directory.
129+
(You might have to add `.local` after `ev3dev` depending on your DNS setup.)
130+
131+
{% include screenshot.html source="/images/osx/PyCharm/clone-repo.png" %}
132+
133+
When all goes wel you get a new window with your fresh empty project. If the
134+
'testing' dialog stays on screen for a long time, it might be that your
135+
PyCharm master password is needed for your PyCharm password storage. Cancel
136+
the checkout, type the master password and try again.
137+
138+
So let's add some code. Right click on the 'myproject' folder in the left
139+
column and choose new > python file. Name it `run-motor`. PyCharm will ask
140+
if you want to add it to Git. That's nice! Of course we want that.
141+
142+
Now add the following code:
143+
144+
{% highlight python %}
145+
from ev3dev.auto import OUTPUT_A, Motor
146+
import time
147+
148+
m = Motor(OUTPUT_A)
149+
m.run_forever(duty_cycle_sp = 100)
150+
time.sleep(1)
151+
m.stop()
152+
{% endhighlight %}
153+
154+
When you're done press cmd-k or choose VCS > Commit Changes...
155+
156+
The commit message is box describing the changes you made to your code. That's
157+
handy later on when you do a lot of changes. For now type: `first commit`.
158+
Then go over the commit button and choose "commit and push" from the dropdown.
159+
In the next dialog click make sure to select the "alternative branch checkbox"
160+
and click "Push". Voila! Our code has arrived on the ev3dev brick. Let's take
161+
a look.
162+
163+
## Running the code ##
164+
165+
It's time to let the first motor run. Plug it into port A on your brick and
166+
ssh to your ev3dev brick. Maybe you have the terminal still open.
167+
168+
Now go
169+
170+
cd myproject
171+
python run_motor.py
172+
173+
Tataaa! The motor is running full power for a second.
174+
175+
## Installing ev3dev-python on the development machine ##
176+
177+
Back to the development machine. Maybe you noticed a problem: PyCharm puts
178+
red curly lines under the ev3dev library.
179+
180+
{% include screenshot.html source="/images/osx/PyCharm/missing-lib.png" %}
181+
182+
And that's logical, because the ev3dev library is missing on the development
183+
machine. If we install it we won't be able to run motors, but the documentation
184+
and autocomplete will be active. So on your development machine start a
185+
terminal and do:
186+
187+
git clone https://github.com/rhempel/ev3dev-lang-python.git
188+
python ev3dev-lang-python/setup.py install
189+
rm -r ev3dev-lang-python/ # Optional to remove the downloaded files. It's installed now anyway.
190+
191+
## Using the power of the IDE ##
192+
193+
With the IDE (PyCharm) set up and the library installed you can code much
194+
faster. PyCharm will highlight most coding errors and typos. It will also
195+
suggest to autocomplete your code and show documentation. You can start
196+
typing `m.` and pycharm will suggest all possible methods and properties.
197+
Choose one. Now you can put your cursor inside the property and press F1 to
198+
see the docs. Or press cmd-down arrow to look inside the library where this
199+
property is defined. Neat huh? Happy coding.

docs/tutorials/setting-up-wifi-on-ev3.md renamed to docs/tutorials/setting-up-wifi-using-the-command-line.md

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,21 @@
11
---
2-
title: Setting up wifi on ev3
2+
title: Setting Up Wi-Fi Using the Command Line
33
subject: Networking
44
---
55

6-
I like to setup wireless networking on my robots. Robots should go untethered! Here is how. It's easy in an interactive tool call `connmanctl`. You connect once, and next time you boot, it's all configured. On my ev3dev machine it went like this:
6+
{% include icon.html type="danger" %}
7+
You must have another way to connect to your robot first before following this
8+
tutorial. On the EV3, that means USB or Bluetooth. If you have a Raspberry Pi,
9+
you can plug in a monitor and keyboard to the Raspberry Pi. The instructions
10+
below are run on your robot itself.
11+
{:.alert .alert-danger}
712

8-
anton@ev3dev:~$ sudo connmanctl
13+
I like to setup wireless networking on my robots. Robots should go untethered!
14+
Here is how. It's easy in an interactive tool call `connmanctl`. You connect
15+
once, and next time you boot, it's all configured. On my ev3dev machine it went
16+
like this:
17+
18+
robot@ev3dev:~$ sudo connmanctl
919
Error getting VPN connections: The name net.connman.vpn was not provided by any
1020
connmanctl> enable wifi
1121
Enabled wifi
@@ -28,4 +38,5 @@ I like to setup wireless networking on my robots. Robots should go untethered! H
2838
Connected wifi_e8de27077de3_41483034303434393134_managed_psk
2939
connmanctl> quit
3040

31-
You're all set up now! After reboot connman automatically finds your local wifi again.
41+
You're all set up now! After reboot connman automatically finds your local
42+
Wi-Fi again.

images/osx/PyCharm/clone-repo.png

-64.7 KB
Loading

images/osx/PyCharm/missing-lib.png

-58.1 KB
Loading

0 commit comments

Comments
 (0)