分享

乐高 EV3 高级编程 – 第一课:安装

 leafcho 2019-01-16

我的学生写的教程,英文版的,好吧,我翻译一下!

先介绍一下我的学生,今年 12 岁 (2018年),普通 2 等中学初中 2 年级(学校名字就不说了,说了你也没听过!),除了数学和科学比较好,其他科目成绩一般,学习电脑编程 3 年,大概每星期学 2 小时。所以,以下的教程,喜欢编程的小学生和初中生都可以看!

学生写的教程有用吗?好吧,他虽然是个普通学生,但是编程得奖不少,包括本地赛冠军(3 年 4 次)和世界赛冠军(2 年 2 次)。不是说他特别厉害,只不过他用文字编程和别人的图形编程比赛,就像是跑车和自行车比赛,赢了也是正常的!

以下就是他写的教程,关于 EV3 的暂时有 8 课,我一课一课的翻译!

EV3: Lesson 1 – Introduction to EV3 Python and Installation

EV3: 第一课 – EV3 Python 编程的介绍及安装

Preface 前言

Who should learn EV3 Python?

Anyone that are interested in robot programming using Lego EV3.

谁应该学习 EV3 Python 编程?

任何人有兴趣使用乐高 EV3 机器人编程

What do you need to learn EV3 Python?

- an EV3 set, either the Home Edition 31313, or the Education Edition 45544 and 45560 (Education Extension Set).

- a Windows PC, with at least 4GB memory and 100GB hard disk space, running Windows 7 or above.

你需要什么才能学习 EV3 Python 编程

- 一台 EV3,可以是 31313 家庭版,或者是 教育版 45544 和 45560

- 一台 Windows 电脑,最少 4GB 内存和 100GB 硬盘,操作系统 Win 7 或以上

1.1 Compare EV3 Lego and EV3 Python

1.1 比较 EV3 乐高图形编程 及 EV3 Python 文字编程

Let’s take a look at a simple python program, this program stores the largest of a,b,c into the variable strBiggest.

我们一起看看一个简单的 Python 程序,这个程序比较 3 个变数 a, b, c 并把最大的存到字符串变数 strBiggest 里。

a = 1b = 2c = 3strBiggest = ''if (a > b): if (a > c): strBiggest = 'a' else: strBiggest = 'c'else: if (b > c): strBiggest = 'b' else: strBiggest = 'c'

To create the same program using Lego Graphical Programming, the program will be like this:

同样的程序如果用乐高图形编程,程序会像下面这样:

乐高 EV3 高级编程 – 第一课:安装

Figure 1.1

It is obvious that EV3 python is more “Readable” than EV3 Lego programs, and, this is only a 2 levels “if” statements, for 4 levels or 5 levels “if”, the EV3 Lego graphical program will become very difficult to read and maintain.

很明显的,EV3 Python 文字编程比 乐高图形编程 有更好的【可读性】,以上只是两层 if ,如果出现 4 到 5 层 if, 那么乐高图形编程的图形就会太大(太高),变得难以查看及修改。

In addtion, features provided by Lego Graphical Programming are limited, you’ll never be able to write some robot programs in Lego grahphical programming, e.g. To control an EV3 using a PC or a mobile phone over the internet!!!

再者,乐高图形编程功能有限,有些程序是肯定写不了的,比方说,你不可能写一个透过互联网,手机远程控制 EV3 的程序!!!

1.2 EV3 Python Installation

1.2 EV3 Python 安装

1.2.1 Download the EV3DEV Operating System

1.2.1 下载 EV3DEV 操作系统

In order to use Python program to control EV3, we need to use a micro sd-card to boot the EV3, this micro sd-card is loaded with a Debian Linux system called EV3DEV.

You can switch back to Lego Operating System at any time by removing the sd-card and reboot the EV3, so it is safe to do so.

为了使用 Python 编程,我们需要一张安装了一个叫 EV3DEV 的 Debian Linux 系统的Micro-SD 卡并插入 EV3 开机。

使用 EV3DEV 操作系统是安全的,你随时可以摆掉 SD 卡,重新开机,EV3 就会用回原来的乐高操作系统。

To download the EV3DEV image, open a browser and go to this web site:

要下载 EV3DEV,用电脑浏览器打开以下网址:

http://www.

【译者(2018/09/22) 按: 请注意,不知道那天开始,ev3dev 已经出了 2.0 beta 版本,版本名字叫 Stretch, 此 Beta 版和 1.0 的 Jessie 版完全不兼容,本教程使用的是 1.0 Jessie 版本,将来 2.0 版本稳定后,才会将源代码改为 2.0 版,据我所知,在功能方面,两个版本基本一样的,只是 2.0 版本用起来更方便,但是由于作者已经把 EV3 功能使用面向对象方法封装在 robot.py 里,因此,使用 1.0 和 2.0 对于读者是没有区别的!】

then click “Downloads”:

然后按【Downloads】: 【这里请务必下载 1.0 Jessie 版本,不要下载2.0 Stretch 版本

乐高 EV3 高级编程 – 第一课:安装

Figure 1.2

Now, click “Download for EV3″, unzip the download file and you will get an .img file.

现在,按【Download for EV3】,解压下载的文档,你会得到一个 .img 档案。

1.2.2 Download the Win32 Disk Imager

1.2.2 下载 Win32 Disk Imager

To make the sd-card bootable, we need to use a program called “Win32 Disk Imager”, download and install it using the following url:

要让那张 SD 卡开机,我们必须用一个叫【Win32 Disk Imager】的程序,使用下面的链接下载它:

sourceforge.net/project

Now, insert the sd-card into your PC, run the Win32 Disk Imager, select the .img file, select your sd-card drive number, and click “Write”:

现在,把空白的 SD 卡插入电脑,运行 Win32 Disk Imager, 选择刚才解压的 .img 档案,选择你的 SD 卡驱动号,然后点击【Write】:

乐高 EV3 高级编程 – 第一课:安装

Figure 1.3

The sd-card will be prepared within a few minutes.

几分钟后,sd-card 就会准备好了

1.2.3 Boot the EV3 brick into the EV3DEV system

1.2.3 使用 EV3DEV 开机

Power off your EV3 brick if it is on, insert the micro sd-card and power on again, after a couple of minutes, it should look like this:

如果你的 EV3 是在开机状态,把它关机,插入 SD 卡,然后开机,几分钟后,画面会变成这样:

乐高 EV3 高级编程 – 第一课:安装

Figure 1.4

The “8.00″ is the approximate voltage of the battery remaining, you need to recharge and replace your battery if this value is under 7.00, otherwise it may not have enough voltage to run the motors.

右上角的【8.00】表示电池电压,如果低于 7.00,你就要换电池了,不然它可能推不动马达。

1.3 Choose an appropriate IDE

1.3 选择合适的编程工具 IDE

To write python programs, you’ll need an IDE, you can use “Notepad”, or “Sublime Text 3″, or any other IDE you like. In later lessons, we’ll learn how to use Client Server Socket connection to control an EV3 over the Internet, that would require some Microsoft Technologies, so we’ll use Microsoft Visual Studio 2017 Community as the IDE.

要写 Python 程序,你需要使用编程工具 IDE,你可以使用【写字板】,或者【Sublime Text 3】,或者其他你喜欢的 IDE。在后面的课程,我们有机会学习如何使用【客户端/服务器 Socket 套接字连接】,并透过互联网控制 EV3,这个程序需要一些【微软】的技术,因此,我们会使用 Microsoft Visual Studio 2017 Community 作为 IDE。

Another reason is that we can use the Team Development features of the Visual Studio, so that your programming team can write/modify the same programs with version controls.

另外一个原因是,很多时候我们需要几个人一起写同一个项目/程序,Visual Studio 里面有团队编写程序功能,可以使用版本控制功能多人一起修改程序。

To download Microsoft Visual Studio 2017 Community, go to the following web-site:

要下载 Microsoft Visual Studio 2017 Community,请到以下网址下载:

http://www.

Then download and run Visual Studio Community installation program. For future developments, we must choose at least the following components during the installation:

然后安装,为了将来的编程,我们最少要安装以下的功能:

- Windows Platform Development

- .NET Desktop Development

- ASP.NET and Web Development

- Python Development

- Node.js Development

- Javascripe Cross Platform Mobile Development

It may take more than an hour to finish the installation.

安装过程大概需要超过 1 小时。

1.4 Tools to upload Python programs into the EV3 brick

1.4 把 Python 程序上传到 EV3 的工具

To upload the python program into the EV3 brick, we’ll need another program called WinSCP, download and install the WinSCP in the following url:

把 Python 程序上传到 EV3,我们需要一个叫 【WinSCP】的程序,可以在下面链接下载并 安装:

winscp.net/eng/download

Now, we are going to write our first “Hello World” program in our next lesson.

下一课,我们将会写第一个 EV3 Python 程序 【Hello World】。

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多