Difference between revisions of "Arduino Laser Cannon"

From OpenCircuits
Jump to navigation Jump to search
 
(27 intermediate revisions by 2 users not shown)
Line 1: Line 1:
= Arduino Command Interpreter =
+
= Arduino Laser Cannon =
  
*Name:   Arduino Command Interpreter
+
This is a somewhat incomplete article, contact me if you need help:  [[russ_hensel]].
*Status: in mid development, but is working.  
+
 
 +
This project was written as part of a course on the Arduino at AS220 in Providence RI.  see: [http://as220.org/labs/pages/Arduino%20and%20Servo%20Motor%20Workshop Arduino and Servo Motor Workshop]
 +
 
 +
Before you get too excited:  the armament is just a laser pointer, so nothing blows up.  The arduino controls the aim of the laser.  Using a terminal program you can aim the laser in a number of directions.  Once aimed you can commit the position to memory and recall it later.
 +
 
 +
 
 +
*Name: Arduino Laser Cannon
 +
*Status: in fairly early development, but is working.  
 
*Technology: Arduino  
 
*Technology: Arduino  
 
*Author: [[russ_hensel]] ( where you can find an email address to reach me )  
 
*Author: [[russ_hensel]] ( where you can find an email address to reach me )  
*Summary:  This is set up to become a library that provides a command interface into the Arduino.
+
*Summary: An Arduino controls two servo motors to aim a laser pointer. A terminal program is used to control the Arduino.
 +
*Archive for the project will be posted. See download section below.
 +
 
 +
This project can be used as is or may give you ideas for other similar projects:
 +
 
 +
*Demonstrating the operation of a servo motor.
 +
*See "other things to try" below.
 +
 
 +
Platform: Arduino ( I used the bare bones board, but any should do ).  Added an external 5 v regulator to power the servos and the laser pointer ( which I got from … ).  Software done using arduino.exe. 
 +
 
 +
A laser pointer is connected to 2 Servos and the servos are connected to each other so one controls the azimuth while the other controls the altitude ( like most standard cannons ).  ( controlled by the RS232 connection ):
 +
 
 +
Commands include:
 +
*Set  azimuth
 +
*Set  altitude
 +
*Save and recall azimuth and altitude
 +
*“Tour” all the saved settings.
 +
 
 +
Example:
 +
 
 +
comming
 +
 
 +
== Hardware ==
 +
 
 +
An Arduino of course, and to run the motors I used an external plug in dc supply of well over 5 volts and a 5 volt linear regulator to power the servos.  I left the arduino powered off the usb port.  I bought a couple of laser pointer lasers ( a laser pointer without the case, batteries, and switch, but with an adjustable lens ), I will try to find a reference when I order more.  I added 2 RC servo motors, one standard size, one micro.  Using a small peice of sheet stock, I drilled 2 holes in in and then using double sided foam tape and a nylon tie, fastened the servo to the sheet.  I fastened the smaller servo to the horn of the larger servo so the axies are at right angles.  Finally I tied on the laser to the horn of the small servo.  ( see the picture ).  The laser is powered from the 5 volt regulator thru a current limiting 200 ohm resistor ( a 150 or perhaps even 100 ohm resistor would give a brighter beam, at some point the beam gets too bright and the laser fails, experiment at your own risk).  My laser came without specs for current or anything else.  In the program the output pins for the Arduino are defined in the header file.
 +
 
 +
[[Image:can1.png|alt text]]
 +
 
 +
The servos come with 3 pin female connectors, these can be plugged into 3 pin male headers, to plug them into the protoboard, make dual males like so:
 +
 
 +
[[Image:con1.png|alt text]]
 +
 
 +
[[Image:con2.png|alt text]]
 +
 
 +
I have some more discussion of this technique at:  [[Solderless protoboard]]
 +
 
 +
My bare bones board plugs right into the protoboard:  this one is a much bigger protoboard than I need even with the additional parts used for a stepper tester ( discussed at [[Stepper Motor Demonstration and Tester]] ).
 +
 
 +
[[Image:ard1.png|alt text]]
 +
 
 +
 
 +
== Command Interface ==
 +
 
 +
All commands ( except stop should be terminated with a carriage return ). Note that the command interface is not very smart, giving parameters that are out of range my blow the whole program up. If so reboot the microcontroller . Do not send a new command ( except stop ) until earlier commands have been completed ( actually you can get ahead some if you are careful ). Commands may be either upper or lower case. The backspace key usually works.
 +
 
  
A project using this library is: [[Arduino Laser Cannon]]
+
{| class="wikitable"
 +
|-valign="top"
 +
! Command
 +
! Code
 +
! Notes, Arduino Response
 +
<!------------------------------->
 +
|-valign="top"
 +
|Report version
 +
|v
 +
|Version of the software something like:
 +
Servo ver Dec 28b 2010
 +
<!------------------------------->
 +
|-valign="top"
 +
|Aim up
 +
|unnn
 +
|Shift the aim up by nnn microseconds.  Software keeps pulse in legal 1 to 2 msec range.
 +
<!------------------------------->
 +
|-valign="top"
 +
|Aim down
 +
|dnnn
 +
|Shift the aim down by nnn microseconds.  Software keeps pulse in legal 1 to 2 msec range.
 +
<!------------------------------->
 +
|-valign="top"
 +
|Where = Request aim position
 +
|w
 +
|tells fire point, index and x and y pulse delays.
 +
<!------------------------------->
 +
|-valign="top"
 +
|Report on all parameters
 +
|r
 +
|Delimited by commas something like:
 +
Dir +1, Permutation 1, Stepper Pos 80, Step Delay Us = 300 .....
 +
<!------------------------------->
 +
|-valign="top"
 +
|more to come
 +
|...
 +
|for now you will have to read the code.
 +
<!-------------------------------
 +
|-valign="top"
 +
|Set the time delay between steps in ms ( max 255 )
 +
|tnnn
 +
|Reports delay set.  nnn = 0 to 255
 +
<!-------------------------------
 +
|-valign="top"
 +
|Micro second delay in addition to to the ms delay.
 +
|unnnn
 +
|Reports delay set. Ok to use values nnn = as high as 5000 us.
 +
<!-------------------------------
 +
|-valign="top"
 +
|Set the permutation of the motor wires.
 +
|pn
 +
|Set the permutation, find the value that works for your motor. ( n = 0 to 5 ) Responds with the permutation set.
 +
<!-------------------------------
 +
|-valign="top"
 +
|Special command 1, Spin the motor in an interesting way. 
 +
|x1
 +
|Motor spins responds with "x special done<cr>" when it is done.  May be stopped with the stop cammand.
 +
<!-------------------------------
 +
|-valign="top"
 +
|Special command 2, Vibrate the motor first a lot then less and less to stop
 +
|x2
 +
|responds with "x special done<cr>" when it is done
 +
<!------------------------------->
 +
|-valign="top"
 +
|Stop
 +
|!
 +
|Should almost immediately stop long running commands like Go or x1 or x2. Responds with  Stopped<cr> when stoped ( wich should be quick ).
 +
<!------------------------------->
 +
|-valign="top"
 +
|Other, not understood commands
 +
|xxx
 +
|Responds with "!Bad Command = xxx" if the command is not understood.
 +
<!------------------------------->
  
Unlike Firmata [http://www.arduino.cc/en/Reference/Firmata] this is meant to be used with a human issuing the commands. 
+
|}
  
Archive for the project will be posted.  See download section below.
 
  
== Interface ==
+
Notes on terminal program set up.
 +
Baud rate should be 19.2K 8N1, but is easily adjustable in the header file for the program.
 +
Most terminal programs can be set to treat a carriage return as a carriage return line feed. Do it.
  
The basic idea is that commands to the Arduino consist of a single letter followed by a carriage return line feed ( a pretty basic line ending used by many terminal program ) Using letters often makes it easy to remember what the command stands for l for load, s for save, ? for help, etc.  (of course what letter stands for what is up to you and your program. ) Often this is not quite enough, you would like to use a number as well so you get commands like f22 meaning something like go forward 22 units. ( numbers are currently all decimal ).  Finally for convientience you may want to make the commands case insensitive so “f” an “F” both have the same meaning.  Finally the backspace character is implemented to back up the cursor within the string ( usefull for terminal programs that send characters as soon as you type them.
+
The alpha commands are case insensitive, use upper or lower case.
  
 
== Program Design ==
 
== Program Design ==
  
In general I tried to avoid the use of Arduino libraries which I was afraid would bulk up the code too muchI did incorporate “Serial” as it is a fairly lean library and I might not due even as well. The code is meant to poll ( not interrupt driven ) the serial port and accumulate characters until a full string is read ( as determined by the ending character – normally a cr ).  If you are a bit late in reading the  Serial library and the hardware do some bufferingIn pratice I do not see input buffer overrun, although by typing fast or other techniques you could probably produce it.  Most non printing characters are just thrown away. You cannot write beyound the code max string length (), characters are just thrown awayThe code is pretty well commented you should be able to fingue out most details by reading it. Aditionally the library is used with a couple of my other programs, the setup and main loop of these programs shows how to use the library in your code.
+
The program does not use the Arduino servo library ( ref would be nice ) or interrupts.  Instead it relys on polling comparing the current time ( mills() ) to a saved time to see if it is time for a new pulse.  This seems to be a common technique, which I borrowed from the web. ( For some info on servo motors see: [http://opencircuits.com/Motors#Servo Motors] )Two variables store the time in microseconds for each pulse, this time is implemented using the delaymicroseconds() function.  See the function: xxx.  The Arduino PWM functions and hardware are not used: on most microcontrollers these give you good resolution in a 0 to 100% duty cycle, but not good for the 5% to 10% duty cycle used by servos ( this may or may not apply to the Arduino, I did not even check ).
 +
 
 +
The archive has 2 versions of the program the Simple Laser Cannon can only aim the laser left, right, up, down and does not save any setings or "fire" at any points.
 +
 
 +
In the more advanced version settings may be saved and recalled from 2 arrays ( one for X one for Y ).  Shifting to one of these arrays moves the laser to that "point" and we say it fires ( actually I leave the laser on all the time ). The laser may also be sent on a tour of the defined points.
 +
 
 +
Most of the important constants are defined ( using #define ) in the servo header file.
 +
 
 +
I have tired to do a good job commenting the file, try reading itEmail me if you have questions [[russ_hensel]].
 +
 
 +
Commands are received via an serial communications routine [[Arduino Command Interpreter]], the main loop checks each time around to see if a complete command has been received. Because commands are only interpreted in the main loop all commands are ignored until the program returns to the main loop. RS232 functions are not driven by an interrupt.
 +
 
 +
== Other Things to Try ==
 +
 
 +
*You can use the pointing feature of the system to implement an instrument with a very large scale: Put a temperature scale on one side of the room, the "cannon" on the other and have it point to the temperature.   
 +
 
 +
*Use the pointer as a meter with a scale.
 +
*I have been thinking about a clock, each hour would be a piece of crystal and the laser would hit it on the hourMinutes might use another laser or other sort of display.
 +
*A servo generally moves from one position to another as fast as it canBy programming in intermediate positions between a start and stop you should be able to control the speed.
 +
*Try to make the beam trace out a defined curve.
 +
*Surely you can think of some other things.
 +
 
  
 +
 +
== Possibly Useful Links ==
 +
 +
*This program uses my: [[Arduino Command Interpreter]]
 +
 +
*[[RS232]] Discusses the sort of interface that is used by this project.
 +
 +
*More information on serial communications with microcontrollers: [[Microcontroller Serial Communications Articles]]
 +
 +
*[[PC-Microcontroller Communications]] discusses free terminal programs, most much better than hyperterminal.
 +
*[http://as220.org/labs/pages/Arduino%20and%20Servo%20Motor%20Workshop Arduino and Servo Motor Workshop] Course link at AS220 Labs.
 +
 +
*[http://www.popsci.com/node/19965How|It Works: The Flying Laser Cannon] for a more distructive version.
 +
 +
There are many projects that use 2 or more servo motors for aiming stuff.  Some of these are:
 +
 +
 +
*[http://www.instructables.com/id/Camera-Panorama-robot-head-panograph/  Camera Panorama robot head (panograph)]
 +
 +
*[http://www.instructables.com/id/Laser-guided-Ghost-Climber/?ALLSTEPS Laser-guided Ghost Climber]
 +
 +
*[http://www.instructables.com/id/Arduino-2-axis-servo-solar-tracker/ Arduino 2-axis servo solar tracker]
 +
 +
http://www.instructables.com/id/Autonomous-Paintball-Sentry-Gun/?ALLSTEPS Autonomous Paintball Sentry Gun]
  
 
== Download ==
 
== Download ==
  
Use the download at [[Arduino Laser Cannon]] the command interface is part of this project.
+
[http://home.comcast.net/~russ_hensel/OC/ArduinoAndServoMotorWorkshop.zip Software and web page archive for the workshop]
 +
 
  
== Links ==
+
== Comment, Questions, Contributions?  ==
  
 +
Email me [[russ_hensel]], or use the talk page for this topic. All feedback is welcome.
  
*More information on serial communications with microcontrollers: [[Microcontroller Serial Communications Articles]]
+
[[category:Projects]][[category:Serial Communications]][[category:Microcontroller]][[category:Arduino]]
*[[Arduino Laser Cannon]]
 
*[http://www.arduino.cc/en/Reference/Firmata| Firmata Reference]
 
*[[]]
 
*[[]]
 

Latest revision as of 11:55, 27 April 2012

Arduino Laser Cannon[edit]

This is a somewhat incomplete article, contact me if you need help: russ_hensel.

This project was written as part of a course on the Arduino at AS220 in Providence RI. see: Arduino and Servo Motor Workshop

Before you get too excited: the armament is just a laser pointer, so nothing blows up. The arduino controls the aim of the laser. Using a terminal program you can aim the laser in a number of directions. Once aimed you can commit the position to memory and recall it later.


  • Name: Arduino Laser Cannon
  • Status: in fairly early development, but is working.
  • Technology: Arduino
  • Author: russ_hensel ( where you can find an email address to reach me )
  • Summary: An Arduino controls two servo motors to aim a laser pointer. A terminal program is used to control the Arduino.
  • Archive for the project will be posted. See download section below.

This project can be used as is or may give you ideas for other similar projects:

  • Demonstrating the operation of a servo motor.
  • See "other things to try" below.

Platform: Arduino ( I used the bare bones board, but any should do ). Added an external 5 v regulator to power the servos and the laser pointer ( which I got from … ). Software done using arduino.exe.

A laser pointer is connected to 2 Servos and the servos are connected to each other so one controls the azimuth while the other controls the altitude ( like most standard cannons ). ( controlled by the RS232 connection ):

Commands include:

  • Set azimuth
  • Set altitude
  • Save and recall azimuth and altitude
  • “Tour” all the saved settings.

Example:

comming

Hardware[edit]

An Arduino of course, and to run the motors I used an external plug in dc supply of well over 5 volts and a 5 volt linear regulator to power the servos. I left the arduino powered off the usb port. I bought a couple of laser pointer lasers ( a laser pointer without the case, batteries, and switch, but with an adjustable lens ), I will try to find a reference when I order more. I added 2 RC servo motors, one standard size, one micro. Using a small peice of sheet stock, I drilled 2 holes in in and then using double sided foam tape and a nylon tie, fastened the servo to the sheet. I fastened the smaller servo to the horn of the larger servo so the axies are at right angles. Finally I tied on the laser to the horn of the small servo. ( see the picture ). The laser is powered from the 5 volt regulator thru a current limiting 200 ohm resistor ( a 150 or perhaps even 100 ohm resistor would give a brighter beam, at some point the beam gets too bright and the laser fails, experiment at your own risk). My laser came without specs for current or anything else. In the program the output pins for the Arduino are defined in the header file.

alt text

The servos come with 3 pin female connectors, these can be plugged into 3 pin male headers, to plug them into the protoboard, make dual males like so:

alt text

alt text

I have some more discussion of this technique at: Solderless protoboard

My bare bones board plugs right into the protoboard: this one is a much bigger protoboard than I need even with the additional parts used for a stepper tester ( discussed at Stepper Motor Demonstration and Tester ).

alt text


Command Interface[edit]

All commands ( except stop should be terminated with a carriage return ). Note that the command interface is not very smart, giving parameters that are out of range my blow the whole program up. If so reboot the microcontroller . Do not send a new command ( except stop ) until earlier commands have been completed ( actually you can get ahead some if you are careful ). Commands may be either upper or lower case. The backspace key usually works.


Command Code Notes, Arduino Response
Report version v Version of the software something like:

Servo ver Dec 28b 2010

Aim up unnn Shift the aim up by nnn microseconds. Software keeps pulse in legal 1 to 2 msec range.
Aim down dnnn Shift the aim down by nnn microseconds. Software keeps pulse in legal 1 to 2 msec range.
Where = Request aim position w tells fire point, index and x and y pulse delays.
Report on all parameters r Delimited by commas something like:

Dir +1, Permutation 1, Stepper Pos 80, Step Delay Us = 300 .....

more to come ... for now you will have to read the code.
Stop ! Should almost immediately stop long running commands like Go or x1 or x2. Responds with Stopped<cr> when stoped ( wich should be quick ).
Other, not understood commands xxx Responds with "!Bad Command = xxx" if the command is not understood.


Notes on terminal program set up. Baud rate should be 19.2K 8N1, but is easily adjustable in the header file for the program. Most terminal programs can be set to treat a carriage return as a carriage return line feed. Do it.

The alpha commands are case insensitive, use upper or lower case.

Program Design[edit]

The program does not use the Arduino servo library ( ref would be nice ) or interrupts. Instead it relys on polling comparing the current time ( mills() ) to a saved time to see if it is time for a new pulse. This seems to be a common technique, which I borrowed from the web. ( For some info on servo motors see: Motors ). Two variables store the time in microseconds for each pulse, this time is implemented using the delaymicroseconds() function. See the function: xxx. The Arduino PWM functions and hardware are not used: on most microcontrollers these give you good resolution in a 0 to 100% duty cycle, but not good for the 5% to 10% duty cycle used by servos ( this may or may not apply to the Arduino, I did not even check ).

The archive has 2 versions of the program the Simple Laser Cannon can only aim the laser left, right, up, down and does not save any setings or "fire" at any points.

In the more advanced version settings may be saved and recalled from 2 arrays ( one for X one for Y ). Shifting to one of these arrays moves the laser to that "point" and we say it fires ( actually I leave the laser on all the time ). The laser may also be sent on a tour of the defined points.

Most of the important constants are defined ( using #define ) in the servo header file.

I have tired to do a good job commenting the file, try reading it. Email me if you have questions russ_hensel.

Commands are received via an serial communications routine Arduino Command Interpreter, the main loop checks each time around to see if a complete command has been received. Because commands are only interpreted in the main loop all commands are ignored until the program returns to the main loop. RS232 functions are not driven by an interrupt.

Other Things to Try[edit]

  • You can use the pointing feature of the system to implement an instrument with a very large scale: Put a temperature scale on one side of the room, the "cannon" on the other and have it point to the temperature.
  • Use the pointer as a meter with a scale.
  • I have been thinking about a clock, each hour would be a piece of crystal and the laser would hit it on the hour. Minutes might use another laser or other sort of display.
  • A servo generally moves from one position to another as fast as it can. By programming in intermediate positions between a start and stop you should be able to control the speed.
  • Try to make the beam trace out a defined curve.
  • Surely you can think of some other things.


Possibly Useful Links[edit]

  • RS232 Discusses the sort of interface that is used by this project.

There are many projects that use 2 or more servo motors for aiming stuff. Some of these are:


http://www.instructables.com/id/Autonomous-Paintball-Sentry-Gun/?ALLSTEPS Autonomous Paintball Sentry Gun]

Download[edit]

Software and web page archive for the workshop


Comment, Questions, Contributions?[edit]

Email me russ_hensel, or use the talk page for this topic. All feedback is welcome.