dobot M1在ROS下的抓取demo

 

#include <ros/ros.h>
#include "ros/console.h"
#include <tf/transform_listener.h>
#include <nav_msgs/Odometry.h>
#include <string.h>
#include <move_base_msgs/MoveBaseAction.h>
#include <actionlib/client/simple_action_client.h>
#include <cmath>
#include <unistd.h>

#include "std_msgs/String.h"
#include "dobot/SetCmdTimeout.h"
#include "dobot/SetQueuedCmdClear.h"
#include "dobot/SetQueuedCmdStartExec.h"
#include "dobot/SetQueuedCmdForceStopExec.h"
#include "dobot/GetDeviceVersion.h"

#include "dobot/SetEndEffectorParams.h"
#include "dobot/SetPTPJointParams.h"
#include "dobot/SetPTPCoordinateParams.h"
#include "dobot/SetPTPJumpParams.h"
#include "dobot/SetPTPCommonParams.h"
#include "dobot/SetPTPCmd.h"
#include "dobot/SetEndEffectorGripper.h"
#include "dobot/SetHOMECmd.h"
#include "dobot/SetHOMEParams.h"
#include "dobot/SetIODO.h"

int main(int argc, char **argv)
{
    ros::init(argc, argv, "DobotClient");
    ros::NodeHandle n;

    ros::ServiceClient client;
//#if 0
    // SetCmdTimeout
    client = n.serviceClient<dobot::SetCmdTimeout>("/DobotServer/SetCmdTimeout");
    dobot::SetCmdTimeout srv1;
    srv1.request.timeout = 3000;
    if (client.call(srv1) == false) {
        ROS_ERROR("Failed to call SetCmdTimeout. Maybe DobotServer isn't started yet!");
        return -1;
    }

    // Clear the command queue
    client = n.serviceClient<dobot::SetQueuedCmdClear>("/DobotServer/SetQueuedCmdClear");
    dobot::SetQueuedCmdClear srv2;
    client.call(srv2);

    // Start running the command queue
    client = n.serviceClient<dobot::SetQueuedCmdStartExec>("/DobotServer/SetQueuedCmdStartExec");
    dobot::SetQueuedCmdStartExec srv3;
    client.call(srv3);

    // Get device version information
    client = n.serviceClient<dobot::GetDeviceVersion>("/DobotServer/GetDeviceVersion");
    dobot::GetDeviceVersion srv4;
    client.call(srv4);
    if (srv4.response.result == 0) {
        ROS_INFO("Device version:%d.%d.%d", srv4.response.majorVersion, srv4.response.minorVersion, srv4.response.revision);
    } else {
        ROS_ERROR("Failed to get device version information!");
    }

    // Set end effector parameters
    client = n.serviceClient<dobot::SetEndEffectorParams>("/DobotServer/SetEndEffectorParams");
    dobot::SetEndEffectorParams srv5;
    srv5.request.xBias = 70;
    srv5.request.yBias = 0;
    srv5.request.zBias = 0;
    client.call(srv5);

    // Set PTP joint parameters
    do {
        client = n.serviceClient<dobot::SetPTPJointParams>("/DobotServer/SetPTPJointParams");
        dobot::SetPTPJointParams srv;

        for (int i = 0; i < 4; i++) {
            srv.request.velocity.push_back(100);
        }
        for (int i = 0; i < 4; i++) {
            srv.request.acceleration.push_back(100);
        }
        client.call(srv);
    } while (0);

    // Set PTP coordinate parameters
    do {
        client = n.serviceClient<dobot::SetPTPCoordinateParams>("/DobotServer/SetPTPCoordinateParams");
        dobot::SetPTPCoordinateParams srv;

        srv.request.xyzVelocity = 100;
        srv.request.xyzAcceleration = 100;
        srv.request.rVelocity = 100;
        srv.request.rAcceleration = 100;
        client.call(srv);
    } while (0);

    // Set PTP jump parameters
    do {
        client = n.serviceClient<dobot::SetPTPJumpParams>("/DobotServer/SetPTPJumpParams");
        dobot::SetPTPJumpParams srv;

        srv.request.jumpHeight = 20;
        srv.request.zLimit = 200;
        client.call(srv);
    } while (0);

    // Set PTP common parameters
    do {
        client = n.serviceClient<dobot::SetPTPCommonParams>("/DobotServer/SetPTPCommonParams");
        dobot::SetPTPCommonParams srv;

        srv.request.velocityRatio = 50;
        srv.request.accelerationRatio = 50;
        client.call(srv);
    } while (0);
//#endif

    client = n.serviceClient<dobot::SetPTPCmd>("/DobotServer/SetPTPCmd");
    dobot::SetPTPCmd srv;
            srv.request.ptpMode = 1;
            srv.request.x = 200;
            srv.request.y = 0;
            srv.request.z = 100;
            srv.request.r = 0;
            client.call(srv);
            if (srv.response.result == 0) 
	    {
                ROS_INFO("PTP 1");
            } 
	    sleep(5); 
            srv.request.ptpMode = 1;
            srv.request.x = 400;
            srv.request.y = 0;
            srv.request.z = 80;
            srv.request.r = 0;
            client.call(srv);
            if (srv.response.result == 0) 
	    {
                ROS_INFO("PTP 2");
            } 
///qibeng
   	client = n.serviceClient<dobot::SetIODO>("/DobotServer/SetIODO");
	dobot::SetIODO IO1;
	do{
		IO1.request.address = 18;
		IO1.request.level = 0;
		IO1.request.isQueued = 0;
		client.call(IO1);
	 	ROS_INFO("SetIODO1 ok, %d", IO1.response.queuedCmdIndex);
	}while(0);
	dobot::SetIODO IO2;
	do{
		IO2.request.address = 17;
		IO2.request.level = 0;
		IO2.request.isQueued = 0;
		client.call(IO2);
	 	ROS_INFO("SetIODO2 ok, %d", IO2.response.queuedCmdIndex);
	}while(0);
///
	    sleep(5);
           client = n.serviceClient<dobot::SetPTPCmd>("/DobotServer/SetPTPCmd");
	    srv.request.ptpMode = 1;
            srv.request.x = 200;
            srv.request.y = 0;
            srv.request.z = 100;
            srv.request.r = 0;
            client.call(srv);
	    if (srv.response.result == 0) 
	    {
                ROS_INFO("PTP 3");
            } 
            sleep(5);

            srv.request.ptpMode = 1;
            srv.request.x = 400;
            srv.request.y = 0;
            srv.request.z = 80;
            srv.request.r = 0;
            client.call(srv);
            if (srv.response.result == 0) 
	    {
                ROS_INFO("PTP 4");
            } 	
	    sleep(5);
            srv.request.ptpMode = 1;
            srv.request.x = 200;
            srv.request.y = 0;
            srv.request.z = 100;
            srv.request.r = 0;
            client.call(srv);
            if (srv.response.result == 0) 
	    {
                ROS_INFO("PTP 5");
            } 
	    sleep(5); 
///close qibeng
   	client = n.serviceClient<dobot::SetIODO>("/DobotServer/SetIODO");
	dobot::SetIODO IO3;
	do{
		IO3.request.address = 18;
		IO3.request.level = 1;
		IO3.request.isQueued = 0;
		client.call(IO3);
	 	ROS_INFO("SetIODO3 ok, %d", IO3.response.queuedCmdIndex);
	}while(0);
	dobot::SetIODO IO4;
	do{
		IO4.request.address = 17;
		IO4.request.level = 1;
		IO4.request.isQueued = 0;
		client.call(IO4);
	 	ROS_INFO("SetIODO4 ok, %d", IO4.response.queuedCmdIndex);
	}while(0);
///*/


    return 0;
}

 

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值