dsr_service_drl_simple.cpp
Go to the documentation of this file.
1 /*
2  * [c++ example simple] DRL(Doosan Robot Language) test for doosan robot
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 <sstream>
12 #include <std_msgs/String.h>
13 
14 #include "dsr_util.h"
15 #include "dsr_robot.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 void msgRobotState_cb(const dsr_msgs::RobotState::ConstPtr& msg)
29 {
30  static int sn_cnt =0;
31 
32  sn_cnt++;
33  if(0==(sn_cnt % 100))
34  {
35  ROS_INFO("________ ROBOT STATUS ________");
36  ROS_INFO(" robot_state : %d", msg->robot_state);
37  ROS_INFO(" robot_state_str : %s", msg->robot_state_str.c_str());
38  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]
39  ,msg->current_posj[3] ,msg->current_posj[4] ,msg->current_posj[5] );
40  ROS_INFO(" io_control_box : %d", msg->io_control_box);
41  //ROS_INFO(" io_modbus : %d", msg->io_modbus);
42  //ROS_INFO(" error : %d", msg->error);
43  ROS_INFO(" access_control : %d", msg->access_control);
44  ROS_INFO(" homming_completed : %d", msg->homming_completed);
45  ROS_INFO(" tp_initialized : %d", msg->tp_initialized);
46  ROS_INFO(" speed : %d", msg->speed);
47  ROS_INFO(" mastering_need : %d", msg->mastering_need);
48  ROS_INFO(" drl_stopped : %d", msg->drl_stopped);
49  ROS_INFO(" disconnected : %d", msg->disconnected);
50  }
51 }
52 
53 static void thread_subscriber()
54 {
55  ros::NodeHandlePtr node = boost::make_shared<ros::NodeHandle>();
58  ros::MultiThreadedSpinner spinner(2);
59  spinner.spin();
60 }
61 
62 void SigHandler(int sig)
63 {
64  // Do some custom action.
65  // For example, publish a stop message to some other nodes.
66 
67  // All the default sigint handler does is call shutdown()
68  ROS_INFO("shutdown time!");
69  ROS_INFO("shutdown time!");
70  ROS_INFO("shutdown time!");
71  //ros::ServiceClient srvMoveStop = nh.serviceClient<dsr_msgs::MoveStop>("/dsr01m1013/motion/move_stop");
72 
73  ros::NodeHandlePtr node = boost::make_shared<ros::NodeHandle>();
74  ros::Publisher pubRobotStop = node->advertise<dsr_msgs::RobotStop>("/"+ROBOT_ID +ROBOT_MODEL+"/stop",100);
75 
76  dsr_msgs::RobotStop msg;
77 
78  msg.stop_mode = STOP_TYPE_QUICK;
79  pubRobotStop.publish(msg);
80 
81  ros::shutdown();
82 }
83 
84 int main(int argc, char** argv)
85 {
86  //----- set target robot ---------------
87  string my_robot_id = "dsr01";
88  string my_robot_model = "m1013";
89  if(1 == argc){
90  ROS_INFO("default arguments: dsr01 m1013");
91  }
92  else{
93  if(3 != argc){
94  ROS_ERROR("invalid arguments: <ns> <model> (ex) dsr01 m1013");
95  exit(1);
96  }
97  for (int i = 1; i < argc; i++){
98  printf("argv[%d] = %s\n", i, argv[i]);
99  }
100  my_robot_id = argv[1];
101  my_robot_model = argv[2];
102  }
103  //std::cout << "my_robot_id= " << my_robot_id << ", my_robot_model= " << my_robot_model << endl;
104  SET_ROBOT(my_robot_id, my_robot_model);
105 
106  //----- init ROS ----------------------
107  ros::init(argc, argv, "dsr_service_drl_cpp", ros::init_options::NoSigintHandler);
108  ros::NodeHandle nh("~");
109  // Override the default ros sigint handler.
110  // This must be set after the first NodeHandle is created.
111  signal(SIGINT, SigHandler);
112  ros::Publisher pubRobotStop = nh.advertise<dsr_msgs::RobotStop>("/"+ROBOT_ID +ROBOT_MODEL+"/stop",10);
114 
115  //----- create DsrRobot ---------------
116  CDsrRobot robot(nh, my_robot_id, my_robot_model);
117 
118  // run subscriber thread (for monitoring)
119  boost::thread thread_sub(thread_subscriber);
120 
122  std::string drlCodeMove = "set_velj(50)\nset_accj(50)\nmovej([0,0,90,0,90,0])\n";
123  std::string drlCodeReset = "movej([0,0,0,0,0,0])\n";
124  std::string mode;
125  int _rate;
126  nh.getParam("/dsr/mode", mode);
127  ROS_INFO("current mode is : %s", mode.c_str());
128  if(mode == "real"){
129  robot.drl_start(ROBOT_SYSTEM_REAL, drlCodeMove + drlCodeReset);
130  }
131  else{
132  robot.drl_start(ROBOT_SYSTEM_VIRTUAL, drlCodeMove + drlCodeReset);
133  }
134  //robot.drl_start(ROBOT_SYSTEM_VIRTUAL, drlCodeReset);
135 
136  while(ros::ok())
137  {
138  }
139  thread_sub.join();
140  ROS_INFO("dsr_service_test finished !!!!!!!!!!!!!!!!!!!!!");
141  return 0;
142 }
void msgRobotState_cb(const dsr_msgs::RobotState::ConstPtr &msg)
int main(int argc, char **argv)
ROSCPP_DECL void init(int &argc, char **argv, const std::string &name, uint32_t options=0)
void SigHandler(int sig)
static void thread_subscriber()
string ROBOT_MODEL
#define ROS_INFO(...)
bool getParam(const std::string &key, std::string &s) const
ROSCPP_DECL bool ok()
Publisher advertise(const std::string &topic, uint32_t queue_size, bool latch=false)
void SET_ROBOT(string id, string model)
ROSCPP_DECL void shutdown()
#define ROS_ERROR(...)
string ROBOT_ID


cpp
Author(s): Kab Kyoum Kim , Jin Hyuk Gong , Jeongwoo Lee
autogenerated on Thu Jun 20 2019 19:43:26