This is a video of a gimbal installed on a quadcopter for video stabilizing. This keeps the camera pointed in exactly the same axis, despite large, rapid movements. I bet it or another similar system could be adapted to keep our cannons level despite heeling or listing. https://www.youtube.com/watch?v=wWdWd6QUNfU
A very quick and easy solution would be to just use a tilt switch on the gun. Mount the switch so that if the ship rolls to a predetermined angle, the switch opens, gun can't be fired. One example: https://www.digikey.com/product-highlights/us/en/ck-components-rolling-ball-tilt-switch/2291
Rolling ball tilt switches are a very poor option. they can only detect when the net acceleration vector is off angle from its installation to the point where the switch activates. the time lag will be the inertia of the ball. the intelligent (multi-axis accelerometers enable this) options for quadcopters/rc helicopters detect changes in the acceleration vector, run that signal through a control loop, and correct appropriately. the rolling ball will not do that. if you accelerate sideways, to the sensor that is the same as rolling to one side. it can not differentiate between a change in the gravity vector relative to the ship and a lateral acceleration. the net effect is that you will either false trigger or fail to trigger the switch depending on the boundary conditions.
Don't forget that a sailing ship will roll slower than more modern ships. The deep, weighted keel and all that sail aloft provides lots of momentum and drag to oppose any rolling forces. However far over the ship rolls, it will not be swaying rapidly back and forth. From what I've seen with mini-Constitution and mini-Victory, they tend to heel over and stay, until I trim the sails or turn the ship, or the wind changes. A few further thoughts. Mark has clearly described what I would consider the ideal stabilizing system. A mechanism that senses the roll of the ship, then adjusts the guns to maintain them at a constant down-angle relative to the horizon. The inherent safety in such a mechanism is clear, especially since the skipper still must pull the trigger to fire the cannons. I just want to put another point forward for consideration. So far, we have only discussed depressing cannons on the up-wind side of the boat, to keep them below the horizon. What do you guys think about allowing cannons on the down-wind side of the boat to elevate above parallel with the ship's deck, as long as they do not point above true horizon? My own thoughts are to keep it as an option, for now. The rules currently are not very specific about the entire topic this thread discusses, and I did that deliberately so we could experiment in the first few years. If auto-leveling mechanisms prove as successful and reliable as I hope, then there should be no problems with allowing cannons to elevate above parallel with the ship's deck, as long as they do not go above true horizontal.