Introduction to Gobbit Programming

Slides:



Advertisements
Similar presentations
Introduction to Programming
Advertisements

Introduction to Programming G51PRG University of Nottingham Revision 1
08/2012Tanya Mishra1 EASYC for VEX Cortex Llano Estacado RoboRaiders FRC Team 1817.
What is a pointer? First of all, it is a variable, just like other variables you studied So it has type, storage etc. Difference: it can only store the.
Chapter 4 Control Structures I. Objectives ► Examine relational and logical operators ► Explore how to form and evaluate logical (Boolean) expressions.
Homework Any Questions?. Statements / Blocks, Section 3.1 An expression becomes a statement when it is followed by a semicolon x = 0; Braces are used.
Copyright © 2012 Pearson Education, Inc. Chapter 1: Introduction to Computers and Programming.
Program Design and Development
CSCE 121, Sec 200, 507, 508 Fall 2010 Prof. Jennifer L. Welch.
Logical Operators Java provides two binary logical operators (&& and ||) that are used to combine boolean expressions. Java also provides one unary (!)
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Java Software Solutions Foundations of Program Design Sixth Edition by Lewis.
Working with Arduino: Lesson #1: Getting Acquainted with the Kit EGN1007.
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.
Copyright © 2012 Pearson Education, Inc. Chapter 1: Introduction to Computers and Programming.
Chapter Introduction to Computers and Programming 1.
CHAPTER 4: INTRODUCTION TO COMPUTER ORGANIZATION AND PROGRAMMING DESIGN Lec. Ghader Kurdi.
Introduction to Python
Chapter 1: Introduction to Computers and Programming.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 1: Introduction to Computers and Programming.
IT253: Computer Organization Lecture 4: Instruction Set Architecture Tonga Institute of Higher Education.
By Nicholas Policelli An Introduction to Java. Basic Program Structure public class ClassName { public static void main(String[] args) { program statements.
Introduction to Computer Systems and the Java Programming Language.
CPS120: Introduction to Computer Science
CPS120: Introduction to Computer Science Decision Making in Programs.
Lecture 2b Dr. Robert D. Kent.  Structured program development  Program control.
CMP-MX21: Lecture 5 Repetitions Steve Hordley. Overview 1. Repetition using the do-while construct 2. Repetition using the while construct 3. Repetition.
BEGINNING PROGRAMMING.  Literally – giving instructions to a computer so that it does what you want  Practically – using a programming language (such.
School of Computer Science & Information Technology G6DICP - Lecture 4 Variables, data types & decision making.
Introduction to Python Dr. José M. Reyes Álamo. 2 Three Rules of Programming Rule 1: Think before you program Rule 2: A program is a human-readable set.
 Control Flow statements ◦ Selection statements ◦ Iteration statements ◦ Jump statements.
CPS120: Introduction to Computer Science Variables and Constants.
Brief Version of Starting Out with C++ Chapter 1 Introduction to Computers and Programming.
Review A program is… a set of instructions that tell a computer what to do. Programs can also be called… software. Hardware refers to… the physical components.
Introduction to Programming the Arduino Dr Gaw 3/21/14.
FILES AND EXCEPTIONS Topics Introduction to File Input and Output Using Loops to Process Files Processing Records Exceptions.
Python Programming Module 4 Sensors and Loops Python Programming, 2/e1.
Computer Basics.
Computers’ Basic Organization
Information and Computer Sciences University of Hawaii, Manoa
The Little man computer
The Machine Model Memory
Prof: Dr. Shu-Ching Chen TA: Samira Pouyanfar Spring 2017
Val Manes Department of Math & Computer Science
Topics Introduction Hardware and Software How Computers Store Data
Primitive Data, Variables, Loops (Maybe)
Introduction of microprocessor
Engineering Innovation Center
Engineering Innovation Center
Using Encoders to go Straight
Unit 2 Programming.
Computers: Hardware and Software
Topics Introduction to File Input and Output
Working with Arduino: Lesson #1: Getting Acquainted with the Kit
CSCE Fall 2013 Prof. Jennifer L. Welch.
An Introduction to Java – Part I, language basics
Topics Introduction Hardware and Software How Computers Store Data
Format String.
Homework Any Questions?.
CSCE Fall 2012 Prof. Jennifer L. Welch.
C Programming Getting started Variables Basic C operators Conditionals
ICT Gaming Lesson 3.
The Java switch Statement
Introduction Level Gobbit Assembly and Programming
Robotics Programming Using Shaft Encoders
Programming Merit Badge
PROGRAMMING.
Chapter 2 Programming Basics.
ECE 103 Engineering Programming Chapter 18 Iteration
Just Enough Java 17-May-19.
Topics Introduction to File Input and Output
Presentation transcript:

Introduction to Gobbit Programming SCOUTBOTICS Introduction to Gobbit Programming

Hardware The two most important hardware components to a programmer are: CPU RAM

The CPU The Central Processing Unit is the ‘brain’ of a computer. It is responsible for executing programs. While a program is running, it uses a processor Thread.

The RAM Random Access Memory gives a computer a place to store information quickly and temporarily. A running program stores its data in RAM RAM loses the stored data when the computer is shut down RAM is not long term storage

What is a Program? A program is a list of instructions to tell a computer what to do. The most basic form of computer instructions is called machine code. Machine code is very difficult for a human to read and understand. Programming in machine language is tedious and error prone. Programming today is usually done in a variety of high level programming languages (e.g. Java, C#, Python, Perl, Erlang, Clojure, ….)

The Building Blocks of Programs Data and Instructions are the two basic components of a program

Data Programs store data in variables. These variables are memory locations that can be accessed and modified. Since a variable might need to represent several different types of information, several can be used: Boolean (true/false) Integers ( 42, 0, -1) Floating Point (3.14, 0.0, -2.1) Characters (‘h’, ‘z’ ‘5’, ‘<‘) Strings (A group of characters): “Hello Programming”

Variables In a computer program its data lives in memory In order to access data you must know its location, or address, in memory It’s much easier to use a variable, which is named by you, than a computer memory address Example: int length = 24; float PI = 3.14; char middleInitial = ‘M’; string firstName = “Jason”;

Instructions A program runs a sequence of instructions from the top down. Control Structures are instructions that alter how the program executes certain commands. Arithmetic instructions Add, subtract, multiply and divide (+, -, *, /)

Instructions Example int area = 0, length = 2, width = 5; area = length * width; Advanced users: Look up “Order of Operations in Programming” http://en.wikipedia.org/wiki/Order_of_operations#Programming_languages

Control Structures All control structures affect program flow Branches – test a condition to decide between two or more courses of action. Conditions evaluate either true or false for example, a condition that tests if 5 is equal to 5 would evaluate to true. Loops – repeat a group of instructions. Subroutines (Functions) – Allow you to “jump” to a group of instructions, perform them and then “jump” back to where you were.

Programming Your Robot We will use an Arduino IDE (Integrated Development Environment) installed on your computer Launch the Arduino IDE from your new desktop icon The programming language used by the Arduino IDE is C/C++

Programming Your Robot (cont.) The other supplied programs you will be working with today: From the menu bar, select File > Examples > GobbitLineCommand MotorDirTest QTRTest GLC_BasicLine GLC_DriveCompetition GLC_Functions

Basics of an Arduino Program Place where we put our robot set-up code or any instructions you only want to run once void setup() { // put your setup code here, to run once: } void loop() { // put your main code here, to run repeatedly: Place where we put our main robot code that will run repeatedly

Basic Line Follower Program // If you are using either an Ardumoto version 14 or 20, or an Adafruit v2.3, uncomment // only the following motor driver define that matches to load the proper default values // If none are uncommented, Ardumoto v14 values will be used. //#define ARDUMOTO_14 //#define ARDUMOTO_20  //#define ADAFRUIT_MS #include <GobbitLineCommand.h> GobbitLineCommand MyBot; void setup() { MyBot.setBatteryVolts(9); MyBot.beginGobbit(); MyBot.calibrateLineSensor(0); } void loop() { MyBot.followLine(0); Uncomment one or more to set the proper motor defaults Includes the GobbitLineCommand library (pre-made functions) into your program Declare a GobbitLineCommand object with the name “MyBot” Sets the battery voltage Initializes the sensor Calibrate the line sensor using the specified calibration speed Line follow with modes 0) follow with no return, 1) follow one motor adjust and return, 3) follow one motor adjust and check for intersection then return, 3) follow until an intersection is found then return

Alternate Basic Line Follower Program #include <GobbitLineCommand.h> GobbitLineCommand MyBot; void setup() {   // kits with Ardumoto v14 will use this while newer kits with v20 use (5, 6, 7, 8, 9, 10, 12, 13)   MyBot.setQTRpins(2, 4, 5, 6, 7, 8, 9, 10);      // kits with Ardumoto v14 will use this while newer kits with v20 use (2, 3)   MyBot.setLeftMotorPinsDirPWM(12, 3);       // kits with Ardumoto v14 will use this while newer kits with v20 use (4, 11)   MyBot.setRightMotorPinsDirPWM(13, 11);   MyBot.setBatteryVolts(9);   MyBot.beginGobbit();   MyBot.calibrateLineSensor(); } void loop() {     MyBot.followLine(0);   } Set the pins based on the version of Ardumoto being used.

Useful Functions in the GobbitLineCommand Library // Run a calibration of the line sensor by sweeping back and forth // over a line at the called speed between 0-100. // Speed must be a 0 or positive value // 0 will load the default values based upon voltage if declared. void calibrateLineSensor(int calSpeed) Examples: MyBot.drive('F'); MyBot.drive('L'); MyBot.drive('R'); MyBot.drive('S');

Useful Functions in the GobbitLineCommand Library (cont.) // Drive will start driving/following the line and continue following // until it is able to complete the requested direction at the next // found intersection or end. If it cannot make the requested // direction, it will spin around fast and stop performing all other commands. // Turn direction value of ('L')eft, ('R')ight, ('F')orward, ('S')top, // or ('U')turn. // The U-turn will be evaluated by the found intersection turns available to // achieve a 180 degree turn. void drive(char turn) Examples: MyBot.drive('F'); MyBot.drive('L'); MyBot.drive('R'); MyBot.drive('S');

Useful Functions in the GobbitLineCommand Library (cont.) // Turns the robot using the line sensor on a lined course. // Uses the 'turnSpeedHigh' and 'turnSpeedLow' motor values while turning. // Turn direction values of ('L')eft, ('R')ight, or ('U')turn // Left turns left until the next line is found, regardless of 90 or 180 degree. // Right turns right until the next line is found, regardless of 90 or 180 degree. // U-turn turns left and assumes a 180 degree turn is requested where one line is // to be passed then stop at next. This is actually the same as running two // turn('L') commands, therefore, if there was no line at 90 degree to the left, // the turn will pass the 180 mark and stop at the next line, wherever it may be. // If that was the case, a single Left or Right turn request would have been // better. void turn(char turnDir) Examples: MyBot.turn(‘L'); MyBot.turn(‘R');

Useful Functions in the GobbitLineCommand Library (cont.) // Follow the line in called Mode: // Mode 0, along the line and never exit so it will not do anything else outside // of the function. // Mode 1, do 1 thing... run through the followLine function one time and make // only one motor adjustment then exit. // Mode 2, do 2 things... run through the followLine function one time and make // only one motor adjustment while checking if an intersection is // present then exit. // Mode 3, follow along the line until an intersection is found, update // intersection turn flags, then exit. void followLine(byte followMode) Examples: MyBot.followLine(0);

Useful Functions in the GobbitLineCommand Library (cont.) // Catch the Line by calling detectLine('A') until any sensor sees the line, // then calling followLine(1) enough times to align the robot with the line. // This assumes there was already some move or other motor command prior that // has the robot moving towards a line. // The function does not exit until it has caught the line. void catchLine(void) Examples: MyBot.catchLine();

Useful Functions in the GobbitLineCommand Library (cont.) // Detect if a line is found in the called part of the QTR sensor, then return a // byte of 1 if found, 0 if not. // Sensor location value of far ('L')eft, far ('R')ight, the two in ('C')enter, // or ('A')ny sensor. byte detectLine(char sensorLRCA) Examples: byte isItFound6 = MyBot.detectLine('L')

Useful Functions in the GobbitLineCommand Library (cont.) // Simple moves without any line following. Typically used with delay // statements as sensorless control. // First float value is the Speed/Velocity, value of -100 to 100. // -100 moveSpeed = reverse full speed // 100 = forward full speed // 0 = stopped; // Second float value is the Turn, value of -100 to 100. // -100 moveTurn = full left // 100 = full right // 0 = straight void move(float moveSpeed, float moveTurn) Examples: MyBot.move(80,65); // move forward at 80% speed and turn to the right MyBot.move(0,0); // stop the robot

Useful Functions in the GobbitLineCommand Library (cont.) // Set the speed and direction of the motors for both motor // shield/driver types. // Receives Left motor velocity/speed, Right motor velocity/speed. // Both are float values: // -100 full reverse // 100 full forward // 0 stopped void setMotors(float leftVelocity, float rightVelocity) Examples: MyBot.setMotors(100, 100);

Useful Variables in the GobbitLineCommand Library // These variables are byte "flags" to indicate if the robot has seen a line to the // left, forward (straight ahead), or right. Also "flags" to indicate if an // end or if a marker was found. // 1 if found // 0 if not found // Calling the drive (not when drive('S')), move, turn, and backup will reset // the flags. byte isItFound1 = MyBot.foundLeft; byte isItFound2 = MyBot.foundRight; byte isItFound3 = MyBot.foundForward; byte isItFound4 = MyBot.foundEnd; byte isItFound5 = MyBot.foundMark; Examples: if(MyBot.foundForward){…} if(MyBot.foundLeft){…}