Planning Exercise 11: Clock Exercise 11

20
1 Design of Embedded Systems (DES) Jozef Hooman http://www.cs.ru.nl/J.Hooman/DES Course 6

Transcript of Planning Exercise 11: Clock Exercise 11

Page 1: Planning Exercise 11: Clock Exercise 11

1

Design of Embedded Systems (DES)

Jozef Hooman

http://www.cs.ru.nl/J.Hooman/DESCourse 6

Page 2: Planning Exercise 11: Clock Exercise 11

2

Planning• Today: instruction on Lego EV3

with each group: demo of exercise 9 in lab

1st exercise with small Lego Rover

• 17 Oct: more info on EV3

2nd exercise with extensions (Bluetooth, …)

• 24 & 31 Oct: Autumn break

• 7 Nov: discuss Rover results +

Domain Specific Language (DSL) explanation

DSL exercise

• 14 Nov etc: DSL for missions of small Rover / Mars Rover

Page 3: Planning Exercise 11: Clock Exercise 11

Lego Mindstorms EV3

Processor:

• ARM9 CPU @ 300 MHz, running linux

Memory

• 64 MB RAM

• 16 MB Flash

• micro SD Slot

Connectivity:

• USB

• WiFi

• Bluetooth3

Page 4: Planning Exercise 11: Clock Exercise 11

EV3 brick

4Image from Lego®

Sensor portsS1, S2, S3, S4

USB to downloadprograms on brick

Motor ports A, B, C, D

Page 5: Planning Exercise 11: Clock Exercise 11

Small EV3 Rover

5

S2: light sensor

S1: touch sensor (left)

S4: touch sensor (right)

A: motor leftD: motor right

(as seen from the back)

S3: ultrasonic sensorLeft and right as seen from the perspective of the driver

Page 6: Planning Exercise 11: Clock Exercise 11

Charge EV3 brick when battery is low

6

Connect below sensor ports:• charging: green and red light• charged: green only

Page 7: Planning Exercise 11: Clock Exercise 11

Buttons EV3 brick1 Backspace

2 Up

3 Left

4 Enter

5 Right

6 Down

Brickman: ev3dev Brick Manager

• Start EV3 brick: Enter

• Stop EV3 Brick: Backspace in main menu or

press and hold from any screen

- select Power Off

• Reset: hold Backspace + Enter for some time

If everything else fails, removing the battery (on the bottom) and placing it back should also reset it 7

Page 8: Planning Exercise 11: Clock Exercise 11

Programming Lego EV3 using ev3devev3dev https://www.ev3dev.org/

• Debian Linux-based operating system

• We use ev3dev-stretch (latest version), also called ev3dev2

already installed on SD-cards of EV3 robots in lab

Supports several programming languages, we use Python

• https://github.com/ev3dev/ev3dev-lang-python

• https://sites.google.com/site/ev3devpython/

A lot of info and examples, also on Python:

https://sites.google.com/site/ev3devpython/learn_python

8

Page 9: Planning Exercise 11: Clock Exercise 11

Set-up development environment1. Make sure you have Python 3 (e.g. current version 3.7)

– if needed install it, see https://www.python.org/downloads/

2. On PC/notebook install ev3dev2 and ev3devcmd

Run, e.g. using linux or Windows Powershell:

– pip install python-ev3dev2

– pip install ev3devcmd

Note: if you also have Python 2, use pip3

3. On Windows, set PATH to location of Python and packages, for instance (for Python 3.6):

– …\Python36_64

– …\Python36_64\Lib\site-packages\

– …\Python36_64\Scripts\

(Usually not needed for linux)9

Page 10: Planning Exercise 11: Clock Exercise 11

Set-up development environment

1. Make sure you have Runtime Environment (JRE) for Java 8 or 10

2. Install Eclipse Photon see https://www.eclipse.org/photon/

– Select “Other Package Downloads”

– Choose “Eclipse IDE for Java and DSL Developers”

– Download it and unpack the zip file (choose a location)

– For Windows: locate “eclipse.exe” file in directory “eclipse” which can be used to start Eclipse. It is convenient to create shortcut on desktop

Linux used “eclipse”

– Create an empty folder (workspace) for Eclipse projects

– Start Eclipse and use the created folder as workspace

10

Page 11: Planning Exercise 11: Clock Exercise 11

Set-up development environment– Eclipse shows the Welcome screen

• Remove the tick in the bottom right corner before “Always show Welcome at start up” to avoid it will be shown every time.

• Close the Welcome screen (use Help > Welcome to get it back)

– If an exit code occurs because it uses a wrong Java version:

• Check the location of the 64-bit Java jre

• Next open “eclipse.ini” in a text editor;

before the line with “-vmargs” insert:

-vm

C:/Program Files/Java/jdk1.8.0_151/bin/javaw.exe

where the last line is the path to the right 64-bit Java version

(so change to own location)

11

Page 12: Planning Exercise 11: Clock Exercise 11

Set-up development environment

3. Install PyDev: Python editor in Eclipse http://www.pydev.org/

– In Eclipse: Help > Eclipse Marketplace, Find: PyDev

– Install and restart when asked for

4. Configure PyDev

– In Eclipse: Windows > Preferences > PyDev > Interpreters > Python Interpreter

– Try Quick Auto-Config – otherwise manually set location of Python executables

More details on http://www.pydev.org/manual_101_root.html

12

Page 13: Planning Exercise 11: Clock Exercise 11

Using ev3devcmdCommands for communication with EV3 brick:https://github.com/harcokuppens/thonny-ev3dev/wiki/ev3devcmdd

• Create ev3dev.bat, e.g. in …\Python36_64\Scripts\ with:

– For Windows: python -mev3devcmd %*

– For linux: #!/bin/bash

python3 -mev3devcmd $@

• Create external commands in Eclipse

Run > External Tools > External Tools Configuration

Example Upload:

– Name: Upload

– Location: Browse file system to

…\Python36_64\Scripts\ev3dev.bat

– Working Directory: ${project_loc}

– Arguments: upload -f ${resource_loc} 13

Page 14: Planning Exercise 11: Clock Exercise 11

Other useful external commands

• Name: CleanUp Arguments: cleanup

• Name: Delete Arguments: delete ${resource_loc} ${resource_loc} [bug: file name has to be given twice]

• Name: GetErrorLog

Arguments: download -f ${selected_resource_loc}.err.log

• Name: InstallAdditions Arguments: install_additions

• Name: List Arguments: list

• Name: SoftReset Arguments: softreset

• Name: Start Arguments: start ${resource_loc}

• Name: Steer [to run program on PC/notebook]

Arguments: steer ${resource_loc} Name: Stop Arguments: stop

14

Page 15: Planning Exercise 11: Clock Exercise 11

Python project in Eclipse• Create a Python project

– File > New > Project > PyDev > PyDev project

– Give name (e.g. ev3_python) and use default settings

– Open PyDev perspective

– You can add a new source folder in the menu: File > new > other > PyDev > &Source Folder - give name – e.g. src

– You can create package by File > New > PyDev package –give, e.g. src.robotica (creates package robotica)

• Set project properties to unix (e.g. when working on Windows):

– Right-click on project name, select Properties > Resource

– Text file encoding: UTF8

– New text line delimiter: Other Unix

15

Page 16: Planning Exercise 11: Clock Exercise 11

Programming in ev3devDocument with tips and API of ev3dev2: https://media.readthedocs.org/pdf/python-ev3dev/latest/python-ev3dev.pdf

See also the examples in http://www.cs.kun.nl/J.Hooman/DES/PythonExamples.zip

Extract in Eclipse: File > Import > General > Existing Projects into Workspace > select archive file

• Connect with EV3 brick via USB cable

• Upload to EV3 brick by Run > External Tools > External Tools Configuration > Upload

• Program can be started on brick or via External Tools: Start

• Errors are logged in program.py.err.log – download via GetErrorLog

• Used commands will become available via button:

16

Page 17: Planning Exercise 11: Clock Exercise 11

Help facilities in Eclipse

• F1

• Help > Help > Help Contents > PyDev User Guide

links to on-line resources

• Code completion with Ctrl+Space

17

Page 18: Planning Exercise 11: Clock Exercise 11

Alternative connection

Use SSH client

For instance, under Windows use PuTTY to start and view error file

• Connect via USB and use PuTTY – 192.168.0.1

– user: robot

– pwd: maker

• Run with: python3 motor.py

18

Page 19: Planning Exercise 11: Clock Exercise 11

Program structure

• Good program structure is important

– for easy extension in next exercise

– for re-use for larger robot

– to allow generation of fragments

think about good program structure for dealing withsensors, actuators (motors, LEDs, ..) and priorities

19

Page 20: Planning Exercise 11: Clock Exercise 11

Assignment 17 October 2018

Develop a Python program for small EV3 robot which –in this order of priority –

• stays within black border

• detects collisions with objects (e.g., use bottle)

• tries to avoid collisions with object

Optionally: • indicate status using sounds and/or LED lights

Mail source files + description / observationsbefore Tuesday 16 October 18:00

20