Skip to Main Content

Robots @ SIT

Get hold of one of the available Robots at SIT Library and start your robotics journey today!

Introduction

Required Knowledge and Parts:

  • EV3 set
  • SD Card

Application:

A remote-controlled robot is very useful. It can go places that humans cannot go. An operator can sit anywhere and remote the robot thousands of miles away to complete tasks. Boston Dynamics' robot dog is very famous in Singapore during the Covid-19 circuit break period. 

 

 

The robot EV3D4 robot is a simple remote-controlled robot created using Lego Mindstorms EV3. You can be assemble it with the following guide from Vassilis Chryssanthakopulos and Philippe “Philo” Hurbain.

Troubleshoot: As the connector wires given in the kit are not long enough, flip the EV3 Brick upside-down as shown in picture below:

                EV3D4 Robot (Python)

 

 

The guide and videos are created by Terence Kon, the Sitizen Ambassador.

Solution

In order to utilize and program the robot in Python, MicroPython is needed. MicroPython is Python for Microcontrollers, In this case, MicroPython for EV3 is needed. The MicroPython image and guide for EV3 can be seen in the following link

What you need

  • Windows 10 or Mac OS computer
  • Internet access and administrator access
  • microSD card
    • Minimum capacity of 4GB and a maximum capacity of 32GB
  • microSD card reader
    • Inbuilt in computer or using an external USB SD card reader
  • microSD flasher tool e.g. balenaEtcher

Steps

  1. Download the EV3 MicroPython microSD card image from the link mentioned above in the Introduction. There is no need to unzip the file
  2. Download and install a microSD card flashing tool. In our case, we used balenaEtcher
  3. Insert the microSD card into your computer or card reader. In our case, a 16GB SD card is used
  4. Launch the flashing tool and install the downloaded EV3 card image into the microSD card. Once installed, eject the SD card
  5. Ensure that the EV3 Brick is turned off. Important: Attach a tape to the back of your SD card to easily remove the card from the EV3 brick. Insert the SD card into the EV3 brick
  6. Turn on the EV3 brick and wait for it to boot up until it reaches the menu screen

Internet connection is needed to update the software as well as to install the dependencies and Python code. A Bluetooth connection to the Computer is used to remotely control the robot from a distance.

Please look at this guide on how to connect to the EV3 Brick via Bluetooth. (You may ignore the Windows 10 warning in the guide, as an Internet Connection was possible on Windows 10)

Connect to EV3 terminal using Secure Shell (SSH)

Using a SSH client such as PuTTY to connect to the EV3 Brick to install additional software and run the program. In our case, PuTTY is used as our SSH client. PuTTY is an open source SSH and telnet client. PuTTY can be downloaded here, Download PuTTY.   The steps to connect PuTTY to the EV3 Brick can be found here, SSH connection to EV3 Brick

Detail Steps

  1. Download a SSH client in your computer. In our case we use PuTTY. Once downloaded, run PuTTY
  2. In the PuTTY Configuration window, type in ev3dev for the “host name”. Then click the Open button to connect
  3. Once you are connected, type in the ev3dev username (robot) and the password (maker) if you haven’t changed it yet and then you should be logged in.

Notes

  • The first time you connect, you'll get a warning about the new fingerprint. This is normal. Just click *Yes* to continue. You won't see this again unless you re-flash your SD card
  • Default username: robot
  • Default password: maker

Preparing the MicroSD

The Python program for the EV3D4 Robot can be downloaded from here

You may also download Visual Studio Code and refer this guide to Set-up Visual Studio Code for EV3

Using Visual Studio for EV3

Ensure that you have LEGO® MINDSTORMS® EV3 MICROPYTHON on your Visual Studio

You should see ‘EV3DEV DEVICE BROWSER’ on the lower left corner of the Visual Studio Interface:

Next, click on ‘Click here to connect to a device’.

You should see ‘ev3dev’ show up:

Troubleshooting: If this does not show up, please check your SSH connection. Refer back to the Bluetooth guide. If Bluetooth connection is not possible, then connect the EV3 brick to the computer using the cable provided. Do note if this option is used, the movement range will be limited by the cable length.

If connection is successful, you should see the ev3dev device in Visual Studio Code:

Next, open the project file previously downloaded:

At the top left hand corner of the Visual Studio Interface, click on File>Open Folder>Downloads>EV3D4-ssh_control-master

After the file is selected, click open

You should see 3 files in the Visual Studio Code Interface as follows

Click on the ev3dev dropdown arrow

Next, click on ‘send workspace to device’:

You should see the files get downloaded onto the EV3 brick:

Note: Any further change made to the python file has to be re-downloaded onto the EV3 brick before it will have effect

Going back to the SSH Interface:

Change directory (cd) of the SSH to the workfile:

i.e., type ‘cd EV3D4-ssh_control-master’ into the interface:

Press Enter if you have not done so

Next, run conbot.py using the python3 method:

i.e., type ‘python3 conbot.py’

Press enter if you have not done so.

Once you see LOG, you can now control the robot

Control Keys:

Explanation of the conbot.py code
Imported Libraries Pupose
import subprocess Allows user to spawn new processes, connect to their input/output/error pipes, and obtain their return code.
import termios

A process that can be run only on UNIX devices (i.e. the EV3 brick)

Provides an interface to the POSIX (i.e. SSH connection) calls for I/O (Input/Output) control
import tty Give ability to define functions on the EV3 brick. Requires termios import
import sys Allows ability to give commands remotely to the EV3 brick via the SSH connection
From ev3dev.ev3 import* Import the functions native to the EV3 device

conbot.py python class variables

Layman terms: modifying this will affect the rest of the code in the python file

 
Class Variables Purpose
motor_left Defines output to the motor connected to port C. It is the left motor of the robot
motor_right Defines output to the motor connected to port B. It is the right motor of the robot
motor_a Defines output to the motor connect to port A. It is the motor that controls the robot’s head

conbot.py python instance variables

Layman terms: modifying this will only affect one function

Instance Variables Purpose
getch() Listens to the user input from the SSH connection and passes it to the EV3 brick
cabezaderecha()

Turns the robot’s head to the left

(You may wish to modify its name to something more understandable. Try to also adjust the speed to a lower rotation to avoid tangling the wires of the head)
cabezaizquierda()

Turns the robot’s head to the right

(You may wish to modify its name to something more understandable. Try to also adjust the speed to a lower rotation to avoid tangling the wires of the head)
marchaimp() Play the Imperial March from Star Wars. You may upload your own file to change songs
fire() Simulates a fire on the robot, making the head turn very fast. It is recommended to remove the wires from the head before coding this function onto the commands
forward() Moves the robot forward.
back() Moves the robot backward.
left() Rotates the robot to the left
right() Rotates the robot to the right
stop() Stops all motors

Control functions

At line 69, the actual instructions given to the robot starts.

getch() is always running, so that the Robot is always listening to user input. User input is thereafter defined by variable k.

For the rest of the functions, the keys are defined by a character.

e.g.

if k == ‘w’:

            back()

This means that if the w key is pressed on the computer, the robot will move backwards forever.

You may wish to input the other defined functions into the control functions by writing the command. Note that python is sensitive to indentation, as can be seen from the example. The back() function is tied to pressing the ‘w’ key.

Troubleshoot: If you have quit the command interface by pressing q, you can re-start the program by typing 'python3 conbot.py'

Files Download