denso_robot_core.cpp
Go to the documentation of this file.
1 
27 #include <boost/thread.hpp>
28 
29 int main(int argc, char** argv)
30 {
31  ros::init(argc, argv, "denso_robot_core");
32 
33  HRESULT hr;
34 
36 
37  hr = engine.Initialize();
38  if(FAILED(hr)){
39  ROS_ERROR("Failed to initialize. (%X)", hr);
40  return 1;
41  } else {
42  boost::thread t(boost::bind(&denso_robot_core::DensoRobotCore::Start, &engine));
43 
44  ros::spin();
45 
46  engine.Stop();
47  t.join();
48 
49  return 0;
50  }
51 }
52 
53 namespace denso_robot_core {
54 
56  : m_ctrlType(0), m_mode(0), m_quit(false)
57 {
58  m_ctrl.reset();
59 }
60 
62 {
63 
64 }
65 
67 {
68  ros::NodeHandle node;
69  std::string name, filename;
70 
71  if(!node.getParam("controller_name", name)){
72  name = "";
73  }
74 
75  if(!node.getParam("controller_type", m_ctrlType)){
76  return E_FAIL;
77  }
78 
79  if(!node.getParam("config_file", filename)){
80  return E_FAIL;
81  }
82 
83  switch(m_ctrlType){
84  case 8:
85  m_ctrl = boost::make_shared<DensoControllerRC8>(name, &m_mode);
86  break;
87  default:
88  return E_FAIL;
89  }
90 
91  return m_ctrl->InitializeBCAP(filename);
92 }
93 
95 {
96  ros::NodeHandle nd;
97 
98  m_quit = false;
99  m_ctrl->StartService(nd);
100 
101  while(!m_quit && ros::ok()){
102  ros::spinOnce();
103  m_ctrl->Update();
104  ros::Rate(1000).sleep();
105  }
106 }
107 
109 {
110  m_quit = true;
111  m_ctrl->StopService();
112 }
113 
114 HRESULT DensoRobotCore::ChangeMode(int mode, bool service)
115 {
116  m_ctrl->StopService();
117 
118  DensoRobot_Ptr pRob;
119  HRESULT hr = m_ctrl->get_Robot(0, &pRob);
120  if(SUCCEEDED(hr)) {
121  switch(m_ctrlType) {
122  case 8:
123  hr = boost::dynamic_pointer_cast<DensoRobotRC8>(pRob)->ChangeMode(mode);
124  break;
125  default:
126  hr = E_FAIL;
127  break;
128  }
129  }
130 
131  m_mode = SUCCEEDED(hr) ? mode : 0;
132 
133  if((m_mode == 0) && service) {
134  ros::NodeHandle nd;
135  m_ctrl->StartService(nd);
136  }
137 
138  return hr;
139 }
140 
141 }
filename
ROSCPP_DECL void init(int &argc, char **argv, const std::string &name, uint32_t options=0)
#define FAILED(hr)
HRESULT ChangeMode(int mode, bool service=false)
#define E_FAIL
int32_t HRESULT
ROSCPP_DECL bool ok()
int main(int argc, char **argv)
#define SUCCEEDED(hr)
ROSCPP_DECL void spin()
bool sleep()
bool getParam(const std::string &key, std::string &s) const
ROSCPP_DECL void spinOnce()
#define ROS_ERROR(...)


denso_robot_core
Author(s): DENSO WAVE INCORPORATED
autogenerated on Mon Jun 10 2019 13:12:27