dsr_control_node.cpp
Go to the documentation of this file.
1 /*
2  * dsr_control_node
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 <signal.h>
12 
13 using namespace dsr_control;
14 
15 int g_nKill_dsr_control = false;
16 void SigHandler(int sig)
17 {
18  // Do some custom action.
19  // For example, publish a stop message to some other nodes.
20 
21  // All the default sigint handler does is call shutdown()
22  ROS_INFO("[dsr_control] shutdown time! (sig = %d)",sig);
23  ROS_INFO("[dsr_control] shutdown time! (sig = %d)",sig);
24  ROS_INFO("[dsr_control] shutdown time! (sig = %d)",sig);
25 
26  g_nKill_dsr_control = true;
28  ros::shutdown();
29 }
30 
31 int main(int argc, char** argv)
32 {
33  //----- init ROS ----------------------
35  ros::init(argc, argv, "dsr_control_node", ros::init_options::NoSigintHandler);
36  ros::NodeHandle private_nh("~");
38  // Override the default ros sigint handler.
39  // This must be set after the first NodeHandle is created.
40  signal(SIGINT, SigHandler);
41 
42  //----- get param ---------------------
43  int rate;
44  private_nh.param<int>("rate", rate, 50);
45  ROS_INFO("rate is %d\n", rate);
46  ros::Rate r(rate);
47 
49  DRHWInterface* pArm = NULL;
50  pArm = new DRHWInterface(private_nh);
51 
52  if(!pArm->init() ){
53  ROS_ERROR("[dsr_control] Error initializing robot");
54  return -1;
55  }
57  controller_manager::ControllerManager cm(pArm, private_nh);
58  ros::AsyncSpinner spinner(1);
59  spinner.start();
60 
61 // int rate;
62 // private_nh.param<int>("rate", rate, 50);
63 // ROS_INFO("rate is %d\n", rate);
64 // ros::Rate r(rate);
65 
66  ros::Time last_time;
67  ros::Time curr_time;
68  ros::Duration elapsed;
69  last_time = ros::Time::now();
70 
71  ROS_INFO("[dsr_control] controller_manager is updating!");
72 
73  while(ros::ok() && (false==g_nKill_dsr_control))
75  {
76  try{
78  curr_time = ros::Time::now();
79  elapsed = curr_time - last_time;
80  if(pArm) pArm->read(elapsed);
81  cm.update(ros::Time::now(), elapsed);
82  if(pArm) pArm->write(elapsed);
83  r.sleep();
84  }
85  catch(std::runtime_error& ex)
86  {
87  ROS_ERROR("[dsr_control] Exception: [%s]", ex.what());
88  ROS_ERROR("[dsr_control] Exception: [%s]", ex.what());
89  ROS_ERROR("[dsr_control] Exception: [%s]", ex.what());
90  break;
91  }
92  }
93 
94  spinner.stop();
95  //if(pArm) delete(pArm);
96 
97  ROS_INFO("[dsr_control] Good-bye!");
98 
99  return 0;
100 }
virtual void read(ros::Duration &elapsed_time)
ROSCPP_DECL void init(int &argc, char **argv, const std::string &name, uint32_t options=0)
void SigHandler(int sig)
int main(int argc, char **argv)
#define ROS_INFO(...)
int g_nKill_dsr_control
bool param(const std::string &param_name, T &param_val, const T &default_val) const
ROSCPP_DECL bool ok()
bool sleep()
virtual void write(ros::Duration &elapsed_time)
static Time now()
ROSCPP_DECL void shutdown()
void update(const ros::Time &time, const ros::Duration &period, bool reset_controllers=false)
#define ROS_ERROR(...)


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