ROS MoveIt 控制机械臂速度的方法汇总


前言

MoveIt是一个专门针对机械臂操作的ROS软件,其对机械臂的运动规划方式包括关节空间规划,工作空间规划,和笛卡尔运动规划。

在一些机器人任务中,速度的快慢对于任务完成的质量至关重要,所以本文就来探讨这些规划方法的速度控制。

关节空间规划:以关节角度为控制量的机器人运动;
工作空间规划:通过机器人末端的位姿控制机器人运动(轨迹无约束);
笛卡尔运动规划:不仅控制机械臂的起始和终止位姿,还可控制运动过程中的位姿(如直线或圆弧)。


方法一:设置最大速度

对于关节空间规划工作空间规划方法,可以直接通过MoveIt的API设定允许的最大速度和加速度,以此来控制机械臂的速度。

关键API如下所示:

# 设置允许的最大速度和加速度
arm.set_max_acceleration_scaling_factor(0.5)
arm.set_max_velocity_scaling_factor(0.5)

需要指出的是这两个API对于笛卡尔运动规划的方法并不起作用,笛卡尔运动规划的速度控制参考下述方法

方法二:轨迹重定义

对于笛卡尔运动规划方法,我们可以对其规划完成的路径的属性进行设置,比如对其速度和加速度进行缩放。

此处给出对轨迹的速度和加速度进行比例缩放的Python函数,如下所示。C++函数可参考博客ROS moveit cartesian_demo 机械臂笛卡尔空间路径速度限制

轨迹重定义Python函数:

def scale_trajectory_speed(traj, scale):
       
       # Create a new trajectory object
       new_traj = RobotTrajectory()
       
       # Initialize the new trajectory to be the same as the input trajectory
       new_traj.joint_trajectory = traj.joint_trajectory
 
       # Get the number of joints involved
       n_joints = len(traj.joint_trajectory.joint_names)
       
       # Get the number of points on the trajectory
       n_points = len(traj.joint_trajectory.points)
        
       # Store the trajectory points
       points = list(traj.joint_trajectory.points)
       
       # Cycle through all points and joints and scale the time from start,
       # as well as joint speed and acceleration
       for i in range(n_points):
           
           point = JointTrajectoryPoint()
           
           # The joint positions are not scaled so pull them out first
           point.positions = traj.joint_trajectory.points[i].positions

           # Next, scale the time_from_start for this point
           point.time_from_start = traj.joint_trajectory.points[i].time_from_start / scale
           
           # Get the joint velocities for this point
           point.velocities = list(traj.joint_trajectory.points[i].velocities)
           
           # Get the joint accelerations for this point
           point.accelerations = list(traj.joint_trajectory.points[i].accelerations)
           
           # Scale the velocity and acceleration for each joint at this point
           for j in range(n_joints):
               point.velocities[j] = point.velocities[j] * scale
               point.accelerations[j] = point.accelerations[j] * scale * scale
        
           # Store the scaled trajectory point
           points[i] = point

       # Assign the modified points to the new trajectory
       new_traj.joint_trajectory.points = points

       # Return the new trajecotry
       return new_traj

当完成轨迹重定义之后就可以运行测试了。

# 用compute_cartesian_path函数得到笛卡尔规划的路径
(plan, fraction) = arm.compute_cartesian_path

# 使用我们上面定义的Python函数对路径进行重定义,然后运行
new_traj = scale_trajectory_speed(plan, 0.2)
arm.execute(new_traj)

方法三:参考Rviz中的函数

在Rviz的交互界面中,在笛卡尔运动规划方式下,仍然可以通过拖动速度和加速度线条来控制机械臂的速度和加速度。那么我们就可以用Rviz中的控制函数来实现相同的功能。

参考moveit_ros/visualization/motion_planning_rviz_plugin/src/motion_planning_frame_planning.cpp 文件,其中调用了iptp 的 computeTimeStamps 函数实现了速度和加速度的控制,类似的,我们也可以使用这个函数实现此功能。

具体代码参考博客使用moveit的运动规划接口不能进行速度设置的问题(2022.11.25更新解决方案)

方法四:修改配置文件的参数

MoveIt的全部配置文件放置在对应功能包的config文件夹下,这些配置文件中有很多.yaml的设置文件,其中就有用于机器人运动关节速度限制的配置文件,joint_limits,yaml文件,可以设置最大速度和最大加速度的数值。代码如下:

joint_limits:
  elbow_joint:
    has_velocity_limits: true
    max_velocity: 3.1415926535897931
    has_acceleration_limits: false
    max_acceleration: 0
  shoulder_lift_joint:
    has_velocity_limits: true
    max_velocity: 3.1415926535897931
    has_acceleration_limits: false
    max_acceleration: 0

如果在运动规划中机器人的运动速度较慢,可以修改该文件中的速度限位值,但是要重新启动move_group节点来完成参数的加载。


总结

本文总结了MoveIt在不同规划模式下的速度控制方法,尤其是对笛卡尔运动规划的速度控制给出了多种方法,供相关人员参考,在实际情况下可以根据便捷性和扩展性采用最合适的速度控制方法。

本文为个人观点,如有错误请指正,也可能还有其他方法,欢迎大家在评论区交流。

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

EAI-Robotics

赞赏是支持,更是共同成长的见证

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值