pick_and_place_simple.cpp
Go to the documentation of this file.
1 /*
2  * [c++ gripper example] pick and place for doosan robot (vitual)
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 
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 
25 int gripper_move(bool flag)
26 {
27  //ros::ServiceClient srvMoveJoint = nh.serviceClient<dsr_msgs::MoveJoint>("/dsr01m1013/motion/move_joint");
28  ros::NodeHandlePtr node = boost::make_shared<ros::NodeHandle>();
29 
30 
31  if(flag) //true -> open ///false -> close
32  {
33  ros::ServiceClient srvRobotiq2FOpen = node->serviceClient<dsr_msgs::Robotiq2FOpen>("/"+ROBOT_ID + ROBOT_MODEL+"/gripper/robotiq_2f_open");
34  dsr_msgs::Robotiq2FOpen srvOpen;
35 
36  if(srvRobotiq2FOpen.call(srvOpen))
37  {
38  //ROS_INFO("receive srv, srv.response.success: %ld\n", (long int)srvOpen.response.success);
39  return (srvOpen.response.success);
40  }
41  else
42  {
43  ROS_ERROR("Failed to call service dr_control_service : gripper_move\n");
44  ros::shutdown();
45  return -1;
46  }
47  }
48  else{
49  ros::ServiceClient srvRobotiq2FClose = node->serviceClient<dsr_msgs::Robotiq2FClose>("/"+ROBOT_ID + ROBOT_MODEL+"/gripper/robotiq_2f_close");
50  dsr_msgs::Robotiq2FClose srvClose;
51 
52  if(srvRobotiq2FClose.call(srvClose))
53  {
54  //ROS_INFO("receive srv, srv.response.success: %ld\n", (long int)srvClose.response.success);
55  return (srvClose.response.success);
56  }
57  else
58  {
59  ROS_ERROR("Failed to call service dr_control_service : robotiq_2f_close\n");
60  ros::shutdown();
61  return -1;
62  }
63  }
64 
65 
66  return 0;
67 }
68 
70 
71 static void thread_subscriber()
72 {
73  ros::NodeHandlePtr node = boost::make_shared<ros::NodeHandle>();
76  ros::MultiThreadedSpinner spinner(2);
77  spinner.spin();
78 }
79 
80 void SigHandler(int sig)
81 {
82  // Do some custom action.
83  // For example, publish a stop message to some other nodes.
84 
85  // All the default sigint handler does is call shutdown()
86  ROS_INFO("shutdown time! sig=%d",sig);
87  ROS_INFO("shutdown time! sig=%d",sig);
88  ROS_INFO("shutdown time! sig=%d",sig);
89  //ros::ServiceClient srvMoveStop = nh.serviceClient<dsr_msgs::MoveStop>("/dsr01m1013/motion/move_stop");
90 
91  ros::NodeHandlePtr node = boost::make_shared<ros::NodeHandle>();
92  ros::Publisher pubRobotStop = node->advertise<dsr_msgs::RobotStop>("/"+ROBOT_ID +ROBOT_MODEL+"/stop",100);
93 
94  dsr_msgs::RobotStop msg;
95 
96  msg.stop_mode = STOP_TYPE_QUICK;
97  pubRobotStop.publish(msg);
98 
99  ros::shutdown();
100 }
101 
102 int main(int argc, char** argv)
103 {
104  //----- set target robot ---------------
105  string my_robot_id = "dsr01";
106  string my_robot_model = "m1013";
107 
108  if(1 == argc){
109  ROS_INFO("default arguments: dsr01 m1013");
110  }
111  else{
112  if(3 != argc){
113  ROS_ERROR("invalid arguments: <ns> <model> (ex) dsr01 m1013");
114  exit(1);
115  }
116  for (int i = 1; i < argc; i++){
117  printf("argv[%d] = %s\n", i, argv[i]);
118  }
119  my_robot_id = argv[1];
120  my_robot_model = argv[2];
121  }
122  //std::cout << "my_robot_id= " << my_robot_id << ", my_robot_model= " << my_robot_model << endl;
123  SET_ROBOT(my_robot_id, my_robot_model);
124 
125 
126  //----- init ROS ----------------------
127  ros::init(argc, argv, "pick_and_place_simple_cpp", ros::init_options::NoSigintHandler);
128  ros::NodeHandle nh("~");
129  // Override the default ros sigint handler.
130  // This must be set after the first NodeHandle is created.
131  signal(SIGINT, SigHandler);
132  ros::Publisher pubRobotStop = nh.advertise<dsr_msgs::RobotStop>("/"+ROBOT_ID +ROBOT_MODEL+"/stop",10);
134 
135  //----- create DsrRobot ---------------
136  CDsrRobot robot(nh, my_robot_id, my_robot_model);
137 
138  // run subscriber thread (for monitoring)
139  boost::thread thread_sub(thread_subscriber);
140 
142  float p0[6]={0.0, 0.0, 0.0, 0.0, 0.0, 0.0};
143  float p1[6]={0.0, 0.0, 90.0, 0.0, 90.0 , 0.0}; //joint
144  float p2[6]={180.0, 0.0, 90, 0.0, 90.0, 0.0}; //joint
145 
146  float x1[6]={0, 0, -200, 0, 0, 0}; //task
147  float x2[6]={0, 0, 200, 0, 0, 0}; //task
148  float velx[2]={50, 50}; // 태스크 속도를 50(mm/sec), 50(deg/sec)로 설정
149  float accx[2]={100, 100}; // 태스크 가속도를 100(mm/sec2), 100(deg/sec2)로 설정
150 
151  while(ros::ok())
152  {
153  robot.movej(p0, 60, 30);
154  robot.movej(p1, 60, 30);
155 
156  robot.movel(x1, velx, accx, 2, 0.f, MOVE_REFERENCE_BASE, MOVE_MODE_RELATIVE);
157  gripper_move(true); //0.0 - close;
158  ros::Duration(1).sleep();
159  robot.movel(x2, velx, accx, 2, 0.f, MOVE_REFERENCE_BASE, MOVE_MODE_RELATIVE);
160 
161  robot.movej(p2, 60, 30, 3);
162  robot.movel(x1, velx, accx, 2, 0.f, MOVE_REFERENCE_BASE, MOVE_MODE_RELATIVE);
163  gripper_move(false); //0.8 - open
164  ros::Duration(1).sleep();
165  robot.movel(x2, velx, accx, 2, 0.f, MOVE_REFERENCE_BASE, MOVE_MODE_RELATIVE);
166  }
167 
168  ROS_INFO("pick_and_place_simple_cpp finished !!!!!!!!!!!!!!!!!!!!!");
169  ROS_INFO("pick_and_place_simple_cpp finished !!!!!!!!!!!!!!!!!!!!!");
170  ROS_INFO("pick_and_place_simple_cpp finished !!!!!!!!!!!!!!!!!!!!!");
171 
173  thread_sub.join();
174 
175  ROS_INFO("pick_and_place_simple_cpp finished !!!!!!!!!!!!!!!!!!!!!");
176  return 0;
177 }
string ROBOT_MODEL
f
float velx[2]
int gripper_move(bool flag)
bool sleep() const
ROSCPP_DECL void init(int &argc, char **argv, const std::string &name, uint32_t options=0)
bool call(MReq &req, MRes &res)
float accx[2]
#define ROS_INFO(...)
static void thread_subscriber()
ROSCPP_DECL bool ok()
Publisher advertise(const std::string &topic, uint32_t queue_size, bool latch=false)
string ROBOT_ID
ROSCPP_DECL void shutdown()
void SigHandler(int sig)
#define ROS_ERROR(...)
void SET_ROBOT(string id, string model)
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