This is my first post on this website and my friends in robotics recommended it to me for math help, so my apologies if I have any of the formatting wrong or any other issues.
So my I have a barrel with a camera attached to it that shoots little rubber balls. However, if I aim directly at the target, bullet drop kicks in and I miss the shot. To account for that I need to aim a little higher, but the question is how much higher do I need to aim. I will explain my current calculations.
In this Image you can see all of my calculations
Shooter Diagram
Variables:
a = length of barrel
b = height of camera from barrel
depth = distance from camera/tip of barrel to the target parallel to the plane of the camera/tip of barrel
range = direct distance from camera to center of target
theta = angle between depth and range from camera
Dp = depth from pivot (depth plus barrel length)
rangep = range from pivot or direct distance from pivot to center of target
rho(denoted as p)= angle between depth and rangep of pivot
v = velocity (I shoot at around 30m/s)
Diffc = difference from depth and range at the end for the camera
Diffp = difference from depth and rangep at the end of the pivot
i = x component of distance from pivot to target
j = y component of distance from pivot to target
PhiF = the final angle we want
t = time
I first drew out the diagram and labeled everything so it would be more clear for me. Hopefully everything makes sense so far. I used all the basic variables that I have laid out to calculate the angle that I want to be aiming at.
I make an equation where i set t = time it takes in the x direction using PhiF and i set the full travel of the bullet in the y direction = vt + 1/2at^2. I plug stuff in there and solve. My final answer was arctan(c1) = PhiF. Obviously this is very wrong and I have tried to check my work and I have asked a lot of my seniors. I hope everything I have said makes sense, I can clarify anything, and if there are any other questions please feel free to ask! Thank you.
Let me start by suggesting that if you can dismount the camera from the barrel, that would make matters easier. Sites are placed on guns because the operators of those guns do not have the ability to make accurate measurements and calculations, and thus rely on other really complex skills to accomplish aiming. Your situation does have the ability to make accurate measurements and calculations, and does not have those other really complex skills.
The purpose of the camera (at least as far as this task is concerned) is solely to locate the target. And that is easiest if the camera doesn't have to move at all. If you can have a fixed camera that sees the entire field of play, then determining the direction of the target is an easy. And if you have some means of determining distance (e.g., by stereographic images from two cameras, or knowledge of the size and shape of the target that cam be exploited), then you can identify the target's exact position.
If the camera cannot see the entire field of play, then it would still be helpful if it could be mounted on its own pivot. Then you could be looking for additional targets while the gun is aiming for the first. If you use the same pivot, then you have to let the camera and gun take turns controlling the pivot: the camera to look for targets, then the gun to shoot at them. In any case, if you are pivoting the camera, the math is easier when both camera centerline and gun barrel align with their pivots. As you've drawn it, the barrel is aligned, but not the camera.
Once you know where the target is, finding the declination angle to hit it is straightforward, but messy. Establish a coordinate system with the gun pivot at the origin, the $y$-axis pointing downwards in the direction of gravity (since that is how you drew the picture), and the $x$-axis pointing towards the target. Let $(x_T, y_T)$ be the coordinates of the target center in this coordinate system (You called it $(i,j)$.) If $a$ is the length of the barrel (your picture seems to indicate the gun being longer than that, but your math treats $a$ as the total length), then the muzzle of the gun is at $(a\cos \phi, a\sin\phi)$. If $v_0$ is the muzzle speed, then the projectile leaves the gun with velocity $v_0\cos \phi$ in the $x$-direction, and $v_0\sin\phi$ in the $y$-direction. Assuming negligible air resistance, the path of the projectile with respect to time since fired is $$x = (a + tv_0)\cos \phi\\y = (a + tv_0)\sin \phi + \frac g2t^2$$
Solving the first for $t$ and plugging into the second yields an equation for $y$ in terms of $x$ for the points on the path of the projectile: $y = x\tan\phi + \frac g{2v_0^2}(x\sec \phi - a)^2$. In particular, when the gun is correctly aimed, $$y_T = x_T\tan\phi + \frac g{2v_0^2}(x_T\sec \phi - a)^2$$ Using $\sec \phi = \sqrt{1+\tan^2\phi}$ (which holds because $\phi$ is restricted to where $\cos$ and $\sec$ are non-negative), this transforms to
$$ \frac{v_0^2y_T}{gax_T}+\frac {a}{2x_T} + \frac{x_T}{2a} + \frac{x_T}{2a}\tan^2 \phi + \frac{v_0^2}{ga}\tan \phi = \sqrt{1 + \tan^2\phi}$$
If you square both sides, you get a quartic equation in $\tan\phi$ which can be solved to find values for $\tan\phi$, and therefore for $\phi$ itself.
At this point it is late, so I will leave it there for now, other than to say that it would probably be easier to solve the equation numerically rather than attempting Ferrari's equations. I'll try to add more tomorrow.