NQC / BricxCC Brief Introduction David Schilling.

Slides:



Advertisements
Similar presentations
Mindstorms State Machines A structured method for handling tasks and events using RoboLab and NQC Brian Smith
Advertisements

1chung 5 th Annual Robofest 2004 Informational Meeting Mar. 20, 2004 Chan Jin Chung Ali Khazaal Jason Lo Computer Science Lawrence Technological University.
Robofest 2005 Introduction to Programming RIS 2.0 RCX Code.
Chung for Robofest 05 1 Introduction to RoboLab CJ Chung Lawrence Technological University.
RCX Workshop Day 2 Programming with Touch Sensor Light Sensor Repeat CJ Chung Associate Professor of Computer Science Lawrence Technological University.
Alma Robotics Challenge March 30, 2007 Alma College.
08/2012Tanya Mishra1 EASYC for VEX Cortex Llano Estacado RoboRaiders FRC Team 1817.
An Introduction to C Adam Gleitman – IAP 2014.
VEX and Robot C Chris Patterson Presented by Modified by J. Andazola.
Programing Concept Ken Youssefi/Ping HsuIntroduction to Engineering – E10 1 ENGR 10 Introduction to Engineering (Part A)
Alternative Programming Languages Myles McNally LMICSE Workshop November , 2004 University of Mississippi.
Motor control drive in circles Pragmas configure motors Turning right in function of time Turning left in function of time Main program starts from here.
LEGO Robotics Lecture 1: Getting acquainted with your robotic environment.
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,
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.
©2006 CSUC Institute for Research in Intelligent Systems Introduction to Coding June 15, 2006.
Preprocessor Directives (last modified 9/19/05 2:47pm) Statements beginning with # are directives to the preprocessor. –They DO NOT end with ; –Before.
Working with Arduino: Lesson #1: Getting Acquainted with the Kit EGN1007.
Using the LEGO NXT March 2007 David Schilling Gus Jansson.
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.
ROBOTC Software Introduction. ROBOTC Software ROBOTC developed specifically for classrooms and competitions Complete programming solution for VEX Cortex.
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.
CSC Intro. to Computing Lecture 16: Robotran.
Teacher/Mentor Institute Using easyC Joel Kirkland July 30-31, 2015.
Programing Concept Ken Youssefi/Ping HsuIntroduction to Engineering – E10 1 ENGR 10 Introduction to Engineering (Part A)
Events Chapter 7 Part 2. While a Key is Pressed Event Specialized event An event occurs when you press a key and continues until you take your finger.
Programming Fundamentals. Today’s lecture Decisions If else …… Switch Conditional Operators Logical Operators.
Robotics Overview of NXT-G Actuators in Mindstorms. Touch sensor Labwork: Right turn. Touch/bump. [Explore move versus Motor Move mini & motor mini. Motor*.]
A tiny turtle robot DEI The University of Padova.
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’
Variables and Functions. Open your Encoder program Let’s begin by opening the “Labyrinth Auto Straight” code. Save this file as Labyrinth with variables.
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.
Motors and Sound Troubleshooting Tips. © H-CCS Problem 1 Why can’t I download my program to the RCX?
Wall Encounter By Made easy by Dwayne Abuel.
2008 SBPLI/FIRST Programming Workshop Tom Boehm Patchogue Medford High School, Team 329 Motorola Inc. Mark McLeod Hauppauge High School Team 358 Northrop.
THE TOUCH SENSOR The Touch Sensor, shown in the picture, gives the robot the sense of touch. It gives too different signals when the orange part is ether.
The George Washington University Department of ECE ECE Intro: Electrical & Computer Engineering Dr. S. Ahmadi Class 4.
Castor Bot. Now, we will begin creating a robot Log onto your computer On your screen, click on the website labeled “castor bot” Your building instructions.
Robotics NXT-G: variables, file Rotation sensor Lab: Use buttons to hit specific ball. Homework: Postings. Start planning mapping the room.
Lesson 4: Conditional Statements Programming Solutions.
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.
ROBOTC Software EV3 Robot Workshop
Mindstorm NXT-G Introduction Towson University Robotics.
BEGINNER FLL PROGRAMMING WORKSHOP BY DROIDS ROBOTICS & EV3LESSONS.
VEX and Robot C Chris Patterson Frisco ISD CTE Center Presented by.
Lesson 1: Motors and Sound Programming Solutions.
1 ©2006 INSciTE Lab Three Task: Move forward for 2 feet, turn right 90º repeat to complete a square path. End up exactly where you started.
The George Washington University Department of ECE ECE Intro: Electrical & Computer Engineering Dr. S. Ahmadi Class 4.
Introduction to Programming in RobotC
ARM from NXT NXC Programming
EGR 2261 Unit 4 Control Structures I: Selection
Automation and Robotics
Programming Concepts (Part B) ENGR 10 Introduction to Engineering
Roller Coaster Design Project
Automation and Robotics
The George Washington University Department of ECE ECE Intro: Electrical & Computer Engineering Dr. S. Ahmadi Class 5.
While Loops and If-Else Structures
While Loops and If-Else Structures
While Loops and If-Else Structures
Lesson 4 Variables.
While Loops and If-Else Structures
While Loops and If-Else Structures
Programming Concepts (Part B) ENGR 10 Introduction to Engineering
While Loops And If-Else Structures
NQC Program Structure 3 types of code blocks with their own features and limitations 1. Tasks 2. Subroutines 3. Inline Functions.
Presentation transcript:

NQC / BricxCC Brief Introduction David Schilling

BricxCC Graphical user interface to programming your RCX

BricxCC Editor Syntax highlighting Programming helps Communication with RCX

F1 – Help

Templates

Just click on a command in the template and the function is inserted into the editor with hints for its parameters Press F10 to go to the next one

Communicating with the RCX

NQC Programming language with C-like syntax Uses Lego’s RCX firmware

Program skeleton task main() { // your program goes here }

Defining Sensors SetSensor( SENSOR_1, SENSOR_TOUCH ); SENSOR_TOUCH SENSOR_LIGHT SENSOR_ROTATION (plus a few rarely used others)

Getting a Sensor’s value First define a variable int x; Then assign the value to that variable x = SENSOR_1;

Testing a Sensor’s value Alternatively you can just use the sensor value in an expression if( SENSOR_1 > 50 ) { }

Sensor Ranges Sensor typeRange SENSOR_TOUCHtrue / false SENSOR_LIGHT advertised is normal SENSOR_ROTATIONany integer value

Using Names for Sensors Early in your program define a name Use that name instead of the sensor # Benefits can easily move sensor to a different port by only making one change code becomes more self-explanatory

Sensor Naming example #define Bumper SENSOR_1 #define Edge SENSOR_2 task main() { SetSensor( Bumper, SENSOR_TOUCH ); SetSensor( Edge, SENSOR_LIGHT ); }

Using Raw Values With “SetSensor”, The light sensor range (a ‘percentage’ from 0 to 100) is very limited Usually you’ll only get a value from around 45 to 70 or so To get a greater range, use SetSensorType and SetSensorMode SetSensorType(SENSOR_1, SENSOR_TYPE_LIGHT ); SetSensorMode(SENSOR_1, SENSOR_MODE_RAW );

Raw Sensor Values The range changes to something like 600 – 800 However, light and dark are reversed: A dark reading of 40 becomes 800 A light reading of 70 becomes 600

Motors Default names for motors are OUT_A, OUT_B and OUT_C Motor state can be ON, OFF, or FLOAT Motor direction and power can be set Just like with sensors, I recommend giving motors names

Motor Commands You can just use motors (since all motors are identical to the RCX there is no need to define them like sensors) eg: On( OUT_A ); You can combine multiple motors in a command by using the “+” sign eg: Off( OUT_A+OUT_C );

Motor Commands Common Commands: On(); Off(); Float(); SetPower(); Fwd(); Rev(); SetDirection(); OnFwd(); OnRev(); OnFor();

Motor States The following functions just take one or more motors as an argument: On();- Turns motor on Off();- Brakes motor Float();- Lets motor float

Motor Power To set a motor’s power level use SetPower( OUT_A, OUT_FULL ); The first argument is one or more motors The second argument is the power level OUT_LOW, OUT_HALF, OUT_FULL or 0 to 7

Motor Direction To set a motor’s direction use SetDirection( OUT_A, OUT_FWD ); The first argument is one or more motors The second argument is the direction OUT_FWD, or OUT_REV

Motor Direction A simpler way to set a motor’s direction is to use: Fwd( OUT_A ); or Rev( OUT_A ); These work the same as SetDirection(); You can also use Toggle( OUT_A ); to change the motor’s direction

Changing a Motor’s Orientation You can rotate the wire 180 degrees You can change every line in your program that references a motor, or You can use SetGlobalDirection(); If your motor goes forward when you want it to go reverse, and vice versa, there are a couple of solutions:

SetGlobalDirection(); SetGlobalDirection( OUT_A, OUT_REV ); This command will change a motor’s direction from now on, so that “FWD” means “REV” and vice versa “OUT_FWD” as the second argument restores a motor back to normal This is a very clean way to write your programs: “FWD” means forward

Motor Example #define Left OUT_A #define Right OUT_C task main() { SetPower( Left+Right, OUT_FULL ); SetDirection( Left+Right, OUT_FWD ); On( Left+Right ); Wait( 100 ); }

Simple Sumo demo program (This is a terrible program! I’m just using it to illustrate the concepts covered in this presentation)

// Simple Sumo demo program #define Bumper SENSOR_1 #define Edge SENSOR_2 #define Left OUT_A #define Right OUT_C #define Both OUT_A+OUT_C Naming sensors and motors

SetSensor( Bumper, SENSOR_TOUCH); SetSensorType( Edge, SENSOR_TYPE_LIGHT ); SetSensorMode( Edge, SENSOR_MODE_RAW ); SetGlobalDirection( Left, OUT_REV ); SetPower( Both, OUT_HALF ); SetDirection( Both, OUT_FWD ); Setting up sensors and motors

Program loop On( Both ); while( true ) { if( Bumper ) SetPower( Both, OUT_FULL ); else SetPower( Both, OUT_HALF ); if( Edge > 750 ) // at edge { Rev( Both ); Wait( 100 ); Fwd( Left ); Wait( 200 ); Fwd( Right ); }

Complete Program...

// Simple Sumo demo program #define Bumper SENSOR_1 #define Edge SENSOR_2 #define Left OUT_A #define Right OUT_C #define Both OUT_A+OUT_C task main() { SetSensor( Bumper, SENSOR_TOUCH);

#define Bumper SENSOR_1 #define Edge SENSOR_2 #define Left OUT_A #define Right OUT_C #define Both OUT_A+OUT_C task main() { SetSensor( Bumper, SENSOR_TOUCH); SetSensorType( Edge, SENSOR_TYPE_LIGHT );

#define Edge SENSOR_2 #define Left OUT_A #define Right OUT_C #define Both OUT_A+OUT_C task main() { SetSensor( Bumper, SENSOR_TOUCH); SetSensorType( Edge, SENSOR_TYPE_LIGHT ); SetSensorMode( Edge, SENSOR_MODE_RAW );

#define Left OUT_A #define Right OUT_C #define Both OUT_A+OUT_C task main() { SetSensor( Bumper, SENSOR_TOUCH); SetSensorType( Edge, SENSOR_TYPE_LIGHT ); SetSensorMode( Edge, SENSOR_MODE_RAW );

#define Left OUT_A #define Right OUT_C #define Both OUT_A+OUT_C task main() { SetSensor( Bumper, SENSOR_TOUCH); SetSensorType( Edge, SENSOR_TYPE_LIGHT ); SetSensorMode( Edge, SENSOR_MODE_RAW ); SetGlobalDirection( Left, OUT_REV );

#define Right OUT_C #define Both OUT_A+OUT_C task main() { SetSensor( Bumper, SENSOR_TOUCH); SetSensorType( Edge, SENSOR_TYPE_LIGHT ); SetSensorMode( Edge, SENSOR_MODE_RAW ); SetGlobalDirection( Left, OUT_REV );

#define Both OUT_A+OUT_C task main() { SetSensor( Bumper, SENSOR_TOUCH); SetSensorType( Edge, SENSOR_TYPE_LIGHT ); SetSensorMode( Edge, SENSOR_MODE_RAW ); SetGlobalDirection( Left, OUT_REV ); SetPower( Both, OUT_HALF );

task main() { SetSensor( Bumper, SENSOR_TOUCH); SetSensorType( Edge, SENSOR_TYPE_LIGHT ); SetSensorMode( Edge, SENSOR_MODE_RAW ); SetGlobalDirection( Left, OUT_REV ); SetPower( Both, OUT_HALF ); SetDirection( Both, OUT_FWD );

task main() { SetSensor( Bumper, SENSOR_TOUCH); SetSensorType( Edge, SENSOR_TYPE_LIGHT ); SetSensorMode( Edge, SENSOR_MODE_RAW ); SetGlobalDirection( Left, OUT_REV ); SetPower( Both, OUT_HALF ); SetDirection( Both, OUT_FWD );

{ SetSensor( Bumper, SENSOR_TOUCH); SetSensorType( Edge, SENSOR_TYPE_LIGHT ); SetSensorMode( Edge, SENSOR_MODE_RAW ); SetGlobalDirection( Left, OUT_REV ); SetPower( Both, OUT_HALF ); SetDirection( Both, OUT_FWD ); On( Both );

SetSensor( Bumper, SENSOR_TOUCH); SetSensorType( Edge, SENSOR_TYPE_LIGHT ); SetSensorMode( Edge, SENSOR_MODE_RAW ); SetGlobalDirection( Left, OUT_REV ); SetPower( Both, OUT_HALF ); SetDirection( Both, OUT_FWD ); On( Both ); while( true )

SetSensorType( Edge, SENSOR_TYPE_LIGHT ); SetSensorMode( Edge, SENSOR_MODE_RAW ); SetGlobalDirection( Left, OUT_REV ); SetPower( Both, OUT_HALF ); SetDirection( Both, OUT_FWD ); On( Both ); while( true ) {

SetSensorType( Edge, SENSOR_TYPE_LIGHT ); SetSensorMode( Edge, SENSOR_MODE_RAW ); SetGlobalDirection( Left, OUT_REV ); SetPower( Both, OUT_HALF ); SetDirection( Both, OUT_FWD ); On( Both ); while( true ) { if( Bumper )

SetSensorMode( Edge, SENSOR_MODE_RAW ); SetGlobalDirection( Left, OUT_REV ); SetPower( Both, OUT_HALF ); SetDirection( Both, OUT_FWD ); On( Both ); while( true ) { if( Bumper ) SetPower( Both, OUT_FULL );

SetGlobalDirection( Left, OUT_REV ); SetPower( Both, OUT_HALF ); SetDirection( Both, OUT_FWD ); On( Both ); while( true ) { if( Bumper ) SetPower( Both, OUT_FULL ); else

SetGlobalDirection( Left, OUT_REV ); SetPower( Both, OUT_HALF ); SetDirection( Both, OUT_FWD ); On( Both ); while( true ) { if( Bumper ) SetPower( Both, OUT_FULL ); else SetPower( Both, OUT_HALF );

SetDirection( Both, OUT_FWD ); On( Both ); while( true ) { if( Bumper ) SetPower( Both, OUT_FULL ); else SetPower( Both, OUT_HALF ); if( Edge > 750 ) // at edge

SetPower( Both, OUT_HALF ); SetDirection( Both, OUT_FWD ); On( Both ); while( true ) { if( Bumper ) SetPower( Both, OUT_FULL ); else SetPower( Both, OUT_HALF ); if( Edge > 750 ) // at edge {

SetDirection( Both, OUT_FWD ); On( Both ); while( true ) { if( Bumper ) SetPower( Both, OUT_FULL ); else SetPower( Both, OUT_HALF ); if( Edge > 750 ) // at edge { Rev( Both );

On( Both ); while( true ) { if( Bumper ) SetPower( Both, OUT_FULL ); else SetPower( Both, OUT_HALF ); if( Edge > 750 ) // at edge { Rev( Both ); Wait( 100 );

On( Both ); while( true ) { if( Bumper ) SetPower( Both, OUT_FULL ); else SetPower( Both, OUT_HALF ); if( Edge > 750 ) // at edge { Rev( Both ); Wait( 100 ); Fwd( Left );

while( true ) { if( Bumper ) SetPower( Both, OUT_FULL ); else SetPower( Both, OUT_HALF ); if( Edge > 750 ) // at edge { Rev( Both ); Wait( 100 ); Fwd( Left ); Wait( 200 );

{ if( Bumper ) SetPower( Both, OUT_FULL ); else SetPower( Both, OUT_HALF ); if( Edge > 750 ) // at edge { Rev( Both ); Wait( 100 ); Fwd( Left ); Wait( 200 ); Fwd( Right );

if( Bumper ) SetPower( Both, OUT_FULL ); else SetPower( Both, OUT_HALF ); if( Edge > 750 ) // at edge { Rev( Both ); Wait( 100 ); Fwd( Left ); Wait( 200 ); Fwd( Right ); }

SetPower( Both, OUT_FULL ); else SetPower( Both, OUT_HALF ); if( Edge > 750 ) // at edge { Rev( Both ); Wait( 100 ); Fwd( Left ); Wait( 200 ); Fwd( Right ); }

else SetPower( Both, OUT_HALF ); if( Edge > 750 ) // at edge { Rev( Both ); Wait( 100 ); Fwd( Left ); Wait( 200 ); Fwd( Right ); }

SetPower( Both, OUT_HALF ); if( Edge > 750 ) // at edge { Rev( Both ); Wait( 100 ); Fwd( Left ); Wait( 200 ); Fwd( Right ); }

if( Edge > 750 ) // at edge { Rev( Both ); Wait( 100 ); Fwd( Left ); Wait( 200 ); Fwd( Right ); }

{ Rev( Both ); Wait( 100 ); Fwd( Left ); Wait( 200 ); Fwd( Right ); }

Rev( Both ); Wait( 100 ); Fwd( Left ); Wait( 200 ); Fwd( Right ); }

Wait( 100 ); Fwd( Left ); Wait( 200 ); Fwd( Right ); }

Fwd( Left ); Wait( 200 ); Fwd( Right ); }

// Simple Sumo demo program #define Bumper SENSOR_1 #define Edge SENSOR_2 #define Left OUT_A #define Right OUT_C #define Both OUT_A+OUT_C task main() { SetSensor( Bumper, SENSOR_TOUCH); SetSensorType( Edge, SENSOR_TYPE_LIGHT ); SetSensorMode( Edge, SENSOR_MODE_RAW ); SetGlobalDirection( Left, OUT_REV ); SetPower( Both, OUT_HALF ); SetDirection( Both, OUT_FWD ); On( Both ); while( true ) { if( Bumper ) SetPower( Both, OUT_FULL ); else SetPower( Both, OUT_HALF ); if( Edge > 750 ) // at edge { Rev( Both ); Wait( 100 ); Fwd( Left ); Wait( 200 ); Fwd( Right ); }