Help

Here are the different Help Tutorials for the class.

If you have issues or find bugs in the software, please email the Teaching Assistants.



LEGO MINDSTORMS

Introduction to the EV3 Kit:

EV3 Kit Overview:

EV3 Brick Structure (via Default Firmware):

Image

EV3 Programmable Brick Overview:

Image

On-brick Programming Overview:

Jan 17 2018 Read →

Building Pieces in EV3 Kit

Jan 17 2018 Read →

Gears in EV3 Brick:

Overview of Gears:

Gear Trains 1:

Gear Trains 2:

Gear Trains 3:

Bevel Gear:

Worm Gear:

Knob Wheel:

Pulley Wheel:

Small TurnTable Wheel:

Jan 17 2018 Read →

Sensors in EV3

Touch Sensor:

Color/Light Sensor:

Ultrasonic Sensor:

Gyro Sensor:

Jan 17 2018 Read →

LEGO MINDSTORMS Walkers

Four-Legged Robots

Biped Robots

Other Walkers

Not a Walker

Jan 18 2018 Read →

IDE + Programming Python

Python IDE Intro

Steps for Using the Python IDE on the EV3 with WiFi on Tufts-Wireless Network:

  • With EV3 off, insert the SD-Card and the WiFi Dongle

  • Start the EV3, and let it boot into Linux

  • Go to Network Settings, and make sure the WiFi Dongle is "Powered"

  • Search for Networks; select "Tufts-Wireless" network

  • If connection fails, un-power WiFi Dongle, unplug, plug-back in, and re-power

    • (Make sure your computer is also on the Tufts-Wireless Network.)
  • Once connected to network, go back to main menu and go to File Browse

  • Find and run (click on) the "RunIDE.sh" script

    • This will start a web server on the EV3 brick, and load the proper files. This TAKES A LONG TIME. Give it time. Once it loads, it'll go back to the main File Browse screen.
  • On your computer (on the same network), open up Chrome Browser, and go to the IP address listed on the top of the EV3 Brick's screen

    • The EZ3IDE (the web-based Python IDE) should load in the browser
  • On the left is a file browser that lets you browse folders/files on the EV3, create new folders/files, etc.
    • Clicking on a file will open it in the IDE for you to edit. You can "save," "run," etc from the buttons in the top right.

Here is a video (5 minutes, 30 seconds) showing this process:

Notes:

  • This environment is being served up by the EV3 brick and the files are stored on the EV3 brick. The brick is NOT a powerful processor, and thus things are slow, take a long time, etc. Be patient.

  • If running a program (e.g. some python code), do NOT close the tab (or close the entire browser window). You need the "stop button" in the top right in order to "stop" the program.

  • If you DO get stuck and something isn't working, hold the "back button" on the EV3 brick, and this will "kill everything" (your running program, the web server, the IDE, communication, etc). Once it has stopped, you'll have to re-start the server/IDE (e.g. go to File Browser and find/run the "RunIDE.py" script. Remember, this takes a long time to restart, so you want to avoid this if possible.

    • If the brick is "frozen" and not responding to anything, you might have to restart the brick. Hold the back button + left button + center button all that the same time for 3 or 4 seconds until the brick reboots.
  • Once you are done with a session, be sure to properly shut down the brick (hit back button until you return to main screen, and one more time to bring up "Power Off" dialog) in order to be sure all files are saved properly. If you have important code, make sure to download and save to your local computer so you have backups/copies.  (If you right-click and download a folder, it should zip it up and download the zip file to your desktop.)

Using Bluetooth Connection:

Note that it's possible to use a Bluetooth connection from the EV3 brick directly to your computer (and not use the WiFi Dongle or the Tufts-Wireless WiFi network). Here are the Bluetooth instructions for connecting an EV3 brick running ev3dev to your computer:

http://www.ev3dev.org/docs/tutorials/connecting-to-the-internet-via-bluetooth/

Once the Bluetooth connection has been made and the internet shared, and the EV3 has been assigned an IP address (in the top left), you can then find/run the "RunIDE.sh" server as instructed above, and then go to the IP in your Chrome browser and load the EZ3IDE following the same procedure.

Jan 18 2018 Read →

Updating the IDE (EV3)

Periodically we may issue updates to the IDE to fix bugs or add new features. Here is how you can update the IDE on your own.

NOTE: if you are using the Raspberry Pi/GoPiGo, use THESE INSTRUCTIONS instead.

STEP 1: Download the Latest Version

Version 0.5 for EV3:

https://drive.google.com/file/d/1HPz-wxQeGruLuBL9bY6JwFhh9k1_K-qw/view

STEP 2: Flash the SD Card

1. Download and install Etcher from their website.

2. Launch Etcher

3. Click the “Select image” button and browse to the folder where you downloaded an EZ3IDE release. Select the file that you downloaded.

4. Using an SD card reader, plug the SD card into your computer. Etcher should detect the new device and display its information under the “Select drive” step. Confirm that the selected drive is correct.

Note: If you have multiple removable drives connect, you may need to use the “Change” button to select the SD Card.

5. Click "Flash!" and wait for the operation to complete.

6. Plug it in the Brick and make sure it boots up.

Jan 18 2018 Read →

Intro to EZ3IDE

The First Screen

Image

This is the first screen you see as soon as you open the ide. The left side contains a panel containing the folder tree which is there to navigate through files and folders. This panel also allows you to:

  • Make new files and folders
  • Copy and paste files and folders
  • Delete Files and folders
  • Import or directly drag files and folders to a destination

Navigating Through Directories

Image

Click on Directories to expand them and see the files and folders inside it. In order to open a file go to the desired location and click on the file.

Operations on files and folders

Image

Right click on the desired folder or file to do the operation you want. You'll see a list of options you can use. You can create new project folders, new files with numerous extensions, and copy, paste and delete files and folders.

Saving files

Image

After you open a file and edit it, you can save the file by clicking the button shown above. Alternatively, you can also use the keyboard shortcut "Ctrl/Cmd"+"S" to save files.

Block commenting on code

Image

While writing any code in the ide you can comment out a block of code by selecting the required block. After selecting you can press "Ctrl/Cmd"+"/" to comment the block.

Running the code on device

Image

To run your code on the device you can click the button shown above to execute the code.

The Console

Image

This part of the page shows the output (if any) when running the code. It also shows errors if any is encountered during the execution in the code. The button on the top right part of the console clears the content in the console.

Stopping the execution

Image

After executing the code, if you want to stop the code during the middle of the execution you can press this button to do so.

Changing the files tabs

Image

While working on multiple files or while multiple files are open, you can change which file to view by selecting on the desired file title (tab titles). Alternatively, you can use the keyboard shortcuts:

  • "Ctrl/Cmd"+"U" to move to the next tab
  • "Ctrl/Cmd"+"Y" to move to the previous tab

Using the available snippets

Image

You can use the pre-written snippets of code that are available for multiple devices. To use them simply drag the snippet you need and drop it on the part of the code you need the snippet.

Searching for snippets

Image

To find the snippet you need you can type a part of the snippet you remember on the search area shown above to immediately see all the snippets that contain the search query.

Showing snippets for a different device

Image

Apart from searching you can also go to the device tab you're working on through the drop down box to find the appropriate heading that contains the snippet you're looking for.

Feb 1 2018 Read →

Gyro

Here are some hints/help when using the LEGO MINDSTORMS Gyro Sensor.

1. Use .value() to read the value

Here is some example code for reading 10 gyro sensor values (angle). While this program was running, I was turning the gyro sensor forwards and then backwards.

Image

2. Resetting (calibrating) the gyro

Sometimes, in the middle of your code, you want to say "where the gyro is right now, consider that to be 0-degrees."  There is no explicit function for resetting, but if you change modes it will reset the gyro back to zero.  Note that you want to make sure the sensor is STILL (not moving) when you reset, else you will get drift in your new readings.

Image

Here are the files:

Feb 5 2018 Read →

Trig Functions in Python

Here is an example doing trigonometric functions in Python:

#!/usr/bin/python3
import math # Uses simple trig functions from the math library
# Make sure to import math lib
# https://docs.python.org/3/library/math.html def main(): # Sample cos(x) at each degree from 0-359 cos_vals = [math.cos(math.radians(i)) for i in range(360)] print("cos(x)") print(cos_vals) # Sample cos(x) at each degree from 0-359 sin_vals = [math.sin(math.radians(i)) for i in range(360)] print("sin(x)") print(sin_vals) if __name__ == '__main__': main()

Uses the Python math library: https://docs.python.org/3/library/math.html

Feb 11 2018 Read →

Motor to Position

Here is some code to move a motor to specific positions (relative to where it is now).

#!/usr/bin/python3 from time import sleep
def main(): position1 = 720 # forward two full rotations speed1 = 400 position2 = -360 # backward one full rotation speed2 = 200 # set up the motor ev3 = Device('this') m = ev3.LargeMotor('outB') # run to position 1 print('Going to Position 1: ' + str(position1)) m.run_to_rel_pos(position_sp=position1, speed_sp=speed1, stop_action="hold") # wait till done moving (keep checking) while m.is_running: sleep(0.1) # wait 1/2 second before moving to next position sleep(0.5) # run to position 2 print('Going to Position 2: ' + str(position2)) m.run_to_rel_pos(position_sp=position2, speed_sp=speed2, stop_action="hold") # wait till done moving (keep checking) while m.is_running: sleep(0.1) # "relax" the motor at end of the program m.stop(stop_action="coast") if __name__ == '__main__': main()

This uses _run_to_relpos.  There is also a _run_to_abspos function.

This also uses a "while m.is_running: sleep(0.1)" trick to wait until motor stops running.  Note there is also a "m.wait_while('running')" command that might work instead.

More on the ev3dev Python motor functions:

Feb 11 2018 Read →

Position Array

Here is some code for storing motor positions into an array:

#!/usr/bin/python3
from time import sleep def main(): print('Save Motor Position') positions = [] # create blank array # set up EV3 ev3 = Device('this') motor = ev3.LargeMotor('outB') # reset motor position to be zero (to start) motor.reset() # collect three motor positions for i in range(3): positions.append(motor.position) print("Position " + str(i) + " = " + str(positions[i])) sleep(1) # print out the individual motor positions (mp) for mp in positions: print(mp) if __name__ == '__main__': main()

More information on arrays in Python:

Feb 11 2018 Read →

Dynamic Arrays in Python Using Numpy

By Hans Tercek on 2/15/2018

Edit 2/19/18: The EV3 bricks do not appear to come with Numpy pre-installed. If working with the EV3, stick to Python's lists. If running Python on a Linux machine or on macOS, run the following command from your terminal to install Numpy:
Python 2.:
>> pip install numpy
Python 3.
:
>> pip3 install numpy

Fun fact: Python's built in "array" system (i.e. declaring x = [1, 2, 3]) is not actually declaring x to be an array of integers. Instead, Python uses lists.

While lists operate, by-and-large, very similarly to traditional arrays, they are stored and accessed in a manner that is much less efficient than traditional arrays and they can be quite tricky to perform mathematic operations on (try multiplying a list and see what outputs).

Enter... Numpy

Numpy is a great mathematical toolkit for Python that also happens to include a phenomenal array feature. It serves as the foundation on which most matrix-heavy Python packages are built (take OpenCV for example... because images are a 2D array of integer values, OpenCV uses Numpy for its array features).

Using Numpy is super easy to use. Just as you'd import any package in Python, at the top of your file, include the following line:

| >> import numpy as np

This allows you to reference any feature in Numpy by typing "np"

Now, let's use Numpy's array feature.

Full documentation can be found here, but I'll write a quick guide to serve as a brief intro:

To create an array, simply initialize a variable as an empty array. The default type for arrays is float64 (64 bit floating point). You can specify datatype if memory constraints are an issue.

| >> x = np.array([1, 2, 3])
| >> print(x)
| [1, 2, 3]

To append elements to an array:

| >> x = np.append(x, 1)
| >> print(x)
| [1, 2, 3, 1]

To index an array:

| >> x2| 3

To delete elements from an array:

| >> x = np.delete(x, [2, 3])
| >> print(x)

To perform a mathematical operation on each element of an array:

>> x = x 2

| >> print(x)
| [2, 4]

While most material for the class can be handled using Python's built-in lists, Numpy arrays are a handy tool to know. They are considered a Python standard, are applied heavily in third party packages, and can be quite handy for writing your own code. Give them a shot in your own projects!

Feb 15 2018 Read →

Raspberry Pi

Raspberry Pi Firmware Update to use EV3IDE

In order to use the IDE, the Dexter firmware must first be updated. This is easy!

Plug everything in and obtain IP address

From your favorite SSH client (macOS and Linux can just use Terminal), run the following:
For Windows, you'll need an SSH client (why??). A popular option is PuTTy (https://www.putty.org/)

Update Firmware:

| >> ssh pi@IP_ADDR
| >> yes
| >> password: tuftsjumbo
| >> cd Dexter/GoPiGo3/Install
| >> sudo ./update_gopigo3.sh
| >> sudo reboot

Build IDE (this takes a while):

| >> ssh pi@IP_ADDR
| >> password: tuftsjumbo
| >> cd setup_ez3
| >> sudo ./setup_build.sh
| >> sudo reboot

Mar 1 2018 Read →

Updating the IDE (Raspberry Pi/GoPiGo)

Periodically we may issue updates to the IDE to fix bugs or add new features. Here is how you can update the IDE on your own.

NOTE: if you are using the LEGO MINDSTORMS EV3, use THESE INSTRUCTIONS instead.

STEP 1: Download the Latest Version

Version 0.5b for Raspberry Pi/GoPiGo:

https://drive.google.com/file/d/1xFsFDPVBZWDRxwaCw3mLbXGNuwb8D57R/view?usp=sharing

STEP 2: Flash the SD Card

1. Download and install Etcher from their website.

2. Launch Etcher

3. Click the “Select image” button and browse to the folder where you downloaded an EZ3IDE release. Select the file that you downloaded.

4. Using an SD card reader, plug the SD card into your computer. Etcher should detect the new device and display its information under the “Select drive” step. Confirm that the selected drive is correct.

Note: If you have multiple removable drives connect, you may need to use the “Change” button to select the SD Card.

5. Click "Flash!" and wait for the operation to complete.

6. Plug it in the Raspberry Pi and make sure it boots up.

Mar 11 2018 Read →

Student and TA Submitted Help

Inverse Kinematics

by Ipek Emekli

Calculation of motor angles based on x-pos and y-pos of robot arm end-effector.

Image

Things to keep in mind/tips and tricks

The trig and math for the angle sign correction can get complicated with all four quadrants involved, so you may consider building your robot so that its motion is physically limited to the first two quadrants.

Image

When you’re testing the robot, you can notice that there are two possible motor positions for each given end effector position (see figure below), thus, the “alpha” variable can be taking random negative or positive values. This would cause theta1 (theta1=alpha+beta) to be very off. To solve this issue, you may want to sketch out different cases and determine the correct angle sign corresponding to each case.

Image

Make sure you’re using radians or degrees consistently throughout the assignment — with your calculations and code. (See the "Angular Conversions" for Python Math module.)

Click here to download the full PDF version of these Tips and Tricks.

Helpful video tutorial that walks through the steps with visual aids (note usage of q instead of theta and a instead of L): Inverse Kinematics for a 2-Joint Robot Arm Using Geometry

Feb 12 2018 Read →

For additional help, email Professor Ethan Danahy or Teaching Assistants.