NQC Programming - Embedded Intelligent Robotics - Lecture Slides, Slides of Robotics

Course title is Embedded Intelligent Robotics. This course is for Electrical engineering students. Though good thing is everyone can learn about robotics in this course. This lecture includes: Nqc Programming, Global Variables, Inline Functions, Subroutines, Tasks, Motors, Control Structures, Functions, Variables, Sensor Modes

Typology: Slides

2013/2014

Uploaded on 01/29/2014

surii
surii šŸ‡®šŸ‡³

3.5

(13)

121 documents

1 / 59

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
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
4. subroutines
docsity.com
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22
pf23
pf24
pf25
pf26
pf27
pf28
pf29
pf2a
pf2b
pf2c
pf2d
pf2e
pf2f
pf30
pf31
pf32
pf33
pf34
pf35
pf36
pf37
pf38
pf39
pf3a
pf3b

Partial preview of the text

Download NQC Programming - Embedded Intelligent Robotics - Lecture Slides and more Slides Robotics in PDF only on Docsity!

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
  4. subroutines

1. You’ll be programming your robot in NQC (Not **Quite C).

  1. You’ll use the BricxCC (Bricx Control Centre)** **as your development environment.
  2. When you first fire up BricxCC (by double** clicking on the BricxCC icon) it looks for the **RCX brick.
  3. It will find it, because you will have switched it** on (using the red On-Off button) and placed it with its infra-red windows facing the IR tower and a few centimetres away from it. NQC Programming

You’ll get this. You should also get another window

If you don’t, press F9 once or twice until you do

Copy and paste the text file ā€˜trusty’ from your email

And save it locally as trusty (a .nqc file)

1. You will get helpful error messages below the **program

  1. If you can’t sort out the errors by yourself, call** Renzo, the GTA If your program won’t compile…

Tasks

task name ( ) { // the task 's code is placed here }

1. name : any legal identifier.

  1. 1 task - named "main" - started when program is run.
  2. Maximum number of tasks on RCX: 10
  3. The body of a task consists of a list of statements.
  4. Tasks started and stopped: start and stop statements 6. StopAllTasks stops all currently running tasks.

In robotC #pragma config(Motor, motorA, RightMotor, tmotorNormal, PIDControl, ) #pragma config(Motor, motorB, LeftMotor, tmotorNormal, PIDControl, ) //!!Code automatically generated by 'ROBOTC' configuration wizard !!// void rightTurn(int turnTime) { motor[RightMotor] = - 100; motor[LeftMotor] = 100; wait10Msec(turnTime); } void leftTurn(int turnTime) { motor[RightMotor] = 100; motor[LeftMotor] = - 100; wait10Msec(turnTime); } sub turn_around() { OnRev(OUT_C); Wait(400); OnFwd( OUT_A + OUT_C ); } This in NQC

In robotC #pragma config(Motor, motorA, RightMotor, tmotorNormal, PIDControl, ) #pragma config(Motor, motorB, LeftMotor, tmotorNormal, PIDControl, ) //!!Code automatically generated by 'ROBOTC' configuration wizard !!// void rightTurn(int turnTime) { motor[RightMotor] = - 100; motor[LeftMotor] = 100; wait10Msec(turnTime); } void leftTurn(int turnTime) { motor[RightMotor] = 100; motor[LeftMotor] = - 100; wait10Msec(turnTime); } task main() { motor[RightMotor] = 100; motor[LeftMotor] = 100; wait10Msec(100); rightTurn(20); motor[RightMotor] = 100; motor[LeftMotor] = 100; wait10Msec(100); leftTurn(20); motor[RightMotor] = 100; motor[LeftMotor] = 100; wait10Msec(100); StopAllTasks(); }

Subroutines sub turn_around() { OnRev(OUT_C); Wait(400); OnFwd(OUT_A+OUT_C); } task main() { OnFwd(OUT_A+OUT_C); Wait(100); turn_around(); Wait(200); turn_around(); Wait(100); turn_around(); Off(OUT_A+OUT_C);}c

Subroutines

1. Subroutines allow a single copy of some code

to be shared between several different callers

(space efficient).

2. Restrictions:

  1. First of all, subroutines cannot use any arguments.
  2. A subroutine cannot call another subroutine.
  3. Maximum number of subroutines: 8 for the RCX
  4. If calling from multiple tasks: no local variables or perform calculations that require temporary variables (this restriction is lifted for the Scout and RCX2).

Control structures

  • If-statements if ( condition ) consequence if ( condition ) consequence else alternative
  • While-statements while ( condition ) body
  • Repeat-statements repeat ( expression ) body
  • Switch-statement switch ( expression ) body
  • Until-macro

    define until (c) while (! (c ))

Inline function, call by reference void turn_around(int turntime) { OnRev(OUT_C); Wait(turntime); OnFwd(OUT_A+OUT_C); } task main() { OnFwd(OUT_A+OUT_C); Wait(100); turn_around(200); Wait(200); turn_around(50); Wait(100); turn_around(300); Off(OUT_A+OUT_C); } task main() { int count=0; while (count<=5) { PlaySound(SOUND_CLICK) ; Wait(count*20); increment(count); } } void increment(int& n) { n++; }