Difference between revisions of "Arduino Laser Cannon"

From OpenCircuits
Jump to navigation Jump to search
Line 1: Line 1:
= Arduino Command Interpreter =
+
= Arduino Laser Cannon =
  
*Name:  Arduino Command Interpreter
+
early draft, some text is mixed from another project, should be better updated in a few days
*Status: in mid development, but is working.
 
*Technology: Arduino
 
*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.
 
  
A project using this library is: [[Arduino Laser Cannon]]
+
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.
  
Unlike Firmata [http://www.arduino.cc/en/Reference/Firmata] this is meant to be used with a human issuing the commands.
+
 
 +
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.  
 
Archive for the project will be posted.  See download section below.  
  
== Interface ==
+
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 ):
  
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.
+
*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.
 +
 
 +
 
 +
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 ==
 
== Program Design ==
  
In general I tried to avoid the use of Arduino libraries which I was afraid would bulk up the code too much. I 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 buffering. In 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 away. The 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.
+
I no longer have the patience for assembly language.
 +
 
 +
Commands are received via an serial communications routine, 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. The exception to this is the stop command which will terminate a g or x command and return to the main loop quickly. RS232 transmission is not driven by an interrupt and so during transmission from the microcontroller no stepping takes place. Commands which do not result in motion execute very quickly, most of the time is for communications.
 +
 
 +
 
 +
== Other Things to Try ==
 +
 
 +
 
 +
Run it faster and faster ( shorter time delay ) until it fails. You may want to turn it 400 turns to clockwise fast, then 400 counter clockwise slow. If it does not end up where it started then it skipped a step or more. If you know how many steps per rev then you need not reverse it just ask it to go a round number of revolutions.  
 +
How many steps per revolution for your motor?
 +
 
 +
Guess, try to make it turn 10 revolutions fairly slowly or at least slowly enough so that it is not skipping steps.. If you number is right it will end up at the same angle it started. If not try a new guess.  
 +
Demo the motor with Special Commands x1 and x2:
 +
x1: spins the motor one way faster and faster, then reverses and returns to original position.  
 +
x2: motor vibrates faster and faster through smaller and smaller arc, then stops where it started.  
 +
 
 +
 
 +
== Additions/Changes ==
 +
 
 +
These are changes I may or may not make: ( or you may take them on )
 +
   
 +
 
 +
== Possibly useful links ==
 +
 
 +
This program uses my: Serial Communications Library -- BoostC and 16F877A
 +
 
 +
A closely related project with a lot of similar code: PIC based Stepper Motor Dancing Analog Clock
 +
 
 +
[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 ==
 
== Download ==
  
Use the download at [[Arduino Laser Cannon]] the command interface is part of this project.
+
email me to see if there have been some unposted revisions – which right now is all there is. [[russ_hensel]]
  
== Links ==
 
  
 +
== Comment, Questions, Contributions?  ==
  
*More information on serial communications with microcontrollers: [[Microcontroller Serial Communications Articles]]
+
Email me russ_hensel, or use the talk page for this topic. All feedback is welcome.
*[[Arduino Laser Cannon]]
+
Categories: Projects | Serial Communications | Microcontroller | Arduino
*[http://www.arduino.cc/en/Reference/Firmata| Firmata Reference]
 
*[[]]
 
*[[]]
 

Revision as of 17:06, 29 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.


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

I no longer have the patience for assembly language.

Commands are received via an serial communications routine, 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. The exception to this is the stop command which will terminate a g or x command and return to the main loop quickly. RS232 transmission is not driven by an interrupt and so during transmission from the microcontroller no stepping takes place. Commands which do not result in motion execute very quickly, most of the time is for communications.


Other Things to Try

Run it faster and faster ( shorter time delay ) until it fails. You may want to turn it 400 turns to clockwise fast, then 400 counter clockwise slow. If it does not end up where it started then it skipped a step or more. If you know how many steps per rev then you need not reverse it just ask it to go a round number of revolutions. How many steps per revolution for your motor?

Guess, try to make it turn 10 revolutions fairly slowly or at least slowly enough so that it is not skipping steps.. If you number is right it will end up at the same angle it started. If not try a new guess. Demo the motor with Special Commands x1 and x2: x1: spins the motor one way faster and faster, then reverses and returns to original position. x2: motor vibrates faster and faster through smaller and smaller arc, then stops where it started.


Additions/Changes

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


Possibly useful links

This program uses my: Serial Communications Library -- BoostC and 16F877A

A closely related project with a lot of similar code: PIC based Stepper Motor Dancing Analog Clock

[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. Categories: Projects | Serial Communications | Microcontroller | Arduino