Programming Your Robot (in C)

Slides:



Advertisements
Similar presentations
1chung 5 th Annual Robofest 2004 Informational Meeting Mar. 20, 2004 Chan Jin Chung Ali Khazaal Jason Lo Computer Science Lawrence Technological University.
Advertisements

1chung Robofest 2005 RCX code Workshop Jan 29, 2005 CJ Chung.
Robofest 2005 Introduction to Programming RIS 2.0 RCX Code.
Chung for Robofest 05 1 Introduction to RoboLab CJ Chung Lawrence Technological University.
Introduction to LEGO RCX robotics and Robot Sumo
Introduction to LEGO RCX robotics and Robot Sumo
Introduction to LEGO NXT robotics and Robot Sumo
Teacher/Mentor Institute Using the Cortex Chuck Powell.
NXT 2-Motor Car Adapted from Physics by Design, Second Edition, by Barbara Bratzel, College House Enterprises, 2007 MAXA ROBOTICS 2011.
Exercise 1: Install PC Software & NXT Firmware
EMS1EP Lecture 4 Intro to Programming Dr. Robert Ross.
BEST Robotic, Inc. easyC Team Training
ENGG1100 Ch6: Introduction To Engineering Design (Digital Logic) Part 2 of digital logic KH WONG ENGG1100. Ch6-Digital Logic (part2) v3h1.
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.
Lab7: Introduction to Arduino
Mini-SumoBot Construction and Programming
Engineering Roles We will be forming groups of 3 students
Automation and Robotics
Handy Board. Why the Handy Board Designed to be the controller of small, mobil robots Has many features that make it ideal for robotics projects –Integrated.
Connecting VEX and ROBOTC
Software Design Project
IR SENSORS AND ENCODERS. LCDs Timothy Friez Class # 2.
1 ©2006 INSciTE Lab Two Task: Make the program from Lab One (Move forward 5 rotations and turn right 90 degrees) into a MyBlock.
Session 2  The Touch Sensor  The Colour Sensor.
Introductory Robotics Workshop “Successful Strategies in Robotics” Terry Grant, NASA, Ames Research Center 2/1/05 2/8/05.
Working with Arduino: Lesson #1: Getting Acquainted with the Kit EGN1007.
Testbed: Exercises.
ROBOTC Software Introduction. ROBOTC Software ROBOTC developed specifically for classrooms and competitions Complete programming solution for VEX Cortex.
The George Washington University Electrical & Computer Engineering Department ECE 002 Dr. S. Ahmadi Class 2.
Lego Robot Construction Project. Adam, Roger, Lu, Riana, Paul.
Teacher/Mentor Institute Using easyC Joel Kirkland July 30-31, 2015.
EasyC Programming Workshop January 30, 2008 Hauppauge High School SPBLI - FIRST Mark McLeod Advisor Hauppauge Team 358 Northrop Grumman Corp.
Introductory Robotics Workshop “Successful Strategies in Robotics” Terry Grant, NASA, Ames Research Center Jeneva Westendorf, Foothill High School 2/5/04.
7.2 V battery pack and charger Put the battery in the charger station at the end of the lab. period. Red light indicates charging. Ken Youssefi Introduction.
EV3 Workshop Oct 3, 2015 Instructor: Chris Cartwright
The George Washington University Department of ECE ECE Intro: Electrical & Computer Engineering –Intro to the Robotics –Introducing the IC –Discuss.
The George Washington University Department of ECE ECE 1010 Intro: Electrical & Computer Engineering –Introducing KIPR Link/Interface and Set-up –Continuation.
The Handy Board Bryan Valentini General Robotics 2003.
Engineering H193 - Team Project Gateway Engineering Education Coalition Lab 1P. 1Spring Quarter Introduction to Sensors Lab 1.
Electronics and Robotics Merit Badges Class 5 – Programming Robot Controllers for Sumo Competition 12/23/2015 Electronics and Robotics Merit Badges - Class.
PHY 235 Robotics Workshop Day 4 Robotic Behaviors, Light Sensing, Voltage Dividers, LCD-MOD.
Variables and Functions ROBOTC Software © 2012 Project Lead The Way, Inc.Principles of Engineering.
The George Washington University Electrical & Computer Engineering Department ECE 002 Dr. S. Ahmadi Class3/Lab 2.
Oregon Robotics Tournament and Outreach Program RCX Basics.
Programming 101 The Common Palette Content provided by Connor Statham (9 th Grade Student) Formatting by Shannon Sieber.
ROBOTC Software EV3 Robot Workshop
BEGINNER FLL PROGRAMMING WORKSHOP BY DROIDS ROBOTICS & EV3LESSONS.
Deriving Consistency from LEGOs What we have learned in 6 years of FLL by Austin and Travis Schuh © 2005 Austin and Travis Schuh, all rights reserved.
Automation and Robotics.  First you select the platform type so that you can use Natural Language PLTW.
Casne.ncl.ac.uk Taking care of the CrumbleBot Please do NOT stress the robot's motors 1.Do NOT push the robot 2.Do NOT hold the.
Connect VEX and ROBOTC Electrical Engineer Responsibilities © 2011 Project Lead The Way, Inc.Automation and Robotics VEX.
ROBOTC for VEX Online Professional Development. Homework Questions Thoughts? Questions?
ROBOTC for CORTEX Teacher Training © 2011 Project Lead The Way, Inc. Automation and Robotics VEX.
Introduction to Programming in RobotC
The George Washington University Department of ECE ECE Intro: Electrical & Computer Engineering Intro to the Robotics Introducing the IC Discuss.
By Sanjay and Arvind Seshan
Stop Light Lab 7 Winter Quarter.
Introduction to Gobbit Programming
Introducing KIPR Link/Interface and Set-up
Electrical Engineer Responsibilities
Automation and Robotics
Programming Part 2 Mod Kit
Describe how NASA remotely controls equipment in space.
Automation and Robotics
BEGINNER EV3 PROGRAMMING Lesson
Working with Arduino: Lesson #1: Getting Acquainted with the Kit
The George Washington University Department of ECE ECE Intro: Electrical & Computer Engineering Dr. S. Ahmadi Class 4.
The George Washington University Department of ECE ECE Intro: Electrical & Computer Engineering Dr. S. Ahmadi Class 4.
Oregon Robotics Tournament and Outreach Program
LEGO Mindstorms Robot and Java
Presentation transcript:

Programming Your Robot (in C) Terry Grant, NASA, Ames Research Center 1/23/03 1/30/03 1

Outline 1/23 1/30 Robotics Hardware & Software Architecture Programming in C Introduction 1/30 Review: Robot Project Requirements & Example Simple Sumo Contest - Simple line follow Teacher as Coach Wrap-up

Robot Building & Coding Completed LEGO robot from MLCAD Ref: http://www.lm-software.com/mlcad/ Art of LEGO Design http://handyboard.com/techdocs/artoflego.pdf Pictures and Code from the Workshop http://robotics.nasa.gov/edu/BBworkshop03 IC4 Environment downloads: http://www.botball.org/about_botball/ic4.html Hands-on Challenges Ref: http://robotics.nasa.gov/students/challenge.htm

Robotics H/W & S/W Architecture Bot Multi-tasking S/W Components Real-Time Operating System * P-code interpreter * Input/Output Drivers - Clock * Load/Run modes Handy Board or RCX H/W *Central Processor * Random Access Memory * Special I/O Circuits * Battery & Power Conditioner Interactive C v. 4.10 * Editor * Debug Interpreter * Loader Other Apps Desktop Operating System Desktop Hardware IR for RCX* Lego Mechanical Lego Motors & Sensors Serial Data Interface Charger (HB only)

Robot Project Requirements Hardware configuration and general environmental constraints Operator Requirements Controller requirements All Three Elements are needed and should be written down for a common team understanding

Team Strategy & Plans Translating a Challenge into Requirements Robot physical capabilities Robot behavior (high level code) Operator – robot interaction Assigning tasks and milestones Writing a total schedule (initial and revised) Plan to test capabilities & behavior Plan for full robot tests & re-planning Plan for team coordination meetings

Programming in C - Introduction IC4 provides an editing, compiling, and downloading environment for either RCX or Handy Board. Follows C syntax (grammar) Uses functions < xyz() > declared and called Many functions for Input/Output are preloaded in a library Good tutorial examples provided with the application Multi-tasking capability in O.S. allows sampling & holding multiple conditions in parallel: position, direction, and other sensors 2

General Syntax declaring: output type Function(inputs e.g. int x, int y) {block of statements} calling: Function(x, y); types: int x, y, z; float a, b, c; all variables must have a declared type. global types are defined at the top, outside of a function, and usable by all functions.

Simple Example Make a Robot Go Forward and Return H/W & Environment: Build a bot with the RCX, wired to motors such that forward power moves wheels forward, and put on a demonstration table with enough flat surface Operator: Write the code, load the RCX, and initiate the execution (running) of the code The controller: Turn on the motors forward, wait 2 seconds, reverse the motors, wait 2 seconds, then stop.

Simple Code Example IC4 void main() { fd(A); fd(C); sleep(2.0); bk(A); bk(C); off(A); off(C); } Open Interactive C to view the actual environment & write code

More Basics Three modes: off, standby, run Use of ‘view’ button function w/o running a program Use of ‘Interaction’ window in IC4 battery_volts() to check battery Test new functions for I/O, Check list of library functions, global variables Download firmware Upload Arrays for spread-sheet analysis Edit aids Auto-indentation Parenthesis matching Syntax checking (on download) Use of ‘save as’ to file new, or trial code

Notation of IC 4 IC notation is the same for RCX & HB if ("condition") { "statements" } else while ("condition") { "statements" }

Notation of IC4 -2 Defining a function or task: xxx “name”() { "statements" } xxx = ‘void’ if no return variables = ‘int’ if integer return variables = ‘float’ if floating point return variables

Notation of IC4 - 3 Starting and ending parallel tasks: pid = start_process(taskname()); kill_process(pid);

Notation of IC4 - 4 Inputs for RCX - light(y) for y = 1,2, or 3 - light_passive(y) - digital(y) or touch(y)

Notation of IC4 - 5 IC Outputs Motor outputs, ports 1 to 3 (or A to C) To use port 1: fd(1); forward, positive voltage bk(1); backward, negative voltage Motor(1, x); x = -100 to 100 off(1); leave port ‘open’ brake(1); for the RCX only, to brake the motor

Notation of IC4 - 6 To display on Controller LCD e.g. printf(“Hello\n”); printf(“X= %d\n”, x); /* x is an integer */ printf(“X= %f\n”, y); /* y is floating point */ printf(“%d -%d\n”, a, b); /* a & b are integers */ In the RCX only five characters total can be displayed, and “\n” is not needed.

Sumo Example

Sumo Requirements Robots start facing each other at the edge of a central ring. Robots must start when a button is pushed or the light comes on. Robots must stop after T (5-15) seconds. The first robot to touch the barrier (or cross line) loses. Starting Light 4’ x 4’ barrier Bot 1 Bot 2

Light Sensor Sensor includes a LED source: red & near IR. Photodetector responds strongly to near IR as well as red. [lower = more] Response changes according to ambient light & Battery voltage. Mounting assembly attaches to front bumper facing down as shown in the cover picture.

Simple Sumo Behavior Display program title Wait for prgm_button push, then beep Wait 3 seconds to start Go straight forward while T not exceeded, Stop quickly and turn if line is sensed Back away & turn if bumped When T exceeded brake to a stop

Simple Sumo code // LEGO-based Sumo #6 for widetrack bot tlg 1/20/03 // assumes front bumper on port 3, light sensor on 2, motors on A & C // start 3 seconds after prgm button push #define TURN_TIME 0.45 #define THRES 750 /* assumes nominal white is ~ 720 */ void main() { long time; printf("SUMo6"); while(!prgm_button()); beep(); sleep(3.); // wait 3 seconds time =mseconds(); //beep();

Simple Sumo code – cont’d motor(A,30); motor(C,30);// start straight ahead while(15000L > (mseconds()-time)){ //run time if(light(2)>THRES){ //wait for edge brake(A);brake(C);sleep(.05); //quick stop motor(C,-45);off(A); //turn sleep(TURN_TIME); motor(A,30); motor(C,30); sleep(.2); } if(digital(3)){//back away and turn if bumped motor(A,-30);motor(C,-30);sleep(.2); brake(A); brake(A); brake(C);

Light Trigger Calibration Hardware & Environment L1 is the remote trigger light. L2 is the room lighting. Pd photodetector has a wide field of view. The Controller display helps the operator measure both the dark and light response. The controller [RCX code] sets the “light vs. dark” threshold and waits for the threshold to be exceeded to trigger the action.

Sumo - Sensor Test Project To support a robot sumo contest with a light start, design a robust light trigger for a “sumo wrestling” action which runs the motors for 5 seconds after a light is turned on. Discuss all requirements (total group) Write a code design for each Bot. Write and debug the code Participate in a Bot Sumo contest Compare trigger and behavior designs and results

Sumo - Sensor Test Behavior e.g. Display program title [for a few seconds] Repeat sequence while program is running While prgm_button is not pushed, Display sensor level and Prompt for prgm_button push While view_button is pushed, display and increment the trigger threshold When prgm_button is pushed, Display sensor level Wait for sensor level to cross the trigger threshold, then go forward, etc as original sumo - measuring run time When T is exceeded: stop, display “done” for a few seconds Repeat

Line Following Experiments

Line Following Experiments Simple, one sensor Line turns to the right Check sensor responses first Use touch sensor to start & stop

Checking sensor first while(digital(1)==0){ // check sensor until switch is hit printf("%d", light(2)); //move on and off line here sleep(.3); } while(digital(1)==1); // wait here to release switch

Follow line until touch sensor hit // follow line to the right motor(A,30); motor(C,30); // start going straight while (digital(1)==0) { // until switch is hit if (light(2) < THRESHOLD) { // if brighter than line motor(C,-30);off(A); // turn right while (light(2) < THRESHOLD); // wait until >= motor(A,30); motor(C,30); // go straight } ao(); // turn off motors when done