EBOT: Programming Primer Sean Donovan Alexander Hecht Justin Woodard.

Slides:



Advertisements
Similar presentations
AP Computer Science Anthony Keen. Computer 101 What happens when you turn a computer on? –BIOS tries to start a system loader –A system loader tries to.
Advertisements

EMS1EP Lecture 4 Intro to Programming Dr. Robert Ross.
Making Choices in C if/else statement logical operators break and continue statements switch statement the conditional operator.
Lab7: Introduction to Arduino
An Introduction to C Adam Gleitman – IAP 2014.
5/17/ Programming Constructs... There are several types of programming constructs in JAVA. - If-else construct or ternary operator - while - do-while.
Programing Concept Ken Youssefi/Ping HsuIntroduction to Engineering – E10 1 ENGR 10 Introduction to Engineering (Part A)
IAT 800 Lab 1: Loops, Animation, and Simple User Interaction.
Classes, methods, and conditional statements We’re past the basics. These are the roots.
CS 240: Data Structures Tuesday, June 5 th Programming Semantics, Software Life Cycle.
1 Introduction to Coding. 2 Example Codes A lot of example codes are given with Arduino IDE A code can often be based on a previous example rather than.
Programming Part 1 Armond R. Smith Zhenying Wu. Overview of this Class ● Transition from FTC -> FRC ● Using Your Resources ● Java Keywords o Data Types.
Embedded Programming and Robotics Lesson 2 C Programming Refresher C Programming1.
RobotC For Beginners Tyler Lutz and Keaton Bonds DRSS Enterprise.
Writing algorithms using the while-statement. Previously discussed Syntax of while-statement:
CMSC 104, Version 8/061L22Arrays1.ppt Arrays, Part 1 of 2 Topics Definition of a Data Structure Definition of an Array Array Declaration, Initialization,
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.
1 CS 177 Week 5 Recitation Slides Loops. 2 Announcements Project 2 due next Thursday at 9PM. Exam 1 this evening (switch and loop not covered) Old exams.
Programing Concept Ken Youssefi/Ping HsuIntroduction to Engineering – E10 1 ENGR 10 Introduction to Engineering (Part A)
Intro to Arduino Programming. Draw your circuits before you build them From Arduino 330 Ohm From Arduino 330 Ohm From Arduino 330 Ohm.
ROBOTC Training Session 1 Timothy Friez 1/10/08 Revision 1.
Week 5 - Wednesday.  What did we talk about last time?  Exam 1!  And before that?  Review!  And before that?  if and switch statements.
The George Washington University Department of ECE ECE Intro: Electrical & Computer Engineering –Intro to the Robotics –Introducing the IC –Discuss.
NA2204.1jcmt CSE 1320 Intermediate Programming C Program Basics Structure of a program and a function type name (parameters) { /* declarations */ statement;
C++ Basics C++ is a high-level, general purpose, object-oriented programming language.
Some Fortran programming tips ATM 562 Fall 2015 Fovell (see also PDF file on class page) 1.
Code The Arduino Environment.
BEGINNING PROGRAMMING.  Literally – giving instructions to a computer so that it does what you want  Practically – using a programming language (such.
Topic 3: C Basics CSE 30: Computer Organization and Systems Programming Winter 2011 Prof. Ryan Kastner Dept. of Computer Science and Engineering University.
Agenda Perform Quiz #1 (20 minutes) Loops –Introduction / Purpose –while loops Structure / Examples involving a while loop –do/while loops Structure /
GCSE Computing: Programming GCSE Programming Remembering Python.
Programming with LabVIEW Intro to programming and.
Programming - Motion Intro to Robotics. Motors and Sensors Setup The first thing we need to do is tell ROBOTC that we have motors on our robot. Choose.
Chapter 2 – The Little Crab Program:. Little Crab Scenario Inheritance: The Arrows Denote Hierarchy Crab is an Animal Animal is an Actor Therefore, It.
Fun fun ’til daddy takes your C turbo away! A C program is organized into one or more modules (source files created by a programmer), within which are.
Sudeshna Sarkar, IIT Kharagpur 1 Programming and Data Structure Sudeshna Sarkar Lecture 3.
CMSC 104, Section 301, Fall Lecture 18, 11/11/02 Functions, Part 1 of 3 Topics Using Predefined Functions Programmer-Defined Functions Using Input.
Introduction to Programming the Arduino Dr Gaw 3/21/14.
CCSA 221 Programming in C CHAPTER 3 COMPILING AND RUNNING YOUR FIRST PROGRAM 1 ALHANOUF ALAMR.
Week 3.  TO PRINT NUMBERS FROM 1 TO 20  TO PRINT EVEN NUMBERS FROM 1 TO 20 2.
Chapter 5: Loops Tarik Booker CS 201 California State University, Los Angeles.
1 Introduction to Coding. 2 Example Codes A lot of example codes are given with Arduino IDE A code can often be based on a previous example rather than.
Arduino Programming. THE ARDUINO IS A MICROCONTROLLER – A LOW COST, LOW PERFORMANCE COMPUTER.
Web Design. How to link the robot How to turn on the robot Sec Getting Started What is python Programming in python How to move the robot How to.
INTRODUCTION TO ROBOTICS Part 5: Programming
Basic concepts of C++ Presented by Prof. Satyajit De
UMBC CMSC 104 – Section 01, Fall 2016
User-Written Functions
The George Washington University Department of ECE ECE Intro: Electrical & Computer Engineering Intro to the Robotics Introducing the IC Discuss.
Lesson #6 Modular Programming and Functions.
Arduino & its hardware interfacing
Lesson #6 Modular Programming and Functions.
Loop Structures.
Introduction to Gobbit Programming
Programming - Motion Intro to Robotics.
Movement using Shaft Encoders
Lesson #6 Modular Programming and Functions.
Arrays, Part 1 of 2 Topics Definition of a Data Structure
1 Code
Working with Arduino: Lesson #1: Getting Acquainted with the Kit
Arrays, Part 1 of 2 Topics Definition of a Data Structure
Arrays, Part 1 of 2 Topics Definition of a Data Structure
Arrays, Part 1 of 2 Topics Definition of a Data Structure
Arrays, Part 1 of 2 Topics Definition of a Data Structure
Lesson #6 Modular Programming and Functions.
Robotics Programming Using Shaft Encoders
Arrays, Part 1 of 2 Topics Definition of a Data Structure
Chapter 15 Debugging.
Chapter 15 Debugging.
Presentation transcript:

EBOT: Programming Primer Sean Donovan Alexander Hecht Justin Woodard

2 Programming Overview  Background  C Control Structures and Paradigms  WPI Framework Structures  Issues and Techniques

3 Background  Microchip MPLAB IDE v6.30 Write Code here Compile here  IFI Loader Physical Programming here

4 Background and Installation

5 Background  Variable A symbol that represents a particular type of data int i = 0;  Comments // Makes robot spin around in wild circles /* This function makes a decision on what the robot should do next, either turn left, turn right, go strait, or stop */

6 Background  Basic Data Types int long char char* float  Compiler Changes Code into actual program computer can understand

7 Programming Overview  Background  C Control Structures and Paradigms  WPI Framework Structures  Issues and Techniques

8 C Control Structures and Paradigms  If statements If else If, else if, else  While Loop  For Loop  Functions

9 If Statements  The most useful and basic control structure if(condition) { do something }

10 If else Statements if(condition) { do something } else { do something else }

11 if else if else statements if(condition) { do something } else if(condition 2) { do something else } else { do something entirely different }

12 If Statement Example int counter; // counter gets modified by some code … if(counter==6)//== mean check for equality { Drive(0,0);//stop moving } else if(counter==5) { Drive(60,10);//turn a little to the left } else { Drive(60,0);//Just go strait }

13 While Loop while(condition) { do something here }

14 While Loop (cont.) int i = 0; while(i<10) { printf(“%d\n”,i); i = i + 1; }

15 While Loop Example int counter = 0; while(counter < 6) { Drive(60,0);//go strait Wait(100);//wait for 100ms counter++;//increment counter }

16 For Loop for(initialization; conditional; do this after each iteration) { do something here }

17 For Loop (cont.) int i; for(i = 0; i<10; i++) { printf(“%d\n”,i); }

18 For Loop Example int counter; for(counter=0; counter<6; counter++) { Drive(60,0);//drive strait Wait(100);//wait for 100ms }

19 Functions  Subroutines Used for splitting up program into modules Can take input and return output Can be used to compute what to do next  Repeatability Code that gets repeated often can be compressed

20 Function Example int modifyvariable(int i) { i = i + 100; if(i<2) { return i; } else { i++; return i; }

21 Programming Overview  Background  C Control Structures and Paradigms  WPI Framework Structures  Issues and Techniques

22 Setup of Robot Joystick to Radio Receiver LeftRight X31 Y42

23 Setup  Minimum required to setup the robot using the WPI Framework  Basic Code for a simple driving robot #include “WPILib.h” void main (void) { WPIInitialize(); TwoWheelDrive(1, 2); Wait(1500); while (1) { Drive(PWMIn(2), PWMIn(1)); Wait(20); }

24 Setup (cont.) #include “WPILib.h” void main (void) { WPIInitialize(); TwoWheelDrive(1, 2); Wait(1500); while (1) { Drive(PWMIn(2), PWMIn(1)); Wait(20); } Lets the program know about the WPI code

25 Setup (cont.) #include “WPILib.h” void main (void) { WPIInitialize(); TwoWheelDrive(1, 2); Wait(1500); while (1) { Drive(PWMIn(2), PWMIn(1)); Wait(20); } -Declaration of the main function -Executed when the program is run

26 Setup (cont.) #include “WPILib.h” void main (void) { WPIInitialize(); TwoWheelDrive(1, 2); Wait(1500); while (1) { Drive(PWMIn(2), PWMIn(1)); Wait(20); } -Starts up the WPI routines to setup the robot

27 Setup (cont.) #include “WPILib.h” void main (void) { WPIInitialize(); TwoWheelDrive(1, 2); Wait(1500); while (1) { Drive(PWMIn(2), PWMIn(1)); Wait(20); } - Setup the robot to be driven by motors attached to ports 1 and 2 -The first value is the left motor -The second value is the right motor

28 Setup (cont.) #include “WPILib.h” void main (void) { WPIInitialize(); TwoWheelDrive(1, 2); Wait(1500); while (1) { Drive(PWMIn(2), PWMIn(1)); Wait(20); } -Do NOT do anything for 1500 milliseconds -Used to make sure WPIInitialize() finishes everything it needs to

29 Setup (cont.) #include “WPILib.h” void main (void) { WPIInitialize(); TwoWheelDrive(1, 2); Wait(1500); while (1) { Drive(PWMIn(2), PWMIn(1)); Wait(20); } -Start an infinite loop -Continues forever

30 Setup (cont.) #include “WPILib.h” void main (void) { WPIInitialize(); TwoWheelDrive(1, 2); Wait(1500); while (1) { Drive(PWMIn(2), PWMIn(1)); Wait(20); } -Drive(Left Side, Right Side)

31 Setup (cont.) #include “WPILib.h” void main (void) { WPIInitialize(); TwoWheelDrive(1, 2); Wait(1500); while (1) { Drive(PWMIn(2), PWMIn(1)); Wait(20); } -Gets PWM input from radio

32 Setup (cont.) #include “WPILib.h” void main (void) { WPIInitialize(); TwoWheelDrive(1, 2); Wait(1500); while (1) { Drive(PWMIn(2), PWMIn(1)); Wait(20); } -Sleep for 20ms -let motors adjust

33 Programming Overview  Background  C Control Structures and Paradigms  WPI Framework Structures  Issues and Techniques

34 Issues and Techniques  Common Issues Misspelling and capitalization Overflow Missing Semi-Colons = vs ==  Common techniques Floating Point vs. Integer math Sensor Normalization Debugging

35 Misspelling  Three Different Variables int var1; int Var1; int VAR1;  Three Bad Variables Int var1; Char* string = “ASDF”; Float somenumber;

36 Misspelling (cont.) int somefunction(int input) { return input; }  Somefunction(6);BAD  someFunction(6);BAD  somefunction(6);GOOD

37 Overflow  int: to  long: to  char: -128 to 127

38 Overflow (cont.)  300*300 = 90000

39 Overflow (cont.)  300*300 =  (int)300*(int)300 = (int)24464?

40 Overflow (cont.)  300*300 =  (int)300*(int)300 = (int)24464?  …,32766,32767, , ,…

41 Overflow (cont.)  300*300 =  (int)300*(int)300 = (int)24464?  …,32766,32767, , ,…  (long)300*(long)300 = (long)90000

42 Overflow (cont.)  Occasions this could happen: Multiplication Counters Sensor normalization

43 Missing Semicolons  Strange errors returned by compiler  “Parse error” is most common  Program won’t compile  Misplaced semicolons

44 = vs ==  = means assignment  == check for equality  Very often one is used in place of the other

45 Floating Point vs. Integer math  Floating Point is SLOW! Multiplication and division takes ~50 clock cycles to compute vs. integer multiply in 1-4 clock cycles  Most things can be done as integers 300*.5 is 300/2 300*.875 is 300*7/8 Be careful about overflow

46 Relative speeds of Data types char - very fast int – fast long – average float – painfully slow

47 Sensor Normalization  Have: Sensor returns values between 300 and 800  Want: -128 to 127

48 Sensor Normalization (cont.)  Solution: (Sensor Value- Min Value)*Desired range - Low Value Desired Range of Sensor  In Example: ( Sensor Value - 300) *  Optimization ((Sensor Value-300)/2) – 128 Sensor Value/

49 Debugging  Extremely useful Find mistakes Testing values Testing sensors

50 Debugging (cont.)  DebugPrintf(“string”);  DebugPrintf(“string %d”, someint);  DebugPrintf(“string %d\n”);  printf(“string”); More description on web of parameters

51 Debugging (cont.)  Bad Adjusted Sensor Value  DebugPrintf(“Sensor Value: %d\n”, sensor);

52 Differences  printf() doesn’t check time Prints out whenever you tell it to  DebugPrintf() checks time Prints out every 100ms