Preprocessor Directives (last modified 9/19/05 2:47pm) Statements beginning with # are directives to the preprocessor. –They DO NOT end with ; –Before.

Slides:



Advertisements
Similar presentations
Unit 4 - I Said Stop!. Introduction New Topics Timing Parallelism Sequence of Operations New Features NXT terminals New Functions Wait For.
Advertisements

Mindstorms State Machines A structured method for handling tasks and events using RoboLab and NQC Brian Smith
Robofest 2005 Introduction to Programming RIS 2.0 RCX Code.
RCX Workshop Day 2 Programming with Touch Sensor Light Sensor Repeat CJ Chung Associate Professor of Computer Science Lawrence Technological University.
Full Speed Ahead Introductory Presentation. Opening Activity Choose one of the objects to the right and in ten or more steps explain how it goes from.
Autonomy using Encoders Intro to Robotics. Goal Our new task is to navigate a labyrinth. But this time we will NOT use motor commands in conjunction with.
Alternative Programming Languages Myles McNally LMICSE Workshop November , 2004 University of Mississippi.
Design of Control Strategy System Dynamics Environmental Disturbances Control Strategy GoalOutput Feedback Sensors.
LEGO Robotics Lecture 1: Getting acquainted with your robotic environment.
NQC: Control Structures: Branching Last updated 10/6/05 10:00am References: Baum Chapter 3 pp NQC Tutorial pp Baum Appendix D pg 368.
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,
RobotC Programming for LEGO Mindstorms NXT Carnegie Mellon Dacta Lego Timothy Friez Miha Štajdohar SOURCES:
Not Quite C: A CS 0 Option LMICSE Workshop June , 2005 Alma College.
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.
LEGO Mindstorms RIS 2.0 Programming: NQC Code B.A. Juliano and R.S. Renner September 2004 California State University, Chico Intelligent Systems Laboratory.
EBOT: Programming Primer Sean Donovan Alexander Hecht Justin Woodard.
An Intro to Robots and Computer Programming
Debugging (updated 9/20/06 12:48pm) It doesn’t work…. What do I do????
Using Variables Variables form a very important aspect of every programming language. Variables are memory locations in which we can store a value. We.
©2006 CSUC Institute for Research in Intelligent Systems Introduction to Coding June 15, 2006.
1 Probability. 2 Probability has three related “meanings.” 1. Probability is a mathematical construct. Probability.
Inline Functions Sometimes you need the same piece of code at multiple places in your task. Inline functions are copied at each place they are used. In.
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.
Repeating Blocks of Code (updated 9/20/05 7:35pm) Reference NQC Tutorial pp 9-12.
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.
Robotics Overview of NXT-G Actuators in Mindstorms. Touch sensor Labwork: Right turn. Touch/bump. [Explore move versus Motor Move mini & motor mini. Motor*.]
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’
Autonomy using Encoders Intro to Robotics. Autonomy/Encoders Forward for Distance In this unit, you will learn to use the encoders to control the distance.
Documentation and Programming Style Appendix A © 2015 Pearson Education, Inc., Hoboken, NJ. All rights reserved.
Technical Writing for Robotic Coding!.  du/products/teaching_robotc_cort ex/fundamentals/introtoprogramm ing/thinking/videos/fundamentals.
Find the Mindstorms Icon on the computer.. To start a new program click go.
NQC / BricxCC Brief Introduction David Schilling.
Coding Conventions  Coding conventions are a set of guidelines for a specific software project that recommend programming style, practices and methods.
Program Development C# Programming January 30, 2007 Professor J. Sciame.
Getting Started in RobotC // Comment task main() motor[] {} wait1Msec() ; = Header Code Compile Download Run Take out your notes.
Vex Robotics Program four: reversing and turning.
NQC Brief Introduction – Part 2 David Schilling. NQC – Where to put code? Programs Tasks Functions Subroutines.
Oregon Robotics Tournament and Outreach Program RCX Basics.
Available at: – Program Functions to Accept Values Program Functions to Accept Values.
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.
Lesson 1: Motors and Sound Programming Solutions.
Vex Robotics Program Two: Using two motors. Program two: using the motors In the last section, you learned how to turn on one motor. Now, you will take.
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.
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.
Forward Until Near Stop when near a wall.
STRUCTURED PROGRAMMING Complete C++ Program. Content 2  Main Function  Preprocessor directives  User comments  Escape characters  cout statement.
EV3 Programming By Dianna de Matos.
Whatcha doin'? Aims: To start using Python. To understand loops.
Chapter 2 Introduction to C++ Programming
Deriving Consistency from LEGOs
Variables and Functions
Chapter 2, Part I Introduction to C Programming
Programming Part 2 Mod Kit
Introductory Presentation
Programming - Motion Intro to Robotics.
Movement using Shaft Encoders
Autonomy using Encoders
Getting Started in RobotC
Variables and Functions
Variables and Functions
Introductory Presentation
Variables and Functions
An Introduction to VEX IQ Programming with Modkit
Getting Started in RobotC
Line Following Behavior
Using the sensor Lesson 5.
Preprocessor Directives
Oregon Robotics Tournament and Outreach Program
NQC Program Structure 3 types of code blocks with their own features and limitations 1. Tasks 2. Subroutines 3. Inline Functions.
Tutorial 10 Automating Tasks with Macros
Presentation transcript:

Preprocessor Directives (last modified 9/19/05 2:47pm) Statements beginning with # are directives to the preprocessor. –They DO NOT end with ; –Before the program is compiled, the preprocssor copies these definitions into the code. –These definitions are not required, but make the code easier to write and more readable –if you want to change the port on which a sensor is connected, and that appears multiple times in the program, then a single change in the #define is all you need to make the change.

// tankbot2.nqc - drive and turn // motors #define LEFT OUT_A #define RIGHT OUT_C // how much time to spend turning or forward #define TURN_TIME 200 #define STRAIGHT_TIME 100 // speed to run a turned motor #define TURN_POWER 3 task main() { // start with both motors on On(LEFT+RIGHT); // repeat the following steps forever while(true) { …… }

Programming Style Use indentation to visually group program blocks. Use comments to document the program

// tankbot2.nqc - drive and turn // motors #define LEFT OUT_A ……… task main() { // start with both motors on On(LEFT+RIGHT); // repeat the following steps forever while(true) { // turn right by slowing down the right tread SetPower(RIGHT, TURN_POWER); Wait(TURN_TIME); // resume going straight SetPower(RIGHT, OUT_FULL); Wait(STRAIGHT_TIME); // turn left SetPower(LEFT, TURN_POWER); Wait(TURN_TIME); // resume going straight SetPower(LEFT, OUT_FULL); Wait(STRAIGHT_TIME); }

Time NQC is a real-time programming language. Time is measured in 1/100 of a second #define TURN_TIME 200 Will define the turning time to be 2 seconds

Using Time to Control Motion Wait(300); The program will wait at that statement for 3 seconds. The following program will drive straight for 4 seconds, then if OUT_A is attached to the left tread, the left tread will stop and the right tread will continue to drive for 1second causing the tankbot to stear toward the left. On(OUT_A + OUT_B); Wait(400); Off(OUT_A); Wait(100);

Generating a Random Number NQC has a random number generating function Random(100); Generates a random integer between 0 and 100. All numbers in the range are equally likely (uniform distribution) 0100

NQC Functions So far we have seen several NQC functions. They have been associated with: Motors: On(arguments); Off(arguments); SetPower(arguments); OnFwd(arguments); Sensors SetSensor(arguments); Mathematical Random(arguments);

All NQC functions begin with a capital letter. As in SetSensor, two capitals are used to make them more readable. The number of arguments depend on the function. Appendix D (Braun) provides a Quick Reference to the language. The functions are grouped into categories. NOTE the restrictions. NOTE THERE ARE A FEW DIFFERENCES BETWEEN RCX AND RCX2.0. Which system do you have?