LEGO Mindstorms NXT SOURCES: Carnegie Mellon Dacta Lego Timothy Friez Miha Štajdohar [email protected] Sensors Sensors and Motors • Four sensor ports – Sonar – Sound – Light – Touch • Three motor ports – Each motor includes rotation counter Touch Sensors • Education kit includes two sensors • Much more robust than old RCX touch sensors Light Sensor • Reports light intensity as percentage • Two modes – Active – Passive • Practical uses – Identify intensity on paper – Identify lit objects in dark room – Detect shadows Sound Sensor • Analogous to light sensor – Reports intensity – Reputed to identify tones • We have little experimented with this • Practical uses – “Clap” to signal robot Ultrasonic (Sonar) Sensor • Reports distances – Range: about 5 cm to 250 cm – In practice: • Longer distances result in more missed “pings” • Mostly reliable – Occasionally gets “stuck” – Moving to a new location helps in receiving a sonar “ping” Using Joysticks • To control your robot using a joystick axis or a button, use these functions • frcRF[port] – gets the value from a joystick axis – [port] – p1_y, p1_x, p1_wheel, … p2_x,…p3_x, etc. • frcOIJoystickButtons[port] – [port] – oiButtonPort1Button1 through oiButtonPort4Button4 Using Loops • A Loop will help a portion of your code execute repeatedly, until told to stop. while(true == true) { motor[port1] = frcRF[p1_y]; motor[port2] = frcRF[p2_y]; } • This code will cause the motors to respond to the joystick values forever. – The loop reads (while true is equal to true) Analog Sensors • Very easy to read analog sensor values – SensorValue[port] – [port] = in1,in2,in3 … in16 while(SensorValue[in1] < 10) { motor[port1] = frcRF[p1_y]; motor[port2] = frcRF[p2_y]; } • This program will run until an analog sensor on port 1 sees a value of less than 10. • Analog sensor values can range from 0 to 1023 Digital Sensors • Digital sensors are a little more complex – First you have to decide if you want the sensor port to be an input or output – frcDigitalIODirection[port] = condition; • port – pio1, pio2, pio3, … pio18 • condition – dirInput or dirOutput – Second you have read or assign the value – frcDigitalIOValue[port] • If an input, this will read the value (either a 1 or 0) • If an output, you can assign the value using a 1 or 0. – frcDigitalIOValue[port] = 1; // turns on the digital output port ROBOTC for IFI – Version 1.14 • New ROBOTC version – Has built in support for: • • • • • encoders, accelerometer, gyro sensor, OI LEDs and more! • Make sure to upgrade! IR Board Review • Rule Clarification from Team Update #3 – 4 Signals Allows – 4 Signals = 4 actions – Signals must repeat when the same button is pressed. Operator Interface LEDs • 11 LEDs installed on Operator Interface – 7 Green – 4 Red • User Controllable with ROBOTC Controlling the LEDs • New ROBOTC function – frcOILEDs[LED] = true or false • Examples – frcOILEDs[oiLEDPWM1_Green] = true; • Turns on PWM1 Green LED – frcOILEDs[oiLEDPWM1_Green] = false; • Turns off PWM1 Green LED
© Copyright 2026 Paperzz