I believe this is the equation you’d need:
v_0 = \sqrt{\frac{g \cdot x^2}{2 \cdot \cos^2(\theta) \cdot (x \cdot \tan(\theta) + h_0 - y)}}
x = Horizontal distance from the goal.
y = The height of the bean bag at X.
\theta (Theta) = The height of the bean bag when it leaves the catapult.
\theta = The launch angle (degrees)
v_0 = The initial speed of the bean bag. (launch Velocity
g = Gravity (9.81 \text{ m/s}^2 or 9810 \text{ mm/s}^2)
Basically what this equation does is once you input launch angle, distance from the goal, and how tall the goal is, it tells you how much speed/power needed to get the bean bag to the desired endpoint. Or in other words do you need to tighten or loosen the tensioner.
There are a couple of problems with using this though, first being it’s not the easiest equation to solve with block code to be fair I don’t even know where to begin solving this in blocks. Second, it would be very hard to calculate the speed of the bean bag on release and what you would have to do to get this equation to work is take the speed it tells you let’s say 4 m/s well then somehow you have to figure out how much tension you need to get the beanbag to that speed, which I wouldn’t even know where to start on that problem.
So, in short I probably wouldn’t go about trying to solve this with an equation instead I would use a lookup table. What I mean by that is you set the robot at a fixed position from the goal then see how much tension you need to use to get the beanbag to the desired endpoint, then move back and repeat the process keep repeating this process until you’ve collected a lot of data (the more the better). Now you might have a table something like this
| Distance from Goal |
Tension |
| 500 mm |
25% |
| 800 mm |
45% |
| 1000 mm |
55% |
| 1500 mm |
80% |
| 1800 mm |
100% |
What you can do this this table is in your code your robot knows how far away it is from the goal, let’s say 650 mm, well it knows its half way between 500mm and 800mm and so can calculate how much power to use in this example it would be 35%. This calculation is called Linear Interpolation and I believe you can use this equation
\text{Power} = \text{Power}_1 + (\text{Distance} - \text{Distance}_1) \cdot \left( \frac{\text{Power}_2 - \text{Power}_1}{\text{Distance}_2 - \text{Distance}_1} \right)
\text{Distance}_1, \text{Power}_1 = Your smaller test point (In that last example it would’ve been 500mm and 25%)
\text{Distance}_2, \text{Power}_2 = your bigger testing point (In that last example it would’ve been 800mm and 45%)
Distance = The actual distance from the goal. (In that last example it would’ve been 650mm)
Power = The output of the equation in our example it would’ve been 35% this is the number that really matters and how much you tension you should apply.
I hope this helped! I’m happy to explain anything further if need just lmk. Your idea of using the LED is really cool, good luck!