Not Quite C: A CS 0 Option LMICSE Workshop June 14 - 17, 2005 Alma College.

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

Robofest 2005 Introduction to Programming RIS 2.0 RCX Code.
Alma Robotics Challenge March 30, 2007 Alma College.
Chapter 3: Editing and Debugging SAS Programs. Some useful tips of using Program Editor Add line number: In the Command Box, type num, enter. Save SAS.
VEX and Robot C Chris Patterson Presented by Modified by J. Andazola.
V EX C OACHES ' T RAINING October 12, Agenda for Today 9 – 10 AM : Tina Reeves and the Engineering Notebook 10 – Noon : Finish Building, Basic Robot.
Mrs. Chapman. Tabs (Block Categories) Commands Available to use Script Area where you type your code Sprite Stage All sprites in this project.
Alternative Programming Languages Myles McNally LMICSE Workshop November , 2004 University of Mississippi.
LEGO Robotics Lecture 1: Getting acquainted with your robotic environment.
The Turtle Laboratory Sequence Myles McNally LMICSE Workshop November , 2004 University of Mississippi.
CC467 Biologically inspired robotics Introduction to Lego Mindstorms Owen Holland Computer Science University of Essex.
Introduction to Lego Mindstorms LMICSE Workshop June , 2005 Alma College.
The Turtle Laboratory Sequence LMICSE Workshop August , 2006 Villanova University.
NQC: Not Quite C (last updated 9/14/05 2:24pm) Each NQC program has a task main () The program is contained within curly braces { ….. } task main() { SetSensor(SENSOR_1,
2. Textual user interface NQC (Not quite C)  C-like programs translated into CRX-bytecode  Composed of: 1.Global variables 2.Task blocks 3.Inline functions.
The Turtle Laboratory Sequence LMICSE Workshop June , 2005 Alma College.
LEGO Mindstorms RIS 2.0 Programming: NQC Code B.A. Juliano and R.S. Renner September 2004 California State University, Chico Intelligent Systems Laboratory.
Using LeJOS LMICSE Workshop June , 2005 Alma College.
Tasks An NQC program consists of at most 10 tasks. Each task has a name. One task must have the name main, and this task will be executed. The other tasks.
Preprocessor Directives (last modified 9/19/05 2:47pm) Statements beginning with # are directives to the preprocessor. –They DO NOT end with ; –Before.
Conceptual Model by Aaron Garrett and David Thornton Mindstorms Internet Control Environment.
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.
LEGO Mindstorms NXT Programming We will be using the Common Palette for our Robots This is how you download your program onto the brick Drag and drop a.
Testbed: Exercises.
Department of Computing and Information Sciences Kansas State University Design Methodology for State based Embedded Systems Case Study: Robot Controller.
Programming Concepts Part B Ping Hsu. Functions A function is a way to organize the program so that: – frequently used sets of instructions or – a set.
[Low-level] Programming of NXT Robots Pavel Petrovič Department of Applied Informatics, Faculty of Mathematics, Physics and Informatics
Programming Concepts (Part B) ENGR 10 Introduction to Engineering 1 Hsu/Youssefi.
Reactive robots UPNA The Public University of Navarra Material for pupils & students.
The George Washington University Department of ECE ECE 1010 Intro: Electrical & Computer Engineering –Introducing KIPR Link/Interface and Set-up –Continuation.
Programming Design ROBOTC Software Principles of Engineering
NXC (and NBC) NXC (Not eXactly C) is a language similar to NQC, which was the most popular way to program the RCX Built on NBC, the Next Byte Code ‘assembler’
NQC Brief Introduction – Part 3 David Schilling. NQC – Where is my data? Programs have 32 global variables Tasks have 16 local variables These are always.
How to link the robot and the computer (Bluetooth) How to turn on and off How to connect the adaptor Fluke card connection Sec Getting Started How.
Technical Writing for Robotic Coding!.  du/products/teaching_robotc_cort ex/fundamentals/introtoprogramm ing/thinking/videos/fundamentals.
Sentry System Multiple Sensors
NQC / BricxCC Brief Introduction David Schilling.
Variables and Functions ROBOTC Software © 2012 Project Lead The Way, Inc.Principles of Engineering.
The George Washington University Department of ECE ECE Intro: Electrical & Computer Engineering Dr. S. Ahmadi Class 4/Lab3.
NQC Brief Introduction – Part 2 David Schilling. NQC – Where to put code? Programs Tasks Functions Subroutines.
The George Washington University Electrical & Computer Engineering Department ECE 002 Dr. S. Ahmadi Class3/Lab 2.
EV3 Software EV3 Robot Workshop
Programming with LabVIEW Intro to programming and.
Available at: – Program Functions to Accept Values Program Functions to Accept Values.
ROBOTC Software EV3 Robot Workshop
ROBOTC Software EV3 Robot Workshop Lawrence Technological University.
Using the BlueJ IDE with Mindstorms LMICSE Workshop June , 2005 Alma College.
VEX and Robot C Chris Patterson Frisco ISD CTE Center Presented by.
Vex Robotics program three: using motors and sensors together.
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.
Programming Design ROBOTC Software. Behavior-Based Programming A behavior is anything your robot does –Turning on a single motor or servo Three main types.
Robotics Programming Wall Follow Line tracking for a set amount of time Line tracking for a distance.
Presentation Outline I. Background Information II. Design Project
Programming Design ROBOTC Software Principles Of Engineering
Programming Concepts (Part B) ENGR 10 Introduction to Engineering
Introduction to Gobbit Programming
Programming Design ROBOTC Software Computer Integrated Manufacturing
Programming Concepts (Part B) ENGR 10 Introduction to Engineering
Variables and Functions
Girl Scout Lego Robotics Workshop
Programming Design ROBOTC Software Principles Of Engineering
Automation with RobotC
Automation with RobotC
Programming Design ROBOTC Software Principles of Engineering
Programming Concepts (Part B) ENGR 10 Introduction to Engineering
Oregon Robotics Tournament and Outreach Program
Programming Robots using Java
LEGO Mindstorms Robot and Java
NQC Program Structure 3 types of code blocks with their own features and limitations 1. Tasks 2. Subroutines 3. Inline Functions.
Presentation transcript:

Not Quite C: A CS 0 Option LMICSE Workshop June , 2005 Alma College

NQC Well suited for those new to programming Often used in non-majors courses Allows the demonstration of most non-object oriented aspects of introductory programming Easy introduction to concurrent programming issues

NQC Basics C-like syntax Limited by use of Lego standard firmware 10 threads 32 global variables, 16 local variables per thread Integers only Byte codes are interpreted No call stack, no memory management Functions Simple event model Limited arrays

RCX Basic Motor Control Recall that there are three power outputs, and in NQC the motors attached to them are called OUT_A OUT_B OUT_C Basic motor control commands OnFwd( … ) : run the … motor(s) forward OnRev( … ) : run the … motor(s) in reverse Off( … ) : stop the … motor(s) Another useful command Wait( …) : pause the program execution for … microseconds

Example 1: Drive Forward Drive forward for 4 seconds task main () { OnFwd(OUT_A); OnFwd(OUT_C); Wait(400); Off(OUT_A); Off(OUT_C); }

Example 1 Revised: Drive Forward Motor specifications can be “added” together. task main () { OnFwd(OUT_A + OUT_C); Wait(400); Off(OUT_A + OUT_C); }

Example 2: Out and Back Move forward for 5 seconds, turn around and come back to the starting point task main () { OnFwd(OUT_A + OUT_C);// Move Forward Wait(500); OnRev(OUT_C);// Turn Around Wait(200); OnFwd(OUT_C);// Come Back Wait(500); Off(OUT_A + OUT_C);// Stop }

Setting Motor Power You can set an output power level by the SetPower command Examples SetPower(OUT_A, 4); SetPower(OUT_A + OUT_C, 1); The first parameter is the output(s), the second a power level in the range 0..7 Affects motor torque more than actual speed

Inline Functions NQC provides for functions which are “inlined” by the compiler Pass by value and pass by reference parameters like in C All functions return void.

Example 3: Square Patrol Repeatedly drive around in a square shape task main () { while (true) { moveForward(500); turnLeft(100); } void moveForward(int time) { OnFwd(OUT_A + OUT_C); Wait(time); Off(OUT_A + OUT_C); } void turnLeft(int time) { OnFwd(OUT_C); OnRev(OUT_A); Wait(time); Off(OUT_A + OUT_C); }

Using Sensors (1) In the Reactive Control paradigm the bot controls its actions in response to input from its sensors. Two types of sensors come with the Mindstorms kit Bump Sensors Light Sensors Recall that there are three sensor connections, and in NQC the sensors attached to them are called SENSOR_1 SENSOR_2 SENSOR_3 More than one sensor can be attached to a connection

Using Sensors (1) To use a sensor we must first define it type using SetSensor Examples SetSensor(SENSOR_1, SENSOR_TOUCH); SetSensor(SENSOR_2, SENSOR_LIGHT); By default, touch sensors return 0 or 1 (1 if currently pressed) By default, light sensors return a value in the range , with 0 meaning no measured light Other return modes are possible, see the NQC manual for details

Example 4: Move till Bump Move forward until a bump Solution uses sensor polling task main () { SetSensor(SENSOR_2, SENSOR_TOUCH); OnFwd(OUT_A + OUT_C);// Move Forward while (SENSOR_2 != 1)// Until a Bump ; Off(OUT_A + OUT_C);// Then Stop }

Example 5: Move till Darker Move forward until light reading becomes tolerance units less that the starting light level task main () { int startLevel; int tolerance = 5; SetSensor(SENSOR_2, SENSOR_LIGHT); startLevel = SENSOR_2; OnFwd(OUT_A + OUT_C);// Move Forward while (SENSOR_2 > startLevel-tolerance) ;// Until Darker Off(OUT_A + OUT_C);// Then Stop }

What’s Wrong? We want the bot to patrol back and forth until a bump sensor is pressed. Why doesn’t this proposed solution work? task main () { SetSensor(SENSOR_2, SENSOR_TOUCH); OnFwd(OUT_A); while(SENSOR_2 != 1) { OnFwd(OUT_C); Wait(400); OnRev(OUT_C); Wait(200); } Off(OUT_A + OUT_C); }

Multitasking The RCX supports up to 10 concurrent threads of execution. Use the start and stop commands to control task execution.

Example 6: Patrol with Bump Stop Patrol back and forth until a bump sensor is pressed. task main () { SetSensor(SENSOR_2, SENSOR_TOUCH); start patrol; while(SENSOR_2 != 1) ; stop patrol; Off(OUT_A + OUT_C); } task patrol () { OnFwd(OUT_A); while(true) { OnFwd(OUT_C); Wait(400); OnRev(OUT_C); Wait(200); }

Using Resources Be careful how tasks use the RCX’s resources Shareable resources: the sensors One task’s reading of them does not affect what other tasks are doing Non-shareable resources: the motors If more than one task is trying to control the motors unpredictable results will occur This is an example of race conditions A typical source of error once tasks have been introduced in the course

NQC Links NQC was developed by Dave Baum and is now maintained by John Hansen For the Macintosh the IDE of choice is MacNQC For Windows the IDE of choice is Bricx Command Center (bricxCC) BricxCC can also be used with BrickOS, LejOS, and pForth

An NQC Laboratory Project: Feed ME! Idea Imagine that your roverbot needs to feed, and becomes increasingly weakened when it has not fed for some time. Food makes it stronger. For our purposes we will assume that the bot can feed at any of the black circles in its playpen. When it has found a food source, it should stop in order to feed on that source. Once full, it should again begin to wander around its world. For a certain period of time after feeding, it will not want to eat again. Once it becomes hungry, however, it must find a food source in a timely manner, or it will begin to lose energy. Materials Robot with two bump sensors and a light senor pointed at the floor A play area containing black circles of various sizes

The Specifics 1. Try to find a food source within ten seconds. 2. If a food source is not found simulate a loss of energy by adjusting the speed of the robot by a fixed amount. Return to the feeding behavior (i.e., return to the first step above). 3. If a food source is found Stop for 3 seconds in order to eat. If the robot was not already at maximum energy capacity, then give it back some of its energy. Used the same fixed amount you used to simulate the loss of energy. Then begin to wander the world again. For 5 seconds the robot should not want to eat. Return to feeding behavior (i.e., return to the first step above). 4. The robot should stop either when someone presses the "off" button or when the robot runs completely out of energy

Project Notes and Stages General Notes: Use five different energy levels. Your bot should be able to wander randomly around its playpen, dealing with any wall or obstruction it may find. Project Stages: Demonstrate each stage to the TA 1. The roverbot randomly moves around until it finds a food source and stops over it. 2. The roverbot loses energy every 5 seconds until it finds food. It stops over the food, or if it doesn't find food eventually stops due to lack of energy. 3. The complete project as described.

Hands-on Activity: Taking Damage Modify the patrol solution (example 6) so that whenever the bot’s bump sensors are pressed instead of stopping it spins around and then goes back to its patrol. More advanced problems: Each time the bot is bumped it spins around one more time. As above, but with a maximum number of times the bot can be bumped before it just stops. As above, but that max number is entered into the bot by pressing its left bumper that many times, followed by a right bumper press. Then the bot begins its patrol.