single_robot_simple.cpp
Go to the documentation of this file.
1 /*
2  * [c++ example simple] single robot basic test
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 
13 #include "dsr_util.h"
14 #include "dsr_robot.h"
15 
16 using namespace std;
17 using namespace DSR_Robot;
18 
19 //----- set tartget robot----------------------------------------------------
20 string ROBOT_ID = "dsr01";
21 string ROBOT_MODEL = "m1013";
22 void SET_ROBOT(string id, string model) {ROBOT_ID = id; ROBOT_MODEL= model;}
23 //---------------------------------------------------------------------------
24 
26 
27 static void thread_subscriber()
28 {
29  ros::NodeHandlePtr node = boost::make_shared<ros::NodeHandle>();
32  ros::MultiThreadedSpinner spinner(2);
33  spinner.spin();
34 }
35 
36 void SigHandler(int sig)
37 {
38  // Do some custom action.
39  // For example, publish a stop message to some other nodes.
40 
41  // All the default sigint handler does is call shutdown()
42  ROS_INFO("shutdown time! sig=%d",sig);
43  ROS_INFO("shutdown time! sig=%d",sig);
44  ROS_INFO("shutdown time! sig=%d",sig);
45  //ros::ServiceClient srvMoveStop = nh.serviceClient<dsr_msgs::MoveStop>("/dsr01m1013/motion/move_stop");
46 
47  ros::NodeHandlePtr node = boost::make_shared<ros::NodeHandle>();
48  ros::Publisher pubRobotStop = node->advertise<dsr_msgs::RobotStop>("/"+ROBOT_ID +ROBOT_MODEL+"/stop",100);
49 
50  dsr_msgs::RobotStop msg;
51 
52  msg.stop_mode = STOP_TYPE_QUICK;
53  pubRobotStop.publish(msg);
54 
55  ros::shutdown();
56 }
57 
58 int main(int argc, char** argv)
59 {
60  //----- set target robot ---------------
61  string my_robot_id = "dsr01";
62  string my_robot_model = "m1013";
63  if(1 == argc){
64  ROS_INFO("default arguments: dsr01 m1013");
65  }
66  else{
67  if(3 != argc){
68  ROS_ERROR("invalid arguments: <ns> <model> (ex) dsr01 m1013");
69  exit(1);
70  }
71  for (int i = 1; i < argc; i++){
72  printf("argv[%d] = %s\n", i, argv[i]);
73  }
74  my_robot_id = argv[1];
75  my_robot_model = argv[2];
76  }
77  //std::cout << "my_robot_id= " << my_robot_id << ", my_robot_model= " << my_robot_model << endl;
78  SET_ROBOT(my_robot_id, my_robot_model);
79 
80  //----- init ROS ----------------------
81  ros::init(argc, argv, "single_robot_simple_cpp", ros::init_options::NoSigintHandler);
82  ros::NodeHandle nh("~");
83  // Override the default ros sigint handler.
84  // This must be set after the first NodeHandle is created.
85  signal(SIGINT, SigHandler);
86  ros::Publisher pubRobotStop = nh.advertise<dsr_msgs::RobotStop>("/"+ROBOT_ID +ROBOT_MODEL+"/stop",10);
88 
89  //----- create DsrRobot ---------------
90  CDsrRobot robot(nh, my_robot_id, my_robot_model);
91 
92  // run subscriber thread (for monitoring)
93  boost::thread thread_sub(thread_subscriber);
94 
96  float p1[6]={0.0,}; //joint
97  float p2[6]={0.0, 0.0, 90.0, 0.0, 90.0, 0.0}; //joint
98 
99  float x1[6]={400, 500, 800.0, 0.0, 180.0, 0.0}; //task
100  float x2[6]={400, 500, 500.0, 0.0, 180.0, 0.0}; //task
101  float velx[2]={50, 50}; // 태스크 속도를 50(mm/sec), 50(deg/sec)로 설정
102  float accx[2]={100, 100}; // 태스크 가속도를 100(mm/sec2), 100(deg/sec2)로 설정
103 
104 
105  float veljx[6] = {50, 50, 50, 50, 50, 50};
106  float accjx[6] = {100, 100, 100, 100, 100, 100};
107  float fCirclePos[2][6] = {{559,434.5,651.5,0,180,0}, {559,434.5,251.5,0,180,0}};
108 
109  float amp[6] = {10,0,0,0,30,0};
110  float periodic[6] = {1,0,1.5,0,0,0};
111 
112  float fSJPos[3][6] = {{10, -10, 20, -30, 10, 20}, {25, 0, 10, -50, 20, 40}, {50, 50, 50, 50, 50, 50}};
113  float fSXPos[3][6] = {{600, 600, 600, 0, 175, 0},{600, 750, 600, 0, 175, 0},{150, 600, 450, 0, 175, 0}};
114 
115  float bx1[2][6] = {{370, 670, 650, 0, 180, 0}, {370, 670, 650, 0, 180, 0}};
116  float bx2[2][6] = {{370, 670, 400, 0, 180, 0},{370, 545, 400, 0, 180, 0}};
117  float bx3[2][6] = {{370, 595, 400, 0, 180, 0}, {370, 595, 400, 0, 180, 0}};
118 
119  MOVE_POSB posb[3];// = {bx1, 0, 40}, {bx2, 1, 40}, {bx3, 1, 40};
120  for(int i=0; i<2; i++){
121  for(int j=0; j<6; j++){
122  posb[0]._fTargetPos[i][j] = bx1[i][j];
123  }
124  }
125  for(int i=0; i<2; i++){
126  for(int j=0; j<6; j++){
127  posb[1]._fTargetPos[i][j] = bx2[i][j];
128  }
129  }
130  for(int i=0; i<2; i++){
131  for(int j=0; j<6; j++){
132  posb[2]._fTargetPos[i][j] = bx3[i][j];
133  }
134  }
135  posb[0]._iBlendType = 0;
136  posb[1]._iBlendType = 1;
137  posb[2]._iBlendType = 0;
138  posb[0]._fBlendRad = 20;
139  posb[1]._fBlendRad = 20;
140  posb[2]._fBlendRad = 20;
141 
142  while(ros::ok())
143  {
144  robot.movej(p1, 30, 30);
145  robot.movej(p2, 30, 30);
146  robot.movel(x1, velx, accx);
147  robot.movel(x2, velx, accx);
148 
149  robot.movec(fCirclePos, velx, accx);
150  robot.move_periodic(amp, periodic, 0.5, 3, 0);
151  robot.move_spiral(9.5, 20.0, 50.0, velx, accx, 20.0, TASK_AXIS_Z);
152  robot.movesj(fSJPos,3, 30, 100);
153  robot.movesx(fSXPos, 3, velx, accx);
154 
155  robot.moveb(posb, 3, velx, accx);
156 
157  }
158 
159  ROS_INFO("single_robot_simple_cpp finished !!!!!!!!!!!!!!!!!!!!!");
160  ROS_INFO("single_robot_simple_cpp finished !!!!!!!!!!!!!!!!!!!!!");
161  ROS_INFO("single_robot_simple_cpp finished !!!!!!!!!!!!!!!!!!!!!");
162 
164  thread_sub.join();
165 
166  ROS_INFO("single_robot_simple_cpp finished !!!!!!!!!!!!!!!!!!!!!");
167  return 0;
168 }
float amp[6]
string ROBOT_ID
float velx[2]
void SigHandler(int sig)
ROSCPP_DECL void init(int &argc, char **argv, const std::string &name, uint32_t options=0)
float accx[2]
void SET_ROBOT(string id, string model)
int main(int argc, char **argv)
#define ROS_INFO(...)
ROSCPP_DECL bool ok()
Publisher advertise(const std::string &topic, uint32_t queue_size, bool latch=false)
static void thread_subscriber()
ROSCPP_DECL void shutdown()
#define ROS_ERROR(...)
string ROBOT_MODEL


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