?????? NXC?NXT - PowerPoint PPT Presentation

1 / 70
About This Presentation
Title:

?????? NXC?NXT

Description:

NXC NXT task main() { // OnFwdReg(OUT_B, 40, OUT_REGMODE_IDLE); // OnFwdReg(OUT_C, 40, OUT_REGMODE_SPEED ... – PowerPoint PPT presentation

Number of Views:108
Avg rating:3.0/5.0
Slides: 71
Provided by: mac165
Category:
Tags: nxc | nxt | lego

less

Transcript and Presenter's Notes

Title: ?????? NXC?NXT


1
???
  • ?????? NXC?NXT

2
??????
  1. NXC-??LEGO?????C??
  2. BricxCC-?????????
  3. ???????
  4. ????
  5. ???
  6. ??
  7. ??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

4
CAVE????
  • 2009?? ?????? NXC?NXT, ?? C?????LEGO NXT?????
  • 2008??CAVE ????? ??????, ???????????. ??C, Java,
    LabVIEW?????.
  • 20002007 ????? ???????

5
CAVE????
  • ???? 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
  • ??????

8
LEGO MindStorms NXT
9
  • NXT?RCX??

NXT
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 ?????
10
Mindstorms (NXT-G)
11
Robolab
12
RobotC
13
NXJ (Java)
14
LabVIEW
15
NXC?NXT-G??
NXT-G
NXC
???(BrixCC) 12??? ???? http//bricxcc.sourceforg
e.net/ ? ????? ?? ????
???? ???? ???? ??????? ???? ??? ??
??? 8??? ?????   ? ?? ?? ????
16
Programming interface
  • Graphical
  • Text based
  • NXT-G
  • MicroSoft
  • Robotic Developer Studio
  • National Instruments
  • LabVIEW NXT toolkit
  • NXC
  • RobotC
  • Java
  • Others PbLua, php

17
Brief comparison
LabVIEW
MSRDS
??
Java
NXC
NXT-G
????
18
NXC
  • Not eXactly C by John C. Hansen.
  • Bricx Command Center (FREE!)
  • C-based language
  • Highly integrated with 3rd party I/O devices.

19
  • NXT????

USB ???
???(??)
  • ??
  • USB
  • ??
  • ??????
  • ??

??
??/??
???
??
??/??
???(???)
20
Bricx Command Center
21
Important settings and interfaces
  • Preferences
  • compiler, font, code completion.
  • Direct control
  • Watching the brick
  • Brick Joystick
  • NXT Explorer
  • NXT Screen

22
First Robot
http//ldd.lego.com/
23
First 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

25
Macro
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)
26
Repeat 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)
27
Nested 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)

28
Control Structure and Variable
29
Variable
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)
30
  • while

01- 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)
31
  • do while

01- 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)
32
SENSORS
33
Touch sensor
  • ?? SetSensorTouch(S1)

33
34
01- 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)
35
Sound sensor
  • ?? SetSensorSound(S2)

35
36
01- 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
37
Ultrasonic sensor
  • ??SetSensorLowspeed(S4)

37
38
01- 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
39
Rotation 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?
40
Light sensor
  • ??SetSensorLight(S3)

40
41
01- 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
  • Macro

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

45
  • ??? ???

01- 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??????????,????????????????????????????
46
  • ?????(unregulated)

OnFwd() OnRev()
47
  • ????(regulation)

OnFwdReg(???,??,????) OnRevReg (???,??,????)
48
  • ???????

OUT_REGMODE_IDLE OUT_REGMODE_SPEED OUT_REGMODE_S
YNC
49
  • ??????(speed regulation)

OnFwdReg(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))
50
  • ????(synchronized)

OnFwdReg(OUT_AC, 40, OUT_REGMODE_SYNC)
51
??????
  • task main()
  • // OnFwdReg(OUT_B, 40, OUT_REGMODE_IDLE)
  • // OnFwdReg(OUT_C, 40, OUT_REGMODE_SPEED)
  • OnFwdReg(OUT_BC, 40, OUT_REGMODE_SYNC)
  • while(true)
  • NumOut(10, LCD_LINE1,
    MotorActualSpeed(OUT_B))
  • NumOut(10, LCD_LINE2,
    MotorActualSpeed(OUT_C))

52
  • ????IDLE?SPEED?SYNC

01- 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)
53
  • ??????????

OnFwdSync() OnRevSync()
OnFwdSync()?OnRevSync()???????? OnFwdSync(???,
??,?????)
0 ?? 50 ??????? 100 ???????????
54
01- 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)
55
  • ?????(tachometer-limited)

RotateMotor(???,??,??)
56
01- 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????????
57
  • ????-RotateMotorEx()

RotateMotorEx(???,??,????,?????,????,????) Rotat
eMotorEx(OUT_AC, 75, 180, 0, true, true)
58
??????
  • task main()
  • SetSensorLight(S3)
  • OnFwd(OUT_BC, 40)
  • while(true)
  • ClearScreen()
  • NumOut(60,20,Sensor(S3))
  • if (Sensor(S3)lt20)
  • Off(OUT_BC)

59
??????
  • task main()
  • SetSensorLight(S3)
  • OnFwd(OUT_BC, 40)
  • while(true)
  • ClearScreen()
  • NumOut(60,20,Sensor(S3))
  • if (Sensor(S3)lt20)
  • OnRev(OUT_BC, 40)
  • Wait(500)
  • OnFwd(OUT_BC, 40)
  • // Off(OUT_BC)

60
??????????
  • define edge 35
  • sub MoveFwd(int pwr)
  • OnFwd(OUT_AC, pwr)
  • Wait(200)
  • sub MoveBack(int pwr)
  • OnRev(OUT_AC, pwr)
  • Wait(1500)
  • sub MoveL(int pwr)
  • OnFwd(OUT_A, pwr)
  • Off(OUT_C)
  • Wait(1000)
  • sub MoveR(int pwr)
  • OnFwd(OUT_C, pwr)
  • Off(OUT_A)
  • Wait(100)

61
????
  • define dist 20
  • task main()
  • SetSensorLowspeed(S4)
  • int a
  • OnFwd(OUT_BC, 40)
  • while(true)
  • ClearScreen()
  • NumOut(60,20,SensorUS(S4))
  • aSensorUS(S4)
  • if (altdist)
  • OnRev(OUT_BC, 40) //?????
  • Wait(500)
  • else
  • OnFwd(OUT_BC, 40)
  • Wait(500)

62
???
  • define dist 20
  • task main()
  • SetSensorSound(S2)
  • int a
  • // OnFwd(OUT_BC, 40)
  • while(true)
  • ClearScreen()
  • NumOut(60,20,Sensor(S2))
  • aSensor(S2)
  • if (a gt 50)
  • OnFwd(OUT_BC, a)
  • Wait(200)
  • Off(OUT_BC)

63
??????
  • define dist 20
  • sub haha(int pwr, int time)
  • OnFwd(OUT_BC, pwr)
  • Wait(time)
  • task main()
  • SetSensorSound(S2)
  • int a
  • // OnFwd(OUT_BC, 40)
  • while(true)
  • ClearScreen()
  • NumOut(60,20,Sensor(S2))
  • aSensor(S2)
  • if (a gt 50)
  • haha(a, a)

64
???????
  • define near 18
  • define far 25
  • sub MoveFwd(int pwr)
  • OnFwd(OUT_AC, pwr)
  • Wait(200)
  • sub MoveL(int pwr)
  • OnFwd(OUT_A, pwr)
  • Off(OUT_C)
  • Wait(300)
  • sub MoveR(int pwr)
  • OnFwd(OUT_C, pwr)
  • Off(OUT_A)
  • Wait(300)
  • task main()
  • SetSensorLowspeed(S1)

65
????????????
  • define line 35
  • sub MoveFwd(int pwr)
  • OnFwd(OUT_AC, pwr)
  • Wait(100)
  • sub MoveL(int pwr)
  • OnFwd(OUT_A, pwr)
  • Off(OUT_C)
  • Wait(100)
  • task main()
  • SetSensorLight(S1)
  • int a
  • while(true)
  • // ClearScreen()
  • NumOut(60,20,Sensor(S1))
  • aSensor(S1)

66
????by??http//tw.myblog.yahoo.com/lego-caveschoo
l/article?mid1759prev1769next1756
  • define H 60define L 40task main()    
    SetSensorLight(S1)     SetSensorLight(S2)    
    SetSensorTouch(S3)     SetSensorTouch(S4)    
    int S1_N     int S2_N     int S1_Br     int
    S1_Da     int S2_Br     int S2_Da         
    until(Sensor(S3)1)     S1_BrSensor(S1)    
    S2_DaSensor(S2)     until(Sensor(S4)1)    
    S1_DaSensor(S1)     S2_BrSensor(S2)    
          S1_N(S1_BrS1_Da)/2     
    S2_N(S2_BrS2_Da)/2         
    while(true)        if(Sensor(S1)gtS1_N
    Sensor(S2)gtS2_N)           OnRev(OUT_AC,
    L)                else if(Sensor(S1)gtS1_N
    Sensor(S2)ltS2_N)           OnRev(OUT_A,
    H)           //OnRev(OUT_C, L)          
    Off(OUT_C)           Wait(500)       
            else if(Sensor(S1)ltS1_N
    Sensor(S2)gtS2_N)           Off(OUT_A)         
      //OnRev(OUT_A, L)           OnRev(OUT_C,
    H)           Wait(500)               
    else           OnRev(OUT_AC, L)          
    //PlayTone(440, 50)            

67
??????by??http//tw.myblog.yahoo.com/jw!tdWkVrqRE
QGy.hGxtJ3wsdY2/article?mid1798
  • define speed 40define scaleChange 20
  • task main()      SetSensorLight(S1)    
    SetSensorLight(S2)     SetSensorLight(S3)    
         int vL Sensor(S1)     int vM
    Sensor(S2)     int vR Sensor(S3)     int
    scaleL (vLvM)/2     int scaleR
    (vRvM)/2     while(true)          
    if((Sensor(S1)-Sensor(S2))gtscaleChange
    (Sensor(S3)-Sensor(S2))gtscaleChange)
                   vL Sensor(S1)              
    vM Sensor(S2)               vR
    Sensor(S3)               scaleL
    (vLvM)/2               scaleR
    (vRvM)/2                             
    if(vLgtscaleL vRgtscaleR)               
    OnRev(OUT_AC, speed)                    else
    if(vLgtscaleL vRltscaleR)               
    OnRev(OUT_A, speed)              
    Off(OUT_C)               until(Sensor(S2)      
                  else if(vLltscaleL vRgtscaleR)
                   OnRev(OUT_C, speed)            
       Off(OUT_A)               until(Sensor(S2)   
                     else               
    PlayTone(600, 200)               OnRev(OUT_AC,
    speed)              

68
???by??http//tw.myblog.yahoo.com/lego-caveschool
/article?mid1903prev1next1895




69
3rd party sensors
70
??
  • Passion
  • Open mind
  • Hard Work
Write a Comment
User Comments (0)
About PowerShow.com