def timer_callback(self):
    ' Calculate Mx1, My1, ...... Mx6, My6 '
    Mx1 = (self.x2 - self.x1)
    My1 = (self.y2 - self.y1)
    Mx2 = (((self.x1 - self.x2) + (self.x3 - self.x2)) / 2)
    My2 = (((self.y1 - self.y2) + (self.y3 - self.y2)) / 2)
    Mx3 = (((self.x2 - self.x3) + (self.x4 - self.x3)) / 2)
    My3 = (((self.y2 - self.y3) + (self.y4 - self.y3)) / 2)
    Mx4 = (((self.x3 - self.x4) + (self.x5 - self.x4)) / 2)
    My4 = (((self.y4 - self.y4) + (self.y5 - self.y4)) / 2)
    Mx5 = (((self.x4 - self.x5) + (self.x6 - self.x5)) / 2)
    My5 = (((self.y4 - self.y5) + (self.y6 - self.y5)) / 2)
    Mx6 = (self.x5 - self.x6)
    My6 = (self.y5 - self.y6)
    ' Use MLP to Predict control inputs '
    relative_pose_1 = [Mx1, My1]
    relative_pose_2 = [Mx2, My2]
    relative_pose_3 = [Mx3, My3]
    relative_pose_4 = [Mx4, My4]
    relative_pose_5 = [Mx5, My5]
    relative_pose_6 = [Mx6, My6]
    u1_predicted = MLP_Model.predict(relative_pose_1, loaded_model)
    u2_predicted = MLP_Model.predict(relative_pose_2, loaded_model)
    u3_predicted = MLP_Model.predict(relative_pose_3, loaded_model)
    u4_predicted = MLP_Model.predict(relative_pose_4, loaded_model)
    u5_predicted = MLP_Model.predict(relative_pose_5, loaded_model)
    u6_predicted = MLP_Model.predict(relative_pose_6, loaded_model)
    u1_predicted_np = np.array([[u1_predicted[0][0]], [u1_predicted[0][1]]])
    u2_predicted_np = np.array([[u2_predicted[0][0]], [u2_predicted[0][1]]])
    u3_predicted_np = np.array([[u3_predicted[0][0]], [u3_predicted[0][1]]])
    u4_predicted_np = np.array([[u4_predicted[0][0]], [u4_predicted[0][1]]])
    u5_predicted_np = np.array([[u5_predicted[0][0]], [u5_predicted[0][1]]])
    u6_predicted_np = np.array([[u6_predicted[0][0]], [u6_predicted[0][1]]])
    ' Calculate V1/W1, V2/W2, V3/W3, V4/W4, V5/W5, V6/W6 '
    S1 = np.array([[self.v1], [self.w1]])
    G1 = np.array([[1, 0], [0, (1 / L)]])
    R1 = np.array([[math.cos(self.Theta1), math.sin(self.Theta1)], [(- math.sin(self.Theta1)), math.cos(self.Theta1)]])
    S1 = np.dot(np.dot(G1, R1), u1_predicted_np)
    S2 = np.array([[self.v2], [self.w2]])
    G2 = np.array([[1, 0], [0, (1 / L)]])
    R2 = np.array([[math.cos(self.Theta2), math.sin(self.Theta2)], [(- math.sin(self.Theta2)), math.cos(self.Theta2)]])
    S2 = np.dot(np.dot(G2, R2), u2_predicted_np)
    S3 = np.array([[self.v3], [self.w3]])
    G3 = np.array([[1, 0], [0, (1 / L)]])
    R3 = np.array([[math.cos(self.Theta3), math.sin(self.Theta3)], [(- math.sin(self.Theta3)), math.cos(self.Theta3)]])
    S3 = np.dot(np.dot(G3, R3), u3_predicted_np)
    S4 = np.array([[self.v4], [self.w4]])
    G4 = np.array([[1, 0], [0, (1 / L)]])
    R4 = np.array([[math.cos(self.Theta4), math.sin(self.Theta4)], [(- math.sin(self.Theta4)), math.cos(self.Theta4)]])
    S4 = np.dot(np.dot(G4, R4), u4_predicted_np)
    S5 = np.array([[self.v5], [self.w5]])
    G5 = np.array([[1, 0], [0, (1 / L)]])
    R5 = np.array([[math.cos(self.Theta5), math.sin(self.Theta5)], [(- math.sin(self.Theta5)), math.cos(self.Theta5)]])
    S5 = np.dot(np.dot(G5, R5), u5_predicted_np)
    S6 = np.array([[self.v6], [self.w6]])
    G6 = np.array([[1, 0], [0, (1 / L)]])
    R6 = np.array([[math.cos(self.Theta6), math.sin(self.Theta6)], [(- math.sin(self.Theta6)), math.cos(self.Theta6)]])
    S6 = np.dot(np.dot(G6, R6), u6_predicted_np)
    ' Calculate VL1/VR1, VL2/VR2, VL3/VR3, VL4/VR4, VL5/VR5, VL6/VR6 '
    D = np.array([[(1 / 2), (1 / 2)], [((- 1) / (2 * d)), (1 / (2 * d))]])
    Di = np.linalg.inv(D)
    Speed_L1 = np.array([[self.vL1], [self.vR1]])
    Speed_L2 = np.array([[self.vL2], [self.vR2]])
    Speed_L3 = np.array([[self.vL3], [self.vR3]])
    Speed_L4 = np.array([[self.vL4], [self.vR4]])
    Speed_L5 = np.array([[self.vL5], [self.vR5]])
    Speed_L6 = np.array([[self.vL6], [self.vR6]])
    M1 = np.array([[S1[0]], [S1[1]]]).reshape(2, 1)
    M2 = np.array([[S2[0]], [S2[1]]]).reshape(2, 1)
    M3 = np.array([[S3[0]], [S3[1]]]).reshape(2, 1)
    M4 = np.array([[S4[0]], [S4[1]]]).reshape(2, 1)
    M5 = np.array([[S5[0]], [S5[1]]]).reshape(2, 1)
    M6 = np.array([[S6[0]], [S6[1]]]).reshape(2, 1)
    Speed_L1 = np.dot(Di, M1)
    Speed_L2 = np.dot(Di, M2)
    Speed_L3 = np.dot(Di, M3)
    Speed_L4 = np.dot(Di, M4)
    Speed_L5 = np.dot(Di, M5)
    Speed_L6 = np.dot(Di, M6)
    VL1 = float(Speed_L1[0])
    VR1 = float(Speed_L1[1])
    VL2 = float(Speed_L2[0])
    VR2 = float(Speed_L2[1])
    VL3 = float(Speed_L3[0])
    VR3 = float(Speed_L3[1])
    VL4 = float(Speed_L4[0])
    VR4 = float(Speed_L4[1])
    VL5 = float(Speed_L5[0])
    VR5 = float(Speed_L5[1])
    VL6 = float(Speed_L6[0])
    VR6 = float(Speed_L6[1])
    ' Publish Speed Commands to Robot 1 '
    msgl1 = Float32()
    msgr1 = Float32()
    msgl1.data = VL1
    msgr1.data = VR1
    self.publisher_l1.publish(msgl1)
    self.publisher_r1.publish(msgr1)
    ' Publish Speed Commands to Robot 2 '
    msgl2 = Float32()
    msgr2 = Float32()
    msgl2.data = VL2
    msgr2.data = VR2
    self.publisher_l2.publish(msgl2)
    self.publisher_r2.publish(msgr2)
    ' Publish Speed Commands to Robot 3 '
    msgl3 = Float32()
    msgr3 = Float32()
    msgl3.data = VL3
    msgr3.data = VR3
    self.publisher_l3.publish(msgl3)
    self.publisher_r3.publish(msgr3)
    ' Publish Speed Commands to Robot 4 '
    msgl4 = Float32()
    msgr4 = Float32()
    msgl4.data = VL4
    msgr4.data = VR4
    self.publisher_l4.publish(msgl4)
    self.publisher_r4.publish(msgr4)
    ' Publish Speed Commands to Robot 5 '
    msgl5 = Float32()
    msgr5 = Float32()
    msgl5.data = VL5
    msgr5.data = VR5
    self.publisher_l5.publish(msgl5)
    self.publisher_r5.publish(msgr5)
    ' Publish Speed Commands to Robot 6 '
    msgl6 = Float32()
    msgr6 = Float32()
    msgl6.data = VL6
    msgr6.data = VR6
    self.publisher_l6.publish(msgl6)
    self.publisher_r6.publish(msgr6)
    self.i += 1
Calculate Mx1, My1, ...... Mx6, My6
def timer_callback(self):
    '  '
    Mx1 = (self.x2 - self.x1)
    My1 = (self.y2 - self.y1)
    Mx2 = (((self.x1 - self.x2) + (self.x3 - self.x2)) / 2)
    My2 = (((self.y1 - self.y2) + (self.y3 - self.y2)) / 2)
    Mx3 = (((self.x2 - self.x3) + (self.x4 - self.x3)) / 2)
    My3 = (((self.y2 - self.y3) + (self.y4 - self.y3)) / 2)
    Mx4 = (((self.x3 - self.x4) + (self.x5 - self.x4)) / 2)
    My4 = (((self.y4 - self.y4) + (self.y5 - self.y4)) / 2)
    Mx5 = (((self.x4 - self.x5) + (self.x6 - self.x5)) / 2)
    My5 = (((self.y4 - self.y5) + (self.y6 - self.y5)) / 2)
    Mx6 = (self.x5 - self.x6)
    My6 = (self.y5 - self.y6)
    ' Use MLP to Predict control inputs '
    relative_pose_1 = [Mx1, My1]
    relative_pose_2 = [Mx2, My2]
    relative_pose_3 = [Mx3, My3]
    relative_pose_4 = [Mx4, My4]
    relative_pose_5 = [Mx5, My5]
    relative_pose_6 = [Mx6, My6]
    u1_predicted = MLP_Model.predict(relative_pose_1, loaded_model)
    u2_predicted = MLP_Model.predict(relative_pose_2, loaded_model)
    u3_predicted = MLP_Model.predict(relative_pose_3, loaded_model)
    u4_predicted = MLP_Model.predict(relative_pose_4, loaded_model)
    u5_predicted = MLP_Model.predict(relative_pose_5, loaded_model)
    u6_predicted = MLP_Model.predict(relative_pose_6, loaded_model)
    u1_predicted_np = np.array([[u1_predicted[0][0]], [u1_predicted[0][1]]])
    u2_predicted_np = np.array([[u2_predicted[0][0]], [u2_predicted[0][1]]])
    u3_predicted_np = np.array([[u3_predicted[0][0]], [u3_predicted[0][1]]])
    u4_predicted_np = np.array([[u4_predicted[0][0]], [u4_predicted[0][1]]])
    u5_predicted_np = np.array([[u5_predicted[0][0]], [u5_predicted[0][1]]])
    u6_predicted_np = np.array([[u6_predicted[0][0]], [u6_predicted[0][1]]])
    ' Calculate V1/W1, V2/W2, V3/W3, V4/W4, V5/W5, V6/W6 '
    S1 = np.array([[self.v1], [self.w1]])
    G1 = np.array([[1, 0], [0, (1 / L)]])
    R1 = np.array([[math.cos(self.Theta1), math.sin(self.Theta1)], [(- math.sin(self.Theta1)), math.cos(self.Theta1)]])
    S1 = np.dot(np.dot(G1, R1), u1_predicted_np)
    S2 = np.array([[self.v2], [self.w2]])
    G2 = np.array([[1, 0], [0, (1 / L)]])
    R2 = np.array([[math.cos(self.Theta2), math.sin(self.Theta2)], [(- math.sin(self.Theta2)), math.cos(self.Theta2)]])
    S2 = np.dot(np.dot(G2, R2), u2_predicted_np)
    S3 = np.array([[self.v3], [self.w3]])
    G3 = np.array([[1, 0], [0, (1 / L)]])
    R3 = np.array([[math.cos(self.Theta3), math.sin(self.Theta3)], [(- math.sin(self.Theta3)), math.cos(self.Theta3)]])
    S3 = np.dot(np.dot(G3, R3), u3_predicted_np)
    S4 = np.array([[self.v4], [self.w4]])
    G4 = np.array([[1, 0], [0, (1 / L)]])
    R4 = np.array([[math.cos(self.Theta4), math.sin(self.Theta4)], [(- math.sin(self.Theta4)), math.cos(self.Theta4)]])
    S4 = np.dot(np.dot(G4, R4), u4_predicted_np)
    S5 = np.array([[self.v5], [self.w5]])
    G5 = np.array([[1, 0], [0, (1 / L)]])
    R5 = np.array([[math.cos(self.Theta5), math.sin(self.Theta5)], [(- math.sin(self.Theta5)), math.cos(self.Theta5)]])
    S5 = np.dot(np.dot(G5, R5), u5_predicted_np)
    S6 = np.array([[self.v6], [self.w6]])
    G6 = np.array([[1, 0], [0, (1 / L)]])
    R6 = np.array([[math.cos(self.Theta6), math.sin(self.Theta6)], [(- math.sin(self.Theta6)), math.cos(self.Theta6)]])
    S6 = np.dot(np.dot(G6, R6), u6_predicted_np)
    ' Calculate VL1/VR1, VL2/VR2, VL3/VR3, VL4/VR4, VL5/VR5, VL6/VR6 '
    D = np.array([[(1 / 2), (1 / 2)], [((- 1) / (2 * d)), (1 / (2 * d))]])
    Di = np.linalg.inv(D)
    Speed_L1 = np.array([[self.vL1], [self.vR1]])
    Speed_L2 = np.array([[self.vL2], [self.vR2]])
    Speed_L3 = np.array([[self.vL3], [self.vR3]])
    Speed_L4 = np.array([[self.vL4], [self.vR4]])
    Speed_L5 = np.array([[self.vL5], [self.vR5]])
    Speed_L6 = np.array([[self.vL6], [self.vR6]])
    M1 = np.array([[S1[0]], [S1[1]]]).reshape(2, 1)
    M2 = np.array([[S2[0]], [S2[1]]]).reshape(2, 1)
    M3 = np.array([[S3[0]], [S3[1]]]).reshape(2, 1)
    M4 = np.array([[S4[0]], [S4[1]]]).reshape(2, 1)
    M5 = np.array([[S5[0]], [S5[1]]]).reshape(2, 1)
    M6 = np.array([[S6[0]], [S6[1]]]).reshape(2, 1)
    Speed_L1 = np.dot(Di, M1)
    Speed_L2 = np.dot(Di, M2)
    Speed_L3 = np.dot(Di, M3)
    Speed_L4 = np.dot(Di, M4)
    Speed_L5 = np.dot(Di, M5)
    Speed_L6 = np.dot(Di, M6)
    VL1 = float(Speed_L1[0])
    VR1 = float(Speed_L1[1])
    VL2 = float(Speed_L2[0])
    VR2 = float(Speed_L2[1])
    VL3 = float(Speed_L3[0])
    VR3 = float(Speed_L3[1])
    VL4 = float(Speed_L4[0])
    VR4 = float(Speed_L4[1])
    VL5 = float(Speed_L5[0])
    VR5 = float(Speed_L5[1])
    VL6 = float(Speed_L6[0])
    VR6 = float(Speed_L6[1])
    ' Publish Speed Commands to Robot 1 '
    msgl1 = Float32()
    msgr1 = Float32()
    msgl1.data = VL1
    msgr1.data = VR1
    self.publisher_l1.publish(msgl1)
    self.publisher_r1.publish(msgr1)
    ' Publish Speed Commands to Robot 2 '
    msgl2 = Float32()
    msgr2 = Float32()
    msgl2.data = VL2
    msgr2.data = VR2
    self.publisher_l2.publish(msgl2)
    self.publisher_r2.publish(msgr2)
    ' Publish Speed Commands to Robot 3 '
    msgl3 = Float32()
    msgr3 = Float32()
    msgl3.data = VL3
    msgr3.data = VR3
    self.publisher_l3.publish(msgl3)
    self.publisher_r3.publish(msgr3)
    ' Publish Speed Commands to Robot 4 '
    msgl4 = Float32()
    msgr4 = Float32()
    msgl4.data = VL4
    msgr4.data = VR4
    self.publisher_l4.publish(msgl4)
    self.publisher_r4.publish(msgr4)
    ' Publish Speed Commands to Robot 5 '
    msgl5 = Float32()
    msgr5 = Float32()
    msgl5.data = VL5
    msgr5.data = VR5
    self.publisher_l5.publish(msgl5)
    self.publisher_r5.publish(msgr5)
    ' Publish Speed Commands to Robot 6 '
    msgl6 = Float32()
    msgr6 = Float32()
    msgl6.data = VL6
    msgr6.data = VR6
    self.publisher_l6.publish(msgl6)
    self.publisher_r6.publish(msgr6)
    self.i += 1