Title: ?????? NXC?NXT
1???
2??????
- NXC-??LEGO?????C??
- BricxCC-?????????
- ???????
- ????
- ???
- ??
- ??I/O??
3????
- ?????? ??????? ??
- A Study of Developing the Technological Curiosity
Inventory and Its Application to LEGO Hands-on
Learning. - ???? ???? ??
- ?????? ?????? ????????
- ?????????
- Educational Robot tutorial and curriculum design
- Mobile Robot
- Robotarm
4CAVE????
- 2009?? ?????? NXC?NXT, ?? C?????LEGO NXT?????
- 2008??CAVE ????? ??????, ???????????. ??C, Java,
LabVIEW?????. - 20002007 ????? ???????
5CAVE????
- ???? Comprehensive LEGO Silver book LEGO?????
- ???? Darkside of LEGO NXT LabVIEW killer apps.
- ???? Java being leJOS on NXT
- Work on I2C devices
- ????????
6????CAVE
- Blog CAVE LEGO
- Youtube allelujahnissin
- Picasa allelujahnissin
- facebook allelujahnissin
7??????
- ??????????????
- ?????? LEGO NXT
- PC-based robot
- Robotarm
- ??????
8LEGO MindStorms NXT
9NXT
RCX
- ????
- ???
- ???
- ????
- ???
- I/O??
- LCD
- ????
1999 Hitachi H8/3292 ???? 8K ROM
32KRAM ????? 2 wire connector system
3????,3???? 43????? 3??? x 6 RCX 2.0?????
2005 32??ARM7????,8??????? 256 K?????, 64 K
RAM4 K?????, 512 B RAM USB 2.0 (PC NXT),?? 6
wire digital platform. 4????,3???? 64 x
100????????????? 3??? x 6 ?????
10Mindstorms (NXT-G)
11Robolab
12RobotC
13NXJ (Java)
14LabVIEW
15 NXC?NXT-G??
NXT-G
NXC
???(BrixCC) 12??? ???? http//bricxcc.sourceforg
e.net/ ? ????? ?? ????
???? ???? ???? ??????? ???? ??? ??
??? 8??? ????? ? ?? ?? ????
16Programming interface
- NXT-G
- MicroSoft
- Robotic Developer Studio
- National Instruments
- LabVIEW NXT toolkit
- NXC
- RobotC
- Java
- Others PbLua, php
17Brief comparison
LabVIEW
MSRDS
??
Java
NXC
NXT-G
????
18NXC
- Not eXactly C by John C. Hansen.
- Bricx Command Center (FREE!)
- C-based language
- Highly integrated with 3rd party I/O devices.
19USB ???
???(??)
??
??/??
???
??
??/??
???(???)
20Bricx Command Center
21Important settings and interfaces
- Preferences
- compiler, font, code completion.
- Direct control
- Watching the brick
- Brick Joystick
- NXT Explorer
- NXT Screen
22First Robot
http//ldd.lego.com/
23First Program
01- 02- 03- 04- 05- 06- 07- 08- 09- task main() OnFwd(OUT_A, 75) OnFwd(OUT_B, 75) Wait(4000) OnRev(OUT_AB, 75) Wait(4000) Off(OUT_AB)
24- F5 Compile
- F6 Download
- F7 Run
25Macro
01- 02- 03- 04- 05- 06- 07- 08- 09- 10- 11- define MOVE 1000 define TURN 850 task main() OnFwd(OUT_BC,75) Wait(MOVE) OnRev(OUT_BC,75) Wait(TURN) Off(OUT_BC)
26Repeat loop
01- 02- 03- 04- 05- 06- 07- 08- 09- 10- 11- 12- 13- define MOVE 1000 define TURN 850 task main() repeat(5) OnFwd(OUT_BC,75) Wait(MOVE) OnRev(OUT_BC,75) Wait(TURN) Off(OUT_BC)
27Nested loop
01- 02- 03- 04- 05- 06- 07- 08- 09- 10- 11- 12- 13- 14- 15- 16- 17- 18- define MOVE 1000 define TURN 850 task main() repeat(2) PlayTone(440,50) Wait (1000) repeat (5) OnFwd(OUT_BC,75) Wait(MOVE) OnRev(OUT_BC,75) Wait(TURN) Off(OUT_BC)
28Control Structure and Variable
29Variable
01- 02- 03- 04- 05- 06- 07- 08- 09- 10- 11- 12- task main() int a 3 while(a lt 5) OnFwd(OUT_BC,75) Wait(1000) PlayTone(440,50) a Off(OUT_BC)
3001- 02- 03- 04- 05- 06- 07- 08- 09- 10- 11- 12- 13- 14- 15- 16- 17- 18- 19- define MOVE_TIME 500 define TURN_TIME 360 task main() while(true) OnFwd(OUT_AC, 75) Wait(MOVE_TIME) if (Random(2) 0) OnRev(OUT_C, 75) else OnRev(OUT_A, 75) Wait(TURN_TIME)
3101- 02- 03- 04- 05- 06- 07- 08- 09- 10- 11- 12- 13- 14- 15- 16- int move_time, turn_time, total_time task main() total_time 0 do move_time Random(1000) turn_time Random(1000) OnFwd(OUT_AC, 75) Wait(move_time) OnRev(OUT_C, 75) Wait(turn_time) total_time move_time total_time turn_time while (total_time lt 20000) Off(OUT_AC)
32SENSORS
33Touch sensor
33
3401- 02- 03- 04- 05- 06- 07 08- 09- 10- 11- 12- 13- task main() SetSensor(S1,SENSOR_TOUCH) while(true) OnFwd(OUT_AC, 50) until (SENSOR(S1) 1) OnRev(OUT_AC, 50) Wait( 500) OnFwd(OUT_A, 50) Wait(1000)
35Sound sensor
35
3601- 02- 03- 04- 05- 06- 07 08- 09- 10- 11- 12- 13- task main() SetSensor(S1,SENSOR_SOUND) while(true) If (SENSOR(S1) gt90) PlayTone(440, 50) Wait( 500)
36
37Ultrasonic sensor
37
3801- 02- 03- 04- 05- 06- 07- 08- 09- 10- 11- 12- 13- 14- 15- 16- 17- 18- 19- 20- 21- 22- 23- 24- 25- 26- 27- 28- 29- define DISTANCE 15 //cm task main() SetSensorLowspeed(IN_4) while(true) OnFwd(OUT_AC,20) if(SensorUS(IN_4) lt DISTANCE) Off(OUT_AC) OnRev(OUT_AC,20) Wait(800) Off(OUT_AC) else if(SensorUS(IN_4) DISTANCE) Off(OUT_AC) PlayTone(440,50) Wait(1000) else if(SensorUS(IN_4) gt DISTANCE) Off(OUT_AC) OnFwd(OUT_AC,20) Wait(800) Off(OUT_AC)
38
39Rotation sensor
??RotateMotor(OUT_Port , Speed , Degree)
01- 02- 03- 04- 05- 06- 07- 08- task main() int x RotateMotor(OUT_A, 75, 180) // ??180? x MotorTachoCount(OUT_A) NumOut(20, LCD_LINE3, x) Wait(3000)
Give a try! x 180?
40Light sensor
40
4101- 02- 03- 04- 05- 06- 07 08- 09- 10- 11- 12- 13- task main() SetSensorLight(S3) // SetSensor(S1,SENSOR_LIGHT) while(true) ClearScreen() TextOut(0,20,"Light is") NumOut(60,20,Sensor(S3)) if (Sensor(S3) gt40) PlayTone(440, 50) //beep Wait( 200) //0.2 sec
41
42??? ???????
- task
- start
- Precedes()
- mutex Acquire() ? Release()
- subroutine
- sub FunctionName (data type varible)
- inline function
- inline int B( ?? )
-
- statements
- return x
-
43????????? define ???????,???????? define
????????????
01- 02- 03- 04- 05- 06- 07- 08- 09- 10- 11- 12- 13- define turning \ OnRev(OUT_B, 75) Wait(3400)OnFwd(OUT_BC, 75) task main() OnFwd(OUT_BC, 75) Wait(1000) turning Wait(2000) turning Wait(1000) turning Off(OUT_BC)
44??? ?????
- NXC????????4??
- 1.unregulated
- 2.speed regulation
- 3.synchronized
- 4.tachometer-limited
4501- 02- 03- 04- 05- 06- 07- 08- 09- 10- task main() OnFwd(OUT_AC, 75) Wait(500) Off(OUT_AC) Wait(1000) OnFwd(OUT_AC, 75) Wait(500) Float(OUT_AC)
Off() Float() Coast()
??Off()?,NXT????????????????????????????Float()??,
NXT??????????,????????????????????????????
46OnFwd() OnRev()
47OnFwdReg(???,??,????) OnRevReg (???,??,????)
48OUT_REGMODE_IDLE OUT_REGMODE_SPEED OUT_REGMODE_S
YNC
49OnFwdReg(OUT_C, 40, OUT_REGMODE_SPEED)
01- 02- 03- 04- 05- 06- 07- 08- 09- 10- task main() OnFwdReg(OUT_A, 40, OUT_REGMODE_IDLE) OnFwdReg(OUT_C, 40, OUT_REGMODE_SPEED) while(true) NumOut(10, LCD_LINE1, MotorActualSpeed(OUT_A)) NumOut(10, LCD_LINE2, MotorActualSpeed(OUT_C))
50OnFwdReg(OUT_AC, 40, OUT_REGMODE_SYNC)
5101- 02- 03- 04- 05- 06- 07- 08- 09- 10- 11- 12- 13- 14- 15- 16- 17- task main() OnFwdReg(OUT_AC,50,OUT_REGMODE_IDLE) Wait(2000) Off(OUT_AC) PlayTone(4000,50) Wait(1000) ResetTachoCount(OUT_AC) OnFwdReg(OUT_AC,50,OUT_REGMODE_SPEED) Wait(2000) Off(OUT_AC) PlayTone(4000,50) Wait(1000) OnFwdReg(OUT_AC,50,OUT_REGMODE_SYNC) Wait(2000) Off(OUT_AC)
52OnFwdSync() OnRevSync()
OnFwdSync()?OnRevSync()???????? OnFwdSync(???,
??,?????)
0 ?? 50 ??????? 100 ???????????
5301- 02- 03- 04- 05- 06- 07- 08- 09- 10- 11- 12- 13- 14- 15- 16- task main() PlayTone(5000,30) OnFwdSync(OUT_AC,50,0) Wait(1000) PlayTone(5000,30) OnFwdSync(OUT_AC,50,50)//?????50 Wait(1000) PlayTone(5000,30) OnFwdSync(OUT_AC,50,-50) //????-50 Wait(1000) PlayTone(5000,30) OnRevSync(OUT_AC,50, -100) //????,????-100 Wait(1000) Off(OUT_AC)
54- ?????(tachometer-limited)
RotateMotor(???,??,??)
5501- 02- 03- 04- 05- 06- 07- 08- task main() RotateMotor(OUT_A, 50,360) //A???????? RotateMotor(OUT_A, 50,-360) //A???????? RotateMotor(OUT_A, -50,-360) //A???????? RotateMotor(OUT_C, 50,-360) //C???????? RotateMotor(OUT_C, -50,360) //C????????
56RotateMotorEx(???,??,????,?????,????,????) Rotat
eMotorEx(OUT_AC, 75, 180, 0, true, true)
573rd party sensors
58??
- Passion
- Open mind
- Hard Work