Ukázkové programy

Tyto příklady můžete otevřít přímo v Normálním režimu přes nabídku Příklady & Cvičení, spustit je a libovolně upravovat. Každý skript si vytváří vlastního klienta a vybírá svět.

Kloubové řízení

Nastavení cílových úhlů jednotlivých kloubů tak, aby robot rukou posunul míček.

def push_the_ball(client: pyCub) -> None:
    """
    Example function to push the ball from the table with joint control.

    :param client: instance of pyCub
    :type client: pyCub
    :return:
    :rtype:
    """
    """
    """

    # move torso pitch so the robot bends over the table
    client.move_position("torso_pitch", 0.325)

    # move torso to push the ball, but do now wait for completion. Hit it a bit faster
    client.move_position("torso_yaw", -0.7, wait=False, velocity=5)

    # wait manually
    while not client.motion_done():
        client.update_simulation()

    """
    Wait could be also achieved with:
    client.wait_motion_done()
    """

    client.logger.info("Moved the ball!")

Kartézské řízení

Posun koncového efektoru (ruky) v prostoru vzhledem k jeho aktuální pozici.

def push_the_ball(client: pyCub) -> None:
    """
    Example function to move the ball with cartesian control.

    :param client: instance of pyCub
    :type client: pyCub
    :return:
    :rtype:
    """

    # Get current pose
    cur_pose = client.end_effector.get_position()

    # Copy, the pose and go 15cm lower and 10cm closer to the robot
    new_pose = Pose(cur_pose.pos, cur_pose.ori)
    new_pose.pos[2] -= 0.15
    new_pose.pos[0] -= 0.1

    # move
    client.move_cartesian(new_pose)

    # get current pose
    pose = client.end_effector.get_position()

    # assign straight to it to move hand left
    pose.pos[1] -= 0.2

    # move; do not wait for completion; and move a bit faster
    client.move_cartesian(pose, wait=False, velocity=2)

    # wait manually
    while not client.motion_done():
        client.update_simulation()

    """
    Wait could be also achieved with:
    client.wait_motion_done()
    """

    client.logger.info("Moved the ball!")

Dotyková kůže

Svět skin_test.yaml ukazuje, které senzory na umělé kůži se aktivují při dopadu míčků na robota.

def main() -> NoReturn:
    """
    Main function to run the example

    :return:
    :rtype:
    """
    client = pyCub(config="skin_test.yaml")

    while client.is_alive():
        client.update_simulation(None)

Minimální smyčka simulace

Stáhněte si startovací skript a otevřete jej v Normálním režimu. Vlastní příkazy pro robota přidejte za vytvoření klienta.

from icub_pybullet.pycub import pyCub

if __name__ == "__main__":
    # Načtení robota se zvolenou konfigurací světa
    client = pyCub(config="with_ball.yaml")

    # Smyčka simulace běží, dokud není okno/proces ukončen
    while client.is_alive():
        client.update_simulation()