00001 #include <iostream>
00002 #include <hrpModel/Sensor.h>
00003 #include <hrpModel/Link.h>
00004 #include "BodyRTC.h"
00005 #include "PortHandler.h"
00006
00007 using namespace hrp;
00008 using namespace RTC;
00009
00010
00011
00012 const char* BodyRTC::bodyrtc_spec[] =
00013 {
00014 "implementation_id", "BodyRTC",
00015 "type_name", "BodyRTC",
00016 "description", "BodyRTC component",
00017 "version", "0.1",
00018 "vendor", "AIST",
00019 "category", "Generic",
00020 "activity_type", "DataFlowComponent",
00021 "max_instance", "10",
00022 "language", "C++",
00023 "lang_type", "compile",
00024
00025
00026 ""
00027 };
00028
00029 BodyRTC::BodyRTC(RTC::Manager* manager)
00030 : Body(),
00031 DataFlowComponentBase(manager),
00032 m_RobotHardwareServicePort("RobotHardwareService"),
00033 m_resetPosition(true),
00034 dummy(0)
00035 {
00036
00037 }
00038
00039 BodyRTC::~BodyRTC(void)
00040 {
00041
00042 for (size_t i=0; i<m_inports.size(); i++){
00043 delete m_inports[i];
00044 }
00045 for (size_t i=0; i<m_outports.size(); i++){
00046 delete m_outports[i];
00047 }
00048 }
00049
00050 void BodyRTC::writeDataPorts(double time)
00051 {
00052 for (size_t i=0; i<m_outports.size(); i++){
00053 m_outports[i]->update(time);
00054 }
00055 }
00056
00057 void BodyRTC::readDataPorts()
00058 {
00059 for (size_t i=0; i<m_inports.size(); i++){
00060 m_inports[i]->update();
00061 }
00062 }
00063
00064 #define DEFAULT_ANGLE_ERROR_LIMIT 0.2 // [rad] // copied from robot.cpp
00065 RTC::ReturnCode_t BodyRTC::setup(){
00066 std::cout << "BodyRTC::setup(), numJoints = " << numJoints() << std::endl;
00067 angles.resize(numJoints());
00068 commands.resize(numJoints());
00069 accels.resize(numSensors(hrp::Sensor::ACCELERATION));
00070 gyros.resize(numSensors(hrp::Sensor::RATE_GYRO));
00071 forces.resize(numSensors(hrp::Sensor::FORCE));
00072 calib_status.resize(numJoints());
00073 servo_status.resize(numJoints());
00074 power_status.resize(numJoints());
00075 m_servoErrorLimit.resize(numJoints());
00076 for(unsigned int i = 0; i < numJoints(); i++) {
00077 calib_status[i] = servo_status[i] = power_status[i] = OpenHRP::RobotHardwareService::SWITCH_ON;
00078 m_servoErrorLimit[i] = DEFAULT_ANGLE_ERROR_LIMIT;
00079 }
00080 m_emergencyReason = EMG_NONE;
00081 m_emergencyId = -1;
00082 return RTC::RTC_OK;
00083 }
00084
00085 void parsePortConfig(const std::string &config,
00086 std::string &name, std::string &type,
00087 std::vector<std::string> &elements)
00088 {
00089 std::string::size_type colon = 0, start=0;
00090 colon = config.find(':', start);
00091 if (colon == std::string::npos){
00092 std::cerr << "can't find the first separator in [" << config << "]"
00093 << std::endl;
00094 return;
00095 }
00096 name = config.substr(start, colon);
00097 start = colon+1;
00098 colon = config.find(':', start);
00099 if (colon == std::string::npos){
00100 type = config.substr(start);
00101 return;
00102 }
00103 std::string elist = config.substr(start, colon-start);
00104 std::string::size_type comma;
00105 start = 0;
00106 comma = elist.find(',', start);
00107 while (comma != std::string::npos){
00108 std::string e = elist.substr(start, comma-start);
00109 elements.push_back(e);
00110 start = comma+1;
00111 comma = elist.find(',', start);
00112 }
00113 elements.push_back(elist.substr(start));
00114 start = colon+1;
00115 type = config.substr(start);
00116 }
00117
00118 bool getJointList(hrp::Body *body, const std::vector<std::string> &elements,
00119 std::vector<hrp::Link *> &joints)
00120 {
00121 if (elements.size() == 0){
00122 for (unsigned int i=0; i<body->numJoints(); i++){
00123 joints.push_back(body->joint(i));
00124 }
00125 }else{
00126 for (size_t i=0; i<elements.size(); i++){
00127 hrp::Link *j = body->link(elements[i]);
00128 if (j){
00129 joints.push_back(j);
00130 }else{
00131 std::cerr << "can't find a joint(" << elements[i] << ")"
00132 << std::endl;
00133 return false;
00134 }
00135 }
00136 }
00137 return true;
00138 }
00139
00140 void BodyRTC::createInPort(const std::string &config)
00141 {
00142 std::string name, type;
00143 std::vector<std::string> elements;
00144 parsePortConfig(config, name, type, elements);
00145 if (type == "JOINT_VALUE"){
00146 std::vector<hrp::Link *> joints;
00147 if (getJointList(this, elements, joints)){
00148 m_inports.push_back(
00149 new JointValueInPortHandler(this, name.c_str(), joints, &servo_status));
00150 }
00151 }else if(type == "JOINT_VELOCITY"){
00152 std::vector<hrp::Link *> joints;
00153 if (getJointList(this, elements, joints)){
00154 m_inports.push_back(
00155 new JointVelocityInPortHandler(this, name.c_str(), joints, &servo_status));
00156 }
00157 }else if(type == "JOINT_ACCELERATION"){
00158 std::vector<hrp::Link *> joints;
00159 if (getJointList(this, elements, joints)){
00160 m_inports.push_back(
00161 new JointAccelerationInPortHandler(this, name.c_str(),joints, &servo_status));
00162 }
00163 }else if(type == "JOINT_TORQUE"){
00164 std::vector<hrp::Link *> joints;
00165 if (getJointList(this, elements, joints)){
00166 m_inports.push_back(
00167 new JointTorqueInPortHandler(this, name.c_str(), joints, &servo_status));
00168 }
00169 }else if(type == "EXTERNAL_FORCE"){
00170 std::cout << "EXTERNAL_FORCE is not implemented yet" << std::endl;
00171 }else if(type == "ABS_TRANSFORM"){
00172 std::vector<hrp::Link *> joints;
00173 if (getJointList(this, elements, joints) && joints.size() == 1){
00174 m_inports.push_back(
00175 new AbsTransformInPortHandler(this, name.c_str(), joints[0]));
00176 } else if (elements.size() == 1) {
00177 hrp::Link *l=this->link(elements[0]);
00178 if (l){
00179 m_inports.push_back(
00180 new AbsTransformInPortHandler(this, name.c_str(), l));
00181 return;
00182 }
00183 std::cerr << "can't find a link(or a sensor)(" << elements[0] << ")"
00184 << std::endl;
00185 }
00186 }else if(type == "ABS_VELOCITY"){
00187 std::vector<hrp::Link *> joints;
00188 if (getJointList(this, elements, joints) && joints.size() == 1){
00189 m_inports.push_back(
00190 new AbsVelocityInPortHandler(this, name.c_str(), joints[0]));
00191 }
00192 }else if(type == "ABS_ACCELERATION"){
00193 std::vector<hrp::Link *> joints;
00194 if (getJointList(this, elements, joints) && joints.size() == 1){
00195 m_inports.push_back(
00196 new AbsAccelerationInPortHandler(this,name.c_str(),joints[0]));
00197 }
00198 }else if(type == "FRAME_RATE"){
00199 VisionSensor *s = this->sensor<VisionSensor>(elements[0]);
00200 if (!s){
00201 std::cerr << "can't find a sensor(" << elements[0] << ")"
00202 << std::endl;
00203 return;
00204 }
00205 m_inports.push_back(new FrameRateInPortHandler(this,name.c_str(),s));
00206 }else if(type == "LIGHT_SWITCH"){
00207 Light *l = this->light(elements[0]);
00208 if (!l){
00209 std::cerr << "can't find a light(" << elements[0] << ")"
00210 << std::endl;
00211 return;
00212 }
00213 m_inports.push_back(new LightSwitchInPortHandler(this,name.c_str(),l));
00214 }else{
00215 std::cerr << "unknown InPort data type(" << type << ")" << std::endl;
00216 }
00217 }
00218
00219 void BodyRTC::createOutPort(const std::string &config)
00220 {
00221 std::string name, type;
00222 std::vector<std::string> elements;
00223 parsePortConfig(config, name, type, elements);
00224 if (type == "JOINT_VALUE"){
00225 std::vector<hrp::Link *> joints;
00226 if (getJointList(this, elements, joints)){
00227 m_outports.push_back(
00228 new JointValueOutPortHandler(this, name.c_str(), joints));
00229 }
00230 }else if(type == "JOINT_VELOCITY"){
00231 std::vector<hrp::Link *> joints;
00232 if (getJointList(this, elements, joints)){
00233 m_outports.push_back(
00234 new JointVelocityOutPortHandler(this, name.c_str(), joints));
00235 }
00236 }else if(type == "JOINT_ACCELERATION"){
00237 std::vector<hrp::Link *> joints;
00238 if (getJointList(this, elements, joints)){
00239 m_outports.push_back(
00240 new JointAccelerationOutPortHandler(this,name.c_str(),joints));
00241 }
00242 }else if(type == "JOINT_TORQUE"){
00243 std::vector<hrp::Link *> joints;
00244 if (getJointList(this, elements, joints)){
00245 m_outports.push_back(
00246 new JointTorqueOutPortHandler(this, name.c_str(), joints));
00247 }
00248 }else if(type == "ABS_TRANSFORM"){
00249 if (elements.size()!=1){
00250 std::cerr << "link name is not specified for port " << name
00251 << std::endl;
00252 return;
00253 }
00254 hrp::Link *l=this->link(elements[0]);
00255 if (l){
00256 m_outports.push_back(
00257 new AbsTransformOutPortHandler(this, name.c_str(), l));
00258 return;
00259 }
00260 hrp::Sensor *s;
00261 s = this->sensor<AccelSensor>(elements[0]);
00262 if (!s) s = this->sensor<RateGyroSensor>(elements[0]);
00263 if (!s) s = this->sensor<ForceSensor>(elements[0]);
00264 if (!s) s = this->sensor<RangeSensor>(elements[0]);
00265 if (!s) s = this->sensor<VisionSensor>(elements[0]);
00266 if (s){
00267 m_outports.push_back(
00268 new AbsTransformOutPortHandler(this, name.c_str(), s));
00269 return;
00270 }
00271 std::cerr << "can't find a link(or a sensor)(" << elements[0] << ")"
00272 << std::endl;
00273 }else if(type == "ABS_VELOCITY"){
00274 if (elements.size()!=1){
00275 std::cerr << "link name is not specified for port " << name
00276 << std::endl;
00277 return;
00278 }
00279 hrp::Link *l=this->link(elements[0]);
00280 if (l){
00281 m_outports.push_back(
00282 new AbsVelocityOutPortHandler(this, name.c_str(), l));
00283 }else{
00284 std::cerr << "can't find a link(" << elements[0] << ")"
00285 << std::endl;
00286 }
00287 }else if(type == "ABS_ACCELERATION"){
00288 if (elements.size()!=1){
00289 std::cerr << "link name is not specified for port " << name
00290 << std::endl;
00291 return;
00292 }
00293 hrp::Link *l=this->link(elements[0]);
00294 if (l){
00295 m_outports.push_back(
00296 new AbsAccelerationOutPortHandler(this, name.c_str(), l));
00297 }else{
00298 std::cerr << "can't find a link(" << elements[0] << ")"
00299 << std::endl;
00300 }
00301 }else if(type == "FORCE_SENSOR"){
00302 if (elements.size()!=1){
00303 std::cerr << "sensor name is not specified for port" << name
00304 << std::endl;
00305 return;
00306 }
00307 ForceSensor *s = this->sensor<ForceSensor>(elements[0]);
00308 if (!s){
00309 std::cerr << "can't find a sensor(" << elements[0] << ")"
00310 << std::endl;
00311 return;
00312 }
00313 m_outports.push_back(new ForceSensorPortHandler(this, name.c_str(),s));
00314
00315 }else if(type == "RATE_GYRO_SENSOR"){
00316 if (elements.size()!=1){
00317 std::cerr << "sensor name is not specified for port " << name
00318 << std::endl;
00319 return;
00320 }
00321 RateGyroSensor *s = this->sensor<RateGyroSensor>(elements[0]);
00322 if (!s){
00323 std::cerr << "can't find a sensor(" << elements[0] << ")"
00324 << std::endl;
00325 return;
00326 }
00327 m_outports.push_back(new RateGyroSensorPortHandler(this, name.c_str(),
00328 s));
00329 }else if(type == "ACCELERATION_SENSOR"){
00330 if (elements.size()!=1){
00331 std::cerr << "sensor name is not specified for port " << name
00332 << std::endl;
00333 return;
00334 }
00335 AccelSensor *s = this->sensor<AccelSensor>(elements[0]);
00336 if (!s){
00337 std::cerr << "can't find a sensor(" << elements[0] << ")"
00338 << std::endl;
00339 return;
00340 }
00341 m_outports.push_back(new AccelSensorPortHandler(this, name.c_str(),s));
00342
00343 }else if(type == "RANGE_SENSOR"){
00344 if (elements.size()!=1){
00345 std::cerr << "sensor name is not specified for port " << name
00346 << std::endl;
00347 return;
00348 }
00349 RangeSensor *s = this->sensor<RangeSensor>(elements[0]);
00350 if (!s){
00351 std::cerr << "can't find a sensor(" << elements[0] << ")"
00352 << std::endl;
00353 return;
00354 }
00355 m_outports.push_back(new RangeSensorPortHandler(this, name.c_str(),s));
00356
00357 }else if(type == "VISION_SENSOR"){
00358 if (elements.size()!=1){
00359 std::cerr << "sensor name is not specified for port " << name
00360 << std::endl;
00361 return;
00362 }
00363 VisionSensor *s = this->sensor<VisionSensor>(elements[0]);
00364 if (!s){
00365 std::cerr << "can't find a sensor(" << elements[0] << ")"
00366 << std::endl;
00367 return;
00368 }
00369 m_outports.push_back(new VisionSensorPortHandler(this,name.c_str(),s));
00370 }else if(type == "POINT_CLOUD"){
00371 if (elements.size()!=1){
00372 std::cerr << "sensor name is not specified for port " << name
00373 << std::endl;
00374 return;
00375 }
00376 VisionSensor *s = this->sensor<VisionSensor>(elements[0]);
00377 if (!s){
00378 std::cerr << "can't find a sensor(" << elements[0] << ")"
00379 << std::endl;
00380 return;
00381 }
00382 m_outports.push_back(new PointCloudPortHandler(this,name.c_str(),s));
00383 }else if(type == "CONSTRAINT_FORCE"){
00384 std::cout << "CONSTRAINT_FORCE is not implemented yet" << std::endl;
00385 }else{
00386 std::cerr << "unknown OutPort data type(" << type << ")" << std::endl;
00387 }
00388
00389 m_outports.push_back(new EmergencySignalPortHandler(this, "emergencySignal", this));
00390 m_outports.push_back(new ServoStatePortHandler(this, "servoState", this));
00391
00392 m_service0.setRobot(this);
00393 m_RobotHardwareServicePort.registerProvider("service0", "RobotHardwareService", m_service0);
00394 addPort(m_RobotHardwareServicePort);
00395 }
00396
00397 bool BodyRTC::names2ids(const std::vector<std::string> &i_names,
00398 std::vector<int> &o_ids)
00399 {
00400 bool ret = true;
00401 for (unsigned int i=0; i<i_names.size(); i++){
00402 hrp::Link *l = this->link(i_names[i].c_str());
00403 if (!l){
00404 std::cout << "joint named [" << i_names[i] << "] not found"
00405 << std::endl;
00406 ret = false;
00407 }else{
00408 o_ids.push_back(l->jointId);
00409 }
00410 }
00411 return ret;
00412 }
00413
00414 void BodyRTC::getStatus(OpenHRP::RobotHardwareService::RobotState* rs) {
00415 rs->angle.length(numJoints());
00416 rs->command.length(numJoints());
00417 for(size_t i = 0; i < numJoints(); i++) {
00418 rs->angle[i] = angles[i];
00419 rs->command[i] = commands[i];
00420 }
00421 rs->force.length(forces.size());
00422 for(size_t j = 0; j < forces.size(); j++) {
00423 rs->force[j].length(6);
00424 for(size_t i = 0; i < 6; i++ ) rs->force[j][i] = forces[j][i];
00425 }
00426 rs->rateGyro.length(gyros.size());
00427 for(size_t j = 0; j < gyros.size() ; j++) {
00428 rs->rateGyro[j].length(3);
00429 for(size_t i = 0; i < 3; i++ ) rs->rateGyro[j][i] = gyros[j][i];
00430 }
00431 rs->accel.length(accels.size());
00432 for(size_t j = 0; j < accels.size(); j++) {
00433 rs->accel[j].length(3);
00434 for(size_t i = 0; i < 3; i++ ) rs->accel[j][i] = accels[j][i];
00435 }
00436
00437 rs->servoState.length(numJoints());
00438 int v, status;
00439 for(unsigned int i=0; i < rs->servoState.length(); ++i){
00440
00441 rs->servoState[i].length(1);
00442 status = 0;
00443 v = readCalibState(i);
00444 status |= v<< OpenHRP::RobotHardwareService::CALIB_STATE_SHIFT;
00445 v = readPowerState(i);
00446 status |= v<< OpenHRP::RobotHardwareService::POWER_STATE_SHIFT;
00447 v = readServoState(i);
00448 status |= v<< OpenHRP::RobotHardwareService::SERVO_STATE_SHIFT;
00449
00450
00451
00452
00453 rs->servoState[i][0] = status;
00454
00455 }
00456
00457 }
00458
00459 void BodyRTC::getStatus2(OpenHRP::RobotHardwareService::RobotState2* rs) {
00460 }
00461
00462 bool BodyRTC::setServoErrorLimit(const char *i_jname, double i_limit)
00463 {
00464 Link *l = NULL;
00465 if (strcmp(i_jname, "all") == 0 || strcmp(i_jname, "ALL") == 0){
00466 for (unsigned int i=0; i<numJoints(); i++){
00467 m_servoErrorLimit[i] = i_limit;
00468 }
00469 }else if ((l = link(i_jname))){
00470 m_servoErrorLimit[l->jointId] = i_limit;
00471 }else{
00472 char *s = (char *)i_jname; while(*s) {*s=toupper(*s);s++;}
00473 const std::vector<int> jgroup = m_jointGroups[i_jname];
00474 if (jgroup.size()==0) return false;
00475 for (unsigned int i=0; i<jgroup.size(); i++){
00476 m_servoErrorLimit[jgroup[i]] = i_limit;
00477 }
00478 }
00479 return true;
00480 }
00481
00482 char *time_string()
00483 {
00484 struct timeval tv;
00485 gettimeofday(&tv, NULL);
00486 struct tm *tm_ = localtime(&tv.tv_sec);
00487 static char time[20];
00488 sprintf(time, "%02d:%02d:%02d.%06d", tm_->tm_hour, tm_->tm_min, tm_->tm_sec, (int)tv.tv_usec);
00489 return time;
00490 }
00491
00492 #define ON 1
00493 #define OFF 0
00494 bool BodyRTC::checkEmergency(emg_reason &o_reason, int &o_id) {
00495 int state;
00496
00497 o_reason = EMG_NONE;
00498 o_id = -1;
00499
00500 for (unsigned int i=0; i<numJoints(); i++){
00501 state = readServoState(i);
00502 if (state == ON && m_servoErrorLimit[i] != 0){
00503 double angle, command;
00504 angle = angles[i];
00505 command = commands[i];
00506 if (fabs(angle-command) > m_servoErrorLimit[i]){
00507 std::cerr << time_string()
00508 << ": servo error limit over: joint = "
00509 << joint(i)->name
00510 << ", qRef = " << command/M_PI*180 << "[deg], q = "
00511 << angle/M_PI*180 << "[deg]" << std::endl;
00512 o_reason = EMG_SERVO_ERROR;
00513 o_id = i;
00514 return true;
00515 }
00516 }
00517 }
00518 return false;
00519 }
00520
00521 bool BodyRTC::preOneStep() {
00522
00523 hrp::Vector3 g(0, 0, 9.8);
00524 calcCM();
00525 rootLink()->calcSubMassCM();
00526 bool all_servo_off = true;
00527 bool emulate_highgain_servo_off_mode = (numJoints() > 0);
00528 for(unsigned int i = 0; i < numJoints(); ++i){
00529 Link *j = joint(i);
00530 commands[i] = j->q;
00531 int p = readPowerState(i);
00532 int s = readServoState(i);
00533 if ( p && s ) { all_servo_off = false; continue; }
00534 switch(j->jointType){
00535 case Link::ROTATIONAL_JOINT:
00536 {
00537 j->q += (j->subm*g).cross(j->submwc / j->subm - j->p).dot(j->R * j->a) *0.005*0.01;
00538 if ( j->q < j->llimit ) {
00539 j->q = j->llimit;
00540 }else if ( j->q > j->ulimit ) {
00541 j->q = j->ulimit;
00542 }
00543 }
00544 break;
00545
00546 default:
00547 std::cerr << "calcCMJacobian() : unsupported jointType("
00548 << j->jointType << std::endl;
00549 }
00550 }
00551 if ( m_resetPosition ) {
00552 getDefaultRootPosition(m_lastServoOn_p, m_lastServoOn_R);
00553 rootLink()->p = m_lastServoOn_p;
00554 rootLink()->setAttitude(m_lastServoOn_R);
00555 m_resetPosition = false;
00556 }
00557 if (emulate_highgain_servo_off_mode) {
00558 if ( all_servo_off ) {
00559 rootLink()->p = m_lastServoOn_p;
00560 rootLink()->setAttitude(m_lastServoOn_R);
00561 } else {
00562 m_lastServoOn_p = rootLink()->p;
00563 m_lastServoOn_R = rootLink()->attitude();
00564 }
00565 }
00566 return true;
00567 }
00568
00569 bool BodyRTC::postOneStep() {
00570
00571 for(unsigned int i = 0; i < numJoints(); ++i){
00572 angles[i] = joint(i)->q;
00573 }
00574 for(unsigned int i = 0; i < numSensors(hrp::Sensor::ACCELERATION); i++ ){
00575 hrp::AccelSensor *s = sensor<AccelSensor>(i);
00576 accels[i][0] = s->dv[0];
00577 accels[i][1] = s->dv[1];
00578 accels[i][2] = s->dv[2];
00579 }
00580 for(unsigned int i = 0; i < numSensors(hrp::Sensor::RATE_GYRO); i++ ){
00581 hrp::RateGyroSensor *s = sensor<RateGyroSensor>(i);
00582 gyros[i][0] = s->w[0];
00583 gyros[i][1] = s->w[1];
00584 gyros[i][2] = s->w[2];
00585 }
00586 for(unsigned int i = 0; i < numSensors(hrp::Sensor::FORCE); i++ ){
00587 hrp::ForceSensor *s = sensor<ForceSensor>(i);
00588 forces[i][0] = s->f[0];
00589 forces[i][1] = s->f[1];
00590 forces[i][2] = s->f[2];
00591 forces[i][3] = s->tau[0];
00592 forces[i][4] = s->tau[1];
00593 forces[i][5] = s->tau[2];
00594 }
00595 if ( checkEmergency(m_emergencyReason, m_emergencyId) ) {
00596 servo("all", false);
00597 }
00598 return true;
00599 }
00600
00601
00602 #define JID_ALL -1
00603 #define JID_INVALID -2
00604
00605 bool BodyRTC::servo(const char *jname, bool turnon)
00606 {
00607 Link *l = NULL;
00608 if (strcmp(jname, "all") == 0 || strcmp(jname, "ALL") == 0){
00609 bool ret = true;
00610 for (unsigned int i=0; i<numJoints(); i++){
00611 ret = ret && servo(i, turnon);
00612 }
00613 return ret;
00614 }else if ((l = link(jname))){
00615 return servo(l->jointId, turnon);
00616 }else{
00617 char *s = (char *)jname; while(*s) {*s=toupper(*s);s++;}
00618 const std::vector<int> jgroup = m_jointGroups[jname];
00619 if (jgroup.size() == 0) return false;
00620 bool ret = true;
00621 for (unsigned int i=0; i<jgroup.size(); i++){
00622 ret = ret && servo(jgroup[i], turnon);
00623 return ret;
00624 }
00625 }
00626 return false;
00627 }
00628
00629 bool BodyRTC::power(const char *jname, bool turnon)
00630 {
00631 int jid = JID_INVALID;
00632
00633 if (strcmp(jname, "all") == 0 || strcmp(jname, "ALL") == 0){
00634 jid = JID_ALL;
00635 }else{
00636 Link *l = link(jname);
00637 if (!l) return false;
00638 jid = l->jointId;
00639 }
00640 return power(jid, turnon);
00641 }
00642
00643 RobotHardwareServicePort::RobotHardwareServicePort() {
00644 }
00645 RobotHardwareServicePort::~RobotHardwareServicePort() {
00646 }
00647
00648 void RobotHardwareServicePort::getStatus(OpenHRP::RobotHardwareService::RobotState_out rs) {
00649 rs = new OpenHRP::RobotHardwareService::RobotState();
00650 m_robot->getStatus(rs);
00651 }
00652
00653 void RobotHardwareServicePort::getStatus2(OpenHRP::RobotHardwareService::RobotState2_out rs) {
00654 rs = new OpenHRP::RobotHardwareService::RobotState2();
00655 m_robot->getStatus2(rs);
00656 }
00657
00658 CORBA::Boolean RobotHardwareServicePort::power(const char* jname, OpenHRP::RobotHardwareService::SwitchStatus turnon) {
00659 return m_robot->power(jname, turnon == OpenHRP::RobotHardwareService::SWITCH_ON);
00660 }
00661
00662 CORBA::Boolean RobotHardwareServicePort::servo(const char* jname, OpenHRP::RobotHardwareService::SwitchStatus turnon) {
00663 return m_robot->servo(jname, turnon == OpenHRP::RobotHardwareService::SWITCH_ON);
00664 }
00665 void RobotHardwareServicePort::setServoGainPercentage(const char *jname, double limit) {
00666 }
00667 void RobotHardwareServicePort::setServoTorqueGainPercentage(const char *jname, double limit) {
00668 }
00669 void RobotHardwareServicePort::setServoErrorLimit(const char *jname, double limit) {
00670 m_robot->setServoErrorLimit(jname, limit);
00671 }
00672 void RobotHardwareServicePort::setJointControlMode(const char *jname, OpenHRP::RobotHardwareService::JointControlMode jcm){
00673 }
00674 void RobotHardwareServicePort::calibrateInertiaSensor() {
00675 }
00676 void RobotHardwareServicePort::removeForceSensorOffset() {
00677 }
00678 void RobotHardwareServicePort::initializeJointAngle(const char* name, const char* option) {
00679 }
00680 CORBA::Boolean RobotHardwareServicePort::addJointGroup(const char* gname, const OpenHRP::RobotHardwareService::StrSequence& jnames) {
00681 char *s = (char *)gname; while(*s) {*s=toupper(*s);s++;}
00682 std::vector<int> jids;
00683 std::vector<std::string> joints;
00684 joints.resize(jnames.length());
00685 for (unsigned int i=0; i<jnames.length(); i++){
00686 joints[i] = jnames[i];
00687 }
00688 bool ret = m_robot->names2ids(joints, jids);
00689
00690 m_robot->addJointGroup(gname, jids);
00691 return ret;
00692 }
00693 CORBA::Boolean RobotHardwareServicePort::readDigitalInput(::OpenHRP::RobotHardwareService::OctSequence_out din) {
00694 return false;
00695 }
00696 CORBA::Long RobotHardwareServicePort::lengthDigitalInput() {
00697 return 0;
00698 }
00699 CORBA::Boolean RobotHardwareServicePort::writeDigitalOutput(const ::OpenHRP::RobotHardwareService::OctSequence& dout) {
00700 return false;
00701 }
00702 CORBA::Boolean RobotHardwareServicePort::writeDigitalOutputWithMask(const ::OpenHRP::RobotHardwareService::OctSequence& dout, const ::OpenHRP::RobotHardwareService::OctSequence& mask) {
00703 return false;
00704 }
00705 CORBA::Long RobotHardwareServicePort::lengthDigitalOutput() {
00706 return 0;
00707 }
00708 CORBA::Boolean RobotHardwareServicePort::readDigitalOutput(::OpenHRP::RobotHardwareService::OctSequence_out dout) {
00709 return false;
00710 }
00711
00712 CORBA::Boolean RobotHardwareServicePort::setJointInertia(const char* name, ::CORBA::Double mn)
00713 {
00714 return true;
00715 }
00716
00717 void RobotHardwareServicePort::setJointInertias(const ::OpenHRP::RobotHardwareService::DblSequence& mns)
00718 {
00719 }
00720 void RobotHardwareServicePort::enableDisturbanceObserver(){}
00721 void RobotHardwareServicePort::disableDisturbanceObserver(){}
00722 void RobotHardwareServicePort::setDisturbanceObserverGain(::CORBA::Double gain){}
00723
00724 void RobotHardwareServicePort::setRobot(BodyRTC *i_robot) { m_robot = i_robot; }
00725
00726 template <class _Delete>
00727 void DummyDelete(RTC::RTObject_impl* rtc)
00728 {
00729
00730 }
00731
00732 void BodyRTC::moduleInit(RTC::Manager* manager)
00733 {
00734 coil::Properties profile(bodyrtc_spec);
00735 manager->registerFactory(profile,
00736 RTC::Create<BodyRTC>,
00737 DummyDelete<BodyRTC>
00738
00739 );
00740 }