denso_controller.cpp
Go to the documentation of this file.
1 
26 
27 namespace denso_robot_core {
28 
29 DensoController::DensoController(const std::string& name, const int* mode)
30  : DensoBase(name, mode)
31 {
32  for(int srvs = DensoBase::SRV_MIN; srvs <= DensoBase::SRV_MAX; srvs++) {
33  BCAPService_Ptr service = boost::make_shared<bcap_service::BCAPService>();
34  service->parseParams();
35  switch(srvs){
36  case DensoBase::SRV_ACT:
37  service->put_Type("udp");
38  break;
39  default:
40  service->put_Type("tcp");
41  break;
42  }
43  m_vecService.push_back(service);
44  }
45 }
46 
48 {
49 
50 }
51 
52 HRESULT DensoController::InitializeBCAP(const std::string& filename)
53 {
54  HRESULT hr;
55  XMLError ret;
56  XMLDocument xmlDoc;
57  XMLElement *xmlCtrl, *xmlRob, *xmlTsk;
58 
59  for(int srvs = DensoBase::SRV_MIN; srvs <= DensoBase::SRV_MAX; srvs++) {
60  hr = m_vecService[srvs]->Connect();
61  if(FAILED(hr)) return hr;
62  }
63 
64  ret = xmlDoc.LoadFile(filename.c_str());
65  if(ret != XML_SUCCESS) return E_FAIL;
66 
67  hr = AddController();
68  if(FAILED(hr)) return hr;
69 
70  xmlCtrl = xmlDoc.FirstChildElement(XML_CTRL_NAME);
71  if(xmlCtrl == NULL) return E_FAIL;
72 
73  hr = AddVariable(xmlCtrl);
74  if(FAILED(hr)) return hr;
75 
76  xmlRob = xmlCtrl->FirstChildElement(XML_ROBOT_NAME);
77  if(xmlRob == NULL) return E_FAIL;
78 
79  hr = AddRobot(xmlRob);
80  if(FAILED(hr)) return hr;
81 
82  xmlTsk = xmlCtrl->FirstChildElement(XML_TASK_NAME);
83  if(xmlTsk == NULL) return E_FAIL;
84 
85  hr = AddTask(xmlTsk);
86 
87  return hr;
88 }
89 
91 {
92  DensoRobot_Vec::iterator itRob;
93  for(itRob = m_vecRobot.begin();
94  itRob != m_vecRobot.end();
95  itRob++)
96  {
97  (*itRob)->StartService(node);
98  }
99 
100  DensoTask_Vec::iterator itTsk;
101  for(itTsk = m_vecTask.begin();
102  itTsk != m_vecTask.end();
103  itTsk++)
104  {
105  (*itTsk)->StartService(node);
106  }
107 
108  DensoVariable_Vec::iterator itVar;
109  for(itVar = m_vecVar.begin();
110  itVar != m_vecVar.end();
111  itVar++)
112  {
113  (*itVar)->StartService(node);
114  }
115 
116  m_serving = true;
117 
118  return S_OK;
119 }
120 
122 {
123  m_mtxSrv.lock();
124  m_serving = false;
125  m_mtxSrv.unlock();
126 
127  DensoRobot_Vec::iterator itRob;
128  for(itRob = m_vecRobot.begin();
129  itRob != m_vecRobot.end();
130  itRob++)
131  {
132  (*itRob)->StopService();
133  }
134 
135  DensoTask_Vec::iterator itTsk;
136  for(itTsk = m_vecTask.begin();
137  itTsk != m_vecTask.end();
138  itTsk++)
139  {
140  (*itTsk)->StopService();
141  }
142 
143  DensoVariable_Vec::iterator itVar;
144  for(itVar = m_vecVar.begin();
145  itVar != m_vecVar.end();
146  itVar++)
147  {
148  (*itVar)->StopService();
149  }
150 
151  return S_OK;
152 }
153 
155 {
156  boost::mutex::scoped_lock lockSrv(m_mtxSrv);
157  if(!m_serving) return false;
158 
159  DensoRobot_Vec::iterator itRob;
160  for(itRob = m_vecRobot.begin();
161  itRob != m_vecRobot.end();
162  itRob++)
163  {
164  (*itRob)->Update();
165  }
166 
167  DensoTask_Vec::iterator itTsk;
168  for(itTsk = m_vecTask.begin();
169  itTsk != m_vecTask.end();
170  itTsk++)
171  {
172  (*itTsk)->Update();
173  }
174 
175  DensoVariable_Vec::iterator itVar;
176  for(itVar = m_vecVar.begin();
177  itVar != m_vecVar.end();
178  itVar++)
179  {
180  (*itVar)->Update();
181  }
182 
183  return true;
184 }
185 
187 {
188  if(robot == NULL) {
189  return E_INVALIDARG;
190  }
191 
192  DensoBase_Vec vecBase;
193  vecBase.insert(vecBase.end(), m_vecRobot.begin(), m_vecRobot.end());
194 
195  DensoBase_Ptr pBase;
196  HRESULT hr = DensoBase::get_Object(vecBase, index, &pBase);
197  if(SUCCEEDED(hr)) {
198  *robot = boost::dynamic_pointer_cast<DensoRobot>(pBase);
199  }
200 
201  return hr;
202 }
203 
204 HRESULT DensoController::get_Task(const std::string& name, DensoTask_Ptr* task)
205 {
206  if(task == NULL) {
207  return E_INVALIDARG;
208  }
209 
210  DensoBase_Vec vecBase;
211  vecBase.insert(vecBase.end(), m_vecTask.begin(), m_vecTask.end());
212 
213  DensoBase_Ptr pBase;
214  HRESULT hr = DensoBase::get_Object(vecBase, name, &pBase);
215  if(SUCCEEDED(hr)) {
216  *task = boost::dynamic_pointer_cast<DensoTask>(pBase);
217  }
218 
219  return hr;
220 }
221 
223 {
224  if(var == NULL) {
225  return E_INVALIDARG;
226  }
227 
228  DensoBase_Vec vecBase;
229  vecBase.insert(vecBase.end(), m_vecVar.begin(), m_vecVar.end());
230 
231  DensoBase_Ptr pBase;
232  HRESULT hr = DensoBase::get_Object(vecBase, name, &pBase);
233  if(SUCCEEDED(hr)) {
234  *var = boost::dynamic_pointer_cast<DensoVariable>(pBase);
235  }
236 
237  return hr;
238 }
239 
241 {
242  int objs;
243  HRESULT hr;
244 
245  Name_Vec vecName;
247  if(SUCCEEDED(hr)) {
248  for(objs = 0; objs < vecName.size(); objs++) {
249  Handle_Vec vecHandle;
251  ID_CONTROLLER_GETTASK, vecName[objs], vecHandle);
252  if(FAILED(hr)) break;
253 
254  DensoTask_Ptr tsk(new DensoTask(this,
255  m_vecService, vecHandle, vecName[objs], m_mode));
256 
257  hr = tsk->InitializeBCAP(xmlElem);
258  if(FAILED(hr)) break;
259 
260  m_vecTask.push_back(tsk);
261  }
262  }
263 
264  return hr;
265 }
266 
267 HRESULT DensoController::AddVariable(const std::string& name)
268 {
270  name, m_vecVar);
271 }
272 
274 {
275  HRESULT hr = S_OK;
276  XMLElement *xmlVar;
277 
278  for(xmlVar = xmlElem->FirstChildElement(XML_VARIABLE_NAME);
279  xmlVar!= NULL;
280  xmlVar = xmlVar->NextSiblingElement(XML_VARIABLE_NAME)) {
281 
283  xmlVar, m_vecVar);
284  if(FAILED(hr)) break;
285  }
286 
287  return hr;
288 }
289 
290 }
virtual HRESULT AddRobot(XMLElement *xmlElem)=0
const XMLElement * FirstChildElement(const char *name=0) const
Definition: tinyxml2.cpp:874
virtual HRESULT InitializeBCAP()
Definition: denso_base.h:107
XMLError LoadFile(const char *filename)
Definition: tinyxml2.cpp:1904
HRESULT AddVariable(int32_t get_id, const std::string &name, std::vector< boost::shared_ptr< class DensoVariable > > &vecVar, int16_t vt=VT_EMPTY, bool bRead=false, bool bWrite=false, bool bID=false, int iDuration=BCAP_VAR_DEFAULT_DURATION)
const XMLElement * NextSiblingElement(const char *name=0) const
Get the next (right) sibling element of this node, with an optionally supplied name.
Definition: tinyxml2.cpp:902
virtual HRESULT StartService(ros::NodeHandle &node)
#define S_OK
std::vector< uint32_t > Handle_Vec
Definition: denso_base.h:67
HRESULT GetObjectNames(int32_t func_id, Name_Vec &vecName)
Definition: denso_base.cpp:194
#define FAILED(hr)
#define E_INVALIDARG
HRESULT get_Robot(int index, DensoRobot_Ptr *robot)
#define E_FAIL
int32_t HRESULT
virtual HRESULT AddTask(XMLElement *xmlElem)
#define SUCCEEDED(hr)
#define XML_ROBOT_NAME
Definition: denso_robot.h:31
HRESULT get_Object(const std::vector< boost::shared_ptr< DensoBase > > &vecBase, int index, boost::shared_ptr< DensoBase > *obj)
#define ID_CONTROLLER_GETTASKNAMES
HRESULT get_Task(const std::string &name, DensoTask_Ptr *task)
std::vector< std::string > Name_Vec
Definition: denso_base.h:66
virtual HRESULT AddController()=0
#define XML_VARIABLE_NAME
#define XML_TASK_NAME
Definition: denso_task.h:31
#define ID_CONTROLLER_GETTASK
std::vector< DensoBase_Ptr > DensoBase_Vec
Definition: denso_base.h:173
HRESULT get_Variable(const std::string &name, DensoVariable_Ptr *var)
HRESULT AddObject(int32_t get_id, const std::string &name, Handle_Vec &vecHandle)
Definition: denso_base.cpp:150
#define XML_CTRL_NAME
HRESULT AddVariable(const std::string &name)
DensoController(const std::string &name, const int *mode)
#define ID_CONTROLLER_GETVARIABLE


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