dsr_service_io_simple.cpp
Go to the documentation of this file.
1 /*
2  * [c++ example simple] I/O 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 
12 #include "dsr_util.h"
13 #include "dsr_robot.h"
14 
15 using namespace std;
16 using namespace DSR_Robot;
17 
18 std::string temp_data;
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 void msgRobotState_cb(const dsr_msgs::RobotState::ConstPtr& msg)
28 {
29  static int sn_cnt =0;
30 
31  sn_cnt++;
32  if(0==(sn_cnt % 100))
33  {
34  ROS_INFO("________ ROBOT STATUS ________");
35  ROS_INFO(" robot_state : %d", msg->robot_state);
36  ROS_INFO(" robot_state_str : %s", msg->robot_state_str.c_str());
37  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]
38  ,msg->current_posj[3] ,msg->current_posj[4] ,msg->current_posj[5] );
39  ROS_INFO(" current_posx : %7.3f %7.3f %7.3f %7.3f %7.3f %7.3f",msg->current_posx[0] ,msg->current_posx[1] ,msg->current_posx[2]
40  ,msg->current_posx[3] ,msg->current_posx[4] ,msg->current_posx[5] );
41  temp_data = "";
42  for(int i = 0; i < 16; i++){
43  temp_data += (std::to_string(msg->ctrlbox_digital_input[i]) + " ");
44  }
45  ROS_INFO(" ctrlbox_digital_input : %s", temp_data.c_str());
46 
47  temp_data = "";
48  for(int i = 0; i < 16; i++){
49  temp_data += (std::to_string(msg->ctrlbox_digital_output[i]) + " ");
50  }
51  ROS_INFO(" ctrlbox_digital_output : %s", temp_data.c_str());
52 
53  temp_data = "";
54  for(int i = 0; i < 6; i++){
55  temp_data += (std::to_string(msg->flange_digital_input[i]) + " ");
56  }
57  ROS_INFO(" flange_digital_input : %s", temp_data.c_str());
58 
59  temp_data = "";
60  for(int i = 0; i < 6; i++){
61  temp_data += (std::to_string(msg->flange_digital_output[i]) + " ");
62  }
63  ROS_INFO(" flange_digital_output : %s", temp_data.c_str());
64 
65  temp_data = "";
66  for(int i = 0; i < msg->modbus_state.size(); i++){
67  temp_data += ("[" + msg->modbus_state[i].modbus_symbol + " , " + std::to_string(msg->modbus_state[i].modbus_value) + "] ");
68  }
69  ROS_INFO(" modbus_state : %s", temp_data.c_str());
70  ROS_INFO(" access_control : %d", msg->access_control);
71  ROS_INFO(" homming_completed : %d", msg->homming_completed);
72  ROS_INFO(" tp_initialized : %d", msg->tp_initialized);
73  ROS_INFO(" joint_speed : %7.3f %7.3f %7.3f %7.3f %7.3f %7.3f",msg->current_velj[0] ,msg->current_velj[1] ,msg->current_velj[2]
74  ,msg->current_velj[3] ,msg->current_velj[4] ,msg->current_velj[5] );
75  ROS_INFO(" task_speed : %7.3f %7.3f %7.3f %7.3f %7.3f %7.3f",msg->current_velx[0] ,msg->current_velx[1] ,msg->current_velx[2]
76  ,msg->current_velx[3] ,msg->current_velx[4] ,msg->current_velx[5] );
77  ROS_INFO(" mastering_need : %d", msg->mastering_need);
78  ROS_INFO(" drl_stopped : %d", msg->drl_stopped);
79  ROS_INFO(" disconnected : %d", msg->disconnected);
80  }
81 }
82 
83 static void thread_subscriber()
84 {
85  ros::NodeHandlePtr node = boost::make_shared<ros::NodeHandle>();
88  ros::MultiThreadedSpinner spinner(2);
89  spinner.spin();
90 }
91 
92 void SigHandler(int sig)
93 {
94  // Do some custom action.
95  // For example, publish a stop message to some other nodes.
96 
97  // All the default sigint handler does is call shutdown()
98  ROS_INFO("shutdown time!");
99  ROS_INFO("shutdown time!");
100  ROS_INFO("shutdown time!");
101  //ros::ServiceClient srvMoveStop = nh.serviceClient<dsr_msgs::MoveStop>("/dsr01m1013/motion/move_stop");
102 
103  ros::NodeHandlePtr node = boost::make_shared<ros::NodeHandle>();
104  ros::Publisher pubRobotStop = node->advertise<dsr_msgs::RobotStop>("/"+ROBOT_ID +ROBOT_MODEL+"/stop",100);
105 
106  dsr_msgs::RobotStop msg;
107 
108  msg.stop_mode = STOP_TYPE_QUICK;
109  pubRobotStop.publish(msg);
110 
111  ros::shutdown();
112 }
113 
114 int main(int argc, char** argv)
115 {
116  //----- set target robot ---------------
117  string my_robot_id = "dsr01";
118  string my_robot_model = "m1013";
119  if(1 == argc){
120  ROS_INFO("default arguments: dsr01 m1013");
121  }
122  else{
123  if(3 != argc){
124  ROS_ERROR("invalid arguments: <ns> <model> (ex) dsr01 m1013");
125  exit(1);
126  }
127  for (int i = 1; i < argc; i++){
128  printf("argv[%d] = %s\n", i, argv[i]);
129  }
130  my_robot_id = argv[1];
131  my_robot_model = argv[2];
132  }
133  //std::cout << "my_robot_id= " << my_robot_id << ", my_robot_model= " << my_robot_model << endl;
134  SET_ROBOT(my_robot_id, my_robot_model);
135 
136  //----- init ROS ----------------------
137  ros::init(argc, argv, "dsr_service_test_cpp", ros::init_options::NoSigintHandler);
138  ros::NodeHandle nh("~");
139  // Override the default ros sigint handler.
140  // This must be set after the first NodeHandle is created.
141  signal(SIGINT, SigHandler);
142  ros::Publisher pubRobotStop = nh.advertise<dsr_msgs::RobotStop>("/"+ROBOT_ID +ROBOT_MODEL+"/stop",10);
144 
145  //----- create DsrRobot ---------------
146  CDsrRobot robot(nh, my_robot_id, my_robot_model);
147 
148  // run subscriber thread (for monitoring)
149  boost::thread thread_sub(thread_subscriber);
150 
152  robot.set_digital_output(2, true);
153  if(robot.get_digital_input(2) == 1){
154  robot.set_digital_output(11, true);
155  }
156 
157  while(ros::ok())
158  {
159  }
160  thread_sub.join();
161  // wait the second thread to finish
162  ROS_INFO("dsr_service_test finished !!!!!!!!!!!!!!!!!!!!!");
163  return 0;
164 }
std::string temp_data
int main(int argc, char **argv)
string ROBOT_ID
ROSCPP_DECL void init(int &argc, char **argv, const std::string &name, uint32_t options=0)
void msgRobotState_cb(const dsr_msgs::RobotState::ConstPtr &msg)
void SigHandler(int sig)
#define ROS_INFO(...)
ROSCPP_DECL bool ok()
Publisher advertise(const std::string &topic, uint32_t queue_size, bool latch=false)
ROSCPP_DECL void shutdown()
void SET_ROBOT(string id, string model)
static void thread_subscriber()
#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