denso_robot.cpp
Go to the documentation of this file.
1 
26 
27 #define NAME_ARMGROUP "_armgroup"
28 
29 namespace denso_robot_core {
30 
32  Service_Vec& service, Handle_Vec& handle,
33  const std::string& name, const int* mode)
34  : DensoBase(parent, service, handle, name, mode),
35  m_ArmGroup(0)
36 {
37 
38 }
39 
41 {
42 
43 }
44 
46 {
47  return AddVariable(xmlElem);
48 }
49 
51 {
52  std::string tmpName = DensoBase::RosName();
53 
54  if(*m_mode == 0) {
55  m_subArmGroup = node.subscribe<Int32>(
56  tmpName + NAME_ARMGROUP, MESSAGE_QUEUE,
58  }
59 
60  DensoVariable_Vec::iterator itVar;
61  for(itVar = m_vecVar.begin();
62  itVar != m_vecVar.end();
63  itVar++)
64  {
65  (*itVar)->StartService(node);
66  }
67 
68  m_serving = true;
69 
70  return S_OK;
71 }
72 
74 {
75  m_mtxSrv.lock();
76  m_serving = false;
77  m_mtxSrv.unlock();
78 
80 
81  DensoVariable_Vec::iterator itVar;
82  for(itVar = m_vecVar.begin();
83  itVar != m_vecVar.end();
84  itVar++)
85  {
86  (*itVar)->StopService();
87  }
88 
89  return S_OK;
90 }
91 
93 {
94  boost::mutex::scoped_lock lockSrv(m_mtxSrv);
95  if(!m_serving) return false;
96 
97  DensoVariable_Vec::iterator itVar;
98  for(itVar = m_vecVar.begin();
99  itVar != m_vecVar.end();
100  itVar++)
101  {
102  (*itVar)->Update();
103  }
104 
105  return true;
106 }
107 
109 {
110  m_ArmGroup = number;
111 }
112 
113 void DensoRobot::Callback_ArmGroup(const Int32::ConstPtr& msg)
114 {
115  ChangeArmGroup(msg->data);
116 }
117 
118 HRESULT DensoRobot::get_Variable(const std::string& name, DensoVariable_Ptr* var)
119 {
120  if(var == NULL) {
121  return E_INVALIDARG;
122  }
123 
124  DensoBase_Vec vecBase;
125  vecBase.insert(vecBase.end(), m_vecVar.begin(), m_vecVar.end());
126 
127  DensoBase_Ptr pBase;
128  HRESULT hr = DensoBase::get_Object(vecBase, name, &pBase);
129  if(SUCCEEDED(hr)) {
130  *var = boost::dynamic_pointer_cast<DensoVariable>(pBase);
131  }
132 
133  return hr;
134 }
135 
136 HRESULT DensoRobot::AddVariable(const std::string& name)
137 {
139  name, m_vecVar);
140 }
141 
143 {
144  HRESULT hr = S_OK;
145  XMLElement *xmlVar;
146 
147  for(xmlVar = xmlElem->FirstChildElement(XML_VARIABLE_NAME);
148  xmlVar!= NULL;
149  xmlVar = xmlVar->NextSiblingElement(XML_VARIABLE_NAME))
150  {
152  xmlVar, m_vecVar);
153  if(FAILED(hr)) break;
154  }
155 
156  return hr;
157 }
158 
160  const PoseData &pose, VARIANT &vnt)
161 {
162  uint32_t i, j;
163  uint32_t num = 3 +
164  (((pose.exjoints.mode != 0) && (pose.exjoints.joints.size() > 0)) ? 1 : 0);
165  float *pfltval;
166  VARIANT *pvntval;
167 
168  vnt.vt = (VT_ARRAY | VT_VARIANT);
169  vnt.parray = SafeArrayCreateVector(VT_VARIANT, 0, num);
170 
171  SafeArrayAccessData(vnt.parray, (void**)&pvntval);
172 
173  for(i = 0; i < num; i++) {
174  switch(i){
175  case 0:
176  pvntval[i].vt = (VT_ARRAY | VT_R4);
177  pvntval[i].parray = SafeArrayCreateVector(VT_R4, 0, pose.value.size());
178  SafeArrayAccessData(pvntval[i].parray, (void**)&pfltval);
179  std::copy(pose.value.begin(), pose.value.end(), pfltval);
180  SafeArrayUnaccessData(pvntval[i].parray);
181  break;
182  case 1:
183  pvntval[i].vt = VT_I4;
184  pvntval[i].lVal = pose.type;
185  break;
186  case 2:
187  pvntval[i].vt = VT_I4;
188  pvntval[i].lVal = pose.pass;
189  break;
190  case 3:
191  CreateExJoints(pose.exjoints, pvntval[i]);
192  break;
193  }
194  }
195 
197 
198  return S_OK;
199 }
200 
202  const ExJoints &exjoints, VARIANT &vnt)
203 {
204  uint32_t i, j;
205  uint32_t num = 1 + exjoints.joints.size();
206  VARIANT *pvntval, *pjntval;
207 
208  vnt.vt = (VT_ARRAY | VT_VARIANT);
209  vnt.parray = SafeArrayCreateVector(VT_VARIANT, 0, num);
210 
211  SafeArrayAccessData(vnt.parray, (void**)&pvntval);
212 
213  for(i = 0; i < num; i++) {
214  if(i == 0) {
215  pvntval[0].vt = VT_I4;
216  pvntval[0].lVal = exjoints.mode;
217  } else {
218  pvntval[i].vt = (VT_ARRAY | VT_VARIANT);
219  pvntval[i].parray = SafeArrayCreateVector(VT_VARIANT, 0, 2);
220  SafeArrayAccessData(pvntval[i].parray, (void**)&pjntval);
221  pjntval[0].vt = VT_I4;
222  pjntval[0].lVal = exjoints.joints.at(i-1).joint;
223  pjntval[1].vt = VT_R4;
224  pjntval[1].fltVal = exjoints.joints.at(i-1).value;
225  SafeArrayUnaccessData(pvntval[i].parray);
226  }
227  }
228 
230 
231  return S_OK;
232 }
233 
234 }
void ChangeArmGroup(int number)
HRESULT SafeArrayUnaccessData(SAFEARRAY *psa)
const XMLElement * FirstChildElement(const char *name=0) const
Definition: tinyxml2.cpp:874
unsigned uint32_t
virtual HRESULT InitializeBCAP()
Definition: denso_base.h:107
SAFEARRAY * SafeArrayCreateVector(uint16_t vt, int32_t lLbound, uint32_t cElements)
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)
Subscriber subscribe(const std::string &topic, uint32_t queue_size, void(T::*fp)(M), T *obj, const TransportHints &transport_hints=TransportHints())
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
HRESULT AddVariable(const std::string &name)
#define S_OK
DensoRobot(DensoBase *parent, Service_Vec &service, Handle_Vec &handle, const std::string &name, const int *mode)
Definition: denso_robot.cpp:31
void Callback_ArmGroup(const Int32::ConstPtr &msg)
ros::Subscriber m_subArmGroup
Definition: denso_robot.h:77
std::vector< uint32_t > Handle_Vec
Definition: denso_base.h:67
int32_t lVal
#define FAILED(hr)
VT_I4
#define E_INVALIDARG
std::vector< BCAPService_Ptr > Service_Vec
Definition: denso_base.h:68
int32_t HRESULT
#define NAME_ARMGROUP
Definition: denso_robot.cpp:27
#define MESSAGE_QUEUE
Definition: denso_base.h:61
VT_ARRAY
SAFEARRAY * parray
HRESULT SafeArrayAccessData(SAFEARRAY *psa, void **ppvData)
VT_VARIANT
#define SUCCEEDED(hr)
DensoVariable_Vec m_vecVar
Definition: denso_robot.h:74
HRESULT CreateExJoints(const ExJoints &exjoints, VARIANT &vnt)
uint16_t vt
#define ID_ROBOT_GETVARIABLE
HRESULT get_Object(const std::vector< boost::shared_ptr< DensoBase > > &vecBase, int index, boost::shared_ptr< DensoBase > *obj)
HRESULT get_Variable(const std::string &name, DensoVariable_Ptr *var)
#define XML_VARIABLE_NAME
virtual HRESULT StartService(ros::NodeHandle &node)
Definition: denso_robot.cpp:50
std::vector< DensoBase_Ptr > DensoBase_Vec
Definition: denso_base.h:173
VT_R4
float fltVal
virtual HRESULT StopService()
Definition: denso_robot.cpp:73
std::string RosName() const
Definition: denso_base.cpp:62
HRESULT CreatePoseData(const PoseData &pose, VARIANT &vnt)


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