Top Banner
Interfacing the LEGO RCX to the outside world John M. Larkin Whitworth College Spokane, WA
21

Interfacing the LEGO RCX to the outside world John M. Larkin Whitworth College Spokane, WA.

Dec 27, 2015

Download

Documents

Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Interfacing the LEGO RCX to the outside world John M. Larkin Whitworth College Spokane, WA.

Interfacing the LEGO RCX to the outside world

John M. LarkinWhitworth CollegeSpokane, WA

Page 2: 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

Page 3: Interfacing the LEGO RCX to the outside world John M. Larkin Whitworth College Spokane, WA.

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

Page 4: Interfacing the LEGO RCX to the outside world John M. Larkin Whitworth College Spokane, WA.

Structure of the electronics course

Contentemphasis on analog electronics for scientific

instrumentation applicationsbrief introduction to digital electronics

Format two 55-minute lectures per week two 3-hour labs per week

Page 5: Interfacing the LEGO RCX to the outside world John M. Larkin Whitworth College Spokane, WA.

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

Page 6: Interfacing the LEGO RCX to the outside world John M. Larkin Whitworth College Spokane, WA.

Motivation for the robotics project

We want students tocollaborate 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

Page 7: Interfacing the LEGO RCX to the outside world John M. Larkin Whitworth College Spokane, WA.

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

Page 8: Interfacing the LEGO RCX to the outside world John M. Larkin Whitworth College Spokane, WA.

What is the RCX? Developed in a collaboration between

MIT’s Media Lab and LEGO RCX details

16 MHz CPU32 kB RAM3 motor outputs3 sensor inputs IR port

Page 9: Interfacing the LEGO RCX to the outside world John M. Larkin Whitworth College Spokane, WA.

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)

passiveactive

Page 10: Interfacing the LEGO RCX to the outside world John M. Larkin Whitworth College Spokane, WA.

Passive sensor mode

Measures resistance with internal 10 k resistor as part of voltage divider

A/D conversion passes a value to software given by

kΩ 10

1024value

R

R

Page 11: Interfacing the LEGO RCX to the outside world John M. Larkin Whitworth College Spokane, WA.

Active sensor mode RCX alternates “input” between two states

when put into active modeFor 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

Page 12: Interfacing the LEGO RCX to the outside world John M. Larkin Whitworth College Spokane, WA.

Useful active sensor interface circuit

Page 13: Interfacing the LEGO RCX to the outside world John M. Larkin Whitworth College Spokane, WA.

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

Page 14: Interfacing the LEGO RCX to the outside world John M. Larkin Whitworth College Spokane, WA.

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

Page 15: Interfacing the LEGO RCX to the outside world John M. Larkin Whitworth College Spokane, WA.

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(); }}

Page 16: Interfacing the LEGO RCX to the outside world John M. Larkin Whitworth College Spokane, WA.

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(); }}

Page 17: Interfacing the LEGO RCX to the outside world John M. Larkin Whitworth College Spokane, WA.

Example: a loudest-sound-seeking robot

Page 18: Interfacing the LEGO RCX to the outside world John M. Larkin Whitworth College Spokane, WA.

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

Page 19: Interfacing the LEGO RCX to the outside world John M. Larkin Whitworth College Spokane, WA.

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

Page 20: Interfacing the LEGO RCX to the outside world John M. Larkin Whitworth College Spokane, WA.

Resources

Web sites leJOS homepage

http://lejos.sourceforge.net

Enthusiastic hobbyists http://www.plazaearth.com/usr/gasperi/lego.htm http://www.philohome.com/

Page 21: Interfacing the LEGO RCX to the outside world John M. Larkin Whitworth College Spokane, WA.

Resources

BooksProgramming LEGO Mindstorms with Java by

Giulio Ferrari, et alCore LEGO Mindstorms Programming by

Brian BagnallLEGO Mindstorms Interfacing by Don Wilcher