DOBOT magician魔术师在ROS下使用moveit编写代码控制(笛卡尔空间控制走圆)

55 篇文章 35 订阅
16 篇文章 10 订阅
#include <math.h>
#include <ros/ros.h>
#include <moveit/move_group_interface/move_group_interface.h>
#include <moveit/robot_trajectory/robot_trajectory.h>

int main(int argc, char **argv)
{
	ros::init(argc, argv, "magician_circle_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.0002);
    arm.setGoalOrientationTolerance(0.0001);

    //设置允许的最大速度和加速度
    arm.setMaxAccelerationScalingFactor(0.5);
    arm.setMaxVelocityScalingFactor(0.5);

    // 控制机械臂先回到初始化位置
    arm.setNamedTarget("home");
    arm.move();
    sleep(1);

    // 设置机器人终端的目标位置
    geometry_msgs::Pose target_pose;
    target_pose.orientation.x = 0;
    target_pose.orientation.y = 0;
    target_pose.orientation.z = 0;
    target_pose.orientation.w = 1;

    target_pose.position.x = 0.17075;
    target_pose.position.y = 0.0;
    target_pose.position.z = -0.041;

    //arm.setPoseTarget(target_pose);
    //arm.move();

	std::vector<geometry_msgs::Pose> waypoints;

    //将初始位姿加入路点列表
	//waypoints.push_back(target_pose);

    double centerA = target_pose.position.x;
    double centerB = target_pose.position.y;
    double radius = 0.04;

    for(double th=0.0; th<6.28; th=th+0.001)
    {
		target_pose.position.x = centerA + radius * sin(th);
        target_pose.position.y = centerB + radius * cos(th);
        waypoints.push_back(target_pose);
    }

	// 笛卡尔空间下的路径规划
	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;
}

 

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
在对Dobot Magician魔术师机械臂的研究学习过程,我首先对其功能和操作进行了深入的学习和理解。Dobot Magician是一款多功能的机械臂,它具有高精度、高自由度和易操作等特点,可以完成各种任务,如抓取、写字、画画等。 在实践,我遇到了一些挑战。首先,了解和掌握机械臂的基本操作是一项重要任务。我通过学习官方提供的文档和教程,熟悉了机械臂的硬件结构、控制方式和编程接口。我还进行了一些简单的操作实践,如控制机械臂运动、调整末端执行器的姿态等,以加深对其功能和操作的理解。 其次,我在使用机械臂完成特定任务时也遇到了一些挑战。例如,在进行抓取操作时需要准确地控制机械臂的位置和力量,并且要考虑到物体的形状和重量等因素。为了解决这些问题,我通过调试和优化控制参数,不断调整机械臂的姿态和动作,以达到精确抓取物体的目标。 此外,我还遇到了一些编程方面的挑战。为了实现复杂的动作和任务,我需要编写适当的控制程序。在这个过程,我学习了机械臂的编程接口和相关的API,使用Python等编程语言进行程序开发。通过不断的实践和调试,我逐渐掌握了机械臂的编程技巧,并成功地实现了一些复杂的任务,如绘制图形和进行精准定位等。 通过这个研究学习过程,我不仅对Dobot Magician魔术师机械臂有了深入的理解,还提升了自己在机械臂操作和编程方面的能力。我学会了解决各种挑战,并通过实践取得了一些成果。这个经历让我更加熟悉智能车领域的机械臂应用,并为我在面试展示自己的能力提供了宝贵的经验。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值