NXC - PowerPoint PPT Presentation

1 / 25
About This Presentation
Title:

NXC

Description:

NBC (p. 168ff) NeXT Byte Codes ... The two files 'nbc' and 'nxtcom' have to have their permissions set to 'Execute' In Terminal ... – PowerPoint PPT presentation

Number of Views:185
Avg rating:3.0/5.0
Slides: 26
Provided by: harryh1
Category:
Tags: nxc | nbc

less

Transcript and Presenter's Notes

Title: NXC


1
NXC
  • Computer Programming through Robotics
  • LING 682
  • Spring 2008

2
Course organization
  • Course home page (http//www.tulane.edu/ling/LING
    682/)
  • Lab (Newcomb 442) will be open for practice with
    3-4 Macs and all robots, but you can bring your
    own laptop
  • MWF 11-12 or TR 1-3
  • Ive graded P2
  • We will skip a project this week

3
NBC, NXTCOM NXC
  • Hansen

4
NBC(p. 168ff)
  • NeXT Byte Codes
  • A compiler that translates a source program in
    NXC into NXT byte codes (.rxe) to be executed by
    the firmware on the NXT
  • It consists of a language like assembly and an
    API (application programming interface)
  • 8 reviews the language, but we will concentrate
    on NXC, which is easier to use

5
NXTCOM
  • The program that downloads the code compiled by
    NBC (a file ending in .rxe) to the NXT brick.
  • It is much faster than the NXT-G program.

6
Macintosh tips
  • The two files 'nbc' and 'nxtcom' have to have
    their permissions set to 'Execute'
  • In Terminal
  • chmod x FilePathToNBC
  • chmod x FilePathToNBTCOM
  • I never did get the AppleScripts to work
  • It is easier to run them from the Terminal

7
A basic program(p. 148)
  • A program must always have at least one task
  • task name()
  • // the task's code is placed here
  • If there is no obvious one, use main, as in our
    test program (next slide)

8
NXC test program
  • task main()
  • TextOut(0, LCD_LINE1, Hello World)
  • Wait(10000)

9
NBC finds mistakes
  • NBC will find some typos
  • As an example, in the test program,
  • change LCD_LINE1 LCD_LIN1
  • leave off the semicolon after Wait(10000)
  • Compile and see what happens.

10
Outputs
  • Hansen pp. 153-4 (7)
  • 236ff (10)
  • 407ff (Appendix A)

11
Motor port outputs
  • Each motor port has an output constant
  • OUT_A
  • OUT_B
  • OUT_C
  • They can be combined to run together
  • OUT_AB
  • OUT_AC
  • OUT_BC
  • OUT_ABC

12
Normal motor control
  • OnFwd(ports, power) - forward
  • OnRev(ports, power) - reverse
  • Coast(ports) - turn off and coast
  • also called Float
  • Off(ports) - turn off and brake
  • reset Block Tacho, but not Rotation counters

13
Challenge
  • SPOT, move forward for 5 seconds at 75 power,
    then do the same in reverse, and then stop.

14
movenorm.nxc
  • task main()
  • OnFwd(OUT_AC, 75) // move forward at 75
  • Wait(5000) // wait 5 secs
  • OnRev(OUT_AC, 75) // move backwards at 75
  • Wait(5000) // wait 5 secs
  • Off(OUT_AC) // stop

15
Regulated motor control
  • The firmware can automatically adjust the power
    level if it is not being achieved due to friction
    or some other external influence (like trying to
    slow one wheel with your fingers)
  • OnFwdReg(ports, power, regmode)
  • OnRevReg(ports, power, regmode)
  • regmode
  • OUT_REGMODE_SPEED turns on regulation
  • OUT_REGMODE_IDLE turns off regulation
  • same as OnFwd/OnRev

16
Challenge
  • SPOT, move forward for 5 seconds at 40 regulated
    power, then do the same in reverse, and coast to
    a stop.
  • While SPOT is moving, slow him down with your
    hand and see if motors try to speed up

17
movereg.nxc
  • task main()
  • OnFwdReg(OUT_AC, 40, OUT_REGMODE_SPEED)
  • Wait(5000) // wait 5 secs
  • OnRevReg (OUT_AC, 40, OUT_REGMODE_SPEED)
  • Wait(5000) // wait 5 secs
  • Coast(OUT_AC) // roll to a stop

18
Synchronized motor control
  • The firmware can automatically adjust the power
    level to keep two motors running at the same
    speed
  • OnFwdSync(ports, power, turnpct)
  • OnRevSync(ports, power, turnpct)
  • turnpct
  • the percentage that the motors turn to one side
    or the either, -100 or 100

19
Challenge
  • SPOT, move forward for 5 seconds at 40
    synchronized power, then do the same in reverse
    but turning to the right, and then coast to a
    stop.

20
movesync.nxc
  • task main()
  • OnFwdSync(OUT_AC, 40, 0)
  • Wait(5000) // wait 5 secs
  • OnRevSync(OUT_AC, 40, 50)
  • Wait(5000) // wait 5 secs
  • Coast(OUT_AC) // roll to a stop

21
Tachometer motor control
  • The rotation sensors built into the motors tell
    the firmware how fast and how far the motors have
    turned, information which can be used to control
    them.
  • RotateMotor(ports, power, angle)
  • angle
  • in degrees, positive or negative

22
Challenge
  • SPOT, move forward at 40 power for two
    rotations, then do the same in reverse, and coast
    to a stop.

23
moverot.nxc
  • task main()
  • RotateMotor(OUT_AC, 40, 720)
  • // the rotations take the place of waiting
  • RotateMotor(OUT_AC, 40, -720)
  • Coast(OUT_AC)

24
P2
  • MIN 5
  • MAX 9
  • AVG 7.6

25
Next time
  • Variables and simple arithmetic
  • Motor programs that report to the LCD screen
Write a Comment
User Comments (0)
About PowerShow.com