Download presentation
Presentation is loading. Please wait.
1
Introduction to Gobbit Programming
SCOUTBOTICS Introduction to Gobbit Programming
2
Hardware The two most important hardware components to a programmer are: CPU RAM
3
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.
4
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
5
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, ….)
6
The Building Blocks of Programs
Data and Instructions are the two basic components of a program
7
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”
8
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”;
9
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 (+, -, *, /)
10
Instructions Example int area = 0, length = 2, width = 5; area = length * width; Advanced users: Look up “Order of Operations in Programming”
11
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.
12
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++
13
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
14
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
15
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
16
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.
17
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 // 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');
18
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');
19
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');
20
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);
21
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();
22
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')
23
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. // moveSpeed = reverse full speed // = forward full speed // = stopped; // Second float value is the Turn, value of -100 to 100. // moveTurn = full left // = full right // = 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
24
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: // full reverse // full forward // 0 stopped void setMotors(float leftVelocity, float rightVelocity) Examples: MyBot.setMotors(100, 100);
25
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){…}
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.