pantor / frankx

High-Level Motion Library for Collaborative Robots
https://pantor.github.io/frankx/
GNU Lesser General Public License v3.0
268 stars 65 forks source link

"cartesian_motion_generator_joint_acceleration_discontinuity" #51

Open bwunaver opened 1 year ago

bwunaver commented 1 year ago

When using async command, very often I run into this error: libfranka: Move command aborted: motion aborted by reflex! ["cartesian_motion_generator_joint_acceleration_discontinuity"] control_command_success_rate: 0.94

The first time this error appears, the robot can keep working after it appears, but when it happens more than twice, it blocks the robot.

Could you help me undersatnd why it is happening and how can I avoid it? Thank you very much!

Here is the test code, I am using the "robot-state" branch of the repo of Toni-SM:robot-state only for measuring the open-loop error:

from argparse import ArgumentParser
from frankx import Affine, Robot, WaypointMotion, Waypoint
import frankx
import time
import numpy as np
import numpy.linalg as LA

def get_robot_state(robot):
    # get robot state
    try:
        robot_state = robot.get_state(read_once=True)
    except frankx.InvalidOperationException:
        robot_state = robot.get_state(read_once=False)
    return np.array(robot_state.O_T_EE[-4:-1])

if __name__ == '__main__':
    parser = ArgumentParser()
    parser.add_argument('--host', default='172.16.0.2', help='FCI IP of the robot')
    args = parser.parse_args()

    robot = Robot(args.host)
    gripper = robot.get_gripper()

    robot.set_default_behavior()
    robot.recover_from_errors()
    robot.set_dynamic_rel(0.2)

    home = Waypoint(Affine(0.5, 0.0, 0.5), 1.65)
    motion = WaypointMotion([home], return_when_finished=False)
    thread = robot.move_async(motion)

    i = 0
    go_left = True
    last_time = time.time()
    while True:
        try:
            if i > 0.4:
                go_left = False
            if i < -0.4: 
                go_left = True
            if go_left:
                i += 0.01
            else:
                i -= 0.01
            print("y (cm): ", round(i*100))
            new_affine = Waypoint(Affine(0.5, i, 0.5), 1.65)

            # print("dt: ", time.time()-last_time)
            last_time = time.time()

            motion.set_next_waypoint(new_affine)

            # measure the open loop error
            cmd = np.array([0.5, i, 0.5])
            time.sleep(0.2) 
            meas = get_robot_state(robot)
            ol_error = LA.norm(cmd-meas)

            print("cmd :", cmd)
            print("meas:", meas)
            # print("ol_error:", ol_error)
            # print("vel:", robot.velocity_rel)
            # print("acc:", robot.acceleration_rel)
            # print("jer:", robot.jerk_rel)
        except KeyboardInterrupt:
            print("ctrl+c pressed")
            motion.finish()
            thread.join()
TimSchneider42 commented 7 months ago

Have you tried calling robot.recover_from_errors() continuously in the loop to ensure that the robot auto-recovers from errors?