Instruction set which describes the most fundamental moves for our purposes.


Imported Libraries



TCP

extends null

Handles movement of TCP relevant to our purposes. Stores information describing the game environment and characteristics of pieces.

class TCP:
    def __init__(self, 
                 T[] host_info = [HOSTNAME, HOST_PORT], 
                 float[] origin = [ORIGIN_X, ORIGIN_Y],
                 float[] TCP_orientation = [TCP_RX, TCP_RY, TCP_RZ], 
                 float[] rest_position = REST_LOCATION,
                 float[] dispense_position = DISPENSE_LOCATION,
                 float height = BOARD_HEIGHT, 
                 float trns_angle = ANGLE):
        
        self.controller = rtde_control.RTDEControlInterface(host_info[0])       # TCP Controller
        self.origin = origin            # Origin of coordinate system
        self.trns_angle = trns_angle    # Angle which coordinate system is 'rotated' by
        self.host_info = host_info      # Host name and port
        
        # TCP State Variables
        self.position = origin              # (m)
        self.velocity = 0.5                 # (m/s)
        self.acceleration = 0.3             # (m/s^2)
        self.orientation = TCP_orientation  # (rad)
        self.isMagnetized = False

        # Board Variables
        self.height = height                        # Height of chess board when measured relative to cobot's base (m)
        self.rest_position = rest_position          # Position which TCP can come to rest at (m)
        self.dispense_position = dispense_position  # Position which TCP can dispence pieces at (m)

        f = open("data\\setup.json", encoding="utf-8")  
        self.board_data = json.load(f)                     # Location of each chess square in board's coordinate space

        self.piece_heights = {                             # Heights of each piece (m)
            "king" : 0.0762,                                  
            "pawn" : 0.0356,                                  
            "rook" : 0.04,                                    
            "knight" : 0.0457,                                  
            "bishop" : 0.0559,                                  
            "queen" : 0.0686                                   
        }

        # Initialization
        self.controller.moveL(                                                            # Moves to board's origin
            [self.origin[0], 
             self.origin[1], 
             self.height + 0.15,
             self.orientation[0],
             self.orientation[1],
             self.orientation[2]],
             0.5,
             0.3
        )
        sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        sock.connect((self.host_info[0], self.host_info[1]))
        sock.send(bytes("sec myProg():\\n\\tset_tool_voltage(0)\\nend\\nmyProg()\\n", "utf-8")) # Ensures magnet is off
        sock.close()
        sleep(0.2)
        

TCP.__translate()

Takes a position in the board's coordinate space, then translates it into the arm's coordinate space.

# Parameters
pos : float[]             # Position in board's coordinate space.

def __translate(self, pos):
        x_1 = pos[1] * math.cos(self.trns_angle) - pos[0] * math.sin(self.trns_angle)
        y_1 = pos[1] * math.sin(self.trns_angle) + pos[0] * math.cos(self.trns_angle)

        return [x_1 + self.origin[0], y_1 + self.origin[1]]

Mathematical Basis