UniversalRobots / Universal_Robots_ROS2_Driver

Universal Robots ROS2 driver supporting CB3 and e-Series
BSD 3-Clause "New" or "Revised" License
400 stars 209 forks source link

Delay in execution #1007

Closed kokkalisko closed 3 months ago

kokkalisko commented 4 months ago

Affected ROS2 Driver version(s)

2.1.2

Used ROS distribution.

Galactic

Which combination of platform is the ROS driver running on.

Ubuntu Linux with realtime patch

How is the UR ROS2 Driver installed.

From binary packets

Which robot platform is the driver connected to.

UR E-series robot

Robot SW / URSim version(s)

URSim 5.15.0 and real robot 5.14.5

How is the ROS driver used.

Through the robot teach pendant using External Control URCap

Issue details

Summary

I am trying to achieve precise synchronization of a UR5e robot with a moving conveyor to pick up objects. Either using URSim or the actual robot and MoveIt2 there is significant time difference (25 up to 100ms) between the plan and the actual execution.

Issue details

I have tried to minimize this delay making multiple changes:

For reference, there are a couple of things that have reduce drastically the delay:

Steps to Reproduce

1) Launch URSim (you can also test it with the real robot and change the robot IP) 2) ros2 launch ur_bringup ur5e.launch.py robot_ip:=127.0.0.1 use_fake_hardware:=false launch_rviz:=false 3) ros2 launch ur_moveit_config ur_moveit.launch.py ur_type:=ur5e 4) Create a C++ node performing motions and time them using something along these lines: Positions: [0,0,0,0,0,3M_PI_22], [0,0,0,0,0,-3M_PI_22]

    moveit_msgs::msg::RobotTrajectory trajectory_msg;
    moveit::planning_interface::MoveGroupInterface::Plan plan;

    moveInterfacePtr->setStartStateToCurrentState();
    moveInterfacePtr->setJointValueTarget(firstPosition);

    moveInterfacePtr->plan(plan);
    trajectory_msg = plan.trajectory_;

    double executionTime = rclcpp::Duration(trajectory_msg.joint_trajectory.points.back().time_from_start).seconds();
    RCLCPP_DEBUG_STREAM(this->get_logger(), "The move should last: " << executionTime);

    auto start = this->get_clock()->now();
    moveInterfacePtr->execute(trajectory_msg);
    auto end = this->get_clock()->now();
    rclcpp::Duration diff = end - start;
    RCLCPP_INFO_STREAM(this->get_logger(), "Execution lasted " << diff.seconds() << " seconds");
    RCLCPP_INFO_STREAM(this->get_logger(), "Time difference is " << (diff.seconds() - executionTime)*1000 << " milliseconds");

    ////////////////////////////

    moveInterfacePtr->setStartStateToCurrentState();
    moveInterfacePtr->setJointValueTarget(secondPosition);

    moveInterfacePtr->plan(plan);
    trajectory_msg = plan.trajectory_;

    executionTime = rclcpp::Duration(trajectory_msg.joint_trajectory.points.back().time_from_start).seconds();
    RCLCPP_DEBUG_STREAM(this->get_logger(), "The move should last: " << executionTime);

    start = this->get_clock()->now();
    moveInterfacePtr->execute(trajectory_msg);
    end = this->get_clock()->now();
    diff = end - start;
    RCLCPP_INFO_STREAM(this->get_logger(), "Execution lasted " << diff.seconds() << " seconds");
    RCLCPP_INFO_STREAM(this->get_logger(), "Time difference is " << (diff.seconds() - executionTime)*1000 << " milliseconds");

Expected Behavior

The motion should last as much as predicted by the plan (up to a small time difference).

Actual Behavior

The log similar to this:

    [simple_move-2] [INFO] [1716557813.182926855] [move_group_interface]: MoveGroup action client/server ready
    [simple_move-2] [INFO] [1716557813.183367335] [move_group_interface]: Planning request accepted
    [simple_move-2] [INFO] [1716557813.191581977] [move_group_interface]: Planning request complete!
    [simple_move-2] [INFO] [1716557813.283252330] [move_group_interface]: time taken to generate plan: 7.9301e-05 seconds
    [simple_move-2] [INFO] [1716557813.283328532] [static_pipeline_scenario]: Computed a plan successfully
    [simple_move-2] [INFO] [1716557813.283809924] [move_group_interface]: Execute request accepted
    [simple_move-2] [INFO] [1716557815.251111738] [move_group_interface]: Execute request success!
    [simple_move-2] [INFO] [1716557815.284803171] [static_pipeline_scenario]: Execution lasted 2.00142 seconds
    [simple_move-2] [INFO] [1716557815.284831580] [static_pipeline_scenario]: Time difference is 51.1607 milliseconds

scaled_joint_trajectory_controller_acc

Relevant log output

No response

Accept Public visibility

fmauch commented 3 months ago

Thanks for sharing your thought with us.

I have a couple of remarks:

kokkalisko commented 3 months ago

Just an update:

At this point, I strongly think that this is not related to the UR driver (maybe related to the controllers) and I will close the issue. In case I ever come up with a solution I will update it.