我是靠谱客的博主 糟糕流沙,这篇文章主要介绍moveit!- moveit!接口编程流程:,现在分享给大家,希望可以做个参考。

moveit!

简书链接

moveit::planning_interface

moveit::planning_interface链接

https://www.guyuehome.com/435

学习笔记整理(古月居视频、书、博客)

moveit编程接口

- moveit!接口编程流程:

  • 连接控制器需要的规划组;
  • 设置目标位姿(关节空间或笛卡尔空间);
  • 设置运动约束(可选)(工作空间,关节姿态);
  • 使用moveit!规划一条达到目标的轨迹;
  • 修改轨迹(如速度等参数);
  • 执行绘画出的轨迹;

官方API:

官方API介绍

1. 关节空间规划(正向运动求解):

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#include <ros/ros.h> #include <moveit/move_group_interface/move_group_interface.h> int main(int argc, char **argv) { ros::init(argc, argv, "moveit_fk_demo"); ros::AsyncSpinner spinner(1); spinner.start(); moveit::planning_interface::MoveGroupInterface arm("manipulator"); arm.setGoalJointTolerance(0.001); arm.setMaxAccelerationScalingFactor(0.2); arm.setMaxVelocityScalingFactor(0.2); // 控制机械臂先回到初始化位置 arm.setNamedTarget("home"); arm.move(); sleep(1); double targetPose[6] = {0.391410, -0.676384, -0.376217, 0.0, 1.052834, 0.454125}; std::vector<double> joint_group_positions(6); joint_group_positions[0] = targetPose[0]; joint_group_positions[1] = targetPose[1]; joint_group_positions[2] = targetPose[2]; joint_group_positions[3] = targetPose[3]; joint_group_positions[4] = targetPose[4]; joint_group_positions[5] = targetPose[5]; arm.setJointValueTarget(joint_group_positions); arm.move(); sleep(1); // 控制机械臂先回到初始化位置 arm.setNamedTarget("home"); arm.move(); sleep(1) ros::shutdown(); return 0; }

2 . 工作空间规划(逆向运动求解):

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#include <string> #include <ros/ros.h> #include <moveit/move_group_interface/move_group_interface.h> int main(int argc, char **argv) { ros::init(argc, argv, "moveit_fk_demo"); ros::AsyncSpinner spinner(1); spinner.start(); moveit::planning_interface::MoveGroupInterface arm("manipulator"); //获取终端link的名称 std::string end_effector_link = arm.getEndEffectorLink(); //设置目标位置所使用的参考坐标系 std::string reference_frame = "base_link"; arm.setPoseReferenceFrame(reference_frame); //当运动规划失败后,允许重新规划 arm.allowReplanning(true); //设置位置(单位:米)和姿态(单位:弧度)的允许误差 arm.setGoalPositionTolerance(0.001); arm.setGoalOrientationTolerance(0.01); //设置允许的最大速度和加速度 arm.setMaxAccelerationScalingFactor(0.2); arm.setMaxVelocityScalingFactor(0.2); // 控制机械臂先回到初始化位置 arm.setNamedTarget("home"); arm.move(); sleep(1); // 设置机器人终端的目标位置 geometry_msgs::Pose target_pose; target_pose.orientation.x = 0.70692; target_pose.orientation.y = 0.0; target_pose.orientation.z = 0.0; target_pose.orientation.w = 0.70729; target_pose.position.x = 0.2593; target_pose.position.y = 0.0636; target_pose.position.z = 0.1787; // 设置机器臂当前的状态作为运动初始状态 arm.setStartStateToCurrentState(); arm.setPoseTarget(target_pose); // 进行运动规划,计算机器人移动到目标的运动轨迹,此时只是计算出轨迹,并不会控制机械臂运动 moveit::planning_interface::MoveGroupInterface::Plan plan; moveit::planning_interface::MoveItErrorCode success = arm.plan(plan); ROS_INFO("Plan (pose goal) %s",success?"":"FAILED"); //让机械臂按照规划的轨迹开始运动。 if(success) arm.execute(plan); sleep(1); // 控制机械臂先回到初始化位置 arm.setNamedTarget("home"); arm.move(); sleep(1); ros::shutdown(); return 0; }

3.笛卡尔空间规划:

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#include <ros/ros.h> #include <moveit/move_group_interface/move_group_interface.h> #include <moveit/robot_trajectory/robot_trajectory.h> int main(int argc, char **argv) { ros::init(argc, argv, "moveit_cartesian_demo"); ros::AsyncSpinner spinner(1); spinner.start(); moveit::planning_interface::MoveGroupInterface arm("manipulator"); //获取终端link的名称 std::string end_effector_link = arm.getEndEffectorLink(); //设置目标位置所使用的参考坐标系 std::string reference_frame = "base_link"; arm.setPoseReferenceFrame(reference_frame); //当运动规划失败后,允许重新规划 arm.allowReplanning(true); //设置位置(单位:米)和姿态(单位:弧度)的允许误差 arm.setGoalPositionTolerance(0.001); arm.setGoalOrientationTolerance(0.01); //设置允许的最大速度和加速度 arm.setMaxAccelerationScalingFactor(0.2); arm.setMaxVelocityScalingFactor(0.2); // 控制机械臂先回到初始化位置 arm.setNamedTarget("home"); arm.move(); sleep(1); // 获取当前位姿数据最为机械臂运动的起始位姿 geometry_msgs::Pose start_pose = arm.getCurrentPose(end_effector_link).pose; std::vector<geometry_msgs::Pose> waypoints; //将初始位姿加入路点列表 waypoints.push_back(start_pose); start_pose.position.z -= 0.2; waypoints.push_back(start_pose); start_pose.position.x += 0.1; waypoints.push_back(start_pose); start_pose.position.y += 0.1; waypoints.push_back(start_pose); // 笛卡尔空间下的路径规划 moveit_msgs::RobotTrajectory trajectory; const double jump_threshold = 0.0; const double eef_step = 0.01; double fraction = 0.0; int maxtries = 100; //最大尝试规划次数 int attempts = 0; //已经尝试规划次数 while(fraction < 1.0 && attempts < maxtries) { fraction = arm.computeCartesianPath(waypoints, eef_step, jump_threshold, trajectory); attempts++; if(attempts % 10 == 0) ROS_INFO("Still trying after %d attempts...", attempts); } if(fraction == 1) { ROS_INFO("Path computed successfully. Moving the arm."); // 生成机械臂的运动规划数据 moveit::planning_interface::MoveGroupInterface::Plan plan; plan.trajectory_ = trajectory; // 执行运动 arm.execute(plan); sleep(1); } else { ROS_INFO("Path planning failed with only %0.6f success after %d attempts.", fraction, maxtries); } // 控制机械臂先回到初始化位置 arm.setNamedTarget("home"); arm.move(); sleep(1); ros::shutdown(); return 0; }

约束

约束工作边界

复制代码
1
2
3
4
5
req.workspace_parameters.min_corner.x = req.workspace_parameters.min_corner.y = req.workspace_parameters.min_corner.z = -2.0; req.workspace_parameters.max_corner.x = req.workspace_parameters.max_corner.y = req.workspace_parameters.max_corner.z = 2.0;

关节约束

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
/* Let's create a new pose goal */ pose.pose.position.x = 0.32; pose.pose.position.y = -0.25; pose.pose.position.z = 0.65; pose.pose.orientation.w = 1.0; moveit_msgs::Constraints pose_goal_2 = kinematic_constraints::constructGoalConstraints("panda_link8", pose, tolerance_pose, tolerance_angle); /* Now, let's try to move to this new pose goal*/ req.goal_constraints.clear(); req.goal_constraints.push_back(pose_goal_2); /* 对关节施加约束 Here, we are asking for the end-effector to stay level*/ geometry_msgs::QuaternionStamped quaternion; quaternion.header.frame_id = "panda_link0"; quaternion.quaternion.w = 1.0; req.path_constraints = kinematic_constraints::constructGoalConstraints("panda_link8", quaternion);

场景避障

古月居博客碰撞检测链接
在场景中生成障碍物

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
// 包含API的头文件 #include <moveit/move_group_interface/move_group.h> #include <moveit/planning_scene_interface/planning_scene_interface.h> #include <moveit_msgs/AttachedCollisionObject.h> #include <moveit_msgs/CollisionObject.h> int main(int argc, char **argv) { ros::init(argc, argv, "add_collision_objct"); ros::NodeHandle nh; ros::AsyncSpinner spin(1); spin.start(); // 创建运动规划的情景,等待创建完成 moveit::planning_interface::PlanningSceneInterface current_scene; sleep(5.0); // 声明一个障碍物的实例,并且为其设置一个id,方便对其进行操作,该实例会发布到当前的情景实例中 moveit_msgs::CollisionObject cylinder; cylinder.id = "seven_dof_arm_cylinder"; // 设置障碍物的外形、尺寸等属性 shape_msgs::SolidPrimitive primitive; primitive.type = primitive.CYLINDER; primitive.dimensions.resize(3); primitive.dimensions[0] = 0.6; primitive.dimensions[1] = 0.2; // 设置障碍物的位置 geometry_msgs::Pose pose; pose.orientation.w = 1.0; pose.position.x = 0.0; pose.position.y = -0.4; pose.position.z = 0.4; // 将障碍物的属性、位置加入到障碍物的实例中 cylinder.primitives.push_back(primitive); cylinder.primitive_poses.push_back(pose); cylinder.operation = cylinder.ADD; // 创建一个障碍物的列表,把之前创建的障碍物实例加入其中 std::vector<moveit_msgs::CollisionObject> collision_objects; collision_objects.push_back(cylinder); // 所有障碍物加入列表后(这里只有一个障碍物),再把障碍物加入到当前的情景中,如果要删除障碍物,使用removeCollisionObjects(collision_objects) current_scene.addCollisionObjects(collision_objects); ros::shutdown(); return 0; }

最后

以上就是糟糕流沙最近收集整理的关于moveit!- moveit!接口编程流程:的全部内容,更多相关moveit!-内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(61)

评论列表共有 0 条评论

立即
投稿
返回
顶部