当前位置:网站首页>Moveit 避障路径规划 demo
Moveit 避障路径规划 demo
2022-07-02 12:20:00 【陈君豪】
#include <moveit/move_group_interface/move_group_interface.h>
#include <moveit/planning_scene_interface/planning_scene_interface.h>
#include <moveit_msgs/CollisionObject.h>
int main(int argc, char **argv)
{
ros::init(argc, argv, "full_demo");
ros::NodeHandle nh;
ros::AsyncSpinner spin(1);
spin.start();
// 创建运动规划的情景,等待创建完成
ros::Publisher planning_scene_diff_publisher = nh.advertise<moveit_msgs::PlanningScene>("planning_scene", 1);
ros::WallDuration sleep_t(0.5);
while (planning_scene_diff_publisher.getNumSubscribers() < 1)
{
sleep_t.sleep();
}
moveit::planning_interface::MoveGroupInterface arm("arm");
//无障碍的动作
std::vector<double> joints={0.7,-1.57,0,0,0};
arm.setJointValueTarget(joints);
moveit::planning_interface::MoveGroupInterface::Plan my_plan;
moveit::planning_interface::MoveItErrorCode success = arm.plan(my_plan);
if(success) {
arm.execute(my_plan);
}
joints={-0.7,-1.57,0,0,0};
arm.setJointValueTarget(joints);
success = arm.plan(my_plan);
if(success) {
arm.execute(my_plan);
}
moveit_msgs::PlanningScene planning_scene;
std::string id_1="1";
std::string id_2="2";
// // 第一个障碍物
moveit_msgs::CollisionObject cylinder;
cylinder.header.frame_id = "base_link";
cylinder.id=id_1;
//定义物体形状尺寸
shape_msgs::SolidPrimitive primitive;
primitive.type=primitive.CYLINDER;
primitive.dimensions.resize(3); //dimensions是一个vector,为其分配3个元素空间
primitive.dimensions[0] =0.6; //圆柱体高度
primitive.dimensions[1] =0.05; //半径
geometry_msgs::Pose pose;
pose.orientation.w =1.0;
pose.position.x=0;
pose.position.y=0.2;
pose.position.z=0;
cylinder.primitives.push_back(primitive);
cylinder.primitive_poses.push_back(pose);
//定义操作为添加
cylinder.operation = cylinder.ADD;
planning_scene.world.collision_objects.emplace_back(cylinder);
//第二个障碍物
cylinder.header.frame_id = "base_link";
cylinder.id=id_2;
//定义物体形状尺寸
primitive.type=primitive.CYLINDER;
primitive.dimensions.resize(3); //dimensions是一个vector,为其分配3个元素空间
primitive.dimensions[0] =0.3; //圆柱体高度
primitive.dimensions[1] =0.05; //半径
pose.orientation.w =1.0;
pose.position.x=-0.07;
pose.position.y=0.2;
pose.position.z=0;
cylinder.primitives.push_back(primitive);
cylinder.primitive_poses.push_back(pose);
cylinder.operation = cylinder.ADD;
planning_scene.world.collision_objects.emplace_back(cylinder);
//发布
planning_scene.is_diff = true;
planning_scene_diff_publisher.publish(planning_scene);
//避障运动
joints={0.7,-1.57,0,0,0};
arm.setJointValueTarget(joints);
success = arm.plan(my_plan);
if(success) {
arm.execute(my_plan);
}
//移除障碍物
moveit::planning_interface::PlanningSceneInterface current_scene;
std::vector<std::string> object_ids;
object_ids.emplace_back(id_1);
object_ids.emplace_back(id_2);
current_scene.removeCollisionObjects(object_ids);
while (ros::ok()){
}
return 0;
}
边栏推荐
- 睿智的目标检测23——Pytorch搭建SSD目标检测平台
- 02.面向容器化后,必须面对golang
- Thoroughly understand browser strong cache and negotiation cache
- [leetcode] 877 stone game
- 【LeetCode】486-预测赢家
- ssh/scp 使不提示 All activities are monitored and reported.
- 高考录取分数线爬取
- College entrance examination score line climbing
- Folium, diagnosis and close contact trajectory above
- Party History Documentary theme public welfare digital cultural and creative products officially launched
猜你喜欢

Leetcode skimming -- incremental ternary subsequence 334 medium

Leetcode question brushing - parity linked list 328 medium

Beijing rental data analysis

终于搞懂了JS中的事件循环,同步/异步,微任务/宏任务,运行机制(附笔试题)

Bing.com網站
![[leetcode] 1905 statistics sub Island](/img/82/d2f7b829f5beb7f9f1eabe8d101ecb.png)
[leetcode] 1905 statistics sub Island
![[experience cloud] how to get the metadata of experience cloud in vscode](/img/45/012c2265402ba1b44f4497f468bc61.png)
[experience cloud] how to get the metadata of experience cloud in vscode

怎样从微信返回的json字符串中截取某个key的值?

Leetcode skimming - remove duplicate letters 316 medium

LeetCode刷题——两整数之和#371#Medium
随机推荐
[leetcode] 977 square of ordered array
LeetCode刷题——递增的三元子序列#334#Medium
微信支付宝账户体系和支付接口业务流程
Yolo format data set processing (XML to txt)
[leetcode] 344 reverse string
04. Some thoughts on enterprise application construction after entering cloud native
/bin/ld: 找不到 -lxslt
【LeetCode】1254-统计封闭岛屿的数量
Redux - detailed explanation
02.面向容器化后,必须面对golang
Be a good gatekeeper on the road of anti epidemic -- infrared thermal imaging temperature detection system based on rk3568
Force deduction solution summarizes the lucky numbers in 1380 matrix
ssh/scp 使不提示 All activities are monitored and reported.
[leetcode] 695 - maximum area of the island
/bin/ld: 找不到 -lssl
Folium, diagnosis and close contact trajectory above
floyed「建议收藏」
6092. 替换数组中的元素
高考分数线爬取
PTA 天梯赛习题集 L2-001 城市间紧急救援