当前位置:网站首页>Moveit obstacle avoidance path planning demo
Moveit obstacle avoidance path planning demo
2022-07-02 15:44:00 【Chenjunhao】
#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();
// Create a scenario for motion planning , Wait for creation to complete
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");
// Barrier free movement
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";
// // The first obstacle
moveit_msgs::CollisionObject cylinder;
cylinder.header.frame_id = "base_link";
cylinder.id=id_1;
// Define the shape and size of the object
shape_msgs::SolidPrimitive primitive;
primitive.type=primitive.CYLINDER;
primitive.dimensions.resize(3); //dimensions It's a vector, Distribution for them 3 Element space
primitive.dimensions[0] =0.6; // Cylinder height
primitive.dimensions[1] =0.05; // radius
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);
// Define the operation as add
cylinder.operation = cylinder.ADD;
planning_scene.world.collision_objects.emplace_back(cylinder);
// The second obstacle
cylinder.header.frame_id = "base_link";
cylinder.id=id_2;
// Define the shape and size of the object
primitive.type=primitive.CYLINDER;
primitive.dimensions.resize(3); //dimensions It's a vector, Distribution for them 3 Element space
primitive.dimensions[0] =0.3; // Cylinder height
primitive.dimensions[1] =0.05; // radius
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);
// Release
planning_scene.is_diff = true;
planning_scene_diff_publisher.publish(planning_scene);
// Obstacle avoidance movement
joints={0.7,-1.57,0,0,0};
arm.setJointValueTarget(joints);
success = arm.plan(my_plan);
if(success) {
arm.execute(my_plan);
}
// Remove obstacles
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;
}
边栏推荐
猜你喜欢
Redux——详解
《大学“电路分析基础”课程实验合集.实验四》丨线性电路特性的研究
2022 college students in Liaoning Province mathematical modeling a, B, C questions (related papers and model program code online disk download)
SQL transaction
使用 percona 工具给 MySQL 表加字段中断后该如何操作
已知两种遍历序列构造二叉树
全是精华的模电专题复习资料:基本放大电路知识点
Pytoch saves tensor to Mat file
Soul torture, what is AQS???
MySQL calculate n-day retention rate
随机推荐
终于搞懂了JS中的事件循环,同步/异步,微任务/宏任务,运行机制(附笔试题)
目标检测—利用labelimg制作自己的深度学习目标检测数据集
【Salesforce】如何确认你的Salesforce版本?
[leetcode] 1020 number of enclaves
Folium, diagnosis and close contact trajectory above
树-二叉搜索树
College entrance examination admission score line climbing
[leetcode] 877 stone game
04. Some thoughts on enterprise application construction after entering cloud native
[leetcode] 417 - Pacific Atlantic current problem
2022 年辽宁省大学生数学建模A、B、C题(相关论文及模型程序代码网盘下载)
LeetCode刷题——奇偶链表#328#Medium
[leetcode] 1254 - count the number of closed Islands
《大学“电路分析基础”课程实验合集.实验四》丨线性电路特性的研究
/bin/ld: 找不到 -lgssapi_krb5
Soul torture, what is AQS???
【LeetCode】1905-统计子岛屿
[salesforce] how to confirm your salesforce version?
二叉树前,中,后序遍历
SQL transaction