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

Similar documents
Variables and Functions. ROBOTC Software

Chapter 3. More Flow of Control. Copyright 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley

Introduction. C provides two styles of flow control:

Control Flow. COMS W1007 Introduction to Computer Science. Christopher Conway 3 June 2003

Movement using Shaft Encoders

Programming Fundamentals - A Modular Structured Approach using C++ By: Kenneth Leroy Busbee

CAMBRIDGE SCHOOL, NOIDA ASSIGNMENT 1, TOPIC: C++ PROGRAMMING CLASS VIII, COMPUTER SCIENCE

All copyrights reserved - KV NAD, Aluva. Dinesh Kumar Ram PGT(CS) KV NAD Aluva

C++ Programming: From Problem Analysis to Program Design, Fourth Edition. Chapter 4: Control Structures I (Selection)

REPETITION CONTROL STRUCTURE LOGO

Control Structures. Control Structures Conditional Statements COMPUTER PROGRAMMING. Electrical-Electronics Engineering Dept.

Introduction to Computers and C++ Programming p. 1 Computer Systems p. 2 Hardware p. 2 Software p. 7 High-Level Languages p. 8 Compilers p.

Technical Questions. Q 1) What are the key features in C programming language?

Introduction to Programming Using Java (98-388)

COSC 123 Computer Creativity. Introduction to Java. Dr. Ramon Lawrence University of British Columbia Okanagan

Objectives. Chapter 4: Control Structures I (Selection) Objectives (cont d.) Control Structures. Control Structures (cont d.) Relational Operators

Le L c e t c ur u e e 3 To T p o i p c i s c t o o b e b e co c v o e v r e ed e Control Statements

Activity Variables and Functions VEX

B.V. Patel Institute of Business Management, Computer & Information Technology, Uka Tarsadia University

Chapter 3. More Flow of Control. Copyright 2008 Pearson Addison-Wesley. All rights reserved.

Chapter 4: Control Structures I (Selection) Objectives. Objectives (cont d.) Control Structures. Control Structures (cont d.

Problem Solving with C++

COP 1220 Introduction to Programming in C++ Course Justification

Activity Robot Behaviors and Writing Pseudocode

Objectives. Chapter 2: Basic Elements of C++ Introduction. Objectives (cont d.) A C++ Program (cont d.) A C++ Program

Chapter 2: Basic Elements of C++

Chapter 2: Basic Elements of C++ Objectives. Objectives (cont d.) A C++ Program. Introduction

Unit 2: Java in the small. Prepared by: Dr. Abdallah Mohamed, AOU-KW

BTE2313. Chapter 2: Introduction to C++ Programming

Java provides a rich set of operators to manipulate variables. We can divide all the Java operators into the following groups:

Sequence structure. The computer executes java statements one after the other in the order in which they are written. Total = total +grade;

Unit 2: Java in the small

Laboratory 0 Week 0 Advanced Structured Programming An Introduction to Visual Studio and C++

STUDENT LESSON A12 Iterations


7/8/10 KEY CONCEPTS. Problem COMP 10 EXPLORING COMPUTER SCIENCE. Algorithm. Lecture 2 Variables, Types, and Programs. Program PROBLEM SOLVING

Working with JavaScript

Chapter 2: Using Data

Coding Workshop. Learning to Program with an Arduino. Lecture Notes. Programming Introduction Values Assignment Arithmetic.

General Syntax. Operators. Variables. Arithmetic. Comparison. Assignment. Boolean. Types. Syntax int i; float j = 1.35; int k = (int) j;

Review for Test 1 (Chapter 1-5)

Decision Making in C

Arduino Uno. Power & Interface. Arduino Part 1. Introductory Medical Device Prototyping. Digital I/O Pins. Reset Button. USB Interface.

3. Java - Language Constructs I

Introduction to Computer Science Midterm 3 Fall, Points

STUDENT OUTLINE. Lesson 8: Structured Programming, Control Structures, if-else Statements, Pseudocode

Operators. Java operators are classified into three categories:

Flow of Control. Flow of control The order in which statements are executed. Transfer of control

Chapter 2: Functions and Control Structures

V2 2/4/ Ch Programming in C. Flow of Control. Flow of Control. Flow of control The order in which statements are executed

Quiz Start Time: 09:34 PM Time Left 82 sec(s)

Software and Programming 1

If you note any errors, typos, etc. with this manual or our software libraries, let us know at

CS201 Latest Solved MCQs

Repetition and Loop Statements Chapter 5

Module 3 SELECTION STRUCTURES 2/15/19 CSE 1321 MODULE 3 1

Visual C# Instructor s Manual Table of Contents

Absolute C++ Walter Savitch

Flow Control. CSC215 Lecture

Functions. Lecture 6 COP 3014 Spring February 11, 2018

PLD Semester Exam Study Guide Dec. 2018

6.096 Introduction to C++ January (IAP) 2009

APCS Semester #1 Final Exam Practice Problems

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

Software and Programming 1

C++ Support Classes (Data and Variables)

Troubleshooting ROBOTC with Cortex

CSc 10200! Introduction to Computing. Lecture 2-3 Edgardo Molina Fall 2013 City College of New York

CS 112 Introduction to Computing II. Wayne Snyder Computer Science Department Boston University

A flow chart is a graphical or symbolic representation of a process.


Controls Structure for Repetition

Introduction to C Programming

Language Proposal: tail

Chapter 2. Lexical Elements & Operators

Language Reference Manual

QUIZ. 1. Explain the meaning of the angle brackets in the declaration of v below:

BRANCHING if-else statements

Following is the general form of a typical decision making structure found in most of the programming languages:

Object-oriented programming. and data-structures CS/ENGRD 2110 SUMMER 2018

Connecting with Computer Science, 2e. Chapter 15 Programming II

V3 1/3/2015. Programming in C. Example 1. Example Ch 05 A 1. What if we want to process three different pairs of integers?

Interpreted vs Compiled. Java Compile. Classes, Objects, and Methods. Hello World 10/6/2016. Python Interpreted. Java Compiled

Course Outline. Introduction to java

C++ Basics. Data Processing Course, I. Hrivnacova, IPN Orsay

COMSC-051 Java Programming Part 1. Part-Time Instructor: Joenil Mistal

CS 251 Intermediate Programming Java Basics

Lab # 02. Basic Elements of C++ _ Part1

Loops and Files. Chapter 04 MIT 12043, Fundamentals of Programming By: S. Sabraz Nawaz

5.1. Chapter 5: The Increment and Decrement Operators. The Increment and Decrement Operators. Looping. ++ is the increment operator.

Chapter 5 Control Statements: Part 2 Section 5.2 Essentials of Counter-Controlled Repetition

Introduction to C Final Review Chapters 1-6 & 13

13 th Windsor Regional Secondary School Computer Programming Competition

C++ Programming: From Problem Analysis to Program Design, Third Edition

SSOL Language Reference Manual

By the end of this section you should: Understand what the variables are and why they are used. Use C++ built in data types to create program

Chapter 1 Getting Started

Programming for Engineers Iteration

DEPARTMENT OF MATHS, MJ COLLEGE

CHRIST THE KING BOYS MATRIC HR. SEC. SCHOOL, KUMBAKONAM CHAPTER 9 C++

Transcription:

RoboCup Rescue EV3 Workshop Part 1 Introduction to RobotC

Why use RobotC? RobotC is a more traditional text based programming language The more compact coding editor allows for large programs to be easily developed, debugged and managed RobotC also has some programming advantages over the EV3 Graphical software, such as; Re usable Functions Complexity of Algorithms Complexity of Calculations Smaller more efficient running of code on the robot A more traditional code layout that allows for easy pseudocode translation Note: BricxCC/NXC does not at this time support EV3. It does support NXT and is a free to use alternative

RobotC and RoboCup Rescue Should be considered by some Secondary and Open teams Lego s EV3 software can be used for complex algorithms, however, it becomes extremely difficult to visualise the entire program RobotC allows teams to develop more complex and precise solutions Teams can develop reusable Functions (a little like MyBlocks) Tasks are easier to manage (turn on and off) Teams need to realise that there is an initial steep learning curve! Prior procedural programming experience is an advantage!

The IDE (Integrated Development Environment) RobotC 4.xxx has a traditional text editor code window including line numbering and colour coded text A basic Debug window displays compilation errors A Text Functions list which I would rather call the Control Structures and Keyword Templates window RobotC does include some IntelliSense code completion delivering logical code in a selectable dropdown list Type you code in here

Text Functions pallet It is impossible for someone to remember ALL of the code syntax for a particular language! The Text Functions pallet contains all the available RobotC Functions used to control the actuators (motors etc) and receive information from all the sensors and finally process all the inputs using control structures to allow the robot to navigate the course. Three levels of menus are available Basic, Expert & Super User Change this from the Windows menu

Programming Syntax and Rules Here is an example program a Left Edge Line Follower Each program must have an Entry Point A Task must have its own pair of { } All Functions have their own pair of ( ) Each Control Structure (While, If.etc) has its own pair of { } between which your process code is placed Every Expression must end with a ; except for Boolean Expressions [ ] brackets are used with Variable functions // are used to write a comment

Tasks Multitasking Tasks are activated in task main() when the program starts Task main() is always at the bottom and always running All other tasks() are positioned above task main() All tasks can start and stop other tasks (except for task main(), it s always running and can t be stopped by another task

Variables Global vs Local In Mindstorms EV3, all variables are Global RobotC allows for Global and Local variables Consider the example code which has 1 global, and 2 local variables Whenever the global variable is called it will display the global value The local variables in this example have the same identifier k but reside in separate control structures as defined by { } This results in k displaying different values (25 & 10) depending on its location

Data Types Variables need to be declared as a particular Data Type. Type Syntax Description Boolean: bool name; has only two values True or False Integer: int name; holds 2 byte integer 32768 to 32767 Long Integer: long name; holds 4 byte integer + 2.1 million Floating Point: float name; same range as int, are decimal/fractions String: string name; can hold a sequence of characters

Unary Operations Lazy programmers C is full of shortcuts because programmers are inherently lazy Rather than writing i= i+ 1 for an accumulator, we can write ++i Here are examples of code shortcuts or Unary Operations ++i is the same as i= i+ 1 which is the same as i +=1 i is the same as i= i 1 which is the same as i =1 i/=2; is the same as i= i/ 2 i *=2; is the same as i= i* 2 i%=2; is the same as i= i% 2

Functions Is a group of statements that run as a single unit when it is called from another location such as task main( ) If you find that you are re typing the same code to do the same action, then it s time to create a Function Firstly, Declare your Function by using the word void Give the Function a meaningful name (no spaces) Write you code between curly braces { } Call you function, by name plus brackets and semicolon Parameters can be passed within the brackets ( ) allowing the Function to behave differently depending on variable inputs

Control Structures Repetition (Loop) is handled by WHILE (conditional expression) {} Pre test loop DO { body } WHILE (conditional expression) Post test loop FOR (initial setup; conditional expression; increment or decrement) {} Counting loop Decision is handled by IF (conditional expression) {body} Binary decision IF (conditional expression) { body } ELSE { body } Binary decision with option Nested IF s can create complex decision making structures SWITCH (variable) { CASE num: body break; default; body } Multiway selection

Debugger Allows you to more easily find Logical Errors in code Start and Stop; the program from the PC Single Step Through; of code line by line Breakpoints; define points in the code to stop execution and view Read and Write values of Variables in your program Read and Write values of Motors and Sensors Another method of debugging robots, is to use datalogging, allowing you to record in real time all of the variables, motor & sensor values and then display them on a chart or graph for further alalysis