dgatwood / arduino_ptz

An Arduino sketch for a basic pan-tilt-zoom controller. It controls panning and tilting by direct voltage control, and controls zooming by sending LANC commands to a compatible camcorder.
BSD 3-Clause "New" or "Revised" License
3 stars 0 forks source link

Trying to figure out how to implement this at my church #1

Open dmanderson22 opened 1 year ago

dmanderson22 commented 1 year ago

My name is David and I am in charge of media at my church. I have two of the Bescor MP 101 heads in use currently. We are moving our control booth to another part of the building and I am looking for a way to control the MP 101 (pan/Tilt) and the zoom (LANC) over ethernet. I would love to have a physical controller connected that would allow me to switch between cameral 1 and 2. Possible Controller

I am sorry if this is not the best way to contact you but I am desperately looking for help with this project.

If you need to contact me in some other way that is fine with me.

dgatwood commented 1 year ago

Another David. I think Dr. Seuss wrote a poem about that. 🤣

The controller you're linking to there is serial-only. You would need to use something more like

to get IP communication.

Or for a cheaper solution, you could comment out all of the video playback parts of the code and use my NDI Camera Control project on a Pi-like device plus a Pimoroni I/O Expander for analog inputs. Without the display or pushbuttons, using a NanoPi NEO3 as the board, you could probably build that for somewhere around $50–60. It doesn't support controlling multiple devices, but that ought to be pretty straightforward to add, at least in theory. 😁

Anyway, I can see a lot of possible approaches.

  1. If you aren't married to the idea of using Arduino, you could probably easily get the actual VISCAPTZ code running on a NanoPi NEO3 (only slightly more expensive than a knock-off of an Arduino 2560). I'm not sure how hard it would be to get bit-banged LANC working reliably on Pi-family hardware without dedicating a core with interrupts turned off, though, so that part is a bit of a question mark.

  2. You could use that approach, but connect the UART lines to an Arduino, and use the Arduino code for actually driving the LANC hardware by sending newline-separated commands. I'm pretty sure somebody has the Arduino part of this by now already. But now you have two single-board computers, which also isn't ideal.

  3. You could write partial support for interpreting VISCA-over-IP traffic on Arduino. As a starting point, I wrote a rudimentary VISCA-over-IP camera-side implementation in my VISCAPTZ project.

The only fully working version of that code is written for Raspberry Pi, but when I first started writing that code, I started out writing it for Arduino. I abandoned that effort because I was building something that needed to support absolute positioning, and a single-threaded Arduino can't possibly reliably listen for VISCA commands, query a network-attached camera for its current zoom position via HTTP, ask rotary encoders for the pan and tilt position, and compute the correct speed to set the motors in real time while recalling a preset position. But for what you're doing, I think an Arduino would be more than adequate.

Anyway, I left the original Arduino sketch (in a badly incomplete state) at the top level of that project, and that would probably be a much easier starting point than trying to write your own VISCA-over-PTZ camera-side listener stack from scratch, with the caveat that I never finished it far enough to actually test it, and I'm not 100% sure it even compiles, so you may be flipping back and forth between that and the Pi version to get it working. 😁

  1. Forget the commercial PTZ controller, forget VISCA, and build something super-simple and bespoke. If I were doing what you're describing, unless you're planning to add some actual VISCA-based PTZ cameras to your rig in the future, that's what I would do.

Basically:

Keep the protocol simple. On the controller side, in place of the code that sets the motor and LANC speed, send a single UDP packet to a specific port at a particular IP address, and make that packet contain exactly three bytes:

Optionally add a fixed 8-byte value at the start of each packet as a sanity check.

On the decode side, rip out all the input handling code, and instead listen for packets on that port. When you get a packet, update the pan, tilt, and zoom speeds by calling the existing functions.

Be sure to use a short-ish timeout of maybe a second in your packet listening code, and if you time out waiting for another packet, set all speed values to zero. That way, a network failure can't cause your camera to keep moving until it points in a dangerous direction (though at least the Bescor has physical stops that likely limit this risk somewhat).

That approach ought to be fairly straightforward using just this project and maybe a dozen extra lines of code to send and receive the packets. You can even look at the preliminary draft of that Arduino-based VISCAPTZ code as a starting point to see how to receive UDP packets.

Hope that helps.

dgatwood commented 1 year ago

One more thing. If you do this, make your changes flag-guarded with something like

#define ENABLE_NETWORK 0  // 0 for disabled, 1 for sending side, 2 for receiving side

#if ENABLE_NETWORK == 1
...
#endif

and then send a pull request so that it can be merged in.

Architecturally, at a high level, I'd suggest something like:

But feel free to disregard that if some other approach seems easier to implement.

dmanderson22 commented 1 year ago

Ok. Wow. I appreciate your input so much. I am looking for the best method to control these for the most budget friendly price. What Arduino devices and joystick hardware would you recommend? Your final setup made the most sense to use and seemed the simplest. I need a controller on one end that could control each of the two pan/tilt heads and the zoom over LANC.

I have no experience with coding other than looking at some coding here and there. I am sure I can get a rudimentary understanding of what is going on by studying your code.

Any help you can point me to would be awesome as well. I had thought about seeking out someone to write the code on a freelance website but I am not sure where I could find the best person for the job as well.