Kinovarobotics / ros_kortex

ROS packages for KINOVA® KORTEX™ robotic arms
Other
168 stars 162 forks source link

How to set the speed when I use the service ExecuteAction? #322

Closed DravenALG closed 6 months ago

DravenALG commented 6 months ago

I am now doing a project that wants to set the speed of the Kinova arm with Python (like using the gamepad to increase the speed of translation and orientation).

I have tried two ways but they did not work. I cannot see any changes of the speed, and I need some helps.

The first one I tried is the way that uses constrained pose like the code in the example:

def send_cartesian_pose(self, pose):
    """
    pose: pose in robot base coordination
    """
    self.last_action_notif_type = None
    req = ExecuteActionRequest()

    x, y, z = pose[0], pose[1], pose[2]
    theta_x, theta_y, theta_z = (
        pose[3] / math.pi * 180.0,
        pose[4] / math.pi * 180.0,
        pose[5] / math.pi * 180.0,
    )
    speed = pose[6]

    my_cartesian_speed = CartesianSpeed()
    my_cartesian_speed.translation = 0.5
    my_cartesian_speed.orientation = 180

    my_constrained_pose = ConstrainedPose()
    my_constrained_pose.constraint.oneof_type.speed.append(my_cartesian_speed)

    my_constrained_pose.target_pose.x = x
    my_constrained_pose.target_pose.y = y
    my_constrained_pose.target_pose.z = z
    my_constrained_pose.target_pose.theta_x = theta_x
    my_constrained_pose.target_pose.theta_y = theta_y
    my_constrained_pose.target_pose.theta_z = theta_z

    req.input.oneof_action_parameters.reach_pose.append(my_constrained_pose)
    req.input.name = "pose" + str(self.identifier)
    req.input.handle.action_type = ActionType.REACH_POSE
    req.input.handle.identifier = self.identifier

    try:
        self.execute_action_srv(req)
        self.identifier = self.identifier + 1
    except rospy.ServiceException:
        rospy.logerr("Failed to call CartesianPose")
        return False

and the second way is using the waypoints with Base_JointSpeeds:

def send_cartesian_pose(self, pose):
    """
    pose: pose in robot base coordination
    """
    self.last_action_notif_type = None
    req = ExecuteActionRequest()
    trajectory = WaypointList()

    x, y, z = pose[0], pose[1], pose[2]
    theta_x, theta_y, theta_z = (
        pose[3] / math.pi * 180.0,
        pose[4] / math.pi * 180.0,
        pose[5] / math.pi * 180.0,
    )
    speed = pose[6]

    trajectory.waypoints.append(
        self.FillCartesianWaypoint(x, y, z, theta_x, theta_y, theta_z, 0)
    )
    trajectory.duration = 0
    trajectory.use_optimal_blending = False
    req.input.oneof_action_parameters.execute_waypoint_list.append(trajectory)

    # set the speed
    base_joint_speeds_list = []
    base_joint_speeds = Base_JointSpeeds()
    for i in range(7):
        joint_speed = JointSpeed()
        joint_speed.joint_identifier = i
        joint_speed.value = speed
        base_joint_speeds.joint_speeds.append(joint_speed)
    base_joint_speeds_list.append(base_joint_speeds)
    req.input.oneof_action_parameters.send_joint_speeds = base_joint_speeds_list
    rospy.loginfo("Setting the grasp speed")

    try:
        self.execute_action_srv(req)
    except rospy.ServiceException:
        rospy.logerr("Failed to call ExecuteWaypointTrajectory")
        return False
DravenALG commented 6 months ago

My problem. I have set the speed limit in the Web and it works.

martinleroux commented 6 months ago

You are correct, the speed limit can be set in the web app.