C++ 版

#include #include #include int main(int argc, char **argv)

{

ros::init(argc, argv, "magician_moveit_cartesian_demo");

ros::AsyncSpinner spinner(1);

spinner.start();

moveit::planning_interface::MoveGroupInterface arm("magician_arm");

//获取终端link的名称

std::string end_effector_link = arm.getEndEffectorLink();

//设置目标位置所使用的参考坐标系

std::string reference_frame = "magician_origin";

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::vectorwaypoints;

//将初始位姿加入路点列表

waypoints.push_back(start_pose);

start_pose.position.z -= 0.093;

waypoints.push_back(start_pose);

start_pose.position.x += 0.04;

waypoints.push_back(start_pose);

start_pose.position.y += 0.04;

waypoints.push_back(start_pose);

start_pose.position.x -= 0.04;

start_pose.position.y -= 0.04;

waypoints.push_back(start_pose);

// 笛卡尔空间下的路径规划

moveit_msgs::RobotTrajectory trajectory;

const double jump_threshold = 0.0;

const double eef_step = 0.005;

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;

}

#include #include #include int main(int argc, char **argv)

{

ros::init(argc, argv, "magician_moveit_cartesian_demo");

ros::AsyncSpinner spinner(1);

spinner.start();

moveit::planning_interface::MoveGroupInterface arm("magician_arm");

//获取终端link的名称

std::string end_effector_link = arm.getEndEffectorLink();

//设置目标位置所使用的参考坐标系

std::string reference_frame = "magician_origin";

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::vectorwaypoints;

//将初始位姿加入路点列表

waypoints.push_back(start_pose);

geometry_msgs::Pose pose1;

geometry_msgs::Pose pose2;

pose1.position.x = 0.1659;

pose1.position.y = 0.0000;

pose1.position.z = -0.027;

pose1.orientation.x = 0.0;

pose1.orientation.y = 0.0;

pose1.orientation.z = 0.0;

pose1.orientation.w = 1.0;

waypoints.push_back(pose1);

pose2.position.x = 0.200;

pose2.position.y = 0.048;

pose2.position.z = -0.027;

pose2.orientation.x = 0.0;

pose2.orientation.y = 0.0;

pose2.orientation.z = 0.0;

pose2.orientation.w = 1.0;

waypoints.push_back(pose2);

// 笛卡尔空间下的路径规划

moveit_msgs::RobotTrajectory trajectory;

const double jump_threshold = 0.0;

const double eef_step = 0.0002;

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;

}

Python版

$ rosrun probot_demo moveit_cartesian_demo.py _cartesian:=False  走自由路径

$ rosrun probot_demo moveit_cartesian_demo.py _cartesian:=True    走直线

代码:

#!/usr/bin/env python

# -*- coding: utf-8 -*-

import rospy, sys

import moveit_commander

from moveit_commander import MoveGroupCommander

from geometry_msgs.msg import Pose

from copy import deepcopy

class MoveItCartesianDemo:

def __init__(self):

# 初始化move_group的API

moveit_commander.roscpp_initialize(sys.argv)

# 初始化ROS节点

rospy.init_node('magician_moveit_cartesian_demo', anonymous=True)

# 是否需要使用笛卡尔空间的运动规划

cartesian = rospy.get_param('~cartesian', True)

# 初始化需要使用move group控制的机械臂中的arm group

arm = MoveGroupCommander('magician_arm')

# 当运动规划失败后,允许重新规划

arm.allow_replanning(True)

# 设置目标位置所使用的参考坐标系

arm.set_pose_reference_frame('magician_origin')

# 设置位置(单位:米)和姿态(单位:弧度)的允许误差

arm.set_goal_position_tolerance(0.001)

arm.set_goal_orientation_tolerance(0.001)

# 设置允许的最大速度和加速度

arm.set_max_acceleration_scaling_factor(0.5)

arm.set_max_velocity_scaling_factor(0.5)

# 获取终端link的名称

end_effector_link = arm.get_end_effector_link()

# 控制机械臂先回到初始化位置

arm.set_named_target('home')

arm.go()

rospy.sleep(1)

# 获取当前位姿数据最为机械臂运动的起始位姿

start_pose = arm.get_current_pose(end_effector_link).pose

# 初始化路点列表

waypoints = []

# 将初始位姿加入路点列表

if cartesian:

waypoints.append(start_pose)

# 设置路点数据,并加入路点列表

wpose = deepcopy(start_pose)

wpose.position.z -= 0.093

if cartesian:

waypoints.append(deepcopy(wpose))

else:

arm.set_pose_target(wpose)

arm.go()

rospy.sleep(1)

wpose.position.x += 0.04

if cartesian:

waypoints.append(deepcopy(wpose))

else:

arm.set_pose_target(wpose)

arm.go()

rospy.sleep(1)

wpose.position.y += 0.04

if cartesian:

waypoints.append(deepcopy(wpose))

else:

arm.set_pose_target(wpose)

arm.go()

rospy.sleep(1)

wpose.position.x -= 0.04

wpose.position.y -= 0.04

if cartesian:

waypoints.append(deepcopy(wpose))

else:

arm.set_pose_target(wpose)

arm.go()

rospy.sleep(1)

if cartesian:

fraction = 0.0 #路径规划覆盖率

maxtries = 100 #最大尝试规划次数

attempts = 0 #已经尝试规划次数

# 设置机器臂当前的状态作为运动初始状态

arm.set_start_state_to_current_state()

# 尝试规划一条笛卡尔空间下的路径,依次通过所有路点

while fraction < 1.0 and attempts < maxtries:

(plan, fraction) = arm.compute_cartesian_path (

waypoints, # waypoint poses,路点列表

0.005, # eef_step,终端步进值

0.0, # jump_threshold,跳跃阈值

True) # avoid_collisions,避障规划

# 尝试次数累加

attempts += 1

# 打印运动规划进程

if attempts % 10 == 0:

rospy.loginfo("Still trying after " + str(attempts) + " attempts...")

# 如果路径规划成功(覆盖率100%),则开始控制机械臂运动

if fraction == 1.0:

rospy.loginfo("Path computed successfully. Moving the arm.")

arm.execute(plan)

rospy.loginfo("Path execution complete.")

# 如果路径规划失败,则打印失败信息

else:

rospy.loginfo("Path planning failed with only " + str(fraction) + " success after " + str(maxtries) + " attempts.")

rospy.sleep(1)

# 控制机械臂先回到初始化位置

arm.set_named_target('home')

arm.go()

rospy.sleep(1)

# 关闭并退出moveit

moveit_commander.roscpp_shutdown()

moveit_commander.os._exit(0)

if __name__ == "__main__":

try:

MoveItCartesianDemo()

except rospy.ROSInterruptException:

pass

dobot moveit 包_DOBOT magician魔术师在ROS下使用moveit编写代码控制(笛卡尔空间控制走直线)...相关推荐

  1. 遨博机器人ROS包aubo_robot 在kinetic版ROS下的编译

    在github上发现遨博机器人支持ROS1,但是对应的版本是indigo的,我已经安了kinetic了,总不能为了体验一下,安装个旧的版本,于是我就硬编,出现了一大堆error,改着改着竟然改通了(当 ...

  2. 遨博机器人ROS包aubo_robot 在kinetic版ROS下的编译(转载)

    在github上发现遨博机器人支持ROS1,但是对应的版本是indigo的,我已经安了kinetic了,总不能为了体验一下,安装个旧的版本,于是我就硬编,出现了一大堆error,改着改着竟然改通了(当 ...

  3. 越疆魔术师DEBOT(magician)机械臂ROS、MoveIt!和Gazebo功能包与ROS-I教程(melodic)

    原文地址:https://blog.csdn.net/qq_42145185/article/details/93501741 喜欢DEBOT的小伙伴,现在可以仿真玩耍机械臂啦,如果已经购买可以配合一 ...

  4. ROS下如何使用moveit驱动UR5机械臂

    转载:http://blog.csdn.net/jayandchuxu/article/details/54693870 原来的moveit实在Ubuntu12.04上安装的,ros版本是hydro, ...

  5. ros kinetic-moveit驱动ur3机械臂------控制真实机械臂并且能动

    ros kinetic-moveit驱动ur3机械臂------控制真实机械臂并且能动 本文工作环境配置: ubuntu16.04.6 ros-kinetic ur3 已验证本教程代码在Ubuntu1 ...

  6. 在ROS下控制dobot(magician)机械手的滑轨

    在ROS下控制越疆科技dobot(magician)机械手的滑轨 GetQueuedCmdCurrentIndex.srv代码: --- int32 result uint64 queuedCmdIn ...

  7. 在ROS下控制dobot(magician)机械手的吸盘

    在ROS下控制越疆科技dobot(magician)机械手的吸盘气泵 代码: #include "ros/ros.h" #include "ros/console.h&q ...

  8. 在ROS下控制dobot(magician)机械手的夹抓

    在ROS下控制越疆科技dobot(magician)机械手的夹抓 代码: #include "ros/ros.h" #include "ros/console.h&quo ...

  9. ROS下连接Dobot魔术师机械臂

    实验室最近购入Dobot 魔术师机械臂,是一款桌面级机械臂,精度较高而且相对便宜,支持二次开发,适合实验室进行学习与开发使用.提供了较为丰富的api,方便使用各种平台及语言进行开发.这里介绍如何在RO ...

最新文章

  1. saltstack 执行结果返回到mysql
  2. 行式填报表轻松搞定流水号
  3. mysql权限清理_mysql清理用户权限
  4. 第六天,字典Dictionary
  5. 想要导航提示直接进入_北斗导航已开始提供全球服务,你的手机怎样连接北斗?...
  6. ajax控件扩展,22.6 扩展控件
  7. 黑马程序员_java之反射
  8. java中弱引用和强信用_Java 强引用 软引用与弱引用,虚引用区别
  9. 某烟草局绩效考核系统分析设计清单
  10. pta初级题库151-200
  11. STM32与ST-Link杜邦线连接
  12. 笔记本电脑键盘的禁用与恢复【亲测有效】
  13. 【读书笔记】金字塔原理-构建金字塔的序言
  14. HDU 5855 Less Time, More profit 【最大流-最大权闭合子图】
  15. python通信自动化测试_基于Python的无线通信设备自动化测试软件的研制
  16. android 启动视频,android 启动页面全屏播放视频
  17. 按键精灵通过句柄获取窗口坐标_按键精灵怎么获取同名窗口的句柄
  18. 电脑画流程图用什么软件好?这3款软件很好用
  19. 安卓 build.prop 进行修改提高性能
  20. Invalid bound statement (not found): com.web.sysmgr.mapper.UserMapper.login

热门文章

  1. 什么是挂载,Linux挂载如何实现详解
  2. 小试牛刀-利用AST平坦化一段瑞数代码
  3. Hive 窗口函数大全
  4. (二)操作系统的发展与分类
  5. 阿里巴巴集团--软件测试--《社招、校招jd、公司具体介绍,校园招聘公告,应届生招聘流程,技术培训,薪资福利》整理
  6. SCAU 1028 求素数
  7. 2.5 CMMI2级——配置管理(Configuration Management)
  8. JavaScript ------ DOM(事件基础)
  9. Eclipse+git中merge代码时出现conflict(冲突)的问题解决方案
  10. 非官方谷歌地图 iOS 应用遭苹果下架