当前位置:网站首页>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;
}
边栏推荐
- [leetcode] 1905 statistics sub Island
- Bing. Com website
- [leetcode] 877 stone game
- College entrance examination admission score line climbing
- [experience cloud] how to get the metadata of experience cloud in vscode
- Steps for Navicat to create a new database
- [salesforce] how to confirm your salesforce version?
- Engineer evaluation | rk3568 development board hands-on test
- 《大学“电路分析基础”课程实验合集.实验五》丨线性有源二端网络等效电路的研究
- MySQL calculate n-day retention rate
猜你喜欢
Leetcode skimming - remove duplicate letters 316 medium
Leetcode skimming -- count the number of numbers with different numbers 357 medium
彻底弄懂浏览器强缓存和协商缓存
XPT2046 四线电阻式触摸屏
Finally, I understand the event loop, synchronous / asynchronous, micro task / macro task, and operation mechanism in JS (with test questions attached)
Bing. Com website
终于搞懂了JS中的事件循环,同步/异步,微任务/宏任务,运行机制(附笔试题)
NBA player analysis
Wechat Alipay account system and payment interface business process
Bing.com網站
随机推荐
/bin/ld: 找不到 -lgssapi_krb5
Moveit 避障路径规划 demo
How to intercept the value of a key from the JSON string returned by wechat?
Leetcode question brushing - parity linked list 328 medium
爱可可AI前沿推介(7.2)
4. Jctree related knowledge learning
【LeetCode】1905-统计子岛屿
locate: 无法执行 stat () `/var/lib/mlocate/mlocate.db‘: 没有那个文件或目录
【Leetcode】167-两数之和II -输入有序数组
动态规划入门二(5.647.62)
[leetcode] 417 - Pacific Atlantic current problem
解决BASE64Encoder报错的问题
folium,确诊和密接轨迹上图
【LeetCode】1162-地图分析
[leetcode] 167 - sum of two numbers II - enter an ordered array
Bing.com网站
【Salesforce】如何确认你的Salesforce版本?
NBA player analysis
[leetcode] 1140 stone game II
(4) Flink's table API and SQL table schema