Joystick controlled pan/tilt camera w/schematics and video
firestorm.v1
Posts: 94
Here's a project component that's part of an even bigger project but it in of itself presents a completed project that I'm sure others here will find beneficial.
This project was to figure out how to control two servos configured in a pan/tilt setup with an ordinary PC gameport joystick. Searches for documentation and examples did not turn up much, but I did find a very nice article on how to interface a playstation controller with the BS2. I saved that article for later testing.
A word about joysticks:
The old PC gameport joysticks were very simple devices. They plugged into a 15 pin D-sub connector that was typically located on add-on sound cards or next to the audio connectors on older motherboards that had them built-in. The joysticks had two variable resistor (pot) controls that changed the analog movement into a variable resistance. One pot for the X axis (left to right) and the other pot for Y axis (up to down). Some sticks like the one I use here also have a third pot that acted like a throttle control. In my specific case, all of the pots were 150Kohm including the throttle. I believe this is a standard, but you might want to check. Also in this case even though the BS2 is wired up for it, I did not choose to use the throttle in this application although with the right camera, you could use this as a "zoom" for full PTZ operation.
The Basic Stamp has a very convenient way of working with variable resistors (RCTIME) and with minimal hardware, you can put analog joystick input into your BS2 projects.
Here's what I used:
2 220 Ohm resistors
2 .1 microfarad ceramic capacitors
1 scavenged 15 pin gameport (Female D-sub) from a motherboard kicking about.
1 gameport joystick. (NO USB or Serial.)
Optional hardware:
1 slightly used (ok, the case was smashed in) but otherwise functional security camera
1 12VDC 8 inch LCD TFT composite display
** For some reason, I was unable to group the I/O pins together. Any attempt to use IO pins 0,1,2 failed and RCTIME went weird. If you know the answer as to why this is, please let me know. I unsuccessfully to use 0,1,2 or 1,2,3 or 0,1,4, etc when using the test application so I finally used 0,4,7 with excellent results. I would love to know why this happens and wonder if it will affect me using the other IO pins?
With this schematic, I found the following possible RC times which I then translated into speed multiplier of sorts:
X axis: Minimum value 1, Median value 4651, Max value 7107
Y axis: Minimum value 1, Median value 4140, Max value 6731
Throttle: Minimum value 1, Maximum value 5707.
After that, I had to find a multiplier "zone" where depending on how far the joystick was pushed one direction dictated how far the servo moved. But for my setup, the Y axis was about 500 us offset to X, which meant I had to have another set of rules. And for another gotcha. What happens if the stick gets unplugged? I don't want the servos to spazz out and risk damaging themselves or the camera. With a little tinkering, I created this chart:
An initial IF..THEN statement that would check to see if RCTIME was less than 20 would protect the servos from going haywire. After working with the servos and RCTIME, I found that a value of 10 and the multipliers listed above would work.
The attached code is built into two subroutines. It would have been one subroutine except for that 500 usec offset between the X and Y values demanded a new set of rules. To conserve variable space, only the "time" variable is a word. The pulse variable is a byte that has +550 added to it when the servo is pulsed to equal the 750 needed to stand still.
The first file, "joystick test" is for testing your setup. It's not very elegant, but it works for getting a feel of what your RCTIMEs will be when you use the final code.
The second file, "joystick interface" is the actual application that you can send to the BS2 and using the above schematic can have this working in no time. Don't forget to set your servo and axes variables at the start of the program.
Here is a link of the camera in action, with the video from the camera on the LCD next to it:
www.youtube.com/watch?v=R3uaVq6OH4c
Here's a link to a schematic that I found after I had gone through the hell of taking apart the joystick and pining it out with my trusty VOM and a notepad:
pinouts.ru/Inputs/GameportPC_pinout.shtml
Post Edited (firestorm.v1) : 3/21/2009 11:37:14 AM GMT
This project was to figure out how to control two servos configured in a pan/tilt setup with an ordinary PC gameport joystick. Searches for documentation and examples did not turn up much, but I did find a very nice article on how to interface a playstation controller with the BS2. I saved that article for later testing.
A word about joysticks:
The old PC gameport joysticks were very simple devices. They plugged into a 15 pin D-sub connector that was typically located on add-on sound cards or next to the audio connectors on older motherboards that had them built-in. The joysticks had two variable resistor (pot) controls that changed the analog movement into a variable resistance. One pot for the X axis (left to right) and the other pot for Y axis (up to down). Some sticks like the one I use here also have a third pot that acted like a throttle control. In my specific case, all of the pots were 150Kohm including the throttle. I believe this is a standard, but you might want to check. Also in this case even though the BS2 is wired up for it, I did not choose to use the throttle in this application although with the right camera, you could use this as a "zoom" for full PTZ operation.
The Basic Stamp has a very convenient way of working with variable resistors (RCTIME) and with minimal hardware, you can put analog joystick input into your BS2 projects.
Here's what I used:
2 220 Ohm resistors
2 .1 microfarad ceramic capacitors
1 scavenged 15 pin gameport (Female D-sub) from a motherboard kicking about.
1 gameport joystick. (NO USB or Serial.)
Optional hardware:
1 slightly used (ok, the case was smashed in) but otherwise functional security camera
1 12VDC 8 inch LCD TFT composite display
** For some reason, I was unable to group the I/O pins together. Any attempt to use IO pins 0,1,2 failed and RCTIME went weird. If you know the answer as to why this is, please let me know. I unsuccessfully to use 0,1,2 or 1,2,3 or 0,1,4, etc when using the test application so I finally used 0,4,7 with excellent results. I would love to know why this happens and wonder if it will affect me using the other IO pins?
BS2 D-sub [noparse][[/noparse]pin 0]--^v^v^-----X---------------[noparse][[/noparse]pin 3] X axis sense 220 ohm | .1uf X--|(--X | [noparse][[/noparse]pin 4]--^V^V^-----X------+--------[noparse][[/noparse]pin 6] Y axis sense 220 ohm | .1uf | X--|(--X | [noparse][[/noparse]pin 7]--^V^V^-----X------+--------[noparse][[/noparse]pin 13] throttle sense 220 ohm | .1uf | x--|(--X--------[noparse][[/noparse]pin 1] common/ground | | --+-- / / / Note: an "X" denotes connection, where a "+" plus does not.
With this schematic, I found the following possible RC times which I then translated into speed multiplier of sorts:
X axis: Minimum value 1, Median value 4651, Max value 7107
Y axis: Minimum value 1, Median value 4140, Max value 6731
Throttle: Minimum value 1, Maximum value 5707.
After that, I had to find a multiplier "zone" where depending on how far the joystick was pushed one direction dictated how far the servo moved. But for my setup, the Y axis was about 500 us offset to X, which meant I had to have another set of rules. And for another gotcha. What happens if the stick gets unplugged? I don't want the servos to spazz out and risk damaging themselves or the camera. With a little tinkering, I created this chart:
-4x -3x -2x (idle) +2x +3x +4x X axis: 19-2k 2k-3k 3k-4k 4k-5k 5k-6k 6k-7k 7k+ Y axis:19-1.5k 1.5k-2.5k 2.5k-3.5k 3.5k-4.5k 4.5k-5.5k 5.5k-6.5k 6.5k+
An initial IF..THEN statement that would check to see if RCTIME was less than 20 would protect the servos from going haywire. After working with the servos and RCTIME, I found that a value of 10 and the multipliers listed above would work.
The attached code is built into two subroutines. It would have been one subroutine except for that 500 usec offset between the X and Y values demanded a new set of rules. To conserve variable space, only the "time" variable is a word. The pulse variable is a byte that has +550 added to it when the servo is pulsed to equal the 750 needed to stand still.
The first file, "joystick test" is for testing your setup. It's not very elegant, but it works for getting a feel of what your RCTIMEs will be when you use the final code.
The second file, "joystick interface" is the actual application that you can send to the BS2 and using the above schematic can have this working in no time. Don't forget to set your servo and axes variables at the start of the program.
Here is a link of the camera in action, with the video from the camera on the LCD next to it:
www.youtube.com/watch?v=R3uaVq6OH4c
Here's a link to a schematic that I found after I had gone through the hell of taking apart the joystick and pining it out with my trusty VOM and a notepad:
pinouts.ru/Inputs/GameportPC_pinout.shtml
Post Edited (firestorm.v1) : 3/21/2009 11:37:14 AM GMT
bs2
292B
Comments
Where did you get the nice looking bracket?
Yeah, I have been having "implementation issues" with the LCD display and the fact that I still don't know which way is "up". I can't figure out if the camera is upside-down or if the LCD is upside down or if they both are and it conveniently works out that way. I have a schematic on how to build in some controls for the OSD for the display so at least one of the two components will be solved once and for all. :P This was primarily practice for being able to control two servos with one stick.
The bracket was part of the original camera mount. The entire assembly was part of a surveillance system like they have at the convenience stores. (Banks already have good PTZ systems in place. :P ) Before I took it apart, the camera was in a water-resistant case, about 5 inches wide, 5 inches deep and an inch tall with a 4 1/2 inch diameter clear plastic "bubble" on the top. Someone had tried to sabotage the camera as the bubble looks like someone tried to hit it with a hammer. I was able to rifle through the box and pick out some other bubbles that weren't so abused. All I did was add servos to the two brackets and remove the stationary hardware that held the camera lens and PCB in a fixed angle.
After looking at Parallax's store, I'm going to have to get some of those pico servos as I'd really like to be able to keep the entire assembly inside the original casing. I didn't see them the last time I ordered stuff from their candy store. :P
I applied the same code and hookup to the Boe-bot kit and found that it worked very well for an analog control platform for the Boe-bot. The Youtube vid link is of the Boe-bot on the ground, with the same analog joystick setup as shown before but this time it's on the ground and antagonizing the cats.
The code has been modified and a new routine added to turn on and off the one "headlight" that doesn't really point down. It's more of a theoretical test of mine than anything. I/O pin 1 is used to detect the trigger button (button 1, pin 2 on the 15 in D-sub) and I/O pin 2 is brought high or low to turn off/on the LED.