-
Notifications
You must be signed in to change notification settings - Fork 158
/
move_test.cpp
executable file
·124 lines (111 loc) · 3.56 KB
/
move_test.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
/* Copyright 2018 UFACTORY Inc. All Rights Reserved.
*
* Software License Agreement (BSD License)
*
* Author: waylon <[email protected]>
Jason <[email protected]>
============================================================================*/
#include "ros/ros.h"
#include <xarm_api/xarm_driver.h>
int go_home_test(xarm_msgs::Move srv, ros::ServiceClient client)
{
srv.request.mvvelo = 20.0 / 57.0;
srv.request.mvacc = 1000;
srv.request.mvtime = 0;
if(client.call(srv))
{
ROS_INFO("%s\n", srv.response.message.c_str());
}
else
{
ROS_ERROR("Failed to call service go home");
return 1;
}
return 0;
}
int move_lineb_test(xarm_msgs::Move srv, ros::ServiceClient client)
{
std::vector<float> pose[5] = { {300, 0, 100, -3.14, 0, 0},
{300, 100, 100, -3.14, 0, 0},
{400, 100, 100, -3.14, 0, 0},
{400, -100, 100, -3.14, 0, 0},
{300, -100, 100, -3.14, 0, 0}};
srv.request.mvvelo = 100;
srv.request.mvacc = 1000;
srv.request.mvtime = 0;
srv.request.mvradii = 20;
for(int k=0; k<3; k++)
{
for(int i = 0; i < 5; i++)
{
srv.request.pose = pose[i];
if(client.call(srv))
{
ROS_INFO("%s\n", srv.response.message.c_str());
}
else
{
ROS_ERROR("Failed to call service move_lineb");
return 1;
}
}
}
return 0;
}
int main(int argc, char **argv)
{
ros::init(argc, argv, "xarm_move_test");
ros::NodeHandle nh;
nh.setParam("/xarm/wait_for_finish", true); // return after motion service finish
ros::Publisher sleep_pub_ = nh.advertise<std_msgs::Float32>("/xarm/sleep_sec", 1);
ros::ServiceClient motion_ctrl_client_ = nh.serviceClient<xarm_msgs::SetAxis>("/xarm/motion_ctrl");
ros::ServiceClient set_mode_client_ = nh.serviceClient<xarm_msgs::SetInt16>("/xarm/set_mode");
ros::ServiceClient set_state_client_ = nh.serviceClient<xarm_msgs::SetInt16>("/xarm/set_state");
ros::ServiceClient go_home_client_ = nh.serviceClient<xarm_msgs::Move>("/xarm/go_home");
ros::ServiceClient move_lineb_client_ = nh.serviceClient<xarm_msgs::Move>("/xarm/move_lineb");
ros::ServiceClient move_servoj_client_ = nh.serviceClient<xarm_msgs::Move>("/xarm/move_servoj");
xarm_msgs::SetAxis set_axis_srv_;
xarm_msgs::SetInt16 set_int16_srv_;
xarm_msgs::Move move_srv_;
set_axis_srv_.request.id = 8;
set_axis_srv_.request.data = 1;
if(motion_ctrl_client_.call(set_axis_srv_))
{
ROS_INFO("%s\n", set_axis_srv_.response.message.c_str());
}
else
{
ROS_ERROR("Failed to call service motion_ctrl");
return 1;
}
set_int16_srv_.request.data = 0;
if(set_mode_client_.call(set_int16_srv_))
{
ROS_INFO("%s\n", set_int16_srv_.response.message.c_str());
}
else
{
ROS_ERROR("Failed to call service set_mode");
return 1;
}
set_int16_srv_.request.data = 0;
if(set_state_client_.call(set_int16_srv_))
{
ROS_INFO("%s\n", set_int16_srv_.response.message.c_str());
}
else
{
ROS_ERROR("Failed to call service set_state");
return 1;
}
if(go_home_test(move_srv_, go_home_client_) == 1)
return 1;
// MOVE_LINEB need some additional configurations: wait=False, sleep before sending commands
nh.setParam("/xarm/wait_for_finish", false); // This configuration is CRITICAL for move_lineb!
std_msgs::Float32 sleep_msg;
sleep_msg.data = 1.0;
sleep_pub_.publish(sleep_msg);
if(move_lineb_test(move_srv_, move_lineb_client_) == 1)
return 1;
nh.setParam("/xarm/wait_for_finish", true);
}