1 / 46

Java and LEGO Robots

Java and LEGO Robots. 齐琨 (Kun Qi) GC Senior Sales Consultant kun.qi@oracle.com. 拥有一个机器人是每个孩子的梦想. 梦想可以成真. Program Agenda. LEGO( 乐高 ) NXT leJOS Java 控制 NXT 机器人 演示. Lego NXT 是什么?. 可编程组合机器人玩具. 硬件 ARM7(32 位 ) AT91SAM7S256(48Mhz) 256K 的闪存, 64K 的内存 蓝牙、 USB2.0 4 个输入、 3 个输出 64*100 像素单色 LCD

ethel
Download Presentation

Java and LEGO Robots

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Java and LEGO Robots 齐琨(Kun Qi)GC Senior Sales Consultant kun.qi@oracle.com

  2. 拥有一个机器人是每个孩子的梦想

  3. 梦想可以成真

  4. Program Agenda • LEGO(乐高) NXT • leJOS • Java控制NXT机器人 • 演示

  5. Lego NXT是什么? 可编程组合机器人玩具 • 硬件 • ARM7(32位) AT91SAM7S256(48Mhz) • 256K的闪存,64K的内存 • 蓝牙、USB2.0 • 4个输入、3个输出 • 64*100像素单色LCD • 编程 • NXT-G/LeJOS/NXC/RobotC/…

  6. LEGO设计工具 LEGO Digital Designer

  7. LEGO编程语言 NXT-G

  8. To fill a shape with an image. Use existing picture box, DO NOT delete and create new picture box. Right click on the shape. At the bottom of the submenu select “Format Shape” Select “Fill” at the top of the “Format Shape” dialog box. Select “Picture or Texture fill” from the options. And select “File” under the “Insert from” option. Navigate to the file you want to use and select “Insert” On the “Format” tab, in the Size group, click on “Crop to Fill” in the Crop tool and drag the image bounding box to the desired size DELETE THIS INSTRUCTION NOTE WHEN NOT IN USE

  9. leJOS: 运行在LEGO上的Java 操作系统 http://lejos.sourceforge.net • 是一个微型的Java VM,替代LEGO操作系统 • 最早来源于TinyVM项目,一个基于Java的用于Lego Mindstorm RCX固件 • 2000年移到到leJOS项目 • 使用C和ARM的汇编指令编写 • 一次只能运行一个Java程序 • leJOS包括两个项目 • leJOS NXJ • leJOS RCX

  10. leJOS NXJ LEGO NXT的Java环境 • JavaVM的NXT固件,替换原有NXT的LEGO固件 • Java 类库,classes.jar • 实现NXJ API • 提供替代的JavaRuntime (java.*) • 工具 • 链接工具,链接java类和classes.jar为二进制文件格式,上传至NXT运行 • PC工具,烧录固件到NXT中,上传程序,调试工具等功能 • PC API,开发与NXJ通讯的程序,在蓝牙和USB连接上使用Java Stream,或使用LCP(LEGO通讯协议)

  11. 为什么要用leJOS? • 使用行业标准的Java语言 • 支持面向对象编程 • 开源项目,有很多贡献者 • 使用专业的IDE,Eclipse/Netbean • 跨平台支持,Windows/Linux/Mac • 比NXT-G更快(主要指开发效率) • 全面支持蓝牙、USB、 I²C和RS485协议 • 提供精确的马达控制 • 支持Java 7语言特性

  12. 为什么要用leJOS? • 支持高级导航设备 • 支持蒙特卡罗定位 • 支持卡尔曼滤波 • 提供行为类来支持复杂机器人行为 • 支持大量第三方传感器 • 支持通过蓝牙或USB的远程事件记录 • 支持PC远程控制和跟踪NXJ程序 • 提供了浮点运算等数学运算函数

  13. 为什么要用leJOS? • 支持java.io访问flash文件系统 • 支持多线程 • 支持监听和事件 • 支持gc安全内存管理 • 支持8位WAV文件播放 • 提供了大量的样例 • 支持NXT到NXT的通讯 • 支持GPS设备 • ……

  14. To fill a shape with an image. Use existing picture box, DO NOT delete and create new picture box. Right click on the shape. At the bottom of the submenu select “Format Shape” Select “Fill” at the top of the “Format Shape” dialog box. Select “Picture or Texture fill” from the options. And select “File” under the “Insert from” option. Navigate to the file you want to use and select “Insert” On the “Format” tab, in the Size group, click on “Crop to Fill” in the Crop tool and drag the image bounding box to the desired size DELETE THIS INSTRUCTION NOTE WHEN NOT IN USE 准备leJOS环境

  15. 环境准备—Windows 获取介质 • JDK 5/6/7 • 要使用32bit的 • http://www.oracle.com/technetwork/java/javase/downloads/ • USB驱动 • 最新的Fantom Driver 1.1.3 • http://mindstorms.lego.com/en-us/support/files/Driver.aspx • Win7专业版+(或setup.ini->AllowWindowsStarter=1) • 蓝牙模块(可选) • 蓝牙设备及驱动

  16. leJOS NXJ软件 • 0.9.1 beta版 • http://lejos.sourceforge.net/nxj-downloads.php • leJOS_NXJ_0.9.1beta-3_win32_setup.exe (21.9 MB) • IDE • Eclipse/Netbean • 必须使用32bit

  17. 安装leJOS 安装步骤

  18. 建立NXT的Java运行环境 写入leJOS到LEGO NXT • NXT刷固件,将NXJ固件使用leJOS的Flash工具写入到NXT中 • 如果刷机失败,可以从LEGO官网中找到固件刷回,NXT不会变砖 • 环境变量 • NXJ_HOME • LEJOS_NXT_JAVA_HOME • PATH=%NXJ%\bin;%PATH%

  19. 选择IDE,连接你的NXT 以Eclipse为例 • 安装新软件 • lejos - http://lejos.sourceforge.net/tools/eclipse/plugin/nxj/

  20. 第一个程序 Hello,World • 与新建类的方式相同 • 屏幕输出的两种方式 • LCD类 • System.out.println

  21. 编译和上传程序 Eclipse方式 • 运行->LeJOS NXT Program • 插件完成Link、上传和运行的工作

  22. 编译和上传程序 手工方式 • nxjc.bat,使用javac编译源码,生成class文件 • nxjc HelloWorld.java • nxjlink.bat,生成LE格式的nxj文件 • nxjlink –o HelloWorld.nxj HelloWorld • nxjupload.bat,上传nxj文件到NXT,执行程序 (–r参数) • nxjupload –r HelloWorld.nxj • nxj.bat,集成link和上传功能 • nxj –r –o HelloWorld.nxj HelloWorld

  23. leJOS的按键

  24. leJOS的菜单

  25. To fill a shape with an image. Use existing picture box, DO NOT delete and create new picture box. Right click on the shape. At the bottom of the submenu select “Format Shape” Select “Fill” at the top of the “Format Shape” dialog box. Select “Picture or Texture fill” from the options. And select “File” under the “Insert from” option. Navigate to the file you want to use and select “Insert” On the “Format” tab, in the Size group, click on “Crop to Fill” in the Crop tool and drag the image bounding box to the desired size DELETE THIS INSTRUCTION NOTE WHEN NOT IN USE 控制轮式小车

  26. 控制伺服电机 Motor类 • Motor类是对NXT马达的抽象 • 马达需要连接A/D端口 • A端口 • B端口 • C端口

  27. 轮式小车 DifferentialPilot类 • 控制两轮驱动的小车高层类,每个轮子都有自己的马达 • 两个轮子的连接端口 • 轮子的直径 • 两个轮子间的距离

  28. To fill a shape with an image. Use existing picture box, DO NOT delete and create new picture box. Right click on the shape. At the bottom of the submenu select “Format Shape” Select “Fill” at the top of the “Format Shape” dialog box. Select “Picture or Texture fill” from the options. And select “File” under the “Insert from” option. Navigate to the file you want to use and select “Insert” On the “Format” tab, in the Size group, click on “Crop to Fill” in the Crop tool and drag the image bounding box to the desired size DELETE THIS INSTRUCTION NOTE WHEN NOT IN USE 演示—两轮小车运行

  29. I/O和传感器 LCD、按键、声音、电池、光线传感器、声音传感器

  30. I/O LCD和按键 • LCD,显示8行16列,图片模式,100×64像素 • LCD.drawString(String str, int x, int y) • LCD.drawInt(int i, int x, int y) • LCD.drawInt(int i, int places, int x, int y) • LCD.clear() • 按键实例 • Button.ENTER(1) • Button.LEFT(2) • Button.RIGHT(4) • Button.ESCAPE(8) • Button.isDown()

  31. I/O 声音和电池 • 播放声音lejos.nxj.Sound • playTone(int aFrequency, int aDuration),播放音频 • systemSound (boolean aQueued, int aCode),播放系统声音 • playSample(File aWAVfile),播放8bit的wav文件 • 电池lejos.nxj.Battery • getVoltage(),获取电压

  32. 传感器 光线传感器和声音传感器 • NXT提供了四个传感器,光线传感器、声音传感器、超声传感器和触碰传感器 • 光线传感器,需要指定端口LightSensor(SensorPort port) • 声音传感器,接收不同的频率响应SoundSensor(SensorPort.S1)

  33. 物体探测 超声传感器和触碰传感器 • 机器人探测路上的对象,做出特定行为 <<interface>> FeatureDetector FeatureDetectorAdapter RangeFeatureDetectector TouchFeatureDetectector

  34. 物体探测 超声传感器 • 自动检测和数据报告 • 通过监听器接口分离“活动—响应”代码 • 一个代码段响应多个传感器

  35. 物体探测 超声传感器和触碰传感器组合

  36. NXJ支持的第三方硬件

  37. To fill a shape with an image. Use existing picture box, DO NOT delete and create new picture box. Right click on the shape. At the bottom of the submenu select “Format Shape” Select “Fill” at the top of the “Format Shape” dialog box. Select “Picture or Texture fill” from the options. And select “File” under the “Insert from” option. Navigate to the file you want to use and select “Insert” On the “Format” tab, in the Size group, click on “Crop to Fill” in the Crop tool and drag the image bounding box to the desired size DELETE THIS INSTRUCTION NOTE WHEN NOT IN USE 演示—物体探测和声音播放

  38. 线程 • leJOS在下面的情况下会单独开线程 • 如果监听在使用,那么按钮和传感器端口会开始一个监听线程 • 每个电机都会开始一个调节器线程 • 蓝牙类会开始一个可以与分开的蓝牙芯片对话的线程 • 每个定时器会打开一个定时器线程

  39. 监听 • leJOS实现了监听器线程来侦听特定事件 • 按键侦听 • 传感器端口侦听 • 按键侦听,无论程序在做什么,发生按键事件时都会被检测到 • 特定按键的侦听,需要注册单独的事件 addButtonListener

  40. 错误处理和调试 • 异常 • 支持绝大多数的Java标准异常 • 也可以自定义 • 数据终止 • NXJ崩溃,屏幕会显示指针和错误信息 • 有问题的nxj文件 • 远程调试 • PC使用Rconsole,USB或蓝牙 • RConsole.println()

  41. 几个工具 • NXJ File Browser,查看和操作NXJ上的文件 • NXJ FlashG • NXJ Monitor,监控线程运行情况

  42. To fill a shape with an image. Use existing picture box, DO NOT delete and create new picture box. Right click on the shape. At the bottom of the submenu select “Format Shape” Select “Fill” at the top of the “Format Shape” dialog box. Select “Picture or Texture fill” from the options. And select “File” under the “Insert from” option. Navigate to the file you want to use and select “Insert” On the “Format” tab, in the Size group, click on “Crop to Fill” in the Crop tool and drag the image bounding box to the desired size DELETE THIS INSTRUCTION NOTE WHEN NOT IN USE leJOS和Android

  43. leJOS和Android • 下载Android SDK • http://developer.android.com/sdk/index.html • 安装Eclipse插件 • http://developer.android.com/sdk/eclipse-adt.html • 配置LeJOS-Droid工程,确保pccomms.jar在build path中 • 样例工程 • TachoCount,获取电机转数 • BTSend,蓝牙发送 • RCNavigationControl,蓝牙控制小车行动

  44. To fill a shape with an image. Use existing picture box, DO NOT delete and create new picture box. Right click on the shape. At the bottom of the submenu select “Format Shape” Select “Fill” at the top of the “Format Shape” dialog box. Select “Picture or Texture fill” from the options. And select “File” under the “Insert from” option. Navigate to the file you want to use and select “Insert” On the “Format” tab, in the Size group, click on “Crop to Fill” in the Crop tool and drag the image bounding box to the desired size DELETE THIS INSTRUCTION NOTE WHEN NOT IN USE 演示—两轮驱动小车

  45. Graphic Section Divider

More Related