LEGO Mindstorms NXT Laser Guided Shooter
I’ve been busy playing with my LASER Sensors , and have put together a Zamor powered LEGO Mindstorms NXT Laser Guided Shooter. If you would like to build your own, I have included the Model Instructions and NXC Program Code.
For this particular version of my LEGO Mindstorms NXT Laser Guided Shooter, I’ve been trialling an 5mW 780nm Infra-red LASER. Thus far all tests have proved very reliable up to around 2 metres. The biggest issue is the fact you can’t see the LASER Beam with the naked eye, which makes alignment rather tricky. To get around this I’ve been using my old Sony DCR-TRV18E MiniDV Camera’s Night Vision & USB streaming capabilities to see the position of the LASER. This method works very well and is only needed for the initial alignment of the LASER Sensor on the Robot, so the Beam runs parallel with the Robot’s Base.

LDraw Model of the LEGO Mindstorms NXT Laser Guided Shooter
The 780nm Infra-red LASER works on par with the standard Red LASER modules I have been using. I would really like to source some Green or Blue LASER modules that are smaller enough to replace the standard Red modules I currently use. Either the Green or Blue LASER modules should increase the detection range as they are outside the normal ambient light pollution levels you need to over come for greater detection distances above 2 metres.

Assembled LEGO Mindstorms NXT Laser Guided Shooter
My standard Red LASER Sensors are reliable below 2 metres, but above, external light sources can make the detection erratic. The difference between natural, florescent and incandescent light source is like chalk and cheese. I find that florescent lighting, which tends towards the blue end of the visible spectrum gives by far the best results.

You Can also build it as a Ultrasonic Guided Shooter
(If you down have one of my LASER Sensors)
View Laser Guided Shooter NXC Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 |
/* ============================================================================ LEGO Mindstorms NXT <= Laser Guided Shooter => September 2011 www.rjmcnamara.com ============================================================================ */ #define FIRE OUT_ #define TURRET OUT_C #define TURRET_PORT S1 #define TRIGGER_PORT S2 #define LASER_PORT S4 #define TURRET_HOME SENSOR_1 #define TRIGGER SENSOR_2 #define LASER SENSOR_4 #define SCAN_SPEED 75 #define CENTER_TURRET 11.5*360 #define ANGLE MotorRotationCount(TURRET) #define CENTER 2 * 360 // Degrees #define SWEEP 9 * 360 // Degrees #define AMBIENT_MARGIN 0 int target, max; int ambient, level; /* ============================================================================ <= Display Laser Sensor Level => ============================================================================ */ task LaserReading() { while (true) { TextOut(0, LCD_LINE3, "Ambient "); NumOut(50, LCD_LINE3, ambient); TextOut(0, LCD_LINE4, "Reading "); NumOut(50, LCD_LINE4, level); if (level > ambient) // Object Found { RotateMotor(FIRE, 100, 360); PlayFile("TargetFound.rso"); // Audible "Target Found!" while (SoundFlags() != SOUND_FLAGS_IDLE); NumOut(50, LCD_LINE4, level); TextOut(0, LCD_LINE2, "Target Found "); PlayFile("Fireing.rso"); // Audible "Target Found!" while (SoundFlags() != SOUND_FLAGS_IDLE); } else { TextOut(0, LCD_LINE2, "No Target Found "); } Wait(50); } } /* ============================================================================ <= Align Robot's Turret => ============================================================================ */ void align() { while (TURRET_HOME != 1) { OnFwd(TURRET, 100); } RotateMotor(TURRET, -100, CENTER_TURRET); Off(TURRET); while (TRIGGER != 1) { OnFwd(FIRE, 20); } Off(FIRE); ResetAllTachoCounts(TURRET); } /* ============================================================================ <= Rotate Robot's Turret => ============================================================================ */ task measureSweep() { RotateMotor(TURRET, 100, CENTER+SWEEP); } /* ============================================================================ <= Measur Ambient Light Level => ============================================================================ */ void measure_light() { ambient = 0; start measureSweep; while (MotorRunState(TURRET) == OUT_RUNSTATE_RUNNING) { level = LASER; if (level > ambient) ambient = level; } ambient += AMBIENT_MARGIN; TextOut(0, LCD_LINE6, "Ambient "); NumOut(50, LCD_LINE6, ambient); } /* ============================================================================ <= Check for Target => ============================================================================ */ void check() { level = LASER; if (level > max) { target = ANGLE; max = level; } } /* ============================================================================ <= Scan Robot's Turret => ============================================================================ */ void scan() { max = 0; if (ANGLE > CENTER) { // look left // OnRevReg(TURRET, SCAN_SPEED, OUT_REGMODE_SPEED); OnRev(TURRET, SCAN_SPEED); while (ANGLE > CENTER-SWEEP) check(); } else { // look right // OnFwdReg(TURRET, SCAN_SPEED, OUT_REGMODE_SPEED); OnFwd(TURRET, SCAN_SPEED); while (ANGLE < CENTER+SWEEP) check(); } Off(TURRET); } /* ============================================================================ <= Turn Laser Off => ============================================================================ */ void SetSensorLightInactive(const int port) { SetSensorType(port, SENSOR_TYPE_LIGHT_INACTIVE); SetSensorMode(port, SENSOR_MODE_PERCENT); ResetSensor(port); PlayFile("LaserOff.rso"); // Audible "Laser is Off!" while (SoundFlags() != SOUND_FLAGS_IDLE); } /* ============================================================================ <= Turn Laser On => ============================================================================ */ void SetSensorLightActive(const int port) { SetSensorType(port, SENSOR_TYPE_LIGHT_ACTIVE); SetSensorMode(port, SENSOR_MODE_PERCENT); ResetSensor(port); PlayFile("LaserOn.rso"); // Audible "Laser is On!" while (SoundFlags() != SOUND_FLAGS_IDLE); Wait(250); PlayFile("LaserOn.rso"); // Audible "Laser is On!" while (SoundFlags() != SOUND_FLAGS_IDLE); Wait(250); } /* ============================================================================ =============================================================================== <= Main Robot Control => =============================================================================== ============================================================================ */ task main() { ClearScreen(); SetSensorLightInactive(LASER_PORT); PlayFile("LaserOff.rso"); // Audible "Laser is Off!" while (SoundFlags() != SOUND_FLAGS_IDLE); start LaserReading; SetSensorTouch(TURRET_PORT); SetSensorMode(TURRET_PORT, IN_MODE_BOOLEAN); SetSensorTouch(TRIGGER_PORT); SetSensorMode(TRIGGER_PORT, IN_MODE_BOOLEAN); Wait(250); PlayFile("Aligning.rso"); // Audible "Aligning!" while (SoundFlags() != SOUND_FLAGS_IDLE); align(); measure_light(); SetSensorLightActive(LASER_PORT); PlayFile("SanningForTarge.rso"); // Audible "SanningForTarget!" while (SoundFlags() != SOUND_FLAGS_IDLE); while (true) { scan(); } StopAllTasks(); } |
Rotacaster - Lego Space Police Sentinel
Bazmarc's (Marc-Andre Bazergui) Lego Space Police Sentinel, Based on the LEGO® Space Police theme, this Sentinel is NXTfied and makes use of Rotacaster's upcoming NXT/Technic compatible Omni Wheels! LEGO ... Read more
Android Control for Lego NXT
If you are the owner of a LEGO MINDSTORMS NXT set and have an Android smartphone and you want to have some fun with your robots, now you have the ... Read more
Leave a Reply