+ All Categories
Home > Documents > NQC / BricxCC Brief Introduction David Schilling.

NQC / BricxCC Brief Introduction David Schilling.

Date post: 29-Jan-2016
Category:
Upload: candice-cobb
View: 217 times
Download: 0 times
Share this document with a friend
Popular Tags:
69
NQC / BricxCC Brief Introduction David Schilling
Transcript
Page 1: NQC / BricxCC Brief Introduction David Schilling.

NQC / BricxCC

Brief Introduction

David Schilling

Page 2: NQC / BricxCC Brief Introduction David Schilling.

BricxCC

Graphical user interface to programming your RCX

Page 3: NQC / BricxCC Brief Introduction David Schilling.

BricxCC

EditorSyntax highlightingProgramming helpsCommunication with RCX

Page 4: NQC / BricxCC Brief Introduction David Schilling.

F1 – Help

Page 5: NQC / BricxCC Brief Introduction David Schilling.

F1 – Help

Page 6: NQC / BricxCC Brief Introduction David Schilling.

Templates

Page 7: NQC / BricxCC Brief Introduction David Schilling.

Templates

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

Page 8: NQC / BricxCC Brief Introduction David Schilling.

Communicating with the RCX

Page 9: NQC / BricxCC Brief Introduction David Schilling.

NQC

Programming language with C-like syntaxUses Lego’s RCX firmware

Page 10: NQC / BricxCC Brief Introduction David Schilling.

Program skeleton

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

Page 11: NQC / BricxCC Brief Introduction David Schilling.

Defining Sensors

SetSensor( SENSOR_1, SENSOR_TOUCH );

SENSOR_TOUCHSENSOR_LIGHTSENSOR_ROTATION

(plus a few rarely used others)

Page 12: NQC / BricxCC Brief Introduction David Schilling.

Getting a Sensor’s value

First define a variable

int x;

Then assign the value to that variable

x = SENSOR_1;

Page 13: NQC / BricxCC Brief Introduction David Schilling.

Testing a Sensor’s value

Alternatively you can just use the sensor value in an expression

if( SENSOR_1 > 50 ) { }

Page 14: NQC / BricxCC Brief Introduction David Schilling.

Sensor Ranges

Sensor type Range

SENSOR_TOUCH true / false

SENSOR_LIGHT0-100 advertised45-70 is normal

SENSOR_ROTATION any integer value

Page 15: NQC / BricxCC Brief Introduction David Schilling.

Using Names for Sensors

Early in your program define a nameUse 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

Page 16: NQC / BricxCC Brief Introduction David Schilling.

Sensor Naming example

#define Bumper SENSOR_1#define Edge SENSOR_2

task main() { SetSensor( Bumper, SENSOR_TOUCH

); SetSensor( Edge, SENSOR_LIGHT ); }

Page 17: NQC / BricxCC Brief Introduction David Schilling.

Using Raw Values

With “SetSensor”, The light sensor range(a ‘percentage’ from 0 to 100) is very limitedUsually you’ll only get a value from around45 to 70 or soTo get a greater range, use SetSensorType and SetSensorMode

SetSensorType(SENSOR_1, SENSOR_TYPE_LIGHT );SetSensorMode(SENSOR_1, SENSOR_MODE_RAW );

Page 18: NQC / BricxCC Brief Introduction David Schilling.

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

Page 19: NQC / BricxCC Brief Introduction David Schilling.

Motors

Default names for motors are OUT_A, OUT_B and OUT_CMotor state can be ON, OFF, or FLOATMotor direction and power can be setJust like with sensors, I recommend giving motors names

Page 20: NQC / BricxCC Brief Introduction David Schilling.

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 );

Page 21: NQC / BricxCC Brief Introduction David Schilling.

Motor Commands

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

Page 22: NQC / BricxCC Brief Introduction David Schilling.

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

Page 23: NQC / BricxCC Brief Introduction David Schilling.

Motor Power

To set a motor’s power level use SetPower( OUT_A, OUT_FULL );

The first argument is one or more motorsThe second argument is the power level OUT_LOW, OUT_HALF, OUT_FULL or 0 to 7

Page 24: NQC / BricxCC Brief Introduction David Schilling.

Motor Direction

To set a motor’s direction use SetDirection( OUT_A, OUT_FWD );

The first argument is one or more motorsThe second argument is the direction OUT_FWD, or OUT_REV

Page 25: NQC / BricxCC Brief Introduction David Schilling.

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

Page 26: NQC / BricxCC Brief Introduction David Schilling.

Changing a Motor’s Orientation

You can rotate the wire 180 degreesYou can change every line in your program that references a motor, orYou can use SetGlobalDirection();

If your motor goes forward when you want it to go reverse, and vice versa, there are a couple of solutions:

Page 27: NQC / BricxCC Brief Introduction David Schilling.

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 normalThis is a very clean way to write your programs: “FWD” means forward

Page 28: NQC / BricxCC Brief Introduction David Schilling.

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 ); }

Page 29: NQC / BricxCC Brief Introduction David Schilling.

Simple Sumo demo program

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

Page 30: NQC / BricxCC Brief Introduction David Schilling.

// 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

Page 31: NQC / BricxCC Brief Introduction David Schilling.

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

Page 32: NQC / BricxCC Brief Introduction David Schilling.

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 );

}

}

Page 33: NQC / BricxCC Brief Introduction David Schilling.

Complete Program...

Page 34: NQC / BricxCC Brief Introduction David Schilling.

// 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);

Page 35: NQC / BricxCC Brief Introduction David Schilling.

#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 );

Page 36: NQC / BricxCC Brief Introduction David Schilling.

#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 );

Page 37: NQC / BricxCC Brief Introduction David Schilling.

#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 );

Page 38: NQC / BricxCC Brief Introduction David Schilling.

#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 );

Page 39: NQC / BricxCC Brief Introduction David Schilling.

#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 );

Page 40: NQC / BricxCC Brief Introduction David Schilling.

#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 );

Page 41: NQC / BricxCC Brief Introduction David Schilling.

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 );

Page 42: NQC / BricxCC Brief Introduction David Schilling.

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 );

Page 43: NQC / BricxCC Brief Introduction David Schilling.

{

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 );

Page 44: NQC / BricxCC Brief Introduction David Schilling.

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 )

Page 45: NQC / BricxCC Brief Introduction David Schilling.

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 )

{

Page 46: NQC / BricxCC Brief Introduction David Schilling.

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 )

Page 47: NQC / BricxCC Brief Introduction David Schilling.

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 );

Page 48: NQC / BricxCC Brief Introduction David Schilling.

SetGlobalDirection( Left, OUT_REV );

SetPower( Both, OUT_HALF );

SetDirection( Both, OUT_FWD );

On( Both );

while( true )

{

if( Bumper )

SetPower( Both, OUT_FULL );

else

Page 49: NQC / BricxCC Brief Introduction David Schilling.

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 );

Page 50: NQC / BricxCC Brief Introduction David Schilling.

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

Page 51: NQC / BricxCC Brief Introduction David Schilling.

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

{

Page 52: NQC / BricxCC Brief Introduction David Schilling.

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 );

Page 53: NQC / BricxCC Brief Introduction David Schilling.

On( Both );

while( true )

{

if( Bumper )

SetPower( Both, OUT_FULL );

else

SetPower( Both, OUT_HALF );

if( Edge > 750 ) // at edge

{

Rev( Both );

Wait( 100 );

Page 54: NQC / BricxCC Brief Introduction David Schilling.

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 );

Page 55: NQC / BricxCC Brief Introduction David Schilling.

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 );

Page 56: NQC / BricxCC Brief Introduction David Schilling.

{

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 );

Page 57: NQC / BricxCC Brief Introduction David Schilling.

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 );

}

Page 58: NQC / BricxCC Brief Introduction David Schilling.

SetPower( Both, OUT_FULL );

else

SetPower( Both, OUT_HALF );

if( Edge > 750 ) // at edge

{

Rev( Both );

Wait( 100 );

Fwd( Left );

Wait( 200 );

Fwd( Right );

}

}

Page 59: NQC / BricxCC Brief Introduction David Schilling.

else

SetPower( Both, OUT_HALF );

if( Edge > 750 ) // at edge

{

Rev( Both );

Wait( 100 );

Fwd( Left );

Wait( 200 );

Fwd( Right );

}

}

}

Page 60: NQC / BricxCC Brief Introduction David Schilling.

SetPower( Both, OUT_HALF );

if( Edge > 750 ) // at edge

{

Rev( Both );

Wait( 100 );

Fwd( Left );

Wait( 200 );

Fwd( Right );

}

}

}

Page 61: NQC / BricxCC Brief Introduction David Schilling.

if( Edge > 750 ) // at edge

{

Rev( Both );

Wait( 100 );

Fwd( Left );

Wait( 200 );

Fwd( Right );

}

}

}

Page 62: NQC / BricxCC Brief Introduction David Schilling.

{

Rev( Both );

Wait( 100 );

Fwd( Left );

Wait( 200 );

Fwd( Right );

}

}

}

Page 63: NQC / BricxCC Brief Introduction David Schilling.

Rev( Both );

Wait( 100 );

Fwd( Left );

Wait( 200 );

Fwd( Right );

}

}

}

Page 64: NQC / BricxCC Brief Introduction David Schilling.

Wait( 100 );

Fwd( Left );

Wait( 200 );

Fwd( Right );

}

}

}

Page 65: NQC / BricxCC Brief Introduction David Schilling.

Fwd( Left );

Wait( 200 );

Fwd( Right );

}

}

}

Page 66: NQC / BricxCC Brief Introduction David Schilling.
Page 67: NQC / BricxCC Brief Introduction David Schilling.
Page 68: NQC / BricxCC Brief Introduction David Schilling.
Page 69: NQC / BricxCC Brief Introduction David Schilling.

// 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 );

}

}

}


Recommended