11 #include "hrpsys/util/VectorConvert.h" 15 #include <hrpModel/Sensor.h> 16 #include <hrpModel/ModelLoaderUtil.h> 25 "implementation_id",
"RobotHardware",
26 "type_name",
"RobotHardware",
27 "description",
"RobotHardware",
28 "version", HRPSYS_PACKAGE_VERSION,
30 "category",
"example",
31 "activity_type",
"DataFlowComponent",
34 "lang_type",
"compile",
36 "conf.default.isDemoMode",
"0",
37 "conf.default.fzLimitRatio",
"2.0",
38 "conf.default.servoErrorLimit",
",",
39 "conf.default.jointAccelerationLimit",
"0",
40 "conf.default.servoOnDelay",
"0",
50 m_qRefIn(
"qRef", m_qRef),
51 m_dqRefIn(
"dqRef", m_dqRef),
52 m_ddqRefIn(
"ddqRef", m_ddqRef),
53 m_tauRefIn(
"tauRef", m_tauRef),
56 m_tauOut(
"tau", m_tau),
57 m_ctauOut(
"ctau", m_ctau),
58 m_pdtauOut(
"pdtau", m_pdtau),
59 m_servoStateOut(
"servoState", m_servoState),
60 m_emergencySignalOut(
"emergencySignal", m_emergencySignal),
61 m_rstate2Out(
"rstate2", m_rstate2),
62 m_RobotHardwareServicePort(
"RobotHardwareService"),
106 std::cerr <<
m_profile.instance_name <<
": joint command velocity check is disabled" << std::endl;
112 std::string nameServer = rtcManager.getConfig()[
"corba.nameservers"];
113 int comPos = nameServer.find(
",");
115 comPos = nameServer.length();
117 nameServer = nameServer.substr(0, comPos);
120 CosNaming::NamingContext::_duplicate(
naming.getRootContext())
122 if (prop[
"model"] ==
""){
123 std::cerr <<
"[" <<
m_profile.instance_name <<
"] path to the model file is not defined. Please check the configuration file" << std::endl;
125 std::cerr <<
"[" <<
m_profile.instance_name <<
"] failed to load model[" << prop[
"model"] <<
"]" << std::endl;
130 for (
unsigned int i=0;
i<keys.size();
i++){
131 m_robot->setProperty(keys[
i].c_str(), prop[keys[
i]].c_str());
133 std::cout <<
"dof = " <<
m_robot->numJoints() << std::endl;
134 if (!
m_robot->init())
return RTC::RTC_ERROR;
149 int ngyro =
m_robot->numSensors(Sensor::RATE_GYRO);
150 std::cout <<
"the number of gyros = " << ngyro << std::endl;
153 for (
unsigned int i=0;
i<
m_rate.size();
i++){
155 std::cout << s->
name << std::endl;
160 int nacc =
m_robot->numSensors(Sensor::ACCELERATION);
161 std::cout <<
"the number of accelerometers = " << nacc << std::endl;
164 for (
unsigned int i=0;
i<
m_acc.size();
i++){
166 std::cout << s->
name << std::endl;
171 int nforce =
m_robot->numSensors(Sensor::FORCE);
172 std::cout <<
"the number of force sensors = " << nforce << std::endl;
175 for (
unsigned int i=0;
i<
m_force.size();
i++){
177 std::cout << s->
name << std::endl;
241 if (
m_robot->checkEmergency(reason,
id)){
286 m_robot->readJointAngles(
m_q.data.get_buffer());
288 m_robot->readJointVelocities(
m_dq.data.get_buffer());
296 for (
unsigned int i=0;
i<
m_rate.size();
i++){
305 for (
unsigned int i=0;
i<
m_acc.size();
i++){
308 m_acc[
i].data.ax = acc[0];
309 m_acc[
i].data.ay = acc[1];
310 m_acc[
i].data.az = acc[2];
314 for (
unsigned int i=0;
i<
m_force.size();
i++){
320 size_t len =
m_robot->lengthOfExtraServoState(
i)+1;
324 status |= v<< OpenHRP::RobotHardwareService::CALIB_STATE_SHIFT;
326 status |= v<< OpenHRP::RobotHardwareService::POWER_STATE_SHIFT;
328 status |= v<< OpenHRP::RobotHardwareService::SERVO_STATE_SHIFT;
330 status |= v<< OpenHRP::RobotHardwareService::SERVO_ALARM_SHIFT;
331 v =
m_robot->readDriverTemperature(
i);
332 status |= v<< OpenHRP::RobotHardwareService::DRIVER_TEMP_SHIFT;
366 rstate.angle.length(robot->numJoints());
367 robot->readJointAngles(rstate.angle.get_buffer());
369 rstate.command.length(robot->numJoints());
370 robot->readJointCommands(rstate.command.get_buffer());
372 rstate.torque.length(robot->numJoints());
373 if (!robot->readJointTorques(rstate.torque.get_buffer())){
374 for (
unsigned int i=0;
i<rstate.torque.length();
i++){
375 rstate.torque[
i] = 0.0;
379 rstate.servoState.length(robot->numJoints());
381 for(
unsigned int i=0;
i < rstate.servoState.length(); ++
i){
382 size_t len = robot->lengthOfExtraServoState(
i)+1;
383 rstate.servoState[
i].length(len);
385 v = robot->readCalibState(
i);
386 status |= v<< OpenHRP::RobotHardwareService::CALIB_STATE_SHIFT;
387 v = robot->readPowerState(
i);
388 status |= v<< OpenHRP::RobotHardwareService::POWER_STATE_SHIFT;
389 v = robot->readServoState(
i);
390 status |= v<< OpenHRP::RobotHardwareService::SERVO_STATE_SHIFT;
391 v = robot->readServoAlarm(
i);
392 status |= v<< OpenHRP::RobotHardwareService::SERVO_ALARM_SHIFT;
393 v = robot->readDriverTemperature(
i);
394 status |= v<< OpenHRP::RobotHardwareService::DRIVER_TEMP_SHIFT;
395 rstate.servoState[
i][0] = status;
396 robot->readExtraServoState(
i, (
int *)(rstate.servoState[
i].get_buffer()+1));
399 rstate.rateGyro.length(robot->numSensors(Sensor::RATE_GYRO));
400 for (
unsigned int i=0;
i<rstate.rateGyro.length();
i++){
401 rstate.rateGyro[
i].length(3);
402 robot->readGyroSensor(
i, rstate.rateGyro[
i].get_buffer());
405 rstate.accel.length(robot->numSensors(Sensor::ACCELERATION));
406 for (
unsigned int i=0;
i<rstate.accel.length();
i++){
407 rstate.accel[
i].length(3);
408 robot->readAccelerometer(
i, rstate.accel[
i].get_buffer());
411 rstate.force.length(robot->numSensors(Sensor::FORCE));
412 for (
unsigned int i=0;
i<rstate.force.length();
i++){
413 rstate.force[
i].length(6);
414 robot->readForceSensor(
i, rstate.force[
i].get_buffer());
417 robot->readPowerStatus(rstate.voltage, rstate.current);
423 #if defined(ROBOT_IOB_VERSION) && ROBOT_IOB_VERSION >= 2 424 rstate2.batteries.length(
m_robot->numBatteries());
425 for(
unsigned int i=0;
i<rstate2.batteries.length();
i++){
427 rstate2.batteries[
i].voltage,
428 rstate2.batteries[
i].current,
429 rstate2.batteries[
i].soc);
431 rstate2.temperature.length(
m_robot->numThermometers());
432 for (
unsigned int i=0;
i<rstate2.temperature.length();
i++){
433 m_robot->readThermometer(
i, rstate2.temperature[
i]);
482 RTC::Create<RobotHardware>,
483 RTC::Delete<RobotHardware>);
ComponentProfile m_profile
png_infop png_charpp int png_charpp profile
TimedDoubleSeq m_q
array of actual angles of joint with jointId
TimedDoubleSeq m_pdtau
array of PD controller torques of joint with jointId
bool stringTo(To &val, const char *str)
InPort< TimedDoubleSeq > m_qRefIn
virtual RTC::ReturnCode_t onInitialize()
RobotHardwareService_impl m_service0
RTC::CorbaPort m_RobotHardwareServicePort
TimedDoubleSeq m_tau
array of actual torques of joint with jointId
InPort< TimedDoubleSeq > m_ddqRefIn
RobotHardware(RTC::Manager *manager)
Constructor.
std::vector< TimedAcceleration3D > m_acc
vector of actual acceleration (vector length = number of acceleration sensors)
std::vector< OutPort< TimedDoubleSeq > * > m_forceOut
TimedDoubleSeq m_tauRef
array of reference torques of joint with jointId
coil::Properties & getProperties()
static Manager & instance()
bool addOutPort(const char *name, OutPortBase &outport)
OpenHRP::RobotHardwareService::TimedRobotState2 m_rstate2
TimedLong m_emergencySignal
TimedDoubleSeq m_ddqRef
array of reference accelerations of joint with jointId
boost::shared_ptr< robot > m_robot
std::vector< TimedAngularVelocity3D > m_rate
vector of actual angular velocity (vector length = number of rate sensors)
InPort< TimedDoubleSeq > m_tauRefIn
TimedDoubleSeq m_dqRef
array of reference velocities of joint with jointId
void RobotHardwareInit(RTC::Manager *manager)
OutPort< TimedDoubleSeq > m_dqOut
ExecutionContextHandle_t UniqueId
std::vector< OutPort< TimedAngularVelocity3D > * > m_rateOut
void getStatus2(OpenHRP::RobotHardwareService::RobotState2 &rstate2)
OutPort< OpenHRP::RobotHardwareService::TimedRobotState2 > m_rstate2Out
bool bindParameter(const char *param_name, VarType &var, const char *def_val, bool(*trans)(VarType &, const char *)=coil::stringTo)
int loadBodyFromModelLoader(::World *world, const char *name, const char *url, CosNaming::NamingContext_var cxt)
emg_reason
reasons of emergency
OutPort< TimedLong > m_emergencySignalOut
TimedDoubleSeq m_qRef
array of reference angles of joint with jointId
void getStatus(boost::shared_ptr< robot > robot, T &rstate)
virtual ~RobotHardware()
Destructor.
TimedDoubleSeq m_dq
array of actual velocities of joint with jointId
static const char * robothardware_spec[]
std::vector< OutPort< TimedAcceleration3D > * > m_accOut
std::vector< TimedDoubleSeq > m_force
vector of actual 6D wrench (vector length = number of F/T sensors) 6D wrench vector = 3D force + 3D m...
OutPort< TimedDoubleSeq > m_pdtauOut
OutPort< TimedDoubleSeq > m_qOut
OutPort< TimedDoubleSeq > m_ctauOut
bool addPort(PortBase &port)
virtual bool write(DataType &value)
TimedDoubleSeq m_ctau
array of commanded torques of joint with jointId
OutPort< OpenHRP::TimedLongSeqSeq > m_servoStateOut
std::vector< std::string > propertyNames(void) const
bool addInPort(const char *name, InPortBase &inport)
virtual void getTimeNow(Time &tm)
virtual RTC::ReturnCode_t onExecute(RTC::UniqueId ec_id)
OutPort< TimedDoubleSeq > m_tauOut
void setRobot(boost::shared_ptr< robot > &i_robot)
void registerOutPort(const char *name, OutPortBase &outport)
bool registerFactory(coil::Properties &profile, RtcNewFunc new_func, RtcDeleteFunc delete_func)
OpenHRP::TimedLongSeqSeq m_servoState
InPort< TimedDoubleSeq > m_dqRefIn
bool registerProvider(const char *instance_name, const char *type_name, PortableServer::RefCountServantBase &provider)