Skip to main content

Automated Turret

November 2025

GitHub Repository

Introduction

My eighth major course at USNA was EW450 (Introduction to Robotic Systems). The course covered modeling and analysis of articulated robots, including robot configurations, workcell layout, reachable and dexterous workspaces, forward and inverse kinematics, and Jacobians, as well as introductory concepts in computer vision and camera modeling.

The final project was to program a UR3e robotic arm to autonomously play the game Tic-tac-Toe.

Tic Tac Toe Robot Andrew Bernas

Demo Video

Design Documentation

The integration of artificial intelligence with robotic manipulation represents a fundamental cornerstone of modern automation. This project explores that intersection by developing a system in which a UR3e robot autonomously plays Tic-Tac-Toe against a human opponent.

Developed as the final project for EW450 (Introduction to Robotic Systems), this system demonstrates the application of articulated robot modeling, forward and inverse kinematics, workcell layout, and computer vision. The UR3e, a six-axis robotic arm, serves as the physical agent, tasked with perceiving the game state, computing the optimal move, and physically executing that move by manipulating game pieces on a board.

To achieve this, the software architecture combines three distinct subsystems:

  • Computer Vision: To detect the board state and human moves.
  • Game Logic: Utilizing the Minimax algorithm to ensure the robot plays optimally.
  • Motion Control: Utilizing Inverse Kinematics to translate board coordinates into precise joint movements.

This report details the design and implementation of these subsystems, analyzing the mathematical foundations and software logic that allow the UR3e to function as an intelligent, autonomous adversary.

Computer Vision

Located above the robotic arm is a calibrated monocular camera used to recognize the game board and game pieces. The system relies on AprilTags (family: tag36h11) for robust fiducial marker detection.

Board and Piece Detection

The board is recognized via two AprilTags (ID: 450 and 460, Size: 29mm). The program detects the board pose if it can see either tag; if both are visible, it averages the board's center pose. The specific position of each grid cell relative to these tags is described in figure below.

Board Andrew Bernas

The system identifies game pieces using unique AprilTags (Size: 25.0mm).

  • Red "X" Pieces: IDs 461–465
  • Blue "O" Pieces: IDs 451–455
Piece Andrew Bernas

The program updates the board and piece poses at a rate of 2Hz. To update the game state, the system calculates the Euclidean distance between the center of a detected piece and the center of a grid cell; the cell is considered filled if this distance is minimized for a specific piece.

Game Logic

To ensure the robot competes effectively, the decision-making engine is built upon the Minimax algorithm. This is a recursive backtracking algorithm widely used in decision theory and game theory for zero-sum games—games where one player's gain is equivalent to the other's loss.

In this context, the robot acts as the Maximizer, seeking to maximize its score, while the human opponent is modeled as the Minimizer, seeking to minimize the robot's score.

Algorithm Execution

The algorithm simulates the game by constructing a Game Tree, exploring all possible future moves from the current state down to the terminal states.

  1. State Evaluation: Terminal states are assigned numerical values:
    • +10: Robot wins.
    • -10: Human wins.
    • 0: Draw.
  2. Backtracking: Values are propagated up the tree. At each layer, the Maximizer chooses the move leading to the highest value, while the Minimizer (simulating optimal human play) chooses the move leading to the lowest value.
  3. Optimality: By assuming the human will always play the best possible move, the robot ensures it selects a strategy that minimizes the maximum possible loss. This guarantees the robot will never lose if it plays first and will force a draw or win if the human makes a mistake.

Motion Control

While the Minimax algorithm determines the target location in Cartesian space (x,y,zx, y, z), the UR3e requires joint angles (θ1,,θ6\theta_1, \dots, \theta_6) to reach that position. This mapping is achieved through Inverse Kinematics (IK), which calculates the specific angle θ\theta for each of the robot's six joints required to reach a desired pose.

For reference, Figure 1 displays the UR3e manipulator's 6 joint poses.

Arm Andrew Bernas

Figure 1: UR3e manipulator joint poses

Assumptions and Constraints

Solving the IK problem is non-trivial due to non-linear mapping and multiple possible solutions (e.g., "elbow up" vs. "elbow down"). The derivation is performed under the following assumptions:

  1. Downward Facing End-Effector: The z-axis of the end-effector opposes the base z-axis:
Z^60=Z^00=[001]\hat{Z}_{6}^{0} = -\hat{Z}_{0}^{0} = \begin{bmatrix} 0 & 0 & -1 \end{bmatrix}^{\top}
  1. Wrist Constraint: This orientation requires the fifth joint to be fixed at θ5=π2\theta_{5}^{*} = -\frac{\pi}{2}.
  2. Task Variables: The target is defined by position and gripper orientation ϕ\phi.

Geometric Derivation

The joint angles are derived using a geometric decomposition of the manipulator.

Step 1: Base Rotation (θ1\theta_1)

Figure 2 displays the Top-Down view of the robotic arm used to derive the base angle.

Top Down 1 Andrew Bernas

Figure 2: Top-Down view of the robotic arm

Based on the geometry shown in Figure 3, we define intermediate variables to solve for the base rotation.

Top Down 2 Andrew Bernas

Figure 3: Derivation of equations 1-4

a1=ya_1 = -y
(1)
b1=xb_1 = -x
(2)
c1=(a1)2+(b1)2c_1 = \sqrt{(a_1)^2 + (b_1)^2} \quad
(3)
α1=atan2(a1,b1)\alpha_1 = \operatorname{atan2}(a_1, b_1) \quad
(4)

Figure 4 displays how equations (5)–(7) are derived to account for the offset l4l_4.

Top Down 3 Andrew Bernas

Figure 4: Derivation of equations 5-7

a2=l4a_2 = l_4 \quad
(5)
b2=(c1)2(a2)2b_2 = \sqrt{(c_1)^2 - (a_2)^2} \quad
(6)
α2=atan2(a2,b2)\alpha_2 = \operatorname{atan2}(a_2, b_2) \quad
(7)

The angle for the base joint is then calculated as:

θ1=α1α2\theta_1^* = \alpha_1 - \alpha_2 \quad
(8)

Step 2: Shoulder and Elbow (θ2,θ3\theta_2, \theta_3) To determine the link lengths in the planar view, we refer to Figure 5.

Top Down 4 Andrew Bernas

Figure 5: Derivation of equation 9

c3=b2l5c_3 = b_2 - l_5 \quad
(9)

Figure 6 displays the Plane of the Manipulator view used for the subsequent calculations.

Plane 5 Andrew Bernas

Figure 6: Plane of the Manipulator view

As shown in Figure 7, we define the vertical and hypotenuse components for the target reach.

Plane 1 Andrew Bernas

Figure 7: Derivation of equations 10-12

a4=(z+l6)l1a_4 = (z + l_6) - l_1 \quad
(10)
c4=(c3)2+(a4)2c_4 = \sqrt{(c_3)^2 + (a_4)^2} \quad
(11)
α4=atan2(a4,c3)\alpha_4 = \operatorname{atan2}(a_4, c_3) \quad
(12)

Using the Law of Cosines as derived in Figure 8, we solve for the internal angles of the arm triangle.

Plane 2 Andrew Bernas

Figure 8: Derivation of equations 13-16

b5=l2b_5 = l_2 \quad
(13)
a5=l3a_5 = l_3 \quad
(14)
α5=arccos((b5)2+(c4)2(a5)22b5c4)\alpha_5 = \arccos\left(\frac{(b_5)^2 + (c_4)^2 - (a_5)^2}{2 b_5 c_4}\right) \quad
(15)
γ5=arccos((a5)2+(b5)2(c4)22a5b5)\gamma_5 = \arccos\left(\frac{(a_5)^2 + (b_5)^2 - (c_4)^2}{2 a_5 b_5}\right) \quad
(16)

Figure 9 displays how Joint angles 2 and 3 are derived from these components.

Plane 3 Andrew Bernas

Figure 9: Derivation of Joint angles 2 and 3

The system uses the Elbow-Up solution:

θ2=(α4+α5)\theta_2^* = -(\alpha_4 + \alpha_5) \quad
(17)
θ3=πγ5\theta_3^* = \pi - \gamma_5 \quad
(18)

Note: An Elbow-Down solution is also mathematically possible but was not required for the robot.

Step 3: Wrist Orientation (θ4,θ6\theta_4, \theta_6) Figure 10 displays how joint angle 4 is derived to maintain the downward orientation.

Plane 4 Andrew Bernas

Figure 10: Derivation of joint angle 4

θ4=(θ2+θ3+π2)\theta_4^* = -(\theta_2^* + \theta_3^* + \frac{\pi}{2}) \quad
(19)

Finally, Figure 11 displays how joint angle 6 is derived to control the gripper rotation.

Top 5 Andrew Bernas

Figure 11: Derivation of joint angle 6

θ6=π2+θ1ϕ\theta_6^* = \frac{\pi}{2} + \theta_1^* - \phi \quad
(20)

With equations (8), (17), (18), (19), and (20), the system can calculate the required joint angles to reach any reachable pose.

System Integration

With a method to extract piece poses, strategize moves, and control the robot to a desired position, we can put it all together into a fully autonomous system. The program starts by asking the player what piece type they want to play with and who wants to start first.

The robot plays against the player in a continuous loop:

  1. Update Board Status: Extract the board pose and piece poses.
  2. Determine Move: If it is the robot's turn, it uses the Minimax algorithm to determine the best move.
  3. Execute Pick-and-Place:
    • The system finds a piece of the correct type that is not on the board.
    • It uses the detected piece pose and Inverse Kinematics to calculating the joint angles required to pick up the piece.
    • It then uses Inverse Kinematics to place the grabbed piece onto the grid cell aligned with the best move.

This process repeats until the game is determined to be a draw or a winner is determined.

Conclusion

This project successfully demonstrated the capability of the UR3e robotic arm to function as an autonomous agent in a structured game environment. By effectively synthesizing computer vision for state estimation, the Minimax algorithm for strategic decision-making, and geometric inverse kinematics for precise motion control, the system achieved robust gameplay against human opponents.

The implementation of the Minimax algorithm ensured that the robot never lost a match when playing first, validating the effectiveness of the game logic. Furthermore, the geometric IK solver proved computationally efficient and accurate, allowing for smooth pick-and-place operations within the robot's workspace. Overall, the system serves as a comprehensive proof-of-concept for human-robot interaction and autonomous manipulation tasks.