RobotHardwareService_impl.cpp
Go to the documentation of this file.
2 #include "robot.h"
3 #include <hrpModel/Sensor.h>
4 
5 using namespace OpenHRP;
6 using namespace hrp;
7 
9 {
10 }
11 
13 {
14 }
15 
16 #define GetStatus \
17  \
18  rs->angle.length(m_robot->numJoints()); \
19  m_robot->readJointAngles(rs->angle.get_buffer()); \
20  \
21  rs->command.length(m_robot->numJoints()); \
22  m_robot->readJointCommands(rs->command.get_buffer()); \
23  \
24  rs->torque.length(m_robot->numJoints()); \
25  if (!m_robot->readJointTorques(rs->torque.get_buffer())){ \
26  for (unsigned int i=0; i<rs->torque.length(); i++){ \
27  rs->torque[i] = 0.0; \
28  } \
29  } \
30  \
31  rs->servoState.length(m_robot->numJoints()); \
32  int v, status; \
33  for(unsigned int i=0; i < rs->servoState.length(); ++i){ \
34  size_t len = m_robot->lengthOfExtraServoState(i)+1; \
35  rs->servoState[i].length(len); \
36  status = 0; \
37  v = m_robot->readCalibState(i); \
38  status |= v<< OpenHRP::RobotHardwareService::CALIB_STATE_SHIFT; \
39  v = m_robot->readPowerState(i); \
40  status |= v<< OpenHRP::RobotHardwareService::POWER_STATE_SHIFT; \
41  v = m_robot->readServoState(i); \
42  status |= v<< OpenHRP::RobotHardwareService::SERVO_STATE_SHIFT; \
43  v = m_robot->readServoAlarm(i); \
44  status |= v<< OpenHRP::RobotHardwareService::SERVO_ALARM_SHIFT; \
45  v = m_robot->readDriverTemperature(i); \
46  status |= v<< OpenHRP::RobotHardwareService::DRIVER_TEMP_SHIFT; \
47  rs->servoState[i][0] = status; \
48  m_robot->readExtraServoState(i, (int *)(rs->servoState[i].get_buffer()+1)); \
49  } \
50  \
51  rs->rateGyro.length(m_robot->numSensors(Sensor::RATE_GYRO)); \
52  for (unsigned int i=0; i<rs->rateGyro.length(); i++){ \
53  rs->rateGyro[i].length(3); \
54  m_robot->readGyroSensor(i, rs->rateGyro[i].get_buffer()); \
55  } \
56  \
57  rs->accel.length(m_robot->numSensors(Sensor::ACCELERATION)); \
58  for (unsigned int i=0; i<rs->accel.length(); i++){ \
59  rs->accel[i].length(3); \
60  m_robot->readAccelerometer(i, rs->accel[i].get_buffer()); \
61  } \
62  \
63  rs->force.length(m_robot->numSensors(Sensor::FORCE)); \
64  for (unsigned int i=0; i<rs->force.length(); i++){ \
65  rs->force[i].length(6); \
66  m_robot->readForceSensor(i, rs->force[i].get_buffer()); \
67  } \
68  \
69  m_robot->readPowerStatus(rs->voltage, rs->current);
70 
71 void RobotHardwareService_impl::getStatus(OpenHRP::RobotHardwareService::RobotState_out rs)
72 {
73  rs = new OpenHRP::RobotHardwareService::RobotState();
74 
75  GetStatus;
76 }
77 
78 void RobotHardwareService_impl::getStatus2(OpenHRP::RobotHardwareService::RobotState2_out rs)
79 {
80  rs = new OpenHRP::RobotHardwareService::RobotState2();
81 
82  GetStatus;
83 
84 #if defined(ROBOT_IOB_VERSION) && ROBOT_IOB_VERSION >= 2
85  rs->batteries.length(m_robot->numBatteries());
86  for(unsigned int i=0; i<rs->batteries.length(); i++){
87  m_robot->readBatteryState(i,
88  rs->batteries[i].voltage,
89  rs->batteries[i].current,
90  rs->batteries[i].soc);
91  }
92  rs->temperature.length(m_robot->numThermometers());
93  for (unsigned int i=0; i<rs->temperature.length(); i++){
94  m_robot->readThermometer(i, rs->temperature[i]);
95  }
96 #endif
97 }
98 
99 CORBA::Boolean RobotHardwareService_impl::power(const char* jname, OpenHRP::RobotHardwareService::SwitchStatus ss)
100 {
101  return m_robot->power(jname, ss==OpenHRP::RobotHardwareService::SWITCH_ON);
102 }
103 
104 CORBA::Boolean RobotHardwareService_impl::servo(const char* jname, OpenHRP::RobotHardwareService::SwitchStatus ss)
105 {
106  return m_robot->servo(jname, ss==OpenHRP::RobotHardwareService::SWITCH_ON);
107 }
108 
110 {
111  m_robot->startInertiaSensorCalibration();
112 }
113 
115 {
116  m_robot->removeForceSensorOffset();
117 }
118 
119 void RobotHardwareService_impl::initializeJointAngle(const char* name, const char* option)
120 {
121  m_robot->initializeJointAngle(name, option);
122 }
123 
124 void RobotHardwareService_impl::setServoGainPercentage(const char *jname, double percentage)
125 {
126  m_robot->setServoGainPercentage(jname, percentage);
127 }
128 
129 void RobotHardwareService_impl::setServoTorqueGainPercentage(const char *jname, double percentage)
130 {
131  m_robot->setServoTorqueGainPercentage(jname, percentage);
132 }
133 
134 void RobotHardwareService_impl::setServoErrorLimit(const char *jname, double limit)
135 {
136  m_robot->setServoErrorLimit(jname, limit);
137 }
138 
139 CORBA::Boolean RobotHardwareService_impl::addJointGroup(const char* gname, const OpenHRP::RobotHardwareService::StrSequence& jnames)
140 {
141  std::vector<std::string> joints;
142  joints.resize(jnames.length());
143  for (unsigned int i=0; i<jnames.length(); i++){
144  joints[i] = jnames[i];
145  }
146  return m_robot->addJointGroup(gname, joints);
147 }
148 
149 CORBA::Boolean RobotHardwareService_impl::readDigitalInput(::OpenHRP::RobotHardwareService::OctSequence_out din)
150 {
151  din = new ::OpenHRP::RobotHardwareService::OctSequence();
152  din->length(lengthDigitalInput());
153  return m_robot->readDigitalInput((char *)(din->get_buffer()));
154 }
155 
157 {
158  return m_robot->lengthDigitalInput();
159 }
160 
161 CORBA::Boolean RobotHardwareService_impl::writeDigitalOutput(const ::OpenHRP::RobotHardwareService::OctSequence& dout)
162 {
163  return m_robot->writeDigitalOutput((const char *)(dout.get_buffer()));
164 }
165 
166 CORBA::Boolean RobotHardwareService_impl::writeDigitalOutputWithMask(const ::OpenHRP::RobotHardwareService::OctSequence& dout, const ::OpenHRP::RobotHardwareService::OctSequence& mask)
167 {
168  return m_robot->writeDigitalOutputWithMask((const char *)(dout.get_buffer()), (const char *)(mask.get_buffer()));
169 }
170 
172 {
173  return m_robot->lengthDigitalOutput();
174 }
175 
176 CORBA::Boolean RobotHardwareService_impl::readDigitalOutput(::OpenHRP::RobotHardwareService::OctSequence_out dout)
177 {
178  dout = new ::OpenHRP::RobotHardwareService::OctSequence();
179  dout->length(lengthDigitalOutput());
180  return m_robot->readDigitalOutput((char *)(dout->get_buffer()));
181 }
182 
183 CORBA::Boolean RobotHardwareService_impl::setJointInertia(const char* name, ::CORBA::Double mn)
184 {
185  m_robot->setJointInertia(name, mn);
186 }
187 
188 void RobotHardwareService_impl::setJointInertias(const ::OpenHRP::RobotHardwareService::DblSequence& mns)
189 {
190  m_robot->setJointInertias(mns.get_buffer());
191 }
192 
193 
195 {
196  m_robot->enableDisturbanceObserver();
197 }
198 
200 {
201  m_robot->disableDisturbanceObserver();
202 }
203 
205 {
206  m_robot->setDisturbanceObserverGain(gain);
207 }
208 
209 void RobotHardwareService_impl::setJointControlMode(const char *jname, OpenHRP::RobotHardwareService::JointControlMode jcm)
210 {
211  joint_control_mode mode;
212  switch(jcm){
213  case OpenHRP::RobotHardwareService::FREE:
214  mode = JCM_FREE;
215  break;
216  case OpenHRP::RobotHardwareService::POSITION:
217  mode = JCM_POSITION;
218  break;
219  case OpenHRP::RobotHardwareService::TORQUE:
220  mode = JCM_TORQUE;
221  break;
222  case OpenHRP::RobotHardwareService::VELOCITY:
223  mode = JCM_VELOCITY;
224  break;
225 #if defined(ROBOT_IOB_VERSION) && ROBOT_IOB_VERSION >= 4
226  case OpenHRP::RobotHardwareService::POSITION_TORQUE:
227  mode = JCM_POSITION_TORQUE;
228  break;
229 #endif
230  default:
231  return;
232  }
233  m_robot->setJointControlMode(jname, mode);
234 }
void getStatus(OpenHRP::RobotHardwareService::RobotState_out rs)
CORBA::Boolean addJointGroup(const char *gname, const OpenHRP::RobotHardwareService::StrSequence &jnames)
void setJointControlMode(const char *jname, OpenHRP::RobotHardwareService::JointControlMode jcm)
CORBA::Boolean writeDigitalOutput(const ::OpenHRP::RobotHardwareService::OctSequence &dout)
CORBA::Boolean readDigitalOutput(::OpenHRP::RobotHardwareService::OctSequence_out dout)
void setServoTorqueGainPercentage(const char *jname, double limit)
boost::shared_ptr< robot > m_robot
void setDisturbanceObserverGain(::CORBA::Double gain)
void getStatus2(OpenHRP::RobotHardwareService::RobotState2_out rs)
png_uint_32 i
torque control
Definition: iob.h:64
CORBA::Boolean writeDigitalOutputWithMask(const ::OpenHRP::RobotHardwareService::OctSequence &dout, const ::OpenHRP::RobotHardwareService::OctSequence &mask)
CORBA::Boolean setJointInertia(const char *name,::CORBA::Double mn)
free
Definition: iob.h:62
CORBA::Boolean readDigitalInput(::OpenHRP::RobotHardwareService::OctSequence_out din)
void setJointInertias(const ::OpenHRP::RobotHardwareService::DblSequence &mns)
CORBA::Boolean power(const char *jname, OpenHRP::RobotHardwareService::SwitchStatus ss)
position control
Definition: iob.h:63
void setServoGainPercentage(const char *jname, double limit)
CORBA::Boolean servo(const char *jname, OpenHRP::RobotHardwareService::SwitchStatus ss)
#define GetStatus
joint_control_mode
Definition: iob.h:61
void initializeJointAngle(const char *name, const char *option)
hrp::BodyPtr m_robot
velocity control
Definition: iob.h:65
void setServoErrorLimit(const char *jname, double limit)


hrpsys
Author(s): AIST, Fumio Kanehiro
autogenerated on Thu May 6 2021 02:41:51