I have seen several people asking about how to shoot while moving and over the past day I’ve been thinking about it too. From what I’ve seen, most solutions appear to be predicting where the robot will be in the amount of time that it will take to shoot. I think the easier solution is to use vectors to calculate the necessary trajectory to shoot at. First, I’m making a few assumptions,
- no friction.
- the robot will be moving at a constant velocity.
- the shooter is capable of achieving any angle and speed and the note comes out of the same place no matter what angle the shooter is at.
- the robot is a swerve robot or has a turret
For all images I use, assume that the robot (specifically, the shooter) is the origin.
If the robot is not moving at all, shooting into the speaker is simple. rotate to the speaker and shoot at the right speed like this:
however, if the robot is moving, the robot velocity and the shooter’s velocity will add together to cause the note to land in the wrong spot like this:
If we think in vectors, you can fix this is to simply subtract the robot velocity from the simple calculated velocity and use that as the actual shooter velocity, like this:
Actually calculating the theoretical shooter velocity is fairly easy as long as you have the distance that the robot is from the speaker.
constants:
height difference between the shooter and speaker: heightDiff
diameter of the shooter wheels: wheelDiameter
If anyone has better math than this please post it. This is somewhat modified code from our cube shooting robot in 2023 so its def not perfect (+ I’m not sure if its even correct)