m1013x2_sync.cpp
Go to the documentation of this file.
1 /*
2  * [c++ demo] muliti robot sync 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 
12 #include "dsr_util.h"
13 #include "dsr_robot.h"
14 
15 using namespace std;
16 using namespace DSR_Util;
17 using namespace DSR_Robot;
18 
19 //----- set tartget robot----------------------------------------------------
20 #define NUM_ROBOT 6
21 string ROBOT_ID = "dsr01";
22 string ROBOT_MODEL = "m1013";
23 string ROBOT_ID2 = "dsr02";
24 string ROBOT_MODEL2 = "m1013";
25 
27 
28 
29 CRobotSync RobotSync(NUM_ROBOT);
30 
31 float JReady[6] = {0, -20, 110, 0, 60, 0}; //posj
32 float TCP_POS[6] = {0, 0, 0,0 ,0, 0};
33 float J00[6] = {-180, 0, -145, 0, -35, 0};
34 float J01r[6] = {-180.0, 71.4, -145.0, 0.0, -9.7, 0.0};
35 
37 {
38  int nRobotID = 0;
39  CDsrRobot r1(nh,"dsr01","m1013");
40 
41  RobotSync.Wait(nRobotID);
42  r1.movej(JReady, 20, 20);
43 
44  while(1)
45  {
46  RobotSync.Wait(nRobotID);
47  r1.movej(J00, 20, 20);
48 
49  RobotSync.Wait(nRobotID);
50  r1.movej(J01r, 20, 20);
51  }
52 }
53 
55 {
56  int nRobotID = 1;
57  CDsrRobot r2(nh,"dsr02","m1013");
58 
59  RobotSync.Wait(nRobotID);
60  r2.movej(JReady, 20, 20);
61 
62  while(1)
63  {
64  RobotSync.Wait(nRobotID);
65  r2.movej(J00, 20, 20);
66 
67  RobotSync.Wait(nRobotID);
68  r2.movej(J01r, 20, 20);
69  }
70 
71 }
72 
74 {
75  int nRobotID = 2;
76  while(1)
77  {
78  //ROS_INFO("thread_robot3 running...");
79  RobotSync.Wait(nRobotID);
80  ROS_INFO("R3 do somethind...");
81  time_sleep(0.1);
83  }
84 }
85 
87 {
88  int nRobotID = 3;
89  while(1)
90  {
91  //ROS_INFO("thread_robot4 running...");
92  RobotSync.Wait(nRobotID);
93  ROS_INFO("R4 do somethind...");
94  time_sleep(0.1);
96  }
97 }
98 
100 {
101  int nRobotID = 4;
102  while(1)
103  {
104  //ROS_INFO("thread_robot5 running...");
105  RobotSync.Wait(nRobotID);
106  ROS_INFO("R5 do somethind...");
107  time_sleep(0.1);
109  }
110 }
111 
113 {
114  int nRobotID = 5;
115  while(1)
116  {
117  //ROS_INFO("thread_robot6 running...");
118  RobotSync.Wait(nRobotID);
119  ROS_INFO("R6 do somethind...");
120  time_sleep(0.1);
121  }
122 }
123 
124 void SigHandler(int sig)
125 {
126  // Do some custom action.
127  // For example, publish a stop message to some other nodes.
128 
129  // All the default sigint handler does is call shutdown()
130  ROS_INFO("shutdown time!");
131  ROS_INFO("shutdown time!");
132  ROS_INFO("shutdown time!");
133  //ros::ServiceClient srvMoveStop = nh.serviceClient<dsr_msgs::MoveStop>("/doosan_robot/motion/move_stop");
134 
135  ros::NodeHandlePtr node = boost::make_shared<ros::NodeHandle>();
136  //ros::Publisher pubRobotStop = node->advertise<dsr_msgs::RobotStop>("/doosan_robot/stop",100);
137  ros::Publisher pubRobotStop = node->advertise<dsr_msgs::RobotStop>("/"+ROBOT_ID +ROBOT_MODEL +"/stop",100);
138  ros::Publisher pubRobotStop2= node->advertise<dsr_msgs::RobotStop>("/"+ROBOT_ID2 +ROBOT_MODEL2+"/stop",100);
139 
140  dsr_msgs::RobotStop msg;
141 
142  msg.stop_mode = STOP_TYPE_QUICK;
143 
144  pubRobotStop.publish(msg);
145  pubRobotStop2.publish(msg);
146 
147  ros::shutdown();
148 }
149 
150 int main(int argc, char** argv)
151 {
152  ros::init(argc, argv, "m1013x2_sync_cpp", ros::init_options::NoSigintHandler);
153  ros::NodeHandle nh("~");
154  // Override the default ros sigint handler.
155  // This must be set after the first NodeHandle is created.
156  signal(SIGINT, SigHandler);
157 
158  ros::Publisher pubRobotStop = nh.advertise<dsr_msgs::RobotStop>("/"+ROBOT_ID +ROBOT_MODEL +"/stop",10);
159  ros::Publisher pubRobotStop2 = nh.advertise<dsr_msgs::RobotStop>("/"+ROBOT_ID2 +ROBOT_MODEL2+"/stop",10);
160 
161  // spawn another thread
162  boost::thread thread_r1(thread_robot1, nh);
163  boost::thread thread_r2(thread_robot2, nh);
164  boost::thread thread_r3(thread_robot3, nh);
165  boost::thread thread_r4(thread_robot4, nh);
166  boost::thread thread_r5(thread_robot5, nh);
167  boost::thread thread_r6(thread_robot6, nh);
168 
169  while(1)
170  {
171  time_sleep(0.01);
172  RobotSync.WakeUpAll();
173  }
174 
175  ROS_INFO("m1013x2_sync2_cpp finished !!!!!!!!!!!!!!!!!!!!!");
176  return 0;
177 }
CRobotSync RobotSync(NUM_ROBOT)
void thread_robot2(ros::NodeHandle nh)
void thread_robot1(ros::NodeHandle nh)
float JReady[6]
void thread_robot6(ros::NodeHandle nh)
ROSCPP_DECL void init(int &argc, char **argv, const std::string &name, uint32_t options=0)
void thread_robot3(ros::NodeHandle nh)
void thread_robot4(ros::NodeHandle nh)
string ROBOT_ID2
void thread_robot5(ros::NodeHandle nh)
#define NUM_ROBOT
#define ROS_INFO(...)
float J01r[6]
Publisher advertise(const std::string &topic, uint32_t queue_size, bool latch=false)
string ROBOT_MODEL
void SigHandler(int sig)
float TCP_POS[6]
float J00[6]
ROSCPP_DECL void shutdown()
string ROBOT_ID
string ROBOT_MODEL2
int main(int argc, char **argv)


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