

Solenoid Control
Beer Pong Sentinel Project Page
- Copper layers
- 2
- Thickness
- 1.6 mm
- Parts
- 17
- Nets
- 11
- Pads
- 40
- Tracks, vias
- 41, 0
- Pours
- 6
- Routed
- Yes
- KiCad
- KiCad 8.0 (file 20240108)
- Created
- 7 Mar 2025
- Updated
- 16 Apr 2025
Overview
Solenoid Control is an open-source printed circuit board by Beer-Pong-Sentinel, from the Beer-Pong-Sentinel/BeerPongSentinelMainframe repository on GitHub. It is a 2-layer board with 17 parts on 11 nets, routed with 41 tracks and 0 vias.
Its parts include 6 connectors, 5 resistors, 3 transistors, 1 diode and 1 switch.
README
README.mdBeer Pong Sentinel Project
This page contains a detailed description of the Beer Pong Sentinel project for the Engineering Physics capstone course at UBC.
Our Team
Background
The inspiration for this project came from an innocent university game - beer pong. We thought, “it would be pretty cool to build a robot that could intercept all of our opponent's shots”!
Although we've pivoted away from ping pong balls to the larger and more predictable tennis balls, our goal remains the same: to prevent a target from reaching a zone at the edge of a table using an interception system.
General Interception Process

The small animation shows the different high level stages our system has to take to intercept a ball.
First you see the general setup of our system, and it's different components. The remaining steps are as follows:
- our cameras detect a tennis ball in the air and triangulate its 3D location
- our cameras continue capturing frames until we have enough data to predict the target's trajectory
- we compute the predicted trajectory and based on our understanding of system latency, determine where along the trajectory to intercept the target
- we rotate our launcher in the altitude and azimuth directions
- we trigger the launcher to fire an interceptor at the right time
Error, Latency, Jitter, and Uncertainty

The last error we need to account for is the error in the prediction itself. This comes from the differences in actual ball trajectories vs the trajectory we predict for them. To measure this simply compare a trajectory of a ball from a video, to a predicted trajectory. Most of the work on this is done and can be found in (...).
Our estimates for all the errors are provided in the table below.
| Source | Symbol | Quantity | Units | Notes |
|---|---|---|---|---|
| Prediction | Ep | N/A | Need to collect data | |
| Integration | Ei | N/A | Need to collect data | |
| Cameras | Ec | 0.3-0.8 | Pixels | Result of camera's triangulation |
| Motors - Azimuth | Eθ,azi | 0.450 | Degrees | Manufacturer data |
| Motors - Altitude | Eθ,alti | 0.057 | Degrees | Manufacturer data |
| Pneumatic Mechanism | Eθ,s | 0.00485 | Radians | Maximum measured spread |
| Electromechanical Jitter | Et | 1.2 | milliseconds | Maximum measured jitter |
Note: The integration error Ei encapsulates the error in the cameras and the motors when trying to aim at a target after motor-calibration. It can be thought of as the shortest distance between a laser beam collinear with the launch barrel and a stationary target's centroid.
Note: Some values such as the integration error Ei are not calculated yet. Prediction is only theoretical as we did not fully integrate it.
Interception Timeline
To truly understand this project you will need to understand the timeline in which the system operate. This might take a few seconds (or a few months).
The important thing to note here that prediction is implemented assuming worst-case latency for all processes. This means that the only jitter that affects our interception error is the electromechanical jitter in our triggering mechanism as we always wait a constant amount of time before firing.

Electrical
Layout

Components
| Designation | Description | Part Number | Amount | Datasheet |
|---|---|---|---|---|
| CM | Blackfly S Camera | BFS-U3-04S2C-C | 2 | Teledyne |
| MAZ | Stepper Motor | CPM-SDSK-3421S-RLN | 1 | Teknic |
| MAL | SDK Motor | CPM-SCSK-3411S-ELNB | 1 | Teknic |
| PS1 | Motor Power Supply | IPC-5 | 1 | Teknic |
| PS2 | 24VDC Power Supply | SE-450-24 | 1 | Mouser |
| SC | Motor Control Hub | SC4-HUB | 1 | Teknic |
| SL | 12V Solenoid 42N | 10MM JF-1253B | 1 | Lee's Electronics |
| TC - N/A | Voltage regulator | LM7805 | 1 | Texas Instruments |
| TC - D2 | Diode | 1N4007 | 1 | Vishay |
| TC - Q1 | MOSFET | IRF540 | 1 | Vishay |
| TC - Q2/Q3 | BJT | 2N3904 | 2 | Onsemi |
Connections
| Designation | Description | Part Number | Amount | Link |
|---|---|---|---|---|
| MPC | Motors Power Cable | CPM-CABLE-PWR-MS120 | 2 | Teknic |
| MDC | Motors Data Cable | CPM-CABLE-CTRL-MU120 | 2 | Teknic |
| PSC | Power Supply Cable | IPC35-CABLE110 | 1 | Teknic |
| HR10 | Camera GPIO Cable | HR10A-7P-6S | 1 | Teledyne |
| C1 | USB-A to USB-B | 2 | ||
| C2 | Micro USB to USB-B/C | 2 | ||
| C3 | 2-pin Molex to Ring Connector | 2 | ||
| C4 | USB3 to Micro-B | 2 | ||
| SJ | Jumber Wire | 2 |
Solenoid Control Circuit
Note: The physical circuit in the current setup of the project is not the printed PCB, but a breadboard version without the option for a manual control and a 5V voltage regulator that steps down the 24V for the solenoid.
The full KiCAD design for the solenoid control PCB can be found inside sol_ctrl_pcb.

Mechanical
The original BB gun we got for this project is the Crosman R1 Full-Auto - Black.
The pneumatic mechanism requires two 12-gram Powerlet CO2 Cartridges.
This magazine uses 4.5mm copper pellets.
Safety
When testing or operating the BB gun pneumatic mechanism/especially in a closed room, make sure to wear face protection. The pellets are copper and tend to bounce around. This will happen after a while even if you have a cardboard stack target.
To learn more about safety and replacing gas cartridges: head to the safety folder and read about safety of operating the BB gun in testing locations and how to safely replace the gas cartridges for the pneumatic mechanism.
Launcher Modifications

The main rational behind modifying the original BB gun is to reduce the mass, size, and moment of inertia to allow up to actuate our launcher with ease. A larger, weirdly shaped, launcher would have required much more expensive motors and a more rigid design for the launcher mounts.
Launcher's Moment of Inertia
Calculating the moment of inertia for the launcher plays a key role in the design and motor selection.
The below figure shows our CAD model of the launcher with its mechanical parameters. The marker/arrows indicate the mounting location for the launcher.
The launcher's model was built by weighting its various components and recreating the rough or exact shapes of its components. The result parameter should be considered as a lower bound. We recommend using a factor of safety of 1.5 at least in any calculations that include these parameters.
Onshape link for the launcher model

Motor Selection
To select motors we ran simulations of motion profiles using both the inertia of our launcher and the rotor inertia of some promising motors. We simulate both a triangular motion profile, which assumes instant change from acceleration to de-acceleration, and a trapezoidal motion profile, which assumes equal time in acceleration, operation in max acceleration, and deceleration.
The model takes the following parameters:
object_inertia
motor_inertia
theta_target
time_window
safety_factorWe recommend being conservative with the safety factor to account for imperfections in tuning, inertia calculations, and motion profile control. An example of such triangular motion profile can be seen below.

Note:
Something we learned in the hard way is that the rotor inertia should match the inertia of the load it drives. This mostly affects tuning the motor. In the case it does not match, you might want to gear the motor. This is not ideal as it will cause a loss in resolution of the encoder, but will provide better tuning.
Our problem:
Specifically with the motors we are using we found out that our altitude motor (SDK controlled) does not allow to limit the velocity for tuning. This causes the motor to saturate in torque and to produce sub-optimal tuning. To mitigate this, we created a program in our software to map the time it take to move to an angle with a certain velocity limit. Creating a map of (velocity, angle) to (time taken). We can use this to find the optimal maximum velocity to use to minimize the time it takes to go to any given angle.
These profiles can be ran for any internal parameters you can change in the motor. We only found that you can change the Jerk and the "Fine-tuning" (how stiff/quite the motor moves) in our altitude (SDK controlled) motor.
Such motion profiles with different jerk control settings are shown below (the graphing script can be found at ./motors/Altitude Time Motion Profile Visualization.ipynb).

From this analysis, we determined that using no jerk control and a velocity limit of 20 RPM produces the optimal jerk and latency over our range of possible altitude angles.
Motor Tuning
Both motors need to to be tuned with ClearPath (azimuth) and ClearView (altitude). The tuning we are using can be found under the ./motors folder with the timestamp and description.
Important Last Minute Note: We found out that the calibration files are readable! That means that you can tune the motor by changing their parameters. A sub-project for this will be to make your own tuning program that will limit the velocity of the altitude motor and tune it well (though this is more Teknic's job).
Components
| Description | Part Number | Amount | Link |
|---|---|---|---|
| Timing Belt Pulley 1.500" OD, for 1/2" Shaft Diameter | 6495K752 | 2 | McMaster |
| Rotary Shaft 1/2" Diameter, 6" Long | 4149N15 | 1 | McMaster |
| Ball Bearing for 1/2" Shaft Diameter | 60355K173 | 3 | McMaster |
| Series Timing Belt | 6484K226 | 1 | McMaster |
| Dry-Running Nylon Sleeve Bearing Flanged, for 1/2" Shaft Diameter and 3/4" Housing ID, 7/16" Long | 6389K233 | 2 | McMaster |
| Carbon Steel Wide-Rim Ring, 0.048" Thick x 1/2" ID x 7/8" OD | 97669A200 | 1 (pack of 25) | McMaster |
Launcher Mount and Maneuvering
Click to open OnShape CAD model
Assembly
Firmware
The full firmware project can be found in the firmware folder. Our firmware runs on an Arduino Uno with the following pins connected.

Firmware Parameters
Solenoid Pulse Width:
Location: firmware
Variable: TRIGGERING_DELAY
Scale: Miliseconds
Current Settings: 75
Considerations:
- Time needs to be enough to allow for the solenoid to provide enough force to open the CO2 valve.
- Time should be too long as it wastes CO2.
Step Signal Pulse Width:
Location: firmware
Variable: AZI_DELAY
Scale: Microseconds
Current Settings: 100
Considerations:
- Minimum specification of motor control must be met
- Rise/fall time affect on the pulse
- Motor minimum control voltage is 5V
- Effect on motion profile; how steps in certain frequencies translate to different velocities
Note: Currently this sets both the pulse width and the frequency of pulses as the high time and low time are symmetric. This can be changed.
Azimuth Motor Settlement Range:
Location: ClearPath MSP
Access: Advanced -> High-Level Feedback (HLFB) Setup -> In-Range Position Window (ctns)
Current Settings: 1
Notes: Current HLFB Output setting is All System Go (ASG) - Position
Considerations:
- Azimuth motor has a smaller encoder resolution than altitude
- See altitude considerations
Azimuth Motor Settlement Delay:
Location: ClearPath MSP
Access: Advanced -> High-Level Feedback (HLFB) Setup -> Verify Time (ms)
Current Settings: 10.1
Notes: Current HLFB Output setting is All System Go (ASG) - Position
Considerations:
- Azimuth motor tuning runs better the altitute
- See altitude considerations
Altitude Motor Settlement Range:
Location: ClearView
Access: Details -> Move Status Indicators... -> In-Range Position Window (ctns)
Current Settings: 5
Considerations:
- We have some tolerance for error so we can settle within some range of the encoder ctns
- Moving faster might take priority.
Altitude Motor Settlement Delay:
Location: ClearView
Access: Details -> Move Status Indicators... -> Verify Time (msec)
Current Settings: 10.1
Considerations:
- Move done might given more than once if the launcher oscillates around a point.
- More delay means more latency before we can trigger.
Camera system
Camera's Parameters
The full camera parameters can be found under /simulations and data analysis/Camera Calculations.xlsx.
This provides the full details of all the intrinsic parameters of the BFS-U3-04S2C-C cameras we are using, inluding some that require calculations.

Intrinsic/Extrinsic Calibration

We use stereo calibration to to correct for lens distortions and determine the precise relative placement of two cameras. We use a printed chessboard pattern of known dimensions and take images at various positions and orientations. By analyzing these images, the calibration algorithm uses the known geometry of the chessboard to first estimate and correct each camera’s intrinsic parameters, “undistorting” the images. It then compares corresponding points in both camera views to determine the cameras’ relative positions and orientations. These calibration results, which include both the intrinsic corrections and the extrinsic parameters describing how the cameras are arranged, can be combined into a projection matrix that enables the reconstruction of a 3D point using an image from each camera.
You can find some calibration data under [./calibration data](https://github.com/Beer-Pong-Sentinel/BeerPongSentinelMainframe/tree/main/clibration data) . As long as the orientation of the two cameras with respect to each other does not change you might not need to re-calibrate. Note that under most new environments it is recommended to recalibrate.
Color Detection
Initially we tried to detect a static target (tennis ball) using conventional methods such as HSV/RGB thresholding. This turned out to be more challenging than we thought, as the camera resolution is only 720x540.
While colors seem green, or red, to us, it is very clear in processing that a tennis ball contains a lot of non-green content. To fix this we tried a few things:
- Putting a black curtain in the background to more easily see the green tennis ball
- Increasing the saturation on the cameras making most of the view look red, but making green more clear to distinguish
- We used clear, consistent lighting that does not flicker and turned off all the other light sources in the room.
In order to intercept the ball at some point along its trajectory, we need to triangulate its position across 3D space both quickly and accurately. However, to triangulate the position of the ball, we need to determine the pixel coordinates of the center of the ball for each image from our two cameras. Thus, we need a robust image processing pipeline that can efficiently and consistently retrieve the centroid of a ball from an image.
We constructed the Ball Detection pipeline to accomplish this task which works as follows:
- First, apply an HSV threshold to the image, which highlights only objects within a certain hue, saturation, and value range.
- Next, apply a MOG2 background subtraction to identify any moving objects in the image.
- Combine these two outputs in order to retrieve only moving objects which match the specified colors defined by the HSV range.
- Once combined, apply a dilation and erosion process to remove any noise. The final image should contain only highlighted pixels that match the position of the ball.
- Lastly, find the centroid of the highlighted pixels for both camera's and pass these values to the triangulation function to determine the position of the ball in 3D space.
To read more about HSV and RGB thresholding, see OpenCV's official documentation.
Yolo-OpenCV Object Detection
Eventually, we decided to use a deep neural network (DNN) for static ball detection. While our final goal is prediction of a moving target, we require this to be able to demo our camera-launcher calibration, and to be able to give an estimation of its error.
YOLO is an open source model for object detection. It is extremely easy to use and has very impressive performance. We are using YOLOv8, for compatibility and reliability.
Read more about YOLO in the official site.
To train our YOLO model we simply found a dataset that looked promising to us and worked well when we tested it online. We found a dataset with 4725 annotated images of tennis balls.
Training the model itself is straightforward and was done using a CLI.After training, we converted the trained model to ONNX format and loaded it into OpenCV’s DNN module, as C++ does not have a native YOLO library.
How to train a YOLO model
Read more about OpenCV DNN
From this point onwards, we also wanted to utilize a dedicated GPU to do our image processing as fast as possible. For this we had to build OpenCV with CUDA nodes for DNN.
You can find how to build OpenCV and CUDA here
Cameras-Launcher calibration
To convert from a predicted point in 3D space to motor positions for interception, we require launcher-camera calibration. We accomplished this using a look-up table, which is created as follows. After placing a large surface in front of the launcher and attaching a laser pointer collinear with the barrel, we can move to a number of motor positions and record the 3D location of the laser dot on the surface. After repeating the process with the same motor positions and a surface further away from the launcher, we can connect the dots to obtain a vector and origin for each motor position. Because this becomes a lengthy process when collecting data for a fine grid, we can instead interpolate to approximate the vectors and origins we would see if we collected more data.
The process of converting from 3D coordinates to motor positions then becomes simple: we compute the distance between the desired 3D coordinate and each vector in the interpolated dataset. Then, we can simply read off the motor positions for the shortest distance.

Ideally, the surfaces are placed such that the expected position of interception lies between them and that the angles swept over encompass all viable angles for interception. Having the surfaces further apart reduces uncertainty in the vector directions, although this means that surface size also has to increase.

The main advantage of this method over others is that it does not assume much from the system (such as that the launcher has spherical symmetry, the surfaces are flat, etc.), making it robust. The main disadvantage is the time required to do such a calibration, which has to be redone whenever the position of the cameras changes relative to the launcher or each other.
We did not have the time to collect extensive test data for this approach but we found that collecting a 20x20 grid of data with altitude angles from 0 to 15 degrees and azimuth angles from -15 to 15 degrees, interpolated to 60x60 grid of data, we were able to measure an average error of 37 millimetres from the center of the target from initial tests.
You can find a full simulation for this calibration that was done prior to implementing it under ./simulations and data analysis/Laser_Cal_Sim.ipynb to see how we came up with this idea for calibration, including some estimations for the error it might have.
Software - System Control and GUI
We developed a GUI using Qt in C++ to facilitate subsystem and integration testing. The full project for the software can be found under [./system control gui](https://github.com/Beer-Pong-Sentinel/BeerPongSentinelMainframe/blob/main/system control gui).
Dependencies
- Qt 6.8.0 or 6.8.3 (we used Qt Creator)
- Spinnaker SDK
- OpenCV Built with Nvidia DNN
- Teknic SDK
- Eigen C++
Programs
Motor Control
This section provides a simple interface for enabling, moving, and disabling the azimuth and altitude motors. This allows to user to make sure both motors are properly connected.
"Test Move Time" runs a script that iterates the altitude motor through a range of angles, repeating for a range of maximum velocities. The (angle, velocity limit, time) values are recorded in altitude_time_test_dat.csv within the Qt build folder.
Chessboard Calibration
This tab lets the user capture images to use for stereo calibration. We recommend taking 20-30 images where each corner of the chessboard is visible in both cameras. It is important that the camera feed on the left always corresponds to the camera physically on the left. If the cameras have not been moved relative to one another since another stereo calibration, the calibration can be loaded from a saved file.
Lookup Table Construction (Camera-Motor Calibration)
This tab is used to generate a lookup table for camera-motor calibration. To do this,
- Select the correct ports for the azimuth and altitude motors.
- Enable the motors and ensure that they can be moved.
- Place a surface some some distance away from the launcher.
- Insert a laser pointer collinear to the barrel.
- Set the upper and lower azimuth and altitude angles such that the laser points to the edge of the surface at those angles.
- With "Far Sweep" selected, press "Sweep", wait for the sweep to conclude, and check "Far Sweep Done".
- Move the surface closer to the launcher, and repeat the process for the near sweep.
- Press "Calculate Lookup" to generate the lookup table.
If the position of two cameras relative to each other and the launcher hasn't changed since the last calibration, the calibration can be loaded from a saved file.
Ball Detection (TODO)

Prediction
Prediction is one of the central tasks of our project. We know our trajectory is going to be approximately parabolic, which allows us to use classical physics to create a prediction for the trajectory of the ball.
The full work for the different methods of prediction we test can be found under ./simulation and data analysis/PredictionSimulation.ipynb Under the ./simulation and data analysis/data folder you can find data that we used for our trajectory simulation. This data can be extracted from our GUI. We used real data we captured from our full camera setup in order to compare the predicted trajectory to a real life trajectory.
Gravity Calibration
To be able to predict accurately, we cannot just assume that gravity points down in our camera coordinates. To produce a gravity vector, we simply take a few videos with our camera system of us letting go off a ball. We then process this data to find the gravity vector, and to estimate the value that we are observing for gravity. This provides much more accurate results than just assuming gravity is 9.8 m/s.
The code we use to estimate the gravity vector can be found under ./simulations and data analysis/GravityEstimation.ipynb.
Our System In Real Life
Launcher - Beerie

Integration Box
Our full integrated circuitry connects all components together through a single hub USB hub for a simple connection.
Labels and markers, with detailed diagrams, make setting up quick and simple.

Cameras Setup
Our cameras are situated high with each 22.5 degree angle offset from their mounting point. This is done to capture a large range of view. We use high-power halogen lights to make sure the target is well lit at all times. These lights do not flicker which helps with background subtraction.

Calibration Chessboard
Our 80cm x 60cm calibration chessboard is sandwiched between two acrylic plates, making it as flat as possible.

Aiming/Look up table calibration

Parts
17| Qty | Value | Footprint | References |
|---|---|---|---|
| 5 | R | Resistor_THT:R_Axial_DIN0207_L6.3mm_D2.5mm_P10.16mm_Horizontal | R1, R2, R3, R4, R5 |
| 2 | 2N3904 | Package_TO_SOT_THT:TO-92L | Q2, Q3 |
| 1 | 1N4007 | 1N4007:DIOAD1060W80L520D270 | D2 |
| 1 | 5V Vin | TerminalBlock_TE-Connectivity:TerminalBlock_TE_282834-2_1x02_P2.54mm_Horizontal | J6 |
| 1 | External_control | TerminalBlock_TE-Connectivity:TerminalBlock_TE_282834-2_1x02_P2.54mm_Horizontal | J5 |
| 1 | GND | TerminalBlock_TE-Connectivity:TerminalBlock_TE_282834-2_1x02_P2.54mm_Horizontal | J4 |
| 1 | Manual_Control_btn | TS02-66-50-BK-160-LCR-D:SW_TS02-66-50-BK-160-LCR-D | S1 |
| 1 | Manual_External_Switch | Button_Switch_THT:SW_Slide-03_Wuerth-WS-SLTV_10x2.5x6.4_P2.54mm | SW |
| 1 | NMOS | IRF540:TO254P1024X444X1989-3 | Q1 |
| 1 | Solenoid_- | TerminalBlock_TE-Connectivity:TerminalBlock_TE_282834-2_1x02_P2.54mm_Horizontal | J2 |
| 1 | Solenoind_+ | TerminalBlock_TE-Connectivity:TerminalBlock_TE_282834-2_1x02_P2.54mm_Horizontal | J1 |
| 1 | VCC | TerminalBlock_TE-Connectivity:TerminalBlock_TE_282834-2_1x02_P2.54mm_Horizontal | J3 |
Similar boards
- 2 layers50 × 35 mm

- 2 layers139.7 × 62.2 mm

- 2 layers29.2 × 55.9 mm

Deniseadapter
hoglet67/RGBtoHDMI
Bare-metal Raspberry Pi project that provides pixel-perfect sampling of Retro Computer RGB/YUV video and conversion to HDMI
17 parts1kGPL-3.0 - 2 layers24.5 × 36.5 mm

- 2 layers56.3 × 55.7 mm

StarNecklace
hackclub/OnBoard
💡 Join 1,000 teenagers and make your first PCB with a $100 grant!
17 parts915 - 2 layers25 × 25 mm

SmallEncoder
DDeGonge/OS-ARM
This arm is not industrial and it will not be fast, but that is not my goal. But it will hopefully be a very nice looking arm fully capable of 6dof motion, cheap enough to keep it accessable but capable enough to…
17 parts498MIT - 2 layers38.9 × 16.1 mm

- 2 layers36 × 51 mm

Questions
What parts does the Solenoid Control use?
17 parts. The full list of its parts is on this page, with links to each part's symbol and footprint where PCBKit's library has them.
Where can I download the Solenoid Control KiCad files?
From the Beer-Pong-Sentinel/BeerPongSentinelMainframe repository on GitHub, at the commit this page was made from: the board is solenoid control pcb/Solenoid Control.kicad_pcb and its schematic solenoid control pcb/Solenoid Control.kicad_sch. PCBKit opens the board in the browser, with nothing to install.
Can I use the Solenoid Control design in my own project?
Its repository states no licence, so its author keeps all rights: ask Beer-Pong-Sentinel before reusing the design.







