Pan and Tilt Control with AndroiDAQ
A pan and tilt mechanism is a positional control assembly that controls both the horizontal and vertical positions of a device, like a camera head, that is attached to the head base plate of the assembly. There are many patents, dating back from 1906, which describes pan and tilt mechanisms that were manually operated, via ropes or cords, that were used to move shrouded carbon-arc bulbs for spotlight stage lighting. A 1925 patent suggests the first use of motors to drive a pan and tilt mechanism. A 1936 patent describes a means to move a pan and tilt mechanism via a joystick, vice switches on a switchboard. Today, pan and tilt positioners are used in hobby and industrial robotics, camera surveillance, defense and homeland security applications. This article will discuss how to construct a simple pan and tilt mechanism using a stepper motor and servo motor. It will also discuss how to control your pan and tilt assembly with a microcontroller data acquisition system such as the AndroiDAQ module.
I have written two previous articles describing how to use the AndroiDAQ module to control Servo motors and Stepper motors, titled “Servo Motor Control with AndroiDAQ” and “Stepper Motor Control with AndroiDAQ” respectively. It is suggest that you review these articles in detail before continuing with this article. In this article I will be using assemblies that are suggested from those two articles and also use methods described in those articles in explaining how to control a pan and tilt assembly in tandem with a microcontroller system. A synopsis of the two past articles is given below.
In my article titled “Servo Motor Control with AndroiDAQ”, I discuss that servo motors are controlled by sending to the servo’s control wire a pulse train of variable width, or better, a pulse width modulated signal. This pulse train has to have specific parameters such as a minimum pulse, a maximum pulse, and a repetition rate. This signal is typically derived and sent to the servo control wire by a microcontroller such as the one on the AndroiDAQ module. The shaft angle of the servo is determined by the duration of the pulse train sent. I also discuss how to connect a servo motor to a microcontroller system like the AndroiDAQ module. In this article we will be using the servo circuit shown in that article (and also shown below in figure 1) to control the servo motor, which will be used for the vertical positioning of the pan and tilt assembly.
Figure 1. Servo connection with AndroiDAQ
In my article titled “Stepper Motor Control with AndroiDAQ” I discuss a simple stepper motor motion control system that consists of: the AndroiDAQ module as the stepper motor controller, a MC3479 IC chip as the stepper motor driver, and a stepper motor with a build-on limit switch to tell us our zero start point for a motion system. In this article we will be using the stepper motor circuit shown in that article (and also shown below in figure 2) to control the stepper motor, which will be used for the horizontal positioning of the pan and tilt assembly.
Figure 2. Connection Diagram Stepper Motor to AndroiDAQ
A simple pan and tilt assembly can be constructed by using a stepper motor for horizontal positioning and a servo motor for vertical positioning. Of course two stepper motors or two servo motors can be used to control the horizontal and vertical positions of a pan and tilt assembly. I chose to use a stepper motor combined with a servo motor for this example, as I feel that this will demonstrate the differences in firmware between the two motor technologies in how to control each with a microcontroller based system like AndroiDAQ. I will also demonstrate how the two motors can be combined or integrated in tandem to work cooperatively in both the microcontroller firmware and later control software. Your final design can use whatever motor drive system that you desire. It is my goal that after this article you should have enough information to do any combination and methods for your pan and tilt assembly.
A teaser code example for the AndroiDAQ module was also provided in my article titled “Stepper Motor Control with AndroiDAQ”. This code example, which is now included in the newest version of the AndroiDAQ firmware, combines the two different sub-routines that are described in their respective articles. One subroutine is used to move the servo motor, set as variable “SERVO”, and the other, set as variable “burst”, to move the stepper motor and sense the zero start point limit switch, which was installed on our stepper motor motion control system in that article.
If you read and follow through the example code, which is shown below, you can see that pin 14 of the AndroiDAQ module (the pin used for the zero start point limit switch) is set as an input, that pin 4 and pin 3 are outputs, used to clock the stepper motor steps and control its rotational direction, respectively, and that a frequency of 96-hertz is used to drive the stepper motor steps in either the clockwise or counterclockwise direction. After all the variables are set in the example code, we enter a ‘repeat’ loop that moves the stepper motor clockwise (while pin 14 is “0”) until pin 14’s limit switch closes (pin 14 will then equal “1” or high, as it is connected to 3.3-volts), which in turn causes the code to leave the ‘repeat’ loop and then move the stepper motor 102 steps counterclockwise. After this is done, the code causes the servo motor be to driven to the centered angular position (“SERVO.leftPulseLength(1500) ”).
The above description and code should give to you some idea on how to control a servo and stepper motor in tandem using a single subroutine, and how to also detect the zero point limit switch in the code with the AndroiDAQ module. If not please read the respective articles as they will provide to you a more in-depth detail on what is necessary to utilize stepper and servo motors with the AndroiDAQ module.
Figure 3. A Simple Pan and Tilt Assembly for AndroiDAQ
It is quite easy to assemble a simple pan and tilt assembly using a Stepper Motor that also has a Zero Point Limit Switch installed on it and a common Servo Motor that has a plate attached to its output shaft, which is used for mounting equipment to it, such as a video camera. During the design process of your pan and tilt assembly, I recommend that you keep in mind the weight of the desired equipment that you plan to mount to it and design your pan and tilt assembly accordingly. Stepper motors have an output drive shaft, which is used to drive motion clockwise or counterclockwise. This output shaft is a convenient place to install a coupler that has attached to it a base plate, which will hold the servo motor assembly. I used the stepper motor’s shaft set screw, which holds the coupler on to the stepper’s shaft, as a pseudo cog used to trigger the zero point limit switch assembly. A servo motor also has an output rotational shaft. This shaft is used mount a Rotational Plate that will be used as mounting place for my webcam. Of course other equipment such as a lamp, laser, or maybe even a Nerf dart pistol can be attached to this mounting plate. Figure 3 is an image of our lab’s no-frill pan and tilt assembly that currently has a Logitech webcam attached to it. Of course your design will vary depending on what you have in your lab or shop for making up your pan and tilt assembly, but yours should be similar so that you can follow this example.
Now that we have a pan and tilt assembly built with a stepper and servo motor, we can now connect it to a microcontroller system like the AndroiDAQ module. As shown in the diagrams above in figures 1 and 2, the connections for the servo motor are ground, 5-volts DC, and AndroiDAQ pin 13, which provides the angular direction via a pulse-width modulated signal of 0.75–2.25 milliseconds. The connections for the zero point limit switch are 3.3-volts and AndroiDAQ pin 14, and the connections for the stepper motor drive circuit are AndroiDAQ pin 4, used for the step clock pulses, and AndroiDAQ pin 3, which is used to control the directional setting signal. To build the stepper motor drive circuit, please refer to the article titled: “Stepper Motor Control with AndroiDAQ” as it provides more detailed information about this circuit.
When all is connected properly to the AndroiDAQ module, and after you have ensured that you have the newest version of AndroiDAQ firmware installed on your AndroiDAQ module, which also contains the above example code, you should be able to send to the AndroiDAQ module the command code of 013, via the Propeller Serial Tool, and upon pressing the Enter key, your pan and tilt assembly will first move clockwise until the zero point limit switch closes and then counterclockwise 102 steps; more or less depending on your stepper motor setup as explained in the article titled: “Stepper Motor Control with AndroiDAQ”. After the stepper motor has centered, the servo motor will be moved by the subroutine to its centered angular position. After the subroutine has finished, the stepper motor and servo motor are posed as centered for other alignment purposes. This centering allows you to adjust your assembly mechanically so that the assembly can later be centered in reference to the field of view of a video camera image. This type of centering, on a video camera’s view, allows for the pan and tilt assembly to be used to interact with a connected webcam for object targeting or motion detection tracking.
The newest version of the AndroiDAQ firmware also contains two more new subroutines named MoveServo and MoveStepper that compliments the CenterPanTilt subroutine example code subroutine. To use the MoveServo subroutine, again using the Propeller Serial Tool for testing, enter AndroiDAQ command 014 and press the Enter key. The Propeller serial terminal will then wait for you to enter an angular direction pulse width, which is based on the servo’s 0.75–2.25 milliseconds angular position span. As shown in the example code above, entering a figure of 01500 into the serial terminal’s input box and pressing the Enter key will center the servo motor. Entering a figure of 0750 and pressing the Enter key will move the servo to its lowest angular extreme and conversely entering a figure of 02250 and pressing the Enter key will move the servo to its other angular extreme. Any figure entered that is within the range or in between these two extreme limits will move the servo to the appropriate angle for that figure.
To use the MoveStepper subroutine, again using the Propeller Serial Tool for testing, enter AndroiDAQ command 015 and press the Enter key. The serial terminal will then wait for you to enter two other commands into its input box for this subroutine to continue. They consists of: the number of steps that you desire to move the stepper motor and the desired direction that you want the stepper motor to move. AndroiDAQ commands are always preceded by a zero and followed by pressing the Enter key. For example, if one enters the command 015 ->enter, and then 0100 -> enter, and then 01 -> enter; the connected stepper motor will turn 100 steps in the clockwise direction. Conversely if one enters the command 015 ->enter, 0075 -> enter, and 00 -> enter; the connected stepper motor will turn 75 steps in the counterclockwise direction.
This article gives a brief history of pan and tilt mechanisms and discusses how to make a simple pan and tilt assembly, using one stepper motor and one servo motor. It also discusses and shows examples of the new subroutines and how to use them, which are now included in the AndroiDAQ firmware. These new subroutines should make it very easy to implement pan and tilt robotics using the AndroiDAQ module. In future articles, I will discuss using Java and Python to communicate with the AndroiDAQ module, via serial connections, and I will expand upon the use of the pan and tilt mechanism using image processing under Java, to develop an object detection and motion tracking and targeting system.