What is RobotC?!?! Team 2425 Hydra. Overview What is RobotC What is RobotC used for What you need to program a robot How a robot program works Framework.

Slides:



Advertisements
Similar presentations
Introduction to Programming
Advertisements

Variables and Functions ROBOTC Software. Variables A variable is a space in your robots memory where data can be stored, including whole numbers, decimal.
08/2012Tanya Mishra1 EASYC for VEX Cortex Llano Estacado RoboRaiders FRC Team 1817.
Jason Howard. Agenda I. How to download robotc II. What is tele-op used for? III. How to build a basic tele-op program IV. Getting the robot to drive.
CS0007: Introduction to Computer Programming Console Output, Variables, Literals, and Introduction to Type.
Team 5220 Roboknights. Outline  Getting Started  Hardware Setup/Wiring  Software Setup/Pragmas  Programming with RobotC  Grammar/Syntax  Basic Statements.
Programming TBE 540 Farah Fisher. Objectives After viewing this presentation, the learner will be able to… Given a task, create pseudocode Given pseudocode,
Lecture 2 Introduction to C Programming
Introduction to C Programming
 2000 Prentice Hall, Inc. All rights reserved. Chapter 2 - Introduction to C Programming Outline 2.1Introduction 2.2A Simple C Program: Printing a Line.
Primitive Data Types There are a number of common objects we encounter and are treated specially by almost any programming language These are called basic.
Programing Concept Ken Youssefi/Ping HsuIntroduction to Engineering – E10 1 ENGR 10 Introduction to Engineering (Part A)
Bellevue University CIS 205: Introduction to Programming Using C++ Lecture 3: Primitive Data Types.
Programming Concepts (Part A) Ping Hsu. What is a program? WHITE CAKE RECIPE 1.Preheat oven to 350 degrees F (175 degrees C). 2.Grease and flour a 9x9.
RobotC Programming for LEGO Mindstorms NXT Carnegie Mellon Dacta Lego Timothy Friez Miha Štajdohar SOURCES:
Introduction to a Programming Environment
Programming Part 1 Armond R. Smith Zhenying Wu. Overview of this Class ● Transition from FTC -> FRC ● Using Your Resources ● Java Keywords o Data Types.
RobotC For Beginners Tyler Lutz and Keaton Bonds DRSS Enterprise.
Basic Elements of C++ Chapter 2.
While Loops and Do Loops. Suppose you wanted to repeat the same code over and over again? System.out.println(“text”); System.out.println(“text”); System.out.println(“text”);
Working with Arduino: Lesson #1: Getting Acquainted with the Kit EGN1007.
ROBOTC Software Introduction. ROBOTC Software ROBOTC developed specifically for classrooms and competitions Complete programming solution for VEX Cortex.
 2003 Prentice Hall, Inc. All rights reserved. 1 Introduction to C++ Programming Outline Introduction to C++ Programming A Simple Program: Printing a.
CSCI 1100/1202 January 16, Why do we need variables? To store intermediate results in a long computation. To store a value that is used more than.
CIS Computer Programming Logic
Coding for the FIRST Tech Challenge: RobotC Presented by: Audrey Yeoh Acknowledgements: Team Unlimited FTC 0001.
Coding for the FIRST Tech Challenge: RobotC
Programing Concept Ken Youssefi/Ping HsuIntroduction to Engineering – E10 1 ENGR 10 Introduction to Engineering (Part A)
Copyright © 2002 W. A. Tucker1 Chapter 7 Lecture Notes Bill Tucker Austin Community College COSC 1315.
CPS120: Introduction to Computer Science
Agenda Exam #1 Review Modulus Conditionals Boolean Algebra Reading: Chapter Homework #5.
5 BASIC CONCEPTS OF ANY PROGRAMMING LANGUAGE Let’s get started …
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Chapter 2 Chapter 2 - Introduction to C Programming.
Variables and Functions. Open your Encoder program Let’s begin by opening the “Labyrinth Auto Straight” code. Save this file as Labyrinth with variables.
Property of Jack Wilson, Cerritos College1 CIS Computer Programming Logic Programming Concepts Overview prepared by Jack Wilson Cerritos College.
CPS120: Introduction to Computer Science Decision Making in Programs.
Programming for Beginners Martin Nelson Elizabeth FitzGerald Lecture 2: Variables & Data Types.
6/3/2016 CSI Chapter 02 1 Introduction of Flow of Control There are times when you need to vary the way your program executes based on given input.
C++ Basics C++ is a high-level, general purpose, object-oriented programming language.
Introduction to Java Java Translation Program Structure
BEGINNING PROGRAMMING.  Literally – giving instructions to a computer so that it does what you want  Practically – using a programming language (such.
PHY-102 SAPVariables and OperatorsSlide 1 Variables and Operators In this section we will learn how about variables in Java and basic operations one can.
Repetition. Loops Allows the same set of instructions to be used over and over again Starts with the keyword loop and ends with end loop. This will create.
School of Computer Science & Information Technology G6DICP - Lecture 4 Variables, data types & decision making.
CRE Programming Club - Class 2 Robert Eckstein and Robert Heard.
Variables and Functions ROBOTC Software © 2012 Project Lead The Way, Inc.Principles of Engineering.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Chapter 2 - Introduction to C Programming Outline.
CPS120: Introduction to Computer Science Variables and Constants.
Variables  A piece of memory set aside to store data  When declared, the memory is given a name  by using the name, we can access the data that sits.
Chad’s C++ Tutorial Demo Outline. 1. What is C++? C++ is an object-oriented programming (OOP) language that is viewed by many as the best language for.
Vex Robotics program three: using motors and sensors together.
Lecture 3: More Java Basics Michael Hsu CSULA. Recall From Lecture Two  Write a basic program in Java  The process of writing, compiling, and running.
1 Lecture 2 - Introduction to C Programming Outline 2.1Introduction 2.2A Simple C Program: Printing a Line of Text 2.3Another Simple C Program: Adding.
Chapter 2 Variables and Constants. Objectives Explain the different integer variable types used in C++. Declare, name, and initialize variables. Use character.
Introduction to Programming in RobotC
Variables and Functions
INTRODUCTION TO ROBOTICS Part 5: Programming
Variables A piece of memory set aside to store data
Primitive Data, Variables, Loops (Maybe)
Variables and Functions
Variables and Functions
Working with Arduino: Lesson #1: Getting Acquainted with the Kit
Introduction to C++ Programming
Program Breakdown, Variables, Types, Control Flow, and Input/Output
C Programming Getting started Variables Basic C operators Conditionals
Robotics Programming Using Shaft Encoders
2. Second Step for Learning C++ Programming • Data Type • Char • Float
RobotC Programming for LEGO Mindstorms NXT
Introduction to C Programming
Variables and Constants
Presentation transcript:

What is RobotC?!?! Team 2425 Hydra

Overview What is RobotC What is RobotC used for What you need to program a robot How a robot program works Framework Assigning values Variables What is logic? Sensors

What is RobotC Computer programming language A way for humans to easily tell machines what to do Converts understandable “words” into machine (or binary) code A text-based form of C specially crafted for use with robots

What is RobotC Used For Tele-operated programs Autonomous programs Used for the FIRST Tech Challenge (along with LabView) Used for the Vex Robotics Competition (along with EasyC)

What You Need to Program a Robot in RobotC Robot with a microcontroller that can be programmed in RobotC A computer A driver for your robot (allows your computer to talk to the robot) A way to connect your microcontroller to your computer (USB, Bluetooth, etc.) A RobotC compiler compatible with the type of microcontroller you are using

What is a Compiler? Basic Concepts You “write” your RobotC as a text document Robots can only understand a file written in binary code Writing in binary is time consuming and difficult Writing in RobotC is easy because it lets you use words and symbols instead of 1’s and 0’s

What is a Compiler? A compiler is what converts your RobotC text file into a binary executable file What you downloaded from RobotC.net is actually called and Integrated Development Environment (IDE) o Allows you to write code o Checks code for errors o Converts code o Downloads code

How a Robot Program Works Follows a linear model (like a list of instructions) Code is written like a book o Reads left to right o Top to bottom o Chronological order Every line of code represents a new instruction. The robot will do EXACTLY what each line of the code says when it reaches that point of the program Line 1 Line 2 Line 3 Line 4 Line 5 Line 1 Line 2 Line 3 Line 4 Line 5

Framework 1.Pragma statements 2.Tasks (task main) o Initializations o Logic o Declarations 3.Open “v1” Pragma statements Void tasks Task main Initializations Logic Declarations Void tasks

Starting Your Program 1.Plan out how you want your program to work 2.Open the autonomous template file 3.Write your pragma statements using the “Motor and Sensor Setup” button in the “Robot” tab 1.Setup your “TETRIX Controllers” 2.Setup your “Motors” 3.Setup your “Sensors”

Task Main First part of the code you write After the pragma statements are read, the microcontroller jumps to the “task main” First part of the code the microcontroller “executes” Usually the main part of your code Can be as simple as one declaration or as complex as a having numerous logic statements

Assigning Values Objective: Make an NXT motor spin Steps: 1.Create a new file called “helloworldv1” 2.Set up the pragma statements with no Tetrix controllers and one NXT motor called “motorA” 3.Create the task main by typing: task main() { }

Assigning Values Steps: 1.Go inside the “task main” 2.Type (will be explained later): while(true) { } 3.Assign a value to the motor inside the loop: motor[motorA] = 100; 4.Select “Compile Program” from the “Robot” tab 5.Test the code

Assigning Values Now that we have a functional program, lets examine what we have written. Task main o The phrase “task main” is specific name that tells the microcontroller that what is contained within its brackets is the main part of the code and where the microcontroller should start. o It is followed by (). This specifies what information is imported into this task, which is not important since no information is imported to the main task o () is followed by {}. These indicate what is contained in the task main.

Assigning Values Assigning the value of the motor o The phrase “motor[]” specifies that you are assigning a value to a motor. o Since “motorA” is written inside the [], you are assigning a value to the motor named motorA. o The “=“ tells the microcontroller that the whatever comes before the = will be set equal to what follows the =. o Motor values can range between -100 and 100 with 0 meaning the motor is not moving. o The line ends with a “;”. All lines end with a ; except for logic statements. (If you forget, the compiler will usually catch this error)

Variables A variable is something within a program that can be assigned a value, have its value recalled, and have its value changed. Think of a variable like a bucket, what you put in stays there until you change it. Like in math, they can be single letters They can also be words Values for motors act like variables

Types of Variables bool – boolean variable: a conditional variable which holds a numerical value of 0 or 1, with 0 for no and 1 for yes (1 byte) byte – byte variable: holds numerical values with no decimal place from 0 to 255 (or -127 to 127 if signed) (1 byte) short – short variable: holds numerical values (2 bytes) char – character variable: holds a sing;e character of text (2 bytes)

Types of Variables int – integer variable: holds numerical values with no decimal place (4 bytes) double – 2 decimal point variable: holds numerical values with two decimal points (all doubles have two decimal places, even if they are.00) float – floating decimal point variables: holds numerical values with almost any number of decimal points string – string variable: holds a text value

Using Variables Before a variable can be used, it must be initialized, or declared. This can be done form within the task main To declare a variable, write the type of variable, followed by the name of the variable Once declared, a variable can be assigned a value by typing the name of the variable, followed by an =, and then the value. You can also assign a value to a variable at the same time that you declare it by writing the type of variable, the variable name, an =, and the variable’s value.

Using Variables Objective: Make an NXT motor spin based off of the value of a variable Steps: 1.Create a new program called “hellloworldv2” 2.Set up the pragma statements with no Tetrix controllers and one NXT motor called “motorA” 3.Create the task main (everything from here will be done within the task main) 4.Create an infinite while loop by typing: while (true) { }

Using Variables 1.Create an integer variable called “speed” outside the while loop: int speed; 2.Assign “speed” a value of 50 inside the while loop : 50 = speed; 3.Set motorA equal to “speed”: motor[motorA] = speed; 4.Compile and test the program

Using Variables Why didn’t this work? o You wrote “50 = speed;” o You cannot assign “50” a value of “speed”, you can only assign “speed” a value of “50” Note that the value of the motor can be easily assigned to an integer variable Now lets try using the “Variables” debugging window. It can be found under “Debugging Windows” under the “Robot” tab

What is Logic? Logic is the way that your program makes decisions. Expressed in logic statements Controls the flow of the program Parts of a logic statement:  Identifier (type of logic statement)  Condition (the question asked that determines if the body of the logic statement is executed)  Body code (the code executed if the conditional statement is found to be true)

Logic Statements while – the program will constantly repeat the lines of code contained within this statement until the condition is no longer valid if – if the condition is satisfied, the program will execute the code contained within the “if” statement else if – if the “if” condition is not satisfied and the “else if” condition is, the program will execute the code contained within the “else if” statement else – if the “if” and “else if” conditions are not met, the program will execute the code contained in the “else” statement

Conditions A condition is a test comparing one thing to another. There are several comparison operators used in conditions A == B – Is A equal to B? A > B – Is A greater than B? A >= B – Is A greater than or equal to B? A < B – Is A less than B? A <= B – Is A less than or equal to B? A != B – Is A not equal to B?

Conditions You can also put multiple conditions in one logic statement using these operators: && - And || - Or You can use parenthesis just like you do in math to set the order in which things are conducted.

Examples if (A == B) { hi } else if (A != B && A != 0) { good bye } else { ? }

What is Logic? Objective: Make an NXT motor spin if a variable equals 4 or 5. Steps: 1.Create a new program called “hellloworldv3” 2.Set up the pragma statements with no Tetrix controllers and one NXT motor called “motorA” 3.Create the task main (everything from here will be done within the task main) 4.Create an infinite while loop by typing (everything from here is in the while loop: while (true) { }

What is Logic? 1.Create an integer variable called “x” with a value of 50 2.Create an if statement with a condition that checks if “x” is equal to 4 or 5: if (x == 4 || x == 5) { } 3.Set motorA equal to 100 inside the if statement. 4.Compile and test the program

What is Logic? Why didn’t the motor stop spinning when the value was changed? We forgot the “else” statement Underneath the if statement, add: else { motor[motorA] = 0; } Try the program again

Sensors Sensors find information about the robot’s surroundings Their values can be put into variables and used for logic statements In FTC, most of the sensors return a numerical value to the microcontroller Sensor values are updated many times per second, so remember that they will change quickly when a robot starts to move

Sensors Objective: Make an NXT motor spin if a touch sensor is pressed. Touch sensors return two possible values, “0” for depressed and “1” for not depressed Steps: 1.Create a new program called “hellloworldv4” 2.Set up the pragma statements with no Tetrix controllers, one NXT motor called “motorA”, and one touch sensor called “touch”. 3.Create the task main 4.Create an infinite while loop by typing: while (true) { }

Sensors 1.Create an if statement with a condition that checks if “touch” is equal to 1: if (SensorValue[touch] == 1) { } 2.Set motorA equal to 100 inside the if statement. 3.Add an “else” statement which sets the motor value to 0. 4.Compile and test the program

That is everything you need to know to start writing RobotC programs! (I hope you aren’t too confused)