dsr_basic_test.cpp
Go to the documentation of this file.
1 /*
2  * [c++ example basic] basic test for doosan robot
3  * Author: Kab Kyoum Kim (kabkyoum.kim@doosan.com)
4  *
5  * Copyright (c) 2019 Doosan Robotics
6  * Use of this source code is governed by the BSD, see LICENSE
7 */
8 
9 #include <ros/ros.h>
10 #include <signal.h>
11 #include <boost/thread/thread.hpp>
12 #include <cstdlib>
13 #include <array>
14 #include <vector>
15 #include <algorithm>
16 #include <sstream>
17 
18 #include <dsr_msgs/RobotState.h>
19 #include <dsr_msgs/RobotStop.h>
20 
21 #include <dsr_msgs/MoveJoint.h>
22 #include <dsr_msgs/MoveLine.h>
23 #include <dsr_msgs/MoveJointx.h>
24 #include <dsr_msgs/MoveCircle.h>
25 #include <dsr_msgs/MoveSplineJoint.h>
26 #include <dsr_msgs/MoveSplineTask.h>
27 #include <dsr_msgs/MoveBlending.h>
28 #include <dsr_msgs/MoveSpiral.h>
29 #include <dsr_msgs/MovePeriodic.h>
30 #include <dsr_msgs/MoveWait.h>
31 
32 #include "dsr_util.h"
33 #include "dsr_robot.h"
34 
35 using namespace std;
36 
37 //----- set tartget robot----------------------------------------------------
38 string ROBOT_ID = "dsr01";
39 string ROBOT_MODEL = "m1013";
40 void SET_ROBOT(string id, string model) {ROBOT_ID = id; ROBOT_MODEL= model;}
41 //---------------------------------------------------------------------------
42 std::string temp_data = "";
43 
44 int movej(float fTargetPos[NUM_JOINT], float fTargetVel, float fTargetAcc, float fTargetTime = 0.f, float fBlendingRadius = 0.f,
45  int nMoveMode = MOVE_MODE_ABSOLUTE, int nBlendingType = BLENDING_SPEED_TYPE_DUPLICATE, int nSyncType = 0)
46 {
47  //ros::ServiceClient srvMoveJoint = nh.serviceClient<dsr_msgs::MoveJoint>("/dsr01m1013/motion/move_joint");
48  ros::NodeHandlePtr node = boost::make_shared<ros::NodeHandle>();
49  ros::ServiceClient srvMoveJoint = node->serviceClient<dsr_msgs::MoveJoint>("/"+ROBOT_ID + ROBOT_MODEL+"/motion/move_joint");
50 
51  dsr_msgs::MoveJoint srv;
52 
53  for(int i=0; i<NUM_JOINT; i++)
54  srv.request.pos[i] = fTargetPos[i];
55  srv.request.vel = fTargetVel;
56  srv.request.acc = fTargetAcc;
57  srv.request.time = fTargetTime;
58  srv.request.radius = fBlendingRadius;
59  srv.request.mode = nMoveMode;
60  srv.request.blendType = nBlendingType;
61  srv.request.syncType = nSyncType;
62 
63  //ROS_INFO("service call: /dsr01m1013/motion/move_joint");
64  //ROS_INFO(" <pos> %7.3f %7.3f %7.3f %7.3f %7.3f %7.3f",srv.request.pos[0],srv.request.pos[1],srv.request.pos[2],srv.request.pos[3],srv.request.pos[4],srv.request.pos[5]);
65  //ROS_INFO(" <vel> %7.3f , <acc> %7.3f, <time> %7.3f",srv.request.vel, srv.request.acc, srv.request.time);
66  //ROS_INFO(" <mode> %d , <radius> %7.3f, <blendType> %d",srv.request.mode, srv.request.radius, srv.request.blendType);
67 
68  if(srvMoveJoint.call(srv))
69  {
70  //ROS_INFO("receive srv, srv.response.success: %ld\n", (long int)srv.response.success);
71  return (srv.response.success);
72  }
73  else
74  {
75  ROS_ERROR("Failed to call service dr_control_service : move_joint\n");
76  ros::shutdown();
77  return -1;
78  }
79 }
80 int amovej(float fTargetPos[NUM_JOINT], float fTargetVel, float fTargetAcc, float fTargetTime = 0.f, float fBlendingRadius = 0.f,
81  int nMoveMode = MOVE_MODE_ABSOLUTE, int nBlendingType = BLENDING_SPEED_TYPE_DUPLICATE, int nSyncType = 1)
82 {
83  return movej(fTargetPos, fTargetVel, fTargetAcc, fTargetTime, fBlendingRadius, nMoveMode, nBlendingType, /*nSyncType=*/ 1);
84 }
85 
86 
87 int movel(float fTargetPos[NUM_JOINT], float fTargetVel[2], float fTargetAcc[2], float fTargetTime = 0.f, float fBlendingRadius = 0.f,
88  int nMoveReference = MOVE_REFERENCE_BASE, int nMoveMode = MOVE_MODE_ABSOLUTE, int nBlendingType = BLENDING_SPEED_TYPE_DUPLICATE, int nSyncType = 0)
89 {
90  ros::NodeHandlePtr node = boost::make_shared<ros::NodeHandle>();
91  ros::ServiceClient srvMoveLine = node->serviceClient<dsr_msgs::MoveLine>("/"+ROBOT_ID +ROBOT_MODEL+"/motion/move_line");
92  dsr_msgs::MoveLine srv;
93 
94  for(int i=0; i<NUM_JOINT; i++)
95  srv.request.pos[i] = fTargetPos[i];
96  for(int i=0; i<2; i++){
97  srv.request.vel[i] = fTargetVel[i];
98  srv.request.acc[i] = fTargetAcc[i];
99  }
100  srv.request.time = fTargetTime;
101  srv.request.radius = fBlendingRadius;
102  srv.request.ref = nMoveReference;
103  srv.request.mode = nMoveMode;
104  srv.request.blendType = nBlendingType;
105  srv.request.syncType = nSyncType;
106 
107  ROS_INFO("service call: /dsr01m1013/motion/move_line");
108  ROS_INFO(" <pos> %7.3f %7.3f %7.3f %7.3f %7.3f %7.3f",srv.request.pos[0],srv.request.pos[1],srv.request.pos[2],srv.request.pos[3],srv.request.pos[4],srv.request.pos[5]);
109  ROS_INFO(" <vel> %7.3f,%7.3f <acc> %7.3f,%7.3f <time> %7.3f",srv.request.vel[0],srv.request.vel[1],srv.request.acc[0],srv.request.acc[1], srv.request.time);
110  ROS_INFO(" <mode> %d, <ref> %d, <radius> %7.3f, <blendType> %d",srv.request.mode,srv.request.ref, srv.request.radius, srv.request.blendType);
111 
112  if(srvMoveLine.call(srv))
113  {
114  //ROS_INFO("receive srv, srv.response.success: %ld\n", (long int)srv.response.success);
115  return (srv.response.success);
116  }
117  else
118  {
119  ROS_ERROR("Failed to call service dr_control_service : move_line\n");
120  ros::shutdown();
121  return -1;
122  }
123 }
124 int amovel(float fTargetPos[NUM_JOINT], float fTargetVel[2], float fTargetAcc[2], float fTargetTime = 0.f, float fBlendingRadius = 0.f,
125  int nMoveReference = MOVE_REFERENCE_BASE, int nMoveMode = MOVE_MODE_ABSOLUTE, int nBlendingType = BLENDING_SPEED_TYPE_DUPLICATE, int nSyncType = 1)
126 {
127  return movel(fTargetPos, fTargetVel, fTargetAcc, fTargetTime, fBlendingRadius, nMoveReference, nMoveMode, nBlendingType, /*nSyncType=*/ 1);
128 }
129 
130 
131 int movejx(float fTargetPos[NUM_TASK], float fTargetVel, float fTargetAcc, float fTargetTime=0.f, float fBlendingRadius = 0.f,
132  int nMoveReference = MOVE_REFERENCE_BASE, int nMoveMode = MOVE_MODE_ABSOLUTE, int nBlendingType = BLENDING_SPEED_TYPE_DUPLICATE, int nSolSpace = 0, int nSyncType = 0)
133 {
134  ros::NodeHandlePtr node = boost::make_shared<ros::NodeHandle>();
135  ros::ServiceClient srvMoveJointx = node->serviceClient<dsr_msgs::MoveJointx>("/"+ROBOT_ID +ROBOT_MODEL+"/motion/move_jointx");
136  dsr_msgs::MoveJointx srv;
137 
138  for(int i=0; i<NUM_TASK; i++)
139  srv.request.pos[i] = fTargetPos[i];
140  srv.request.vel = fTargetVel;
141  srv.request.acc = fTargetAcc;
142  srv.request.time = fTargetTime;
143  srv.request.radius = fBlendingRadius;
144  srv.request.ref = nMoveReference;
145  srv.request.mode = nMoveMode;
146  srv.request.blendType = nBlendingType;
147  srv.request.sol = nSolSpace;
148 
149  if(srvMoveJointx.call(srv))
150  {
151  //ROS_INFO("receive srv, srv.response.success: %ld\n", (long int)srv.response.success);
152  return (srv.response.success);
153  }
154  else
155  {
156  ROS_ERROR("Failed to call service dr_control_service : move_jointx\n");
157  ros::shutdown();
158  return -1;
159  }
160 }
161 int amovejx(float fTargetPos[NUM_TASK], float fTargetVel, float fTargetAcc, float fTargetTime=0.f, float fBlendingRadius = 0.f,
162  int nMoveReference = MOVE_REFERENCE_BASE, int nMoveMode = MOVE_MODE_ABSOLUTE, int nBlendingType = BLENDING_SPEED_TYPE_DUPLICATE, int nSolSpace = 0, int nSyncType = 1)
163 {
164  return movejx(fTargetPos, fTargetVel, fTargetAcc, fTargetTime, fBlendingRadius, nMoveReference, nMoveMode, nBlendingType, nSolSpace, /*nSyncType=*/ 1);
165 }
166 
167 
168 int movec(float fTargetPos[2][NUM_TASK], float fTargetVel[2], float fTargetAcc[2], float fTargetTime = 0.f, float fBlendingRadius = 0.f,
169  int nMoveReference = MOVE_REFERENCE_BASE, int nMoveMode = MOVE_MODE_ABSOLUTE, int nBlendingType = BLENDING_SPEED_TYPE_DUPLICATE, int nSyncType = 0)
170 {
171  ros::NodeHandlePtr node = boost::make_shared<ros::NodeHandle>();
172  ros::ServiceClient srvMoveCircle = node->serviceClient<dsr_msgs::MoveCircle>("/"+ROBOT_ID +ROBOT_MODEL+"/motion/move_circle");
173 
174  dsr_msgs::MoveCircle srv;
175  std::vector<std_msgs::Float64MultiArray> poses;
176  std_msgs::Float64MultiArray pos;
177  for(int i=0; i<2; i++){
178  pos.data.clear();
179  for(int j = 0; j < NUM_TASK; j++){
180  pos.data.push_back(fTargetPos[i][j]);
181  }
182  poses.push_back(pos);
183  }
184 
185  ROS_INFO(" <xxx pos1> %7.3f %7.3f %7.3f %7.3f %7.3f %7.3f",fTargetPos[0][0],fTargetPos[0][1],fTargetPos[0][2],fTargetPos[0][3],fTargetPos[0][4],fTargetPos[0][5]);
186  ROS_INFO(" <xxx pos2> %7.3f %7.3f %7.3f %7.3f %7.3f %7.3f",fTargetPos[1][0],fTargetPos[1][1],fTargetPos[1][2],fTargetPos[1][3],fTargetPos[1][4],fTargetPos[1][5]);
187 
188  ROS_INFO(" <pos1> %7.3f %7.3f %7.3f %7.3f %7.3f %7.3f",poses[0].data[0],poses[0].data[1],poses[0].data[2],poses[0].data[3],poses[0].data[4],poses[0].data[5]);
189  ROS_INFO(" <pos2> %7.3f %7.3f %7.3f %7.3f %7.3f %7.3f",poses[1].data[0],poses[1].data[1],poses[1].data[2],poses[1].data[3],poses[1].data[4],poses[1].data[5]);
190 
191  srv.request.pos = poses;
192 
193  for(int i=0; i<2; i++){
194  srv.request.vel[i] = fTargetVel[i];
195  srv.request.acc[i] = fTargetAcc[i];
196  }
197  srv.request.time = fTargetTime;
198  srv.request.radius = fBlendingRadius;
199  srv.request.ref = nMoveReference;
200  srv.request.mode = nMoveMode;
201  srv.request.blendType = nBlendingType;
202  srv.request.syncType = nSyncType;
203 
204  ROS_INFO("service call: /dsr01m1013/motion/move_circle");
205  ROS_INFO(" <pos1> %7.3f %7.3f %7.3f %7.3f %7.3f %7.3f",srv.request.pos[0].data[0],srv.request.pos[0].data[1],srv.request.pos[0].data[2],srv.request.pos[0].data[3],srv.request.pos[0].data[4],srv.request.pos[0].data[5]);
206  ROS_INFO(" <pos2> %7.3f %7.3f %7.3f %7.3f %7.3f %7.3f",srv.request.pos[1].data[0],srv.request.pos[1].data[1],srv.request.pos[1].data[2],srv.request.pos[1].data[3],srv.request.pos[1].data[4],srv.request.pos[1].data[5]);
207  ROS_INFO(" <vel> %7.3f,%7.3f <acc> %7.3f,%7.3f <time> %7.3f",srv.request.vel[0],srv.request.vel[1],srv.request.acc[0],srv.request.acc[1], srv.request.time);
208  ROS_INFO(" <mode> %d, <ref> %d, <radius> %7.3f, <blendType> %d",srv.request.mode,srv.request.ref, srv.request.radius, srv.request.blendType);
209 
210  if(srvMoveCircle.call(srv))
211  {
212  //ROS_INFO("receive srv, srv.response.success: %ld\n", (long int)srv.response.success);
213  return (srv.response.success);
214  }
215  else
216  {
217  ROS_ERROR("Failed to call service dr_control_service : move_circle\n");
218  ros::shutdown();
219  return -1;
220  }
221 }
222 int amovec(float fTargetPos[2][NUM_TASK], float fTargetVel[2], float fTargetAcc[2], float fTargetTime = 0.f, float fBlendingRadius = 0.f,
223  int nMoveReference = MOVE_REFERENCE_BASE, int nMoveMode = MOVE_MODE_ABSOLUTE, int nBlendingType = BLENDING_SPEED_TYPE_DUPLICATE, int nSyncType = 1)
224 {
225  return movec(fTargetPos, fTargetVel, fTargetAcc, fTargetTime, fBlendingRadius, nMoveReference, nMoveMode, nBlendingType, /*nSyncType=*/ 1);
226 }
227 
228 
229 int movesj(float fTargetPos[MAX_SPLINE_POINT][NUM_JOINT], int nPosCount, float fTargetVel, float fTargetAcc, float fTargetTime = 0.f,
230  int nMoveMode = MOVE_MODE_ABSOLUTE, int nSyncType = 0)
231 {
232  ros::NodeHandlePtr node = boost::make_shared<ros::NodeHandle>();
233  ros::ServiceClient srvMoveSplineJoint = node->serviceClient<dsr_msgs::MoveSplineJoint>("/"+ROBOT_ID +ROBOT_MODEL+"/motion/move_spline_joint");
234  dsr_msgs::MoveSplineJoint srv;
235  std::vector<std_msgs::Float64MultiArray> poses;
236  std_msgs::Float64MultiArray pos;
237 
238  for(int i = 0; i < MAX_SPLINE_POINT; i++){
239  pos.data.clear();
240  for(int j = 0; j < NUM_JOINT; j++){
241  pos.data.push_back(fTargetPos[i][j]);
242  }
243  poses.push_back(pos);
244  }
245  srv.request.pos = poses;
246  srv.request.posCnt = nPosCount;
247 
248  srv.request.vel = fTargetVel;
249  srv.request.acc = fTargetAcc;
250  srv.request.time = fTargetTime;
251  srv.request.mode = nMoveMode;
252  srv.request.syncType = nSyncType;
253 
254  if(srvMoveSplineJoint.call(srv))
255  {
256  //ROS_INFO("receive srv, srv.response.success: %ld\n", (long int)srv.response.success);
257  return (srv.response.success);
258  }
259  else
260  {
261  ROS_ERROR("Failed to call service dr_control_service : move_spline_joint\n");
262  ros::shutdown();
263  return -1;
264  }
265 }
266 int amovesj(float fTargetPos[MAX_SPLINE_POINT][NUM_JOINT], int nPosCount, float fTargetVel, float fTargetAcc, float fTargetTime = 0.f,
267  int nMoveMode = MOVE_MODE_ABSOLUTE, int nSyncType = 1)
268 {
269  return movesj(fTargetPos, nPosCount, fTargetVel, fTargetAcc, fTargetTime, nMoveMode, /*nSyncType=*/ 1);
270 }
271 
272 
273 int movesx(float fTargetPos[MAX_SPLINE_POINT][NUM_TASK], int nPosCount, float fTargetVel[2], float fTargetAcc[2], float fTargetTime = 0.f,
274  int nMoveReference = MOVE_REFERENCE_BASE, int nMoveMode = MOVE_MODE_ABSOLUTE, int nVelOpt = SPLINE_VELOCITY_OPTION_DEFAULT, int nSyncType = 0)
275 {
276  ros::NodeHandlePtr node = boost::make_shared<ros::NodeHandle>();
277  ros::ServiceClient srvMoveSplineTask = node->serviceClient<dsr_msgs::MoveSplineTask>("/"+ROBOT_ID +ROBOT_MODEL+"/motion/move_spline_task");
278  dsr_msgs::MoveSplineTask srv;
279  std::vector<std_msgs::Float64MultiArray> poses;
280  std_msgs::Float64MultiArray pos;
281 
282  for(int i = 0; i < MAX_SPLINE_POINT; i++){
283  pos.data.clear();
284  for(int j = 0; j < NUM_TASK; j++){
285  pos.data.push_back(fTargetPos[i][j]);
286  }
287  poses.push_back(pos);
288  }
289  srv.request.pos = poses;
290  srv.request.posCnt = nPosCount;
291 
292  for(int i=0; i<2; i++){
293  srv.request.vel[i] = fTargetVel[i];
294  srv.request.acc[i] = fTargetAcc[i];
295  }
296  srv.request.time = fTargetTime;
297  srv.request.ref = nMoveReference;
298  srv.request.mode = nMoveMode;
299  srv.request.opt = nVelOpt;
300  srv.request.syncType = nSyncType;
301 
302  if(srvMoveSplineTask.call(srv))
303  {
304  //ROS_INFO("receive srv, srv.response.success: %ld\n", (long int)srv.response.success);
305  return (srv.response.success);
306  }
307  else
308  {
309  ROS_ERROR("Failed to call service dr_control_service : move_spline_task\n");
310  ros::shutdown();
311  return -1;
312  }
313 }
314 int amovesx(float fTargetPos[MAX_SPLINE_POINT][NUM_TASK], int nPosCount, float fTargetVel[2], float fTargetAcc[2], float fTargetTime = 0.f,
315  int nMoveReference = MOVE_REFERENCE_BASE, int nMoveMode = MOVE_MODE_ABSOLUTE, int nVelOpt = SPLINE_VELOCITY_OPTION_DEFAULT, int nSyncType = 1)
316 {
317  return movesx(fTargetPos, nPosCount, fTargetVel, fTargetAcc, fTargetTime, nMoveReference, nMoveMode, nVelOpt, /*nSyncType=*/ 1);
318 }
319 
320 
321 int moveb(MOVE_POSB* fTargetPos, int nPosCount, float fTargetVel[2], float fTargetAcc[2], float fTargetTime = 0.f,
322  int nMoveReference = MOVE_REFERENCE_BASE, int nMoveMode = MOVE_MODE_ABSOLUTE, int nSyncType = 0)
323 {
324  ros::NodeHandlePtr node = boost::make_shared<ros::NodeHandle>();
325  ros::ServiceClient srvMoveBlending = node->serviceClient<dsr_msgs::MoveBlending>("/"+ROBOT_ID +ROBOT_MODEL+"/motion/move_blending");
326  dsr_msgs::MoveBlending srv;
327 
328  std::vector<std_msgs::Float64MultiArray> segments;
329  std_msgs::Float64MultiArray segment;
330 
331  for(int i=0; i<nPosCount; i++){
332  segment.data.clear();
333 
334  for(int j=0; j<NUM_TASK; j++)
335  segment.data.push_back( fTargetPos[i]._fTargetPos[0][j]);
336  for(int j=0; j<NUM_TASK; j++)
337  segment.data.push_back( fTargetPos[i]._fTargetPos[1][j]);
338 
339  segment.data.push_back( fTargetPos[i]._iBlendType );
340  segment.data.push_back( fTargetPos[i]._fBlendRad );
341 
342  segments.push_back(segment);
343  }
344  srv.request.segment = segments;
345  srv.request.posCnt = nPosCount;
346 
347  for(int i=0; i<2; i++){
348  srv.request.vel[i] = fTargetVel[i];
349  srv.request.acc[i] = fTargetAcc[i];
350  }
351  srv.request.time = fTargetTime;
352  srv.request.ref = nMoveReference;
353  srv.request.mode = nMoveMode;
354  srv.request.syncType = nSyncType;
355 
356  if(srvMoveBlending.call(srv))
357  {
358  //ROS_INFO("receive srv, srv.response.success: %ld\n", (long int)srv.response.success);
359  return (srv.response.success);
360  }
361  else
362  {
363  ROS_ERROR("Failed to call service dr_control_service : move_spline_blending\n");
364  ros::shutdown();
365  return -1;
366  }
367 
368  return 0;
369 }
370 int amoveb(MOVE_POSB* fTargetPos, int nPosCount, float fTargetVel[2], float fTargetAcc[2], float fTargetTime = 0.f,
371  int nMoveReference = MOVE_REFERENCE_BASE, int nMoveMode = MOVE_MODE_ABSOLUTE, int nSyncType = 1)
372 {
373  return moveb(fTargetPos, nPosCount, fTargetVel, fTargetAcc, fTargetTime, nMoveReference, nMoveMode, /*nSyncType=*/ 1);
374 }
375 
376 
377 int move_spiral(float fRevolution, float fMaxRadius, float fMaxLength, float fTargetVel[2], float fTargetAcc[2], float fTargetTime = 0.f,
378  int nTaskAxis = TASK_AXIS_Z, int nMoveReference = MOVE_REFERENCE_TOOL, int nSyncType = 0)
379 {
380  ros::NodeHandlePtr node = boost::make_shared<ros::NodeHandle>();
381  ros::ServiceClient srvMoveSpiral = node->serviceClient<dsr_msgs::MoveSpiral>("/"+ROBOT_ID +ROBOT_MODEL+"/motion/move_spiral");
382  dsr_msgs::MoveSpiral srv;
383 
384  srv.request.revolution = fRevolution;
385  srv.request.maxRadius = fMaxRadius;
386  srv.request.maxLength = fMaxLength;
387  for(int i=0; i<2; i++){
388  srv.request.vel[i] = fTargetVel[i];
389  srv.request.acc[i] = fTargetAcc[i];
390  }
391  srv.request.time = fTargetTime;
392  srv.request.taskAxis = nTaskAxis;
393  srv.request.ref = nMoveReference;
394  srv.request.syncType = nSyncType;
395 
396  if(srvMoveSpiral.call(srv)){
397  //ROS_INFO("receive srv, srv.response.success: %ld\n", (long int)srv.response.success);
398  return (srv.response.success);
399  }
400  else{
401  ROS_ERROR("Failed to call service dr_control_service : move_spiral\n");
402  ros::shutdown();
403  return -1;
404  }
405 }
406 int amove_spiral(float fRevolution, float fMaxRadius, float fMaxLength, float fTargetVel[2], float fTargetAcc[2], float fTargetTime = 0.f,
407  int nTaskAxis = TASK_AXIS_Z, int nMoveReference = MOVE_REFERENCE_TOOL, int nSyncType = 1)
408 {
409  return move_spiral(fRevolution, fMaxRadius, fMaxLength, fTargetVel, fTargetAcc, fTargetTime, nTaskAxis, nMoveReference, /*nSyncType=*/ 1);
410 }
411 
412 
413 int move_periodic(float fAmplitude[NUM_TASK], float fPeriodic[NUM_TASK], float fAccelTime = 0.f, int nRepeat = 1, int nMoveReference = MOVE_REFERENCE_TOOL, int nSyncType = 0)
414 {
415  ros::NodeHandlePtr node = boost::make_shared<ros::NodeHandle>();
416  ros::ServiceClient srvMovePeriodic = node->serviceClient<dsr_msgs::MovePeriodic>("/"+ROBOT_ID +ROBOT_MODEL+"/motion/move_periodic");
417  dsr_msgs::MovePeriodic srv;
418 
419  for(int i=0; i<NUM_TASK; i++){
420  srv.request.amp[i] = fAmplitude[i];
421  srv.request.periodic[i] = fPeriodic[i];
422  }
423  srv.request.acc = fAccelTime;
424  srv.request.repeat = nRepeat;
425  srv.request.ref = nMoveReference;
426  srv.request.syncType = nSyncType;
427 
428  if(srvMovePeriodic.call(srv))
429  {
430  //ROS_INFO("receive srv, srv.response.success: %ld\n", (long int)srv.response.success);
431  return (srv.response.success);
432  }
433  else
434  {
435  ROS_ERROR("Failed to call service dr_control_service : move_periodic\n");
436  ros::shutdown();
437  return -1;
438  }
439 
440  return 0;
441 }
442 int amove_periodic(float fAmplitude[NUM_TASK], float fPeriodic[NUM_TASK], float fAccelTime = 0.f, int nRepeat = 1, int nMoveReference = MOVE_REFERENCE_TOOL, int nSyncType = 1)
443 {
444  return move_periodic(fAmplitude, fPeriodic, fAccelTime, nRepeat, nMoveReference, /*nSyncType=*/ 1);
445 }
446 
447 
449 {
450  ros::NodeHandlePtr node = boost::make_shared<ros::NodeHandle>();
451  ros::ServiceClient srvMoveWait = node->serviceClient<dsr_msgs::MoveWait>("/"+ROBOT_ID +ROBOT_MODEL+"/motion/move_wait");
452  dsr_msgs::MoveWait srv;
453 
454  if(srvMoveWait.call(srv))
455  {
456  //ROS_INFO("receive srv, srv.response.success: %ld\n", (long int)srv.response.success);
457  return (srv.response.success);
458  }
459  else
460  {
461  ROS_ERROR("Failed to call service dr_control_service : move_wait\n");
462  ros::shutdown();
463  return -1;
464  }
465 
466  return 0;
467 }
469 void msgRobotState_cb(const dsr_msgs::RobotState::ConstPtr& msg)
470 {
471  static int sn_cnt =0;
472 
473  sn_cnt++;
474  if(0==(sn_cnt % 100))
475  {
476  ROS_INFO("________ ROBOT STATUS ________");
477  ROS_INFO(" robot_state : %d", msg->robot_state);
478  ROS_INFO(" robot_state_str : %s", msg->robot_state_str.c_str());
479  ROS_INFO(" current_posj : %7.3f %7.3f %7.3f %7.3f %7.3f %7.3f", msg->current_posj[0], msg->current_posj[1] ,msg->current_posj[2]
480  , msg->current_posj[3], msg->current_posj[4] ,msg->current_posj[5] );
481  ROS_INFO(" current_velj : %7.3f %7.3f %7.3f %7.3f %7.3f %7.3f" , msg->current_velj[0], msg->current_velj[1], msg->current_velj[2], msg->current_velj[3],msg->current_velj[4],msg->current_velj[5]);
482  ROS_INFO(" joint_abs : %7.3f %7.3f %7.3f %7.3f %7.3f %7.3f" , msg->joint_abs[0],msg->joint_abs[1],msg->joint_abs[2],msg->joint_abs[3],msg->joint_abs[4],msg->joint_abs[5]);
483  ROS_INFO(" joint_err : %7.3f %7.3f %7.3f %7.3f %7.3f %7.3f" , msg->joint_err[0],msg->joint_err[1],msg->joint_err[2],msg->joint_err[3],msg->joint_err[4],msg->joint_err[5]);
484  ROS_INFO(" target_posj : %7.3f %7.3f %7.3f %7.3f %7.3f %7.3f" , msg->target_posj[0],msg->target_posj[1],msg->target_posj[2],msg->target_posj[3],msg->target_posj[4],msg->target_posj[5]);
485  ROS_INFO(" target_velj : %7.3f %7.3f %7.3f %7.3f %7.3f %7.3f" , msg->target_velj[0],msg->target_velj[1],msg->target_velj[2],msg->target_velj[3],msg->target_velj[4],msg->target_velj[5]);
486  ROS_INFO(" current_posx : %7.3f %7.3f %7.3f %7.3f %7.3f %7.3f", msg->current_posx[0] ,msg->current_posx[1] ,msg->current_posx[2]
487  , msg->current_posx[3] ,msg->current_posx[4] ,msg->current_posx[5]);
488  ROS_INFO(" current_velx : %7.3f %7.3f %7.3f %7.3f %7.3f %7.3f" , msg->current_velx[0],msg->current_velx[1],msg->current_velx[2],msg->current_velx[3],msg->current_velx[4],msg->current_velx[5]);
489  ROS_INFO(" task_err : %7.3f %7.3f %7.3f %7.3f %7.3f %7.3f" , msg->task_err[0],msg->task_err[1],msg->task_err[2],msg->task_err[3],msg->task_err[4],msg->task_err[5]);
490  ROS_INFO(" solution_space : %d" ,(msg->solution_space));
491 
492  temp_data = "";
493  for(int i = 0; i < 3; i++){
494  temp_data += ("dim[" + std::to_string(i) + "] [");
495  for(int j = 0; j < 3; j++){
496  temp_data += (std::to_string(msg->rotation_matrix[i].data[j]) + " ");
497  }
498  temp_data += "] ";
499  }
500  ROS_INFO(" rotation_matrix : %s", temp_data.c_str());
501  ROS_INFO(" dynamic_tor : %7.3f %7.3f %7.3f %7.3f %7.3f %7.3f" , msg->dynamic_tor[0],msg->dynamic_tor[1],msg->dynamic_tor[2],msg->dynamic_tor[3],msg->dynamic_tor[4],msg->dynamic_tor[5]);
502  ROS_INFO(" actual_jts : %7.3f %7.3f %7.3f %7.3f %7.3f %7.3f" , msg->actual_jts[0],msg->actual_jts[1],msg->actual_jts[2],msg->actual_jts[3],msg->actual_jts[4],msg->actual_jts[5]);
503  ROS_INFO(" actual_ejt : %7.3f %7.3f %7.3f %7.3f %7.3f %7.3f" , msg->actual_ejt[0],msg->actual_ejt[1],msg->actual_ejt[2],msg->actual_ejt[3],msg->actual_ejt[4],msg->actual_ejt[5]);
504  ROS_INFO(" actual_ett : %7.3f %7.3f %7.3f %7.3f %7.3f %7.3f" , msg->actual_ett[0],msg->actual_ett[1],msg->actual_ett[2],msg->actual_ett[3],msg->actual_ett[4],msg->actual_ett[5]);
505  ROS_INFO(" sync_time : %7.3f" , msg->sync_time);
506  ROS_INFO(" actual_bk : %d %d %d %d %d %d" , msg->actual_bk[0],msg->actual_bk[1],msg->actual_bk[2],msg->actual_bk[3],msg->actual_bk[4],msg->actual_bk[5]);
507  ROS_INFO(" actual_bt : %d %d %d %d %d " , msg->actual_bt[0],msg->actual_bt[1],msg->actual_bt[2],msg->actual_bt[3],msg->actual_bt[4]);
508  ROS_INFO(" actual_mc : %7.3f %7.3f %7.3f %7.3f %7.3f %7.3f" , msg->actual_mc[0],msg->actual_mc[1],msg->actual_mc[2],msg->actual_mc[3],msg->actual_mc[4],msg->actual_mc[5]);
509  ROS_INFO(" actual_mt : %7.3f %7.3f %7.3f %7.3f %7.3f %7.3f" , msg->actual_mt[0],msg->actual_mt[1],msg->actual_mt[2],msg->actual_mt[3],msg->actual_mt[4],msg->actual_mt[5]);
510 
511 
512  temp_data = "";
513  for(int i = 0; i < 16; i++){
514  temp_data += (std::to_string(msg->ctrlbox_digital_input[i]) + " ");
515  }
516  ROS_INFO(" ctrlbox_digital_input : %s", temp_data.c_str());
517 
518  temp_data = "";
519  for(int i = 0; i < 16; i++){
520  temp_data += (std::to_string(msg->ctrlbox_digital_output[i]) + " ");
521  }
522  ROS_INFO(" ctrlbox_digital_output : %s", temp_data.c_str());
523 
524  temp_data = "";
525  for(int i = 0; i < 6; i++){
526  temp_data += (std::to_string(msg->flange_digital_input[i]) + " ");
527  }
528  ROS_INFO(" flange_digital_input : %s", temp_data.c_str());
529 
530  temp_data = "";
531  for(int i = 0; i < 6; i++){
532  temp_data += (std::to_string(msg->flange_digital_output[i]) + " ");
533  }
534  ROS_INFO(" flange_digital_output : %s", temp_data.c_str());
535 
536  temp_data = "";
537  for(int i = 0; i < msg->modbus_state.size(); i++){
538  temp_data += ("[" + msg->modbus_state[i].modbus_symbol + " , " + std::to_string(msg->modbus_state[i].modbus_value) + "] ");
539  }
540  ROS_INFO(" modbus_state : %s", temp_data.c_str());
541  ROS_INFO(" access_control : %d", msg->access_control);
542  ROS_INFO(" homming_completed : %d", msg->homming_completed);
543  ROS_INFO(" tp_initialized : %d", msg->tp_initialized);
544  ROS_INFO(" mastering_need : %d", msg->mastering_need);
545  ROS_INFO(" drl_stopped : %d", msg->drl_stopped);
546  ROS_INFO(" disconnected : %d", msg->disconnected);
547  }
548 }
549 
551 {
552  ros::NodeHandlePtr node = boost::make_shared<ros::NodeHandle>();
553  ros::Subscriber subRobotState = node->subscribe("/"+ROBOT_ID +ROBOT_MODEL+"/state", 100, msgRobotState_cb);
554 
555  ros::MultiThreadedSpinner spinner(2);
556  spinner.spin();
557 
558  /*
559  ros::AsyncSpinner spinner(4); // Use 4 threads
560  spinner.start();
561  ros::waitForShutdown();
562  */
563 }
564 
565 void SigHandler(int sig)
566 {
567  // Do some custom action.
568  // For example, publish a stop message to some other nodes.
569 
570  // All the default sigint handler does is call shutdown()
571  ROS_INFO("shutdown time! sig=%d",sig);
572  ROS_INFO("shutdown time! sig=%d",sig);
573  ROS_INFO("shutdown time! sig=%d",sig);
574  //ros::ServiceClient srvMoveStop = nh.serviceClient<dsr_msgs::MoveStop>("/dsr01m1013/motion/move_stop");
575 
576  ros::NodeHandlePtr node = boost::make_shared<ros::NodeHandle>();
577  ros::Publisher pubRobotStop = node->advertise<dsr_msgs::RobotStop>("/"+ROBOT_ID +ROBOT_MODEL+"/stop",100);
578 
579  dsr_msgs::RobotStop msg;
580 
581  msg.stop_mode = STOP_TYPE_QUICK;
582  pubRobotStop.publish(msg);
583 
584  ros::shutdown();
585 }
586 
587 int main(int argc, char** argv)
588 {
589  //----- set target robot ---------------
590  string my_robot_id = "dsr01";
591  string my_robot_model = "m1013";
592  if(1 == argc){
593  ROS_INFO("default arguments: dsr01 m1013");
594  }
595  else{
596  if(3 != argc){
597  ROS_ERROR("invalid arguments: <ns> <model> (ex) dsr01 m1013");
598  exit(1);
599  }
600  for (int i = 1; i < argc; i++){
601  printf("argv[%d] = %s\n", i, argv[i]);
602  }
603  my_robot_id = argv[1];
604  my_robot_model = argv[2];
605  }
606  //std::cout << "my_robot_id= " << my_robot_id << ", my_robot_model= " << my_robot_model << endl;
607  SET_ROBOT(my_robot_id, my_robot_model);
608 
609  //----- init ROS ----------------------
610  int rate_sub = 1; // 1 Hz = 1 sec
611  int nPubRate = 100; // 100 Hz (10ms)
612  int i=0, nRes=0;
613  ros::init(argc, argv, "dsr_basic_test_cpp", ros::init_options::NoSigintHandler);
614  ros::NodeHandle nh("~");
615  // Override the default ros sigint handler.
616  // This must be set after the first NodeHandle is created.
617  signal(SIGINT, SigHandler);
618 
619  ros::Publisher pubRobotStop = nh.advertise<dsr_msgs::RobotStop>("/"+ROBOT_ID +ROBOT_MODEL+"/stop",10);
621 
622  ros::ServiceClient srvMoveJoint = nh.serviceClient<dsr_msgs::MoveJoint>("/"+ROBOT_ID +ROBOT_MODEL+"/motion/move_joint");
623  ros::ServiceClient srvMoveLine = nh.serviceClient<dsr_msgs::MoveLine>("/"+ROBOT_ID +ROBOT_MODEL+"/motion/move_line");
624  ros::ServiceClient srvMoveCircle = nh.serviceClient<dsr_msgs::MoveCircle>("/"+ROBOT_ID +ROBOT_MODEL+"/motion/move_circle");
625 
626  // spawn another thread
627  boost::thread thread_sub(thread_subscriber);
628 
629  /*
630  if(argc !=3)
631  {
632  ROS_INFO("cmd : rosrun dsr_control dsr_control_service arg0 arg1");
633  ROS_INFO("arg0: double number, arg1: double number");
634  return 1;
635  }
636  */
637 
639  float p1[6]={0.0,}; //joint
640  float p2[6]={0.0, 0.0, 90.0, 0.0, 90.0, 0.0}; //joint
641 
642  float x1[6]={400, 500, 800.0, 0.0, 180.0, 0.0}; //task
643  float x2[6]={400, 500, 500.0, 0.0, 180.0, 0.0}; //task
644  float velx[2]={50, 50}; // 태스크 속도를 50(mm/sec), 50(deg/sec)로 설정
645  float accx[2]={100, 100}; // 태스크 가속도를 100(mm/sec2), 100(deg/sec2)로 설정
646 
647  float fCirclePos[2][6] = {{559,434.5,651.5,0,180,0}, {559,434.5,251.5,0,180,0}};
648 
649  while(ros::ok())
650  {
651  movej(p1, 30, 30);
652  movej(p2, 100, 100);
653 
654  movel(x1, velx, accx);
655  movel(x2, velx, accx);
656 
657  movec(fCirclePos, velx, accx);
658  }
659 
660  // wait the second thread to finish
661  //thread_sub.join();
662 
663  ros::shutdown();
664  //thread_sub.join();
665 
666  ROS_INFO("dsr_basic_test_cpp finished !!!!!!!!!!!!!!!!!!!!!");
667  return 0;
668 }
int movel(float fTargetPos[NUM_JOINT], float fTargetVel[2], float fTargetAcc[2], float fTargetTime=0.f, float fBlendingRadius=0.f, int nMoveReference=MOVE_REFERENCE_BASE, int nMoveMode=MOVE_MODE_ABSOLUTE, int nBlendingType=BLENDING_SPEED_TYPE_DUPLICATE, int nSyncType=0)
ServiceClient serviceClient(const std::string &service_name, bool persistent=false, const M_string &header_values=M_string())
int amove_spiral(float fRevolution, float fMaxRadius, float fMaxLength, float fTargetVel[2], float fTargetAcc[2], float fTargetTime=0.f, int nTaskAxis=TASK_AXIS_Z, int nMoveReference=MOVE_REFERENCE_TOOL, int nSyncType=1)
std::string temp_data
int amovec(float fTargetPos[2][NUM_TASK], float fTargetVel[2], float fTargetAcc[2], float fTargetTime=0.f, float fBlendingRadius=0.f, int nMoveReference=MOVE_REFERENCE_BASE, int nMoveMode=MOVE_MODE_ABSOLUTE, int nBlendingType=BLENDING_SPEED_TYPE_DUPLICATE, int nSyncType=1)
int move_periodic(float fAmplitude[NUM_TASK], float fPeriodic[NUM_TASK], float fAccelTime=0.f, int nRepeat=1, int nMoveReference=MOVE_REFERENCE_TOOL, int nSyncType=0)
float velx[2]
void msgRobotState_cb(const dsr_msgs::RobotState::ConstPtr &msg)
int amovesj(float fTargetPos[MAX_SPLINE_POINT][NUM_JOINT], int nPosCount, float fTargetVel, float fTargetAcc, float fTargetTime=0.f, int nMoveMode=MOVE_MODE_ABSOLUTE, int nSyncType=1)
int movec(float fTargetPos[2][NUM_TASK], float fTargetVel[2], float fTargetAcc[2], float fTargetTime=0.f, float fBlendingRadius=0.f, int nMoveReference=MOVE_REFERENCE_BASE, int nMoveMode=MOVE_MODE_ABSOLUTE, int nBlendingType=BLENDING_SPEED_TYPE_DUPLICATE, int nSyncType=0)
ROSCPP_DECL void init(int &argc, char **argv, const std::string &name, uint32_t options=0)
int amovesx(float fTargetPos[MAX_SPLINE_POINT][NUM_TASK], int nPosCount, float fTargetVel[2], float fTargetAcc[2], float fTargetTime=0.f, int nMoveReference=MOVE_REFERENCE_BASE, int nMoveMode=MOVE_MODE_ABSOLUTE, int nVelOpt=SPLINE_VELOCITY_OPTION_DEFAULT, int nSyncType=1)
int movesj(float fTargetPos[MAX_SPLINE_POINT][NUM_JOINT], int nPosCount, float fTargetVel, float fTargetAcc, float fTargetTime=0.f, int nMoveMode=MOVE_MODE_ABSOLUTE, int nSyncType=0)
void thread_subscriber()
int amovejx(float fTargetPos[NUM_TASK], float fTargetVel, float fTargetAcc, float fTargetTime=0.f, float fBlendingRadius=0.f, int nMoveReference=MOVE_REFERENCE_BASE, int nMoveMode=MOVE_MODE_ABSOLUTE, int nBlendingType=BLENDING_SPEED_TYPE_DUPLICATE, int nSolSpace=0, int nSyncType=1)
int movej(float fTargetPos[NUM_JOINT], float fTargetVel, float fTargetAcc, float fTargetTime=0.f, float fBlendingRadius=0.f, int nMoveMode=MOVE_MODE_ABSOLUTE, int nBlendingType=BLENDING_SPEED_TYPE_DUPLICATE, int nSyncType=0)
float accx[2]
int main(int argc, char **argv)
#define ROS_INFO(...)
ROSCPP_DECL bool ok()
int amove_periodic(float fAmplitude[NUM_TASK], float fPeriodic[NUM_TASK], float fAccelTime=0.f, int nRepeat=1, int nMoveReference=MOVE_REFERENCE_TOOL, int nSyncType=1)
int amovej(float fTargetPos[NUM_JOINT], float fTargetVel, float fTargetAcc, float fTargetTime=0.f, float fBlendingRadius=0.f, int nMoveMode=MOVE_MODE_ABSOLUTE, int nBlendingType=BLENDING_SPEED_TYPE_DUPLICATE, int nSyncType=1)
Publisher advertise(const std::string &topic, uint32_t queue_size, bool latch=false)
int amovel(float fTargetPos[NUM_JOINT], float fTargetVel[2], float fTargetAcc[2], float fTargetTime=0.f, float fBlendingRadius=0.f, int nMoveReference=MOVE_REFERENCE_BASE, int nMoveMode=MOVE_MODE_ABSOLUTE, int nBlendingType=BLENDING_SPEED_TYPE_DUPLICATE, int nSyncType=1)
virtual void spin(CallbackQueue *queue=0)
int move_wait()
void SigHandler(int sig)
string ROBOT_ID
int amoveb(MOVE_POSB *fTargetPos, int nPosCount, float fTargetVel[2], float fTargetAcc[2], float fTargetTime=0.f, int nMoveReference=MOVE_REFERENCE_BASE, int nMoveMode=MOVE_MODE_ABSOLUTE, int nSyncType=1)
void SET_ROBOT(string id, string model)
int move_spiral(float fRevolution, float fMaxRadius, float fMaxLength, float fTargetVel[2], float fTargetAcc[2], float fTargetTime=0.f, int nTaskAxis=TASK_AXIS_Z, int nMoveReference=MOVE_REFERENCE_TOOL, int nSyncType=0)
string ROBOT_MODEL
ROSCPP_DECL void shutdown()
int moveb(MOVE_POSB *fTargetPos, int nPosCount, float fTargetVel[2], float fTargetAcc[2], float fTargetTime=0.f, int nMoveReference=MOVE_REFERENCE_BASE, int nMoveMode=MOVE_MODE_ABSOLUTE, int nSyncType=0)
int movejx(float fTargetPos[NUM_TASK], float fTargetVel, float fTargetAcc, float fTargetTime=0.f, float fBlendingRadius=0.f, int nMoveReference=MOVE_REFERENCE_BASE, int nMoveMode=MOVE_MODE_ABSOLUTE, int nBlendingType=BLENDING_SPEED_TYPE_DUPLICATE, int nSolSpace=0, int nSyncType=0)
#define ROS_ERROR(...)
int movesx(float fTargetPos[MAX_SPLINE_POINT][NUM_TASK], int nPosCount, float fTargetVel[2], float fTargetAcc[2], float fTargetTime=0.f, int nMoveReference=MOVE_REFERENCE_BASE, int nMoveMode=MOVE_MODE_ABSOLUTE, int nVelOpt=SPLINE_VELOCITY_OPTION_DEFAULT, int nSyncType=0)


cpp
Author(s): Kab Kyoum Kim , Jin Hyuk Gong , Jeongwoo Lee
autogenerated on Sat May 18 2019 02:32:53