Branching Error (a.k.a. the VM Program Instruction Break Error) By Sanjay and Arvind Seshan DEBUGGING LESSON

Similar documents
How to Use EV3Lessons

EV3Dev Lessons. Introduction to EV3Dev: Setup with Python

ADVANCED EV3 PROGRAMMING LESSON. Arrays. By Droids Robotics

BEGINNER PROGRAMMING LESSON

INTERMEDIATE PROGRAMMING LESSON

INTERMEDIATE PROGRAMMING LESSON

INTERMEDIATE PROGRAMMING LESSON

PixyCam for MINDSTORMS Introduction

EV3 Programming Workshop for FLL Coaches

WIZ-PRO2 CURRICULUM HIGHLIGHTS

LEGO Mindstorm EV3 Robots

Introduction to Robotics using Lego Mindstorms EV3

Unit 03 Tutorial 3: Sensors: Touch Sensor Brighton H.S Engineering By: Matthew Jourden

EduRob EV3 Technical User Guide

LEGO mindstorm robots

EPUB # LEGO MINDSTORMS CERTIFICATION STUDY OPERATING INSTRUCTIONS DOCUMENT

Programming Techniques Workshop for Mindstorms EV3. Opening doors to the worlds of science and technology for Oregon s youth

Project from Real-Time Systems Lego Mindstorms EV3

Control Structures. Code can be purely arithmetic assignments. At some point we will need some kind of control or decision making process to occur

the NXT-G programming environment

Loops and Switches Pre-Quiz

What is EV3DEV? Send commands to the EV3 Upload programs and run them on the EV3

COPYRIGHTED MATERIAL. Introducing LEGO CHAPTER. Did you get a box that looks like the one shown in Figure 1-1?

Autonomous Parking. LEGOeducation.com/MINDSTORMS. Duration Minutes. Learning Objectives Students will: Di culty Beginner

Robot Design Hardware

CODAPPS. Adding Labels and Buttons to a Form. Clément Levallois

Programming in ROBOTC ROBOTC Rules

Tutorial: Making Legobot Move Steering Command Brighton H.S Engineering By: Matthew Jourden

LME Software Block Quick Reference 1. Common Palette

CODAPPS. Adding Labels and Buttons to a Form. Clément Levallois

24-vm.txt Mon Nov 21 22:13: Notes on Virtual Machines , Fall 2011 Carnegie Mellon University Randal E. Bryant.

Chapter 2: Operating-System Structures. Operating System Concepts 9 th Edit9on

Introduction to Lab 2

what is an algorithm? analysis of algorithms classic algorithm example: search

Robotics 2c. The Programming Interface

Some call it a robot. EV3 Programming APP Available March Locally operated globally connected. Freecall:

B - Broken Track Page 1 of 8

Chapter 19 Assembly Modeling with the TETRIX by Pitsco Building System Autodesk Inventor

Computing and compilers

Part A: Monitoring the Rotational Sensors of the Motor

Development of a System for Teaching. Robots

Introduction to Lab 2

The Unofficial Guide To LEGO MINDSTORMS Robots By Jonathan Knudsen READ ONLINE

How to start with Intelligent VOICE

Robotics II. Module 1: Introduction to Data & Advanced Programming Blocks

EQ-ROBO Programming : Ladybird Robot

Loops and Switches Pre-Quiz

Do-While Example. In C++ In assembly language. do { z--; while (a == b); z = b; loop: addi $s2, $s2, -1 beq $s0, $s1, loop or $s2, $s1, $zero

USER GUIDE. BuWizz brick 2.0. ios & Android app. Table of Contents. 1. Introduction Compatibility Do this first 3

An Introduction to the Lego Mindstorms

Colin Harman and Jonathan Kim

Portland State University ECE 587/687. Virtual Memory and Virtualization

1. What is the name of the control unit in Robotics? a. R2D2 b. MSN c. Pilot d. XJ7 e. RCX

Java using LEGO Mindstorms and LeJOS. University of Idaho

Getting Started with FTC Using RobotC

CHAPTER 2: SYSTEM STRUCTURES. By I-Chen Lin Textbook: Operating System Concepts 9th Ed.

Robolab. Table of Contents. St. Mary s School, Panama. Robotics. Ch. 5: Robolab, by: Ernesto E. Angulo J.

Chapter 2: Operating-System Structures

Winning LEGO MINDSTORMS programming

SMART PLANNER Online Training Guides

Tech Tips. BeeBots. WeDo

TETRIX Getting Started Guide FTC Extension

Integrated Software Environment. Part 2

All Blocks of Scratch

G. Tardiani RoboCup Rescue. EV3 Workshop Part 1 Introduction to RobotC

Top Down Breaking a Problem Down

Robotics II. Module 4: Bluetooth Communication

Digital Devices in the Digital Technologies curriculum (F-10) Steve Allen VCAA Digital Coding Specialist Teacher

Chapter 2: Operating-System Structures. Operating System Concepts 9 th Edition

Computer Science 324 Computer Architecture Mount Holyoke College Fall Topic Notes: MIPS Instruction Set Architecture

EPUB / LEGO MINDSTORMS NXT SEGWAY BUILDING REPAIR MANUAL EBOOK

Robotics with Elixir

Linux Everywhere. A look at Linux outside the world of desktops. CIS 191 Spring 2012 Guest Lecture by Philip Peng

Technology in Action. Alan Evans Kendall Martin Mary Anne Poatsy. Eleventh Edition. Copyright 2015 Pearson Education, Inc.

Topic Notes: MIPS Instruction Set Architecture

COMP 3500 Introduction to Operating Systems Project 5 Virtual Memory Manager

2Control NXT FAQ For the latest version of this document please go to > support

RIS version 2.0 Software Training Lab

============================================================================

Rui Wang, Assistant professor Dept. of Information and Communication Tongji University.

This page outlines some of the alternate pieces that can be used for building.

contents in detail introduction...xix comic: the EV3L scientist s apprentice your LEGO MINDSTORMS EV3 set building ROV3R...

When an instruction is initially read from memory it goes to the Instruction register.

T Jarkko Turkulainen, F-Secure Corporation

Overview. EE 4504 Computer Organization. Much of the computer s architecture / organization is hidden from a HLL programmer

Chapter 18 Assembly Modeling with the LEGO MINDSTORMS NXT Set Autodesk Inventor

Figure 1 Common Sub Expression Optimization Example

Variables and Functions. ROBOTC Software

Virtualization. ...or how adding another layer of abstraction is changing the world. CIS 399: Unix Skills University of Pennsylvania.

switch case Logic Syntax Basics Functionality Rules Nested switch switch case Comp Sci 1570 Introduction to C++

USB. Bluetooth. Display. IO connectors. Sound. Main CPU Atmel ARM7 JTAG. IO Processor Atmel AVR JTAG. Introduction to the Lego NXT

Robotics Study Material School Level 1 Semester 2

More advanced CPUs. August 4, Howard Huang 1

In groups take a Mindstorms kit and decide on what sort of chassis will work best.

The Maze Runner. Alexander Kirillov

Control Structures. Lecture 4 COP 3014 Fall September 18, 2017

Chapter 9. Introduction to High-Level Language Programming. INVITATION TO Computer Science

Android Programmierung leichtgemacht. Lars Vogel

Lab 4: Interrupts and Realtime

CS510 Operating System Foundations. Jonathan Walpole

Transcription:

Branching Error (a.k.a. the VM Program Instruction Break Error) By Sanjay and Arvind Seshan DEBUGGING LESSON

HISTORY We first encountered the VM Program Instruction Break error on our brick during the fall of 2013 during the Nature s Fury FLL season. We searched online for any documentation about this error, but could not find any. We were the first to report this problem on the FLL Forum. Many FLL and WRO teams have encountered this error since then. While they persisted and tried to come up with a workaround, the solution was never enough. Without knowing what was causing the error, it was difficult to come up with a permanent solution. The only solution available at the time was trial and error. This presentation documents what the underlying causes were and the solution.

COMMON SYMPTOMS The robot stops in the middle of a program and displays VM Program Instruction Break on the screen Adding debugging code may make the error appear in a different location of the code. The error would appear even with minimal changes to the code such as the movement of the relative position of two My Blocks Often occurs in more complex programs (e.g. it often happened to us each season as we added more code to our main sequencer) Image provided by David Gilday

WHAT IS A VM? A virtual machine (VM) is an emulation of a computer system. This emulated system maybe totally different than the computer you run the VM on. For example, you may run a VM emulating an iphone on your laptop to run or test phone software. The EV3 uses a TI's Sitara AM1808 ARM9 processor running the Linux OS. However, the code you download to the EV3 is not a ARM9 binary. It contains EV3 bytecode that is interpreted by a VM running on the EV3. The bytecode for the EV3 defines a simple set of instructions to perform computations and access the hardware connected to the EV3 (screen, bluetooth, motors, etc.)

WHAT IS BYTECODE? The bytecodes are closely related to the blocks you see in EV3-G. For example: BYTECODE: OUTPUT_POWER(0,1,50). This particular command sets the power of the motor on port 1. Other bytecodes actually start and stop the motor Port # Bitfield OUTPUT_POWER(0,1,50) Command Brick # Power To learn more, visit: http://analyticphysics.com/diversions/assembly%20language%20programming%20for%20lego%20mindstorms%20ev3.htm

WHAT ROLE DOES THE VM PLAY EV3-G Programs Robot C Other Languages Virtual Machine Linux ARM9 CPU EV3 Hardware (screen, sensors, etc.) The VM sits between your programs and the operating system running on the EV3 Note that systems such ev3dev run their own updated Linux installation with their own drivers for the EV3 hardware (i.e. they don t use a VM bytecode interpreter)

SOURCE OF THE PROBLEM Was it really a bug in the VM? No. Turns out it an issue with the compiler on your PC generating incorrect bytecode. Specifically, it was a problem with the branches in the code generated. What is branch code? Normally, your EV3 executes instructions in sequential order A branch (or jump) instruction is one that tests a condition (e.g. is the button pressed) and causes the EV3 to jump to a different set of instructions if the condition is met Branches are used to implement Switches, Loops and almost any command that results in different possible results. EV3 bytecode has unconditional branches that always jump to another piece of code, and conditional branches that test one or two pieces of data

A SIMPLE VIEW Each box is one bytecode instruction. Read the touch sensor. Was it pressed? Try again. Stop all the motors. No What you want your code to do: In the top case, the branches jump to the beginning of each sentence Read the touch sensor. Was it pressed? Try again. Stop all the motors. No What happens in a VM Program Instruction Break: In the bottom case, the branch jumps too far. The EV3 tries to interpret what the command the motors means and fails.

A BYTECODE VIEW buttonpushed: INPUT_READ (0,0,16,0,pushed) JR_FALSE(pushed,buttonNotPushed) JR(buttonPushed) buttonnotpushed: This is the button pushed loop label Read touch on port 1 in touch mode and store in variable pushed If pushed is FALSE exit the loop by jumping to the buttonnotpushed code. If it is not pushed, it just goes to the next instruction Go back to the beginning of the button pushed loop label buttonnotpushed: label OUTPUT_STOP(0,1,0) Stop motor B

EXAMPLE BYTECODE INPUT_READ (0,0,16,0,pushed) JR_FALSE(pushed,32) JR(-32) OUTPUT_STOP(0,1,0) Actual executed code does not include the labels, but does include the offsets. Length (or offset) of the jump is in red. Arrows point to the destination of the jump. Note, the jump is to the start of each command.

THE PROBLEM INPUT_READ (0,0,16,0,pushed) JR_FALSE(pushed,33) JR(-32) OUTPUT_STOP(0,1,0) The offset of the branch was sometimes calculated incorrectly. In this case, it says 33 instead of 32 (in red). As a result, the branch would jump to the middle of OUTPUT_STOP instruction. This is like jumping to the middle of a sentence. Most often the partial instruction made no sense and the VM would respond with a VM Instruction Break Sometimes the partial command was a valid instruction just not the one you wanted. Therefore, your robot would act incorrectly.

WHY? AND WHAT HAPPENS NOW? The source of the problem is that the code compiler on your PC calculated an incorrect branch length (offset). LEGO has released an update to the EV3 programming software with a bug fix As of of 10/25/2016, both Retail and Education editions of V. 1.2.2 are available for download Download and install the update on your PC After that, you can load any program you had symptoms such as VM Instruction Break that were caused by the bad branches and just download again to your EV3. The newly downloaded code should not have any bad branching code!

SOME LESSONS Reporting errors can be useful A big part of finding the solution to the VM Program Instruction Break error was FLL, WRO teams and other robot builders reporting and discussing errors Similar to when you see a Google or Microsoft report this error message on your screen. Learning debugging skills FIRST LEGO League teams, in particular, faced this error as their code became come complex They persisted and worked around the problem as well as they could.

A COMMUNITY EFFORT Thank you to MINDSTORMS Community Partners, FLL Teams, WRO Teams, other builders in the community, National Instruments, and LEGO who worked together to identify this error and create a solution.

CREDITS This tutorial was created by Sanjay Seshan and Arvind Seshan More lessons at www.ev3lessons.com This work is licensed under a Creative Commons Attribution- NonCommercial-ShareAlike 4.0 International License.