The TSSP5038 library is used to read and calculate ball direction and strength. When you read a pin on the teensy digitally, it can read either HIGH or LOW (1 or 0). In the TSSP library, each TSSP is read 255 times to get a value between 0 and 255, 255 meaning the ball is read every single time, and 0 meaning that the ball isn't seen at all. However, if a TSSP is broken, it normally reads 255 (reading 255 is almost impossible, as it means that every time the sensor is read, it is seeing the ball). When a sensor is broken, a short-term fix is applied while the robot is running. The two sensors beside it are averaged to produce a value, which is then used in place of the broken reading. Clusters of broken TSSPs cannot be used and will need to be fixed from a hardware perspective.
With this 0-255 value that is given, each TSSP is ordered from highest reading to lowest reading. The 4 highest TSSPs are then taken, and are multiplied by their respective X and Y co-ordinates on the unit circle. With the x and y values, the arctan function can be used to find the angle at which the ball is. An example of this is seen below.
With the 0-255 values given by reading the sensors, the ball strength is calculated using a "weighted average". This is the largest TSSP reading x 3 + the 2nd largest TSSP reading x 2 + the 3rd largest TSSP reading + the 4th largest TSSP reading all divided by 7 (3+2+1+1 = 7). This allows us to get an average of the highest sensors on the robot.
Detection of the ball is determined by the strength value; if the ball strength does not equal 0, then the ball is most likely on the field.
The drive system is responsible for translating directional movement and rotation commands into specific speeds for each of the robot’s four motors. When the system is initialised, the relevant pins for motor control are set to output mode, preparing them to receive PWM signals for speed and digital signals for direction. During operation, the system receives a target movement speed, an angle, and an optional rotational correction. The angle is internally shifted to align with the robot’s orientation system, and for each motor, a calculation determines how much it should contribute to the desired direction. This is done by projecting the movement vector onto the motor’s relative orientation using a cosine function, then scaling it by the given speed and adding the rotation correction. After computing motor values, the system checks for any that exceed the maximum allowable PWM value of 255. If any do, all are scaled down proportionally to preserve movement accuracy. If debugging is enabled, the calculated values for each motor are printed to the serial monitor. Finally, each motor receives its speed through a PWM signal and is assigned a forward or reverse direction based on whether its calculated value is positive or negative. This system enables smooth, omnidirectional movement with integrated rotational control.
The battery reading library is used to measure the robot’s voltage at a specific moment. It works by performing an analog read on a pin connected to a voltage divider circuit. This provides an analog value corresponding to the voltage level. By applying a linear conversion function to this value, the actual voltage of the robot can be accurately calculated. This system also helps determine whether the motor switch is on or off—if the switch is off and not drawing power, the voltage reading will be significantly lower.
The Bluetooth library enables communication between two paired HC-05 Bluetooth modules. To establish this connection, the Arduino IDE is used to configure one module as the master and the other as the slave. Once paired, the robots transmit three key variables: logic state, ball strength, and ball direction. These values are then used to calculate switching logic, allowing the robots to coordinate their actions effectively.
The Camera library enables the camera to communicate with the teensy to tell it the position of the blue and yellow goals in pixels. In the python code for the open mv camera the find blobs function is used to find the center of blobs of both blue and yellow colour in the cameras view. This then allows us to use the positions x and y of the goal to get the angle using trig in order to angle the robot towards the goal.
The direction calculation library handles key components of our robot's orbit and speed determination. It uses the ball's direction and strength values as inputs for an exponential function designed to offset the robot’s movement direction. This offset helps position the robot behind the ball to enable effective pushing. The calculate speed function processes the ball strength and direction values to determine the appropriate movement speed. Typically, the robot accelerates faster when it is farther from the ball and slows down as it gets closer. However, when the ball is directly in front of the robot, it moves forward at maximum speed. This final condition is managed by the main control logic, not the direction library itself.
The light sensor library is used to detect the direction of a white line in order to avoid it. First, the pins are initialized. To calculate the direction, all sensors are read and checked against a white threshold, with the results stored in an array. The system then identifies clusters of adjacent sensors that detect white, calculates the center of each cluster, and averages these centers to determine the overall direction of the white line.
The timer library allows customisation of time intervals in microseconds, based on the specific instance created. This enables the use of effective timers within main.cpp for functions that require precise timing.