資訊管理系 -...

52
資訊管理系 樂高掃地機器人設計 組長:BF98904 組員:BF98005 洪宛琪 BF98009 黃瑋婷 BF98014 陳凱惠 BF98043 林品慧 指 導 教 師 :張

Upload: lelien

Post on 03-Apr-2018

237 views

Category:

Documents


4 download

TRANSCRIPT

  • BF98904

    BF98005 BF98009 BF98014 BF98043

  • I

    NXT LEJOS API

  • II

    ........................................................ I

    ....................................................... II

    ..................................................... IV

    ..................................................... VI

    ................................................ 1

    1-1 ........................................... 2

    1-2 ........................................... 2

    .................................. 3

    ............................................ 5

    3-1 ........................................... 5

    3-2 NXT ........................................ 6

    3-3 NXT .................................. 12

    3-4 JCreator ............................ 13

    3-5 JDK .......................................... 14

    3-6 LeJOS NXJ ..................................... 17

    ......................................... 22

    4-1 .......................................... 22

    4-2 ........................................ 23

  • III

    4-3 ............................................ 28

    4-4 ................................ 36

    ........................................... 38

    ..................................... 39

    6-1 .............................................. 39

    6-2 .......................................... 39

    ................................................... 40

    ....................................................... 41

  • IV

    1 .............................................. 6

    2 NXT ............................................... 7

    3 ............................................ 8

    4 .............................................. 8

    5 ............................................ 9

    6 .......................................... 9

    7 ......................................... 10

    8 ........................................... 10

    9 ............................................. 11

    10 ............................................ 15

    11 ........................................ 15

    12 ........................................ 16

    13 ............................................ 20

    14 .......................................... 21

    15 ............................................ 21

    16 ............................................ 22

    17 .............................................. 23

    18 .......................................... 23

  • V

    19 .............................................. 26

    20 .......................................... 26

    21 ...................................... 27

    22 ................................ 29

    23 .................... 29

    24 ...................... 31

    25 90 ........................... 32

    26 45 ........................... 32

    27 30 ......................... 33

    28 ............................................ 34

    29 ............................................ 34

    30 .......................................... 35

    31 .......................................... 35

    32 ...................................... 41

    33 ............................................ 41

  • VI

    1 ............................................ 3

    2 ............................................ 4

    3 NXT ..................................... 7

    4 ........................................... 12

    5 NXT .................................... 25

    7 ........................................... 30

  • 1

    Lego

  • 2

    1-1

    NXT

    1-2

    NXT USB

  • 3

    1

    2

    1

  • 4

    2

  • 5

    3-1

    1984

    RCX LEGO

    LEGO 2006 9

    LEGO Mindstorms NXT

    Mindstorms LEGO

    2009 8

    Lego Mindstorms NXT 2.0 NXTP/N 9841

    150

    LEGO Mindstorms NXT 8547

  • 6

    3-2 NXT

    1

    NXT 1

    Prot1NXT

    Prot2

    Prot3

    Prot4

    Prot5

    Prot6

  • 7

    3-2-1 NXTIntelligent Brick

    2 NXT

    1234ABC

    3 NXT

    1

    2 NXT

    3 NXT

    NXT

    CPU ARM 732AT91SAM7S25648 MHz

    USB2.0

    4 1234

    3 3 ABC

    64100 LCD

    256K bytes & 64K bytes

    6 3AA

    NXTMMJ-12 RJ-12

  • 8

    3-2-2 Touch Sensor

    3 1

    0/

    2

    3

    3-2-3 Light Sensor

    4

    1 2

    4

  • 9

    3-2-4 Sound Sensor

    5

    DB DBA

    5

    3-2-5 Compass Sensor

    6

    1

    0 359NXT 100

    NXT

    6

  • 10

    3-2-6 Ultra Sonic Sensor

    7

    0-255 3

    150

    7

    3-2-7 Color Sensor

    8

    8

  • 11

    3-2-8 Motor with Tacho

    9 NXT

    /

    180 A

    30 5

    NXT

    2

    9

  • 12

    3-3 NXT

    LEGO MINDSTORMS NXT NXT

    USB NXT 44

    4

    Windows Mac

    Intel Pentium

    1GHz 1.5GHz

    600 MHz PowerPC G3G4

    G5

    Windows XP

    SP2Vista

    SP1

    Mac OS X 10.3.9

    10.4 10.5

    512 MB RAM 512 MB RAM

    700 MB 700 MB

    XGA1024768 XGA1024768

    1 USB 1 USB

    CD-ROM CD-ROM

  • 13

    3-4 JCreator

    JCreator JAVA IDE

    Java

    C++

    Java JDK Doc

    JDK

    Help JCreator

    JAVA JCreator Applet

    Html JCreator

    JCreator Windows

    JDK IDE

  • 14

    3-5 JDK

    JDK Java JDK

    JavaJDKSun

    JDKJ2SEJ2EE

    J2ME JDK

    JDK 6.0

    JDK

    Javaccompiler Java

    .java Java.class

    JavainterpreterJava

    Applet viewerapplet Java

    Javadoc Java

    /***/ html

    Jdbdebugger Java

  • 15

    3-5-1

    JDKsystem variable

    JDK 6.0 Path

    Windows XP Path

    1. 10

    10

    2. JAVA_HOME JDK 11

    11

  • 16

    3. Path JDK bin

    javac java 12

    ;

    12

    Java JDK

    http://www.oracle.com/technetwork/java/index.html

    3-5-2 USB

    Microsoft Windows LeJOS NXJ LEGO NXT

    USB driver PCMicrosoft Windows

    USB LEGO NXT

  • 17

    3-6 LeJOS NXJ

    LeJOS NXJ LEGO MINDSTORMS NXT Java

    LeJOS NXJ Java

    LeJOS NXJ WindowsLinux

    Mac OS Android

    5

    LeJOS NXJ

    Java VM

    LeJOS NXJ API Java classes.jar

    java classes classes.jar

    NXT

    PC PC

    USB LeJOS NXJ API LCPLEGO

    Communications Protocol

  • 18

    3-6-1 LeJOS NXJ

    LeJOS NXJ NXT-G NXT

    Java

    object-oriented programming

    open source

    Eclipse Netbeans

    WindowsLinuxMac OS X

    NXT-G

    Behavior classes

    third partysensors

    PC LeJOS NXJ

    J2ME LCD

    multithreading listeners events

  • 19

    garbage collectionsafe

    memory management

    USB USB Java streamsdebugging

    Java streams

    flash file system javaio

    data logginglogs

    8-bit WAV

    PC iCommand

    Web site

    ideas

    TCP/IP sockets

    NXT NXT

    third party RCX Mindsensors

    NRLink

    Lego LEGO

    LeJOS

    menu system iCommand

  • 20

    3-6-2 LeJOS NXJ

    1. c:\test

    2. c:\test

    3. >> cmd Enter

    4. DOS

    cd\ c:\

    cd test c:\test 13

    13

  • 21

    nxjc xxx.java xxx.java xxx.class

    14

    14

    nxj xxx xxx.class JSK LeJOS SDK

    NXT xxx.nxj 15

    15

  • 22

    4-1

    16(a)

    16(b)

    16(a 16(b)

    16

  • 23

    4-2

    USB 17

    18

    3 5

    17

    18(a)

    18(b)

    18(c)

    18

  • 24

    4-2-1

    4mm

    0.7mm

    3mm0.6mm

    356

    1 70%

    90%70%

    2 28

    10100

    3

    2%

    1/3-1/2

  • 25

    4-2-2 NXT

    NXT 6

    I2C RS-485 NXT 5

    7

    5 NXT

    1 ANA +5V/+9V

    2 GND

    3 GND

    4 IPOWERA +4.3V

    5 DIGIAI0 I2CSCLRS-485 A

    6 DIGIAI1 I2CSDARS-485 B

  • 26

    4-2-3

    19

    19

    20 98

    20

  • 27

    21

    1 NXT C pin 3 2 NXT

    C pin 4 3

    NXT C 9 pin 3 pin 4

    21

    + + - -

    6

    5

    4

    3

    2

    1

    NXT

    1

    2

    3

  • 28

    4-3

    HiTechnic

    HiTechnic

    9

    NXT 4-6

    10-15

    NXT 2~3 360

    20

  • 29

    22a

    offset12

    XYX maxY maxX minY min

    2310

    22

    23

  • 30

    4-3-1

    7

    7

    90 202

    90 199

    1090 1.3

    90 349

    90 347

    10120 1.7

    180 170

    360 271

    1075 1

  • 31

    90

    90

    46

    45 11

    0

    304

    270

    198

    180

    NXT

    24

    24

  • 32

    90 180 270 360

    1 -1 48 158 249 323

    2 -1 54 177 270 343

    3 -1 58 180 270 345

    -50

    0

    50

    100

    150

    200

    250

    300

    350

    400

    10145 2

    315 270 225 180 135 90 450(360

    )315 270

    1 1 317 280 218 163 166 71 36 6

    2 1 318 281 226 166 115 70 85 2 320 285

    3 0 316 277 222 162 117 75 37 0 317 278

    0

    50

    100

    150

    200

    250

    300

    350

    10145 2

    4-3-2

    25

    25 90

    26

    26 45

  • 33

    330 300 270 240 210 180 150 120 90 60 30

    0

    (360)

    330 300

    1 0 330 302 278 243 201 163 136 107 76 46 23 0 330 302

    2 0 327 299 276 239 193 160 136 106 82 50 28 358 327 300

    3 0 334 315 293 254 214 180 149 110 74 44 24 359 334 316

    4 0 336 315 291 257 215 108 143 110 69 43 24 0 336 316

    5 0 336 316 294 254 211 180 145 107 72 46 25 0 335 317

    0

    50

    100

    150

    200

    250

    300

    350

    400

    10145 130

    27 30

    27 30

  • 34

    4-3-3

    28

    28

    29

    29

  • 35

    30 NXT 10-15

    30

    31 NXT

    31

  • 36

    4-4

    4-4-1 12

  • 37

    4-4-2

  • 38

    1 450

    2

    NXT 2~3

    ( 360)

    3

    10

    4 10~15

    NXT

    5

  • 39

    6-1

    6-2

  • 40

    1

    http://zh.wikipedia.org/wiki/%E6%A8%82%E9%AB%98Mindstorms_NXT

    2LEGO

    http://www.lego.com/en-us/default.aspx

    3LeJOS Java for Lego Mindstorms

    http://lejos.sourceforge.net/index.php

    4NXT

    http://software.gotop.com.tw/ItemB.aspx?pg=softItem&bn=2011070118&Types=a&Gr

    oup=%E6%95%99%E5%AD%B8%E5%A5%97%E4%BB%B6&ID=1

    5LeJOS NXJ

    http://www.diy-robots.com/resources/LejosNxtTutorial_cn/index.aspx

    6

    http://km.emotors.ncku.edu.tw/emotor/worklog/EMTRC/admin_function/learnweb/pdf/n

    o415_23175.pdf

    7NXT

    http://www.stewartallen.org/2010/08/designing-lego-mindstorms-nxt-sensors/

    8

    http://www.yd-tech.com.tw/product_info.php/products_id/61503

    9NXT

    http://www.hitechnic.com/cgi-bin/commerce.cgi?preadd=action&key=NMC1034

    10

    http://www.robotworld.org.tw/oper/file_download.php?fn=1268126548_1.doc

    11JAVA

    12()

    http://zh.wikipedia.org/wiki/%E6%A8%82%E9%AB%98Mindstorms_NXThttp://www.lego.com/en-us/default.aspxhttp://lejos.sourceforge.net/index.phphttp://software.gotop.com.tw/ItemB.aspx?pg=softItem&bn=2011070118&Types=a&Group=%E6%95%99%E5%AD%B8%E5%A5%97%E4%BB%B6&ID=1http://software.gotop.com.tw/ItemB.aspx?pg=softItem&bn=2011070118&Types=a&Group=%E6%95%99%E5%AD%B8%E5%A5%97%E4%BB%B6&ID=1http://www.diy-robots.com/resources/LejosNxtTutorial_cn/index.aspxhttp://km.emotors.ncku.edu.tw/emotor/worklog/EMTRC/admin_function/learnweb/pdf/no415_23175.pdfhttp://km.emotors.ncku.edu.tw/emotor/worklog/EMTRC/admin_function/learnweb/pdf/no415_23175.pdfhttp://www.stewartallen.org/2010/08/designing-lego-mindstorms-nxt-sensors/http://www.yd-tech.com.tw/product_info.php/products_id/61503http://www.hitechnic.com/cgi-bin/commerce.cgi?preadd=action&key=NMC1034http://www.robotworld.org.tw/oper/file_download.php?fn=1268126548_1.doc

  • 41

    32

    33

  • 42

    import lejos.robotics.navigation.*; import lejos.robotics.*; import lejos.nxt.LCD; import lejos.nxt.Motor; import lejos.nxt.UltrasonicSensor; import lejos.nxt.*; import lejos.nxt.addon.*; import lejos.nxt.Sound; public class SquareTracer3 { static DifferentialPilot pilot ; static SquareTracer3 sq ; static CompassHTSensor cs = new CompassHTSensorSensorPort.S1; static int dir=0; static int start_len=60; public static void main String[] args { int x; int k; sq = new SquareTracer3; sq.cs = new CompassHTSensorSensorPort.S1; Calibratecs; // sq.pilot = new DifferentialPilot4.2f, 14.8f, Motor.A, Motor.B ; sq.pilot.setRotateSpeed30; // sq.pilot.setTravelSpeed8; // 8 x=Button.waitForAnyPress; // Sound.pause1000; cs.resetCartesianZero ; // dir=0; // k=int cs.getDegreesCartesian; // Sound.pause200; LCD.drawIntk, 3, 0, 0; // Motor.C.setSpeed1000; // C Motor.C.forward; int length = start_len ; //cm

  • 43

    int cn=2 ; // 2 whilelength>=0 { sq.walklength,3 ; //, 3 pilot.rotate-90; // 90 dir=dir+90 ; ifdir==360 dir=0 ; cn-- ; // ifcn==0{ // length-=10 ; // 10 cn=1; // length 1 } } } //--------------------------------------------------------------- private static void CalibrateCompassHTSensor cs{ // cs.startCalibration; // Motor.A.setSpeed250; Motor.B.setSpeed250; Motor.A.backward; // Motor.B.forward; // Sound.pause11200; // 5600 Motor.A.stop; Motor.B.stop; cs.stopCalibration; // } //--------------------------------------------------------------- public void walkint len,int sn { int k=0 ; // int x=0 ; // int t=0 ; // int sum; int max=0; int min=0; for int z = 0 ; z < len; z+=sn{

  • 44

    pilot.travelsn; // 3 //--------------------------------------------------------------- max=min=0 ; forint j=0;jdir ifk-dir>180 x=k-dir+360; else x=k-dir; else x=k-dir ; ifx>max max=x; ifx180 x=k+dir+360/2; else x=k+dir/2; else x=k+dir/2; // t=k-x ; // pilot.rotatet; } } }