Difference between revisions of "Arduino Laser Cannon"

From OpenCircuits
Jump to navigation Jump to search
Line 40: Line 40:
  
 
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.
 
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.
 +
 +
 +
{| class="wikitable"
 +
|-valign="top"
 +
! Command
 +
! Code
 +
! Notes, PIC Response
 +
<!------------------------------->
 +
|-valign="top"
 +
|Report version
 +
|v
 +
|Version of the PIC software something like:
 +
Serial Stepper Test ver July 4 2008
 +
<!------------------------------->
 +
|-valign="top"
 +
|Set direction
 +
|d+
 +
d-
 +
|plus for forward, minus for back
 +
Direction set.
 +
<!------------------------------->
 +
|-valign="top"
 +
|Where = Request motor position
 +
|w
 +
|Steps taken since power on or reset.
 +
Signed int.
 +
<!------------------------------->
 +
|-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"
 +
|Go for a number of steps
 +
|gnnn
 +
|go for a number of steps ( max. about 30,000 ) Direction set with d.
 +
Responds with "g starting<cr>" when rotation begins, then with "g done<cr>" when done.  May be stopped early with stop command.
 +
<!------------------------------->
 +
|-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.
 +
<!------------------------------->
 +
 +
|}
 +
 +
  
  
Line 46: Line 124:
 
Most terminal programs can be set to treat a carriage return as a carriage return line feed. Do it.  
 
Most terminal programs can be set to treat a carriage return as a carriage return line feed. Do it.  
  
Some terminal programs will not transmit in lower case ( all our commands are lower case ) unless specially set to do so. Set it to allow lower case.  
+
Some terminal programs will not transmit in lower case ( all our commands are lower case ) unless specially set to do so. Set it to allow lower case.
  
 
== Program Design ==
 
== Program Design ==

Revision as of 08:26, 30 December 2010

Arduino Laser Cannon

early draft, some text is mixed from another project, should be better updated in a few days

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: Example code for stepper motor control and for RS232 communications ( interrupt driven on the receive end ) on the PIC16F877A. Determining which drive wire is which on a unipolar stepper motor. This is the type of motor that I have most commonly found surplus or in salvage equipment Determining angle per step or steps per revolution of a stepper motor. Determining maximum speed of stepper motor. Demonstrating the operation of a stepper motor.

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.ext.

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 ):

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

Example:


Hardware


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.


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

Serial Stepper Test ver July 4 2008

Set direction d+

d-

plus for forward, minus for back

Direction set.

Where = Request motor position w Steps taken since power on or reset.

Signed int.

Report on all parameters r Delimited by commas something like:

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

Go for a number of steps gnnn go for a number of steps ( max. about 30,000 ) Direction set with d.

Responds with "g starting<cr>" when rotation begins, then with "g done<cr>" when done. May be stopped early with stop command.

Set the time delay between steps in ms ( max 255 ) tnnn Reports delay set. nnn = 0 to 255
Micro second delay in addition to to the ms delay. unnnn Reports delay set. Ok to use values nnn = as high as 5000 us.
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.
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.
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
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.

Some terminal programs will not transmit in lower case ( all our commands are lower case ) unless specially set to do so. Set it to allow lower case.

Program Design

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 tenique, 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.

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 ).

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.
  • 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.
  • Surely you can think of something.

Additions/Changes

These are changes I may or may not make: ( or you may take them on )


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

A free terminal program, I like this much better than hyperterminal: Welcome to our Free Download/New Products Page! http://www.rs485.com/psoftware.html

Download

email me to see if there have been some unposted revisions – which right now is all there is. russ_hensel


Comment, Questions, Contributions?

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