pollen-robotics / reachy2-sdk

Reachy 2 Python SDK
https://www.pollen-robotics.com
Apache License 2.0
5 stars 0 forks source link

Bug with send_goal_positions on both arms #345

Closed glannuzel closed 3 months ago

glannuzel commented 3 months ago

When using something like "make_circle":

def go_to_pose(reachy: ReachySDK, pose: npt.NDArray[np.float64], arm: str) -> None:
    if arm == "r_arm":
        ik = reachy.r_arm.inverse_kinematics(pose)
        for joint, goal_pos in zip(reachy.r_arm.joints.values(), ik):
            joint.goal_position = goal_pos
    elif arm == "l_arm":
        ik = reachy.l_arm.inverse_kinematics(pose)
        for joint, goal_pos in zip(reachy.l_arm.joints.values(), ik):
            joint.goal_position = goal_pos
    reachy.send_goal_positions()

def make_circle(
    reachy: ReachySDK,
    center: npt.NDArray[np.float64],
    orientation: npt.NDArray[np.float64],
    radius: float,
    nbr_points: int = 100,
    number_of_turns: int = 3,
) -> None:
    Y_r = center[1] + radius * np.cos(np.linspace(0, 2 * np.pi, nbr_points))
    Z = center[2] + radius * np.sin(np.linspace(0, 2 * np.pi, nbr_points))
    X = center[0] * np.ones(nbr_points)
    Y_l = -center[1] + radius * np.cos(np.linspace(0, 2 * np.pi, nbr_points))

    for k in range(number_of_turns):
        for i in range(nbr_points):
            position = np.array([X[i], Y_r[i], Z[i]])
            rotation_matrix = R.from_euler("xyz", orientation).as_matrix()
            pose = make_homogenous_matrix_from_rotation_matrix(position, rotation_matrix)
            go_to_pose(reachy, pose, "r_arm")

            l_position = np.array([X[i], Y_l[i], Z[i]])
            l_rotation_matrix = R.from_euler("xyz", orientation).as_matrix()
            l_pose = make_homogenous_matrix_from_rotation_matrix(l_position, l_rotation_matrix)
            go_to_pose(reachy, l_pose, "l_arm")

            time.sleep(0.01)

r_arm has strong behavior. If we print goal positions and present positions, we even notice present_pos never move (but the robot is moving on rviz).