Camera placement
Figuring out the best extrinsic settings for our cameras on the court.
- Stereo Vision
What I’m trying to achieve
The goal is to figure out the optimal placement of the cameras relative to the court (and each other) such that they can see the most area possible.
The assumptions are:
- We can mount the cameras as high or as low as we want.
- We can yaw, pitch and roll the cameras relative to each other and the court as much as we’d like.
- We have about 2.5 m of baseline behind the court to place our cameras.
- We can change the distance between the cameras as we wish.
Figure 1 below is an animated side view of what a clear looks like. We need to find a configuration of the cameras which captures the most of this arc, so that we get as much information about the trajectory of the birdie as possible.
Something we still don’t fully know is the best place to put the cameras: whether it’s on the robot side or the other player’s side is still up for debate. If it’s on the other player’s side, our best data happens closer to the camera. If it’s on the robot side, our best data happens when the trajectory is closer to its end.
Intuitively, I believe it’s better to have the cameras on the robot side, because we can use the frames from further away to give the robot a general guide on where to go, and then use the frames that are closer by for more precise motion as the birdie approaches. This remains to be confirmed. We’re going to assume that the cameras are on the robot side, facing downwards towards the other player.
As a reminder, clears take around 2.5 seconds to hit the ground, which means the robot has that much time to travel and intercept the birdie.
Quantifying performance
Given a trajectory, we want to optimise for the number of frames in which we can see the full thing.
We also need to make sure the camera can see every part of the floor that the robot can drive to (the 3 x 6 m section of the court). It should also be able to see the robot clearly enough so that it can localise it.
The field of view
Based on our camera specs for the BFS-U3-23S3C-C with our 8 mm lens, the FOV is 45.0° by 29.0°.
When we did calibration on our own, the FOV came out to be [44.9°, 29.0°]. 44.9° is the horizontal FOV, and 29.0° is the vertical FOV.
Here is the court area that we are interested in, for reference.
Naturally, since all we care about is a 3 x 6 m section, we are going to rotate the cameras, almost like you would rotate your phone from landscape to portrait when taking a picture of a person. We don’t want a wide FOV, we want a tall one.
Trajectories
Equation:
Using this equation for the acceleration of the birdie, which we got from this paper, we are going to run many trajectories with many different initial velocities, starting from one spot. We are forcing each of these trajectories to meet the constraints we described at the very start of this entry, as well as to cross the net. This way we have a workable set of trajectories.
To simplify things, we are making sure that we start the trajectories from the same spot on the “me” side.
Getting the trajectories in 3D
Here are the requirements for the trajectories explicitly:
- Must have a max height of 7 m or below.
- Must stay within the half courts in Figure 3, and land in the robot’s half (3.05 x 6.70 m).
- Starts from the same point.
- Must be above the net (1.55 m) when it crosses it.
Introducing the math
The court frame is as follows:
- across the width of the court
- up
- towards the net
See the figure below.
The birdie’s start point is always going to be either
We can write the initial velocity as a function of its magnitude (how hard it was hit), , and the angle pointing up from the ground and pointing right or left from the axis:
Equations of motion
Here are the equations of motion from above, written out for each axis:
where
And we can set or at .
Massaging the equations
Take the and equations:
This means that the motion stays in one plane.
Learn more
is the direction the birdie is heading along the floor. Think rise over run. If rise over run doesn’t change, the heading stays the same, meaning the motion is in one plane.
We can use this to our advantage and reduce three equations of motion into two. Let’s call a new variable the distance along the floor in the heading direction and the height.
is the birdie’s speed along the floor in the heading direction. This is equal to
and is how fast it is going up:
Let’s take a look at the equations of motion again. They’re describing accelerations, so let’s see what happens when we take the second derivative of and respectively.
For , since , its second derivative is just the equation:
For , we take the derivative of with the chain rule:
Simplify:
Then substitute and from the and equations:
Leaving us with (since ):
The magnitude of can also be written in terms of and :
Now we have simplified the three equations into two. We started with
and now all we have is
with the constraints
This means at any given moment, the birdie’s position is
We can use RK4 (like in our badminton bot prediction system in the repository) with a floor at to project the trajectory forward from the starting position.
Let’s introduce as the final distance along the floor, and as the peak height.
Enforcing requirements
Let’s go through each one step by step.
For max height, this one’s pretty obvious:
For the net, if the trajectory crossed the net, it would have reached a value of 6.70 m. Our starting position is 12.40 m in and the net is at 6.70 m, which means it’s 5.70 m away along . With an angle :
This isn’t a constraint. This is just giving us the value for . The actual constraint is that we check the height at is greater than or equal to the net:
For landing in the robot’s half, we have and from before, at the landing:
We limit and such that in they’re restricted to 0 and 3.05, and in they’re restricted to 0 and 6.70:
Computing the set
Here are the equations of motion that we created earlier:
Here are the constraints that they have to face:
There is also a constraint on .
From the diagram above, it should be easy to conclude that must be constrained to and if it is to stay within the zone:
Therefore,
The cameras
The camera baseline is constrained to
The yaw is mirrored:
They’re pitched the same amount , where tilts up:
The roll is either landscape or portrait:
We can choose any orientation for them relative to each other. With camera 1 at , camera 2 sits at
They can be offset forwards and backwards, which is the angle :
or placed stacked on top of each other, which is the angle :
And both cameras sit in the space behind the robot’s baseline:
Building the optimiser
Generating the trajectory set
A trajectory is set by choosing , , and the starting point ( or ). We want to limit the amount of times we’re using RK4 to forward project the trajectory, so we’re going to worry about ways we can simplify generating the set.
The following is a conversation I had with Claude about this. All the quotation blocks were Claude’s questions to me, and everything afterward was my answer.
Which of , , and the start point change the 2D flight , ? And which ones can we apply afterwards without flying again?
We can worry about and , and then sweep for for the ones that don’t fail.
and differ only in height, 2.6 m against 1.1 m. Look at the starting values for the flight: , or , , . Does the start point need its own flights, or can it be applied afterwards like ?
You need to have the start height to know the overall shape of the trajectory.
To check every later without flying again, what do we need to save from each flight?
. is how far along you travelled on the floor.
Does the peak height change with ?
No, it shouldn’t.
moves with : it’s 5.70 m at and grows to m at the widest heading. What do we need to save from a flight to check m for any in that range?
You look at whatever you had noted, and you say: did it clear the net on all of its distances, 5.70 to 5.90 m?
Claude then pushed back and said that all we care about is whether, at , it was greater than the height of the net. So all we do is save each trajectory’s height between 5.70 and 5.90 m, and then later, for every sweep across , we check if is greater than 1.55 m in that range.
With that, we’re ready to actually start coding this.
The script is in our repository at vision/analysis/trajectory_set.py.
After running the code, we were able to generate this table, which represents the amount of valid shots within the constraints we set. In another column, I’m also introducing the trajectories that land within 1 m of what we’re calling .
| Start | Valid (shot, ) pairs | Landing within 1 m of |
|---|---|---|
| , 2.6 m | 73,162 | 13,575 |
| , 1.1 m | 66,029 | 11,149 |
is where the robot is going to be placed on the court:
All in all, what we care about here are the 25,000 shots landing within the home zone.
Scoring a placement
First, we’re going to make sure that we only use the camera conditions which see the entire home zone.
We’re also only considering the trajectories that land within this home zone for now, and we’re going to optimise for the camera conditions within this subset which see the trajectories the most they can. For starters, we’re going to weigh every point along the trajectory the same.
Since some trajectories have more frames than others (they take longer to reach the ground), what we’re looking for is the average fraction.
One camera first
Searching every camera setting at once is about a billion placements, so what we’re going to do is look at one camera first, and then search a range of stereo cameras around that solution.
| Setting | Range |
|---|---|
| Height | 0.5 to 5 m, in 0.1 m steps |
| Distance behind the robot’s baseline | 0 to 2.5 m, in 0.25 m steps |
| Pitch | to , in 2° steps |
| Roll | landscape or portrait |
| Yaw | 0°, no need to sweep this since it’s just one camera |
Each placement is scored on a fifth of the shots that land in the home zone (4,945 shots). The script is vision/analysis/placement_one_cam.py.
How low the camera can go
You might have noticed I only started at 0.5 m. This is because we need to make sure the cameras have enough of an angle to be able to see the difference between the LEDs on the badminton robot. If the camera was at the same height as those LEDs, it would be difficult to tell depth apart (LEDs at the front would blend in with LEDs at the back of the robot).
Results
It turns out portrait was better than landscape every time. Here’s a heat map comparing camera height to distance behind the robot, where the colour represents the average fraction of each shot in view (not shown in the heat map is the pitch).
| Roll | Height | Distance behind the baseline | Pitch | Score |
|---|---|---|---|---|
| portrait | 0.50 m | 2.50 m | 0.999 | |
| portrait | 0.50 m | 2.25 m | 0.997 | |
| portrait | 0.70 m | 2.50 m | 0.997 | |
| portrait | 0.60 m | 2.50 m | 0.995 |
The best camera placement is portrait, 0.5 m high, 2.5 m behind the robot’s baseline, pitched up 16°. It sees 99.9% of the frames of each shot that lands in the home zone, on average. Many placements score close to 1, so we have a range of options.
Two cameras
Next, we run the two camera stage and find the complete orientation that gets the highest score. We’re going to restrict the baseline to a 1 m max for now, to make sure that the cables have enough room to reach the laptop. If we get better cables, we can do a bigger baseline.
| Setting | Range |
|---|---|
| Height of the rig centre | 0.5 to 1.5 m, in 0.1 m steps |
| Distance behind the robot’s baseline | 1.5 to 2.5 m, in 0.25 m steps |
| Baseline | 0.2 to 1 m, in 0.1 m steps |
| to , in 45° steps | |
| to , in 45° steps | |
| Yaw | 0° to 10° in 2° steps, and 15° |
| Pitch | 4° to 20°, in 2° steps |
| Roll | portrait (from the one camera results) |
Step sizes were a little more aggressive and constraints were a little more tight than I wanted them to be, in the interest of time.
Results
| Setting | Best |
|---|---|
| Height of the rig centre | 0.5 m |
| Distance behind the robot’s baseline | 2.5 m |
| Baseline | 1 m |
| 0° (side by side) | |
| 0° (level) | |
| Yaw | 2° |
| Pitch | |
| Roll | portrait |
| Score | 0.999 |
| Depth error | 34 mm |
These were other options that we had, but I’m just going to go with the 0.5 m one for now and see how well it does. We can adjust in the future.
| Height of the rig centre | Score | Depth error | Pitch |
|---|---|---|---|
| 0.5 m | 0.999 | 34 mm | |
| 0.6 m | 0.995 | 34 mm | |
| 0.7 m | 0.996 | 34 mm | |
| 0.8 m | 0.990 | 41 mm | |
| 0.9 m | 0.979 | 33 mm | |
| 1.0 m | 0.983 | 32 mm | |
| 1.2 m | 0.975 | 32 mm | |
| 1.5 m | 0.950 | 30 mm |
Driving questions
- What do I tell Steven to CAD up for the new mounts?
- How will I put the laptop on the mount so I can use my laptop as I get info?
Next
I’M TELLING STEVEN TO BUILD A MOUNT WITH THE FOLLOWING SPECS:
- Height: 0.5 m
- Baseline: 1 m
- Yawed inwards: 2°
- Pitched upwards: 16°
- Portrait
We’re now ready to go to the badminton court and do a full test of the stereo vision setup.