当前位置:网站首页>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;
}
边栏推荐
- Leetcode skimming - remove duplicate letters 316 medium
- 03. Preliminary use of golang
- There are 7 seats with great variety, Wuling Jiachen has outstanding product power, large humanized space, and the key price is really fragrant
- MD5 encryption
- 使用FFmpeg命令行进行UDP、RTP推流(H264、TS),ffplay接收
- Cultural scores of summer college entrance examination
- 【idea】推荐一个idea翻译插件:Translation「建议收藏」
- Folium, diagnosis and close contact trajectory above
- Redux - detailed explanation
- Leetcode skimming -- verifying the preorder serialization of binary tree # 331 # medium
猜你喜欢

5. Practice: jctree implements the annotation processor at compile time

Yolo format data set processing (XML to txt)
![[network security] network asset collection](/img/3e/6665b5af0dedfcbc7bd548cc486878.png)
[network security] network asset collection

PTA ladder game exercise set l2-001 inter city emergency rescue

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

【LeetCode】1905-统计子岛屿

微信支付宝账户体系和支付接口业务流程

03. Preliminary use of golang

二叉树前,中,后序遍历
![[leetcode] 417 - Pacific Atlantic current problem](/img/30/c541bc1e81eb4e348ca11116a05e84.png)
[leetcode] 417 - Pacific Atlantic current problem
随机推荐
密码学基础知识
Build your own semantic segmentation platform deeplabv3+
[leetcode] 977 - carré du tableau ordonné
【Experience Cloud】如何在VsCode中取得Experience Cloud的MetaData
高考分数线爬取
彻底弄懂浏览器强缓存和协商缓存
[leetcode] 877 stone game
6096. 咒语和药水的成功对数
2279. 装满石头的背包的最大数量
Basic knowledge of cryptography
2278. 字母在字符串中的百分比
Equipped with Ti am62x processor, Feiling fet6254-c core board is launched!
5. Practice: jctree implements the annotation processor at compile time
/bin/ld: 找不到 -llz4
NBA player analysis
Party History Documentary theme public welfare digital cultural and creative products officially launched
党史纪实主题公益数字文创产品正式上线
制作p12证书[通俗易懂]
beforeEach
[leetcode] 1162 map analysis