210 likes | 411 Views
Interfacing the LEGO RCX to the outside world. John M. Larkin Whitworth College Spokane, WA. Outline. Electronics at Whitworth Motivation for the Robotics Project Description of the Robotics Project Conclusions. Who takes electronics at Whitworth?.
E N D
Interfacing the LEGO RCX to the outside world John M. Larkin Whitworth College Spokane, WA
Outline • Electronics at Whitworth • Motivation for the Robotics Project • Description of the Robotics Project • Conclusions
Who takes electronics at Whitworth? • Electronics is a required course for physics majors (both B.A. and B.S.) and computer science majors (only B.S.) • It is offered each spring • typically taken by physics majors as sophomores • typically taken by CS majors as juniors or seniors • Average enrollment is 16-20 students
Structure of the electronics course • Content • emphasis on analog electronics for scientific instrumentation applications • brief introduction to digital electronics • Format • two 55-minute lectures per week • two 3-hour labs per week
Structure of the electronics labs • 16 sessions working on guided labs • DC and AC circuits • RC and RLC circuits • diodes and DC power supplies • transistors (simple amplifier and follower) • op-amps • light detection (photodiodes & phototransistors) • sound filtering with CD player source • 10 sessions working on robotics project • Presentation of project to campus-wide audience
Motivation for the robotics project • We want students to • collaborate with a student from a different department • leave the course enthusiastic about electronics • integrate and apply knowledge from throughout the course • leave the course confident that they can design analog circuits
Project Description • General project requirements • construct 2 custom transducers that can interface with the LEGO RCX • use those transducers, the RCX, plus other materials to do something interesting • Students are required to submit a project proposal before project work days begin • feedback on appropriate level of difficulty • lead time to order specialized components
What is the RCX? • Developed in a collaboration between MIT’s Media Lab and LEGO • RCX details • 16 MHz CPU • 32 kB RAM • 3 motor outputs • 3 sensor inputs • IR port
Overview of sensor inputs • LEGO packages RCX with basic light and touch sensors as part of kit for schools • Sensor inputs have a 10 bit A/D converter • Sensor modes (software selected) • passive • active
Passive sensor mode • Measures resistance with internal 10 kW resistor as part of voltage divider • A/D conversion passes a value to software given by
Active sensor mode • RCX alternates “input” between two states when put into active mode • For 3 ms, sensor “input” is actually an output providing approximately 8 V to power the sensor circuit • For 0.1 ms, an A/D converter captures the voltage generated by the sensor • 0 V → 0 • 5 V → 1023
Overview of outputs • RCX outputs designed to power DC motors • Output provides 8 V • Pulse width modulation varies motor speed • Eight “power levels” can be software selected • power level 7 = continuous output • power level 6 = on for 7 ms, off for 1 ms • power level 0 = on for 1 ms, off for 7 ms
Programming the RCX with leJOS • leJOS is a version of Java for the RCX • Why leJOS? • many of our CS majors have previously used the RCX and leJOS in an artificial intelligence class • freeware so students can install on their own computers for development outside of the lab • more traditional programming language than the LEGO graphical programming system
Sample motor control code import josx.platform.rcx.*; public class GoAndTurn { public static void main (String[] aArg) throws Exception { Motor.A.setPower(2); Motor.C.setPower(2); Motor.A.forward(); Motor.C.forward(); Thread.sleep(3000); Motor.C.backward(); Thread.sleep(1000); Motor.C.stop(); Motor.A.stop(); } }
Sample sensor interface code import josx.platform.rcx.*; public class ReadAndRespond { public static void main (String[] aArg) throws Exception { Sensor.S1.setTypeAndMode(SENSOR_TYPE_RAW, SENSOR_MODE_RAW); Sensor.S1.activate(); int x = Sensor.S1.readRawValue(); if (x > 512) Sound.twoBeeps(); } }
What are the challenges? • First portion of course must be fast paced so students have background for project • Must help 8-10 teams working on different projects • Transition from highly structured labs to open-ended project is too abrupt for some students
What are the rewards? • Students enjoy the project and are proud of their work • Students discover that they really learned something • Faculty discover that the students really learned something • Presentation day is good PR for physics on campus
Resources • Web sites • leJOS homepage • http://lejos.sourceforge.net • Enthusiastic hobbyists • http://www.plazaearth.com/usr/gasperi/lego.htm • http://www.philohome.com/
Resources • Books • Programming LEGO Mindstorms with Java by Giulio Ferrari, et al • Core LEGO Mindstorms Programming by Brian Bagnall • LEGO Mindstorms Interfacing by Don Wilcher