real_pick_and_place_simple.cpp
Go to the documentation of this file.
1 /*
2  * [c++ gripper example] pick and place for doosan robot (real)
3  * Author: Jin Hyuk Gong (jinhyuk.gong@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 #include "dsr_serial.h"
16 
17 using namespace std;
18 using namespace DSR_Robot;
19 
20 //----- set tartget robot----------------------------------------------------
21 string ROBOT_ID = "dsr01";
22 string ROBOT_MODEL = "m1013";
23 void SET_ROBOT(string id, string model) {ROBOT_ID = id; ROBOT_MODEL= model;}
24 //---------------------------------------------------------------------------
25 
27 
28 int gripper_send_data(string send_data){
29  //unsigned char ask[16] = {0x09, 0x10, 0x03, 0xE8, 0x00, 0x03, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x73, 0x30};
30  ros::NodeHandlePtr node = boost::make_shared<ros::NodeHandle>();
31  ros::ServiceClient srvSerialSendData = node->serviceClient<dsr_msgs::SerialSendData>("/"+ROBOT_ID +ROBOT_MODEL+"/gripper/serial_send_data");
32  dsr_msgs::SerialSendData srv;
33 
34  srv.request.data = send_data;
35 
36  if(srvSerialSendData.call(srv))
37  {
38  //ROS_INFO("receive srv, srv.response.success: %ld\n", (long int)srv.response.success);
39  return (srv.response.success);
40  }
41  else
42  {
43  ROS_ERROR("Failed to call service dr_control_service : serial_send_data\n");
44  //ros::shutdown();
45  return -1;
46  }
47  return 0;
48 }
49 
50 
51 
53 
54 static void thread_subscriber()
55 {
56  ros::NodeHandlePtr node = boost::make_shared<ros::NodeHandle>();
59  ros::MultiThreadedSpinner spinner(2);
60  spinner.spin();
61 }
62 
63 void SigHandler(int sig)
64 {
65  // Do some custom action.
66  // For example, publish a stop message to some other nodes.
67 
68  // All the default sigint handler does is call shutdown()
69  ROS_INFO("shutdown time! sig=%d",sig);
70  ROS_INFO("shutdown time! sig=%d",sig);
71  ROS_INFO("shutdown time! sig=%d",sig);
72  //ros::ServiceClient srvMoveStop = nh.serviceClient<dsr_msgs::MoveStop>("/dsr01m1013/motion/move_stop");
73 
74  ros::NodeHandlePtr node = boost::make_shared<ros::NodeHandle>();
75  ros::Publisher pubRobotStop = node->advertise<dsr_msgs::RobotStop>("/"+ROBOT_ID +ROBOT_MODEL+"/stop",100);
76 
77  dsr_msgs::RobotStop msg;
78 
79  msg.stop_mode = STOP_TYPE_QUICK;
80  pubRobotStop.publish(msg);
81 
82  ros::shutdown();
83 }
84 
85 int main(int argc, char** argv)
86 {
87  //----- set target robot ---------------
88  string my_robot_id = "dsr01";
89  string my_robot_model = "m1013";
90  if(1 == argc){
91  ROS_INFO("default arguments: dsr01 m1013");
92  }
93  else{
94  if(3 != argc){
95  ROS_ERROR("invalid arguments: <ns> <model> (ex) dsr01 m1013");
96  exit(1);
97  }
98  for (int i = 1; i < argc; i++){
99  printf("argv[%d] = %s\n", i, argv[i]);
100  }
101  my_robot_id = argv[1];
102  my_robot_model = argv[2];
103  }
104  //std::cout << "my_robot_id= " << my_robot_id << ", my_robot_model= " << my_robot_model << endl;
105  SET_ROBOT(my_robot_id, my_robot_model);
106 
107  //----- init ROS ----------------------
108  ros::init(argc, argv, "real_pick_and_place", ros::init_options::NoSigintHandler);
109  ros::NodeHandle nh("~");
110  // Override the default ros sigint handler.
111  // This must be set after the first NodeHandle is created.
112  signal(SIGINT, SigHandler);
113  ros::Publisher pubRobotStop = nh.advertise<dsr_msgs::RobotStop>("/"+ROBOT_ID +ROBOT_MODEL+"/stop",10);
115 
116  //----- create DsrRobot ---------------
117  CDsrRobot robot(nh, my_robot_id, my_robot_model);
118 
119  // run subscriber thread (for monitoring)
120  boost::thread thread_sub(thread_subscriber);
121 
123 
124  float p0[6]={0.0, 0.0, 0.0, 0.0, 0.0, 0.0};
125  float p1[6]={0.0, 0.0, 90.0, 0.0, 90.0 , 0.0}; //joint
126  float p2[6]={180.0, 0.0, 90, 0.0, 90.0, 0.0}; //joint
127 
128  float x1[6]={0, 0, -200, 0, 0, 0}; //task
129  float x2[6]={0, 0, 200, 0, 0, 0}; //task
130  float velx[2]={50, 50}; // 태스크 속도를 50(mm/sec), 50(deg/sec)로 설정
131  float accx[2]={100, 100}; // 태스크 가속도를 100(mm/sec2), 100(deg/sec2)로 설정
132  unsigned char init_data[15] = {0x09, 0x10, 0x03, 0xE8, 0x00, 0x03, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x73, 0x30};
133  unsigned char activation_data[15] = {0x09, 0x10, 0x03, 0xE8, 0x00, 0x03, 0x06, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x72, 0xE1};
134  unsigned char open_data[15] = {0x09, 0x10, 0x03, 0xE8, 0x00, 0x03, 0x06, 0x09, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0x72, 0x19};
135  unsigned char close_data[15] = {0x09, 0x10, 0x03, 0xE8, 0x00, 0x03, 0x06, 0x09, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0x42, 0x29};
136 
137  int cnt = 0;
138 
139  while(ros::ok())
140  {
141  if(cnt == 0){
142  gripper_send_data("0x09\\0x10\\0x03\\0xE8\\0x00\\0x03\\0x06\\0x00\\0x00\\0x00\\0x00\\0x00\\0x00\\0x73\\0x30");
143  //gripper_send_data("abcd");
144  ros::Duration(4).sleep();
145  //gripper_send_data("efgh");
146  gripper_send_data("0x09\\0x10\\0x03\\0xE8\\0x00\\0x03\\0x06\\0x00\\0x00\\0x00\\0x00\\0x00\\0x00\\0x73\\0x30");
147 
148  //gripper_send_data("0x09\\0x10\\0x03\\0xE8\\0x00\\0x03\\0x06\\0x01\\0x00\\0x00\\0x00\\0x00\\0x00\\0x72\\0xE1");
149  ros::Duration(4).sleep();
150  }
151  //gripper_send_data("1234");
152  gripper_send_data("0x09\\0x10\\0x03\\0xE8\\0x00\\0x03\\0x06\\0x09\\0x00\\0x00\\0x00\\0xFF\\0xFF\\0x72\\0x19");
153  ros::Duration(4).sleep();
154  //gripper_send_data("3456");
155  gripper_send_data("0x09\\0x10\\0x03\\0xE8\\0x00\\0x03\\0x06\\0x09\\0x00\\0x00\\0xFF\\0xFF\\0xFF\\0x42\\0x29");
156  ros::Duration(4).sleep();
157 
158  cnt++;
159  }
160 
161  ROS_INFO("real_pick_and_place finished !!!!!!!!!!!!!!!!!!!!!");
162  ROS_INFO("real_pick_and_place finished !!!!!!!!!!!!!!!!!!!!!");
163  ROS_INFO("real_pick_and_place finished !!!!!!!!!!!!!!!!!!!!!");
164 
166  thread_sub.join();
167 
168  ROS_INFO("real_pick_and_place finished !!!!!!!!!!!!!!!!!!!!!");
169  return 0;
170 }
void SET_ROBOT(string id, string model)
float velx[2]
bool sleep() const
ROSCPP_DECL void init(int &argc, char **argv, const std::string &name, uint32_t options=0)
int main(int argc, char **argv)
void SigHandler(int sig)
float accx[2]
int gripper_send_data(string send_data)
static void thread_subscriber()
#define ROS_INFO(...)
ROSCPP_DECL bool ok()
Publisher advertise(const std::string &topic, uint32_t queue_size, bool latch=false)
string ROBOT_MODEL
ROSCPP_DECL void shutdown()
#define ROS_ERROR(...)


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