while time.time() - time_start < total_duration:
        contacts = pam_mujoco.get_contact("table")
        if contacts.contact_occured and not contact_detected:
            print("contact !")
            contact_detected = True
        time.sleep(0.05)

    # computing the distance between the 2 balls
    # getting all observations (i.e. history of ball states
    # as recorded by the o80 backend in the shared memory)
    observations_ball1 = frontend_ball1.get_observations_since(first_iteration)
    observations_ball2 = frontend_ball2.get_observations_since(first_iteration)
    distances = []
    for ball1, ball2 in zip(observations_ball1, observations_ball2):
        position1 = ball1.get_position()
        position2 = ball2.get_position()
        distance = math.sqrt(
            sum([(p1 - p2) ** 2 for p1, p2 in zip(position1, position2)])
        )
        distances.append(distance)
    # plotting the distance
    plt.plot(range(len(distances)), distances)
    plt.show()

    # resetting contacts
    pam_mujoco.reset_contact("table")

# stopping the mujoco thread
pam_mujoco.request_stop(mujoco_id)
process.join()
Exemple #2
0
        dof, target, o80.Duration_us.seconds(duration), o80.Mode.QUEUE
    )


# sending ball trajectory and robot motion
frontend_ball.pulse()
frontend_robot.pulse()

# bug ? during first iterations, contact are detected ...
time.sleep(1)

# reading shared memory for contact informations
time_start = time.time()
first_contact_racket = False
first_contact_table = False
while time.time() - time_start < duration:
    contacts_racket = pam_mujoco.get_contact("racket")
    if contacts_racket.contact_occured and not first_contact_racket:
        print("-- contact with racket")
        first_contact_racket = True
    contacts_table = pam_mujoco.get_contact("table")
    if contacts_table.contact_occured and not first_contact_table:
        print("-- contact with table")
        print("\tposition:", ",".join([str(a) for a in contacts_table.position]))
        first_contact_table = True
    time.sleep(0.1)

# stopping the mujoco thread
pam_mujoco.request_stop("mj")
process.join()