PortHandler.cpp
Go to the documentation of this file.
00001 #include <hrpModel/Link.h>
00002 #include <hrpModel/Sensor.h>
00003 #include <hrpModel/Light.h>
00004 #include "PortHandler.h"
00005 
00006 using namespace hrp;
00007 
00008 JointInPortHandler::JointInPortHandler(
00009     RTC::DataFlowComponentBase *i_rtc, 
00010     const char *i_portName,
00011     const std::vector<Link *> &i_joints,
00012     std::vector<OpenHRP::RobotHardwareService::SwitchStatus> *i_servo) :
00013     InPortHandler<RTC::TimedDoubleSeq>(i_rtc, i_portName),
00014     m_joints(i_joints),
00015     m_servo(*i_servo)
00016 {
00017     m_data.data.length(m_joints.size());
00018 }
00019 
00020 JointOutPortHandler::JointOutPortHandler(
00021     RTC::DataFlowComponentBase *i_rtc, 
00022     const char *i_portName,
00023     const std::vector<Link *> &i_joints) : 
00024     OutPortHandler<RTC::TimedDoubleSeq>(i_rtc, i_portName),
00025     m_joints(i_joints)
00026 {
00027     m_data.data.length(m_joints.size());
00028 }
00029 
00030 JointValueInPortHandler::JointValueInPortHandler(
00031     RTC::DataFlowComponentBase *i_rtc, 
00032     const char *i_portName,
00033     const std::vector<Link *> &i_joints,
00034     std::vector<OpenHRP::RobotHardwareService::SwitchStatus> *i_servo) :
00035     JointInPortHandler(i_rtc, i_portName, i_joints, i_servo)
00036 {
00037 }
00038 
00039 void JointValueInPortHandler::update()
00040 {
00041     if (m_port.isNew()){
00042         do {
00043             m_port.read();
00044         }while(m_port.isNew());
00045         for (size_t i=0; i<m_joints.size(); i++){
00046             if (m_joints[i] && m_servo[i] == OpenHRP::RobotHardwareService::SWITCH_ON) m_joints[i]->q = m_data.data[i];
00047         }
00048     }
00049 }
00050 
00051 JointValueOutPortHandler::JointValueOutPortHandler(
00052     RTC::DataFlowComponentBase *i_rtc, 
00053     const char *i_portName,
00054     const std::vector<Link *> &i_joints) : 
00055     JointOutPortHandler(i_rtc, i_portName, i_joints)
00056 {
00057 }
00058 
00059 void JointValueOutPortHandler::update(double time)
00060 {
00061     for (size_t i=0; i<m_joints.size(); i++){
00062         if (m_joints[i]) m_data.data[i] = m_joints[i]->q;
00063     }
00064     write(time);
00065 }
00066 
00067 JointVelocityInPortHandler::JointVelocityInPortHandler(
00068     RTC::DataFlowComponentBase *i_rtc, 
00069     const char *i_portName,
00070     const std::vector<Link *> &i_joints,
00071     std::vector<OpenHRP::RobotHardwareService::SwitchStatus> *i_servo) :
00072     JointInPortHandler(i_rtc, i_portName, i_joints, i_servo)
00073 {
00074 }
00075 
00076 void JointVelocityInPortHandler::update()
00077 {
00078     if (m_port.isNew()){
00079         do{
00080             m_port.read();
00081         }while(m_port.isNew());
00082         for (size_t i=0; i<m_joints.size(); i++){
00083             if (m_joints[i] && m_servo[i] == OpenHRP::RobotHardwareService::SWITCH_ON) m_joints[i]->dq = m_data.data[i];
00084         }
00085     }
00086 }
00087 
00088 JointVelocityOutPortHandler::JointVelocityOutPortHandler(
00089     RTC::DataFlowComponentBase *i_rtc, 
00090     const char *i_portName,
00091     const std::vector<Link *> &i_joints) : 
00092     JointOutPortHandler(i_rtc, i_portName, i_joints)
00093 {
00094 }
00095 
00096 void JointVelocityOutPortHandler::update(double time)
00097 {
00098     for (size_t i=0; i<m_joints.size(); i++){
00099         if (m_joints[i]) m_data.data[i] = m_joints[i]->dq;
00100     }
00101     write(time);
00102 }
00103 
00104 JointAccelerationInPortHandler::JointAccelerationInPortHandler(
00105     RTC::DataFlowComponentBase *i_rtc, 
00106     const char *i_portName,
00107     const std::vector<Link *> &i_joints,
00108     std::vector<OpenHRP::RobotHardwareService::SwitchStatus> *i_servo) :
00109     JointInPortHandler(i_rtc, i_portName, i_joints, i_servo)
00110 {
00111 }
00112 
00113 void JointAccelerationInPortHandler::update()
00114 {
00115     if (m_port.isNew()){
00116         do{
00117             m_port.read();
00118         }while(m_port.isNew());
00119         for (size_t i=0; i<m_joints.size(); i++){
00120             if (m_joints[i] && m_servo[i] == OpenHRP::RobotHardwareService::SWITCH_ON) m_joints[i]->ddq = m_data.data[i];
00121         }
00122     }
00123 }
00124 
00125 JointAccelerationOutPortHandler::JointAccelerationOutPortHandler(
00126     RTC::DataFlowComponentBase *i_rtc, 
00127     const char *i_portName,
00128     const std::vector<Link *> &i_joints) : 
00129     JointOutPortHandler(i_rtc, i_portName, i_joints)
00130 {
00131 }
00132 
00133 void JointAccelerationOutPortHandler::update(double time)
00134 {
00135     for (size_t i=0; i<m_joints.size(); i++){
00136         if (m_joints[i]) m_data.data[i] = m_joints[i]->ddq;
00137     }
00138     write(time);
00139 }
00140 
00141 JointTorqueInPortHandler::JointTorqueInPortHandler(
00142     RTC::DataFlowComponentBase *i_rtc, 
00143     const char *i_portName,
00144     const std::vector<Link *> &i_joints,
00145     std::vector<OpenHRP::RobotHardwareService::SwitchStatus> *i_servo) :
00146     JointInPortHandler(i_rtc, i_portName, i_joints, i_servo)
00147 {
00148 }
00149 
00150 void JointTorqueInPortHandler::update()
00151 {
00152     if (m_port.isNew()){
00153         do{
00154             m_port.read();
00155         }while(m_port.isNew());
00156         if (m_data.data.length() != m_joints.size()){
00157             std::cerr << "JointTorqueInPortHandler: data length mismatch(length of input data:"
00158                       << m_data.data.length() << "<->the number of joints:" << m_joints.size()
00159                       << ")" << std::endl;
00160         } 
00161         for (size_t i=0; i<m_joints.size(); i++){
00162             if (m_joints[i] && m_servo[i] == OpenHRP::RobotHardwareService::SWITCH_ON) m_joints[i]->u = m_data.data[i];
00163         }
00164     }
00165 }
00166 
00167 JointTorqueOutPortHandler::JointTorqueOutPortHandler(
00168     RTC::DataFlowComponentBase *i_rtc, 
00169     const char *i_portName,
00170     const std::vector<Link *> &i_joints) : 
00171     JointOutPortHandler(i_rtc, i_portName, i_joints)
00172 {
00173 }
00174 
00175 void JointTorqueOutPortHandler::update(double time)
00176 {
00177     for (size_t i=0; i<m_joints.size(); i++){
00178         if (m_joints[i]) m_data.data[i] = m_joints[i]->u;
00179     }
00180     write(time);
00181 }
00182 
00183 ForceSensorPortHandler::ForceSensorPortHandler(
00184     RTC::DataFlowComponentBase *i_rtc, 
00185     const char *i_portName,
00186     ForceSensor *i_sensor) : 
00187     SensorPortHandler<ForceSensor, RTC::TimedDoubleSeq>(i_rtc, i_portName, i_sensor)
00188 {
00189     m_data.data.length(6);
00190 }
00191 
00192 void ForceSensorPortHandler::update(double time)
00193 {
00194     setVector3(m_sensor->f,   m_data.data, 0);
00195     setVector3(m_sensor->tau, m_data.data, 3);
00196     write(time);
00197 }
00198 
00199 RateGyroSensorPortHandler::RateGyroSensorPortHandler(
00200     RTC::DataFlowComponentBase *i_rtc, 
00201     const char *i_portName,
00202     RateGyroSensor *i_sensor) : 
00203     SensorPortHandler<RateGyroSensor, RTC::TimedAngularVelocity3D>(i_rtc, i_portName, i_sensor)
00204 {
00205 }
00206 
00207 void RateGyroSensorPortHandler::update(double time)
00208 {
00209     m_data.data.avx = m_sensor->w[0];
00210     m_data.data.avy = m_sensor->w[1];
00211     m_data.data.avz = m_sensor->w[2];
00212     write(time);
00213 }
00214 
00215 AccelSensorPortHandler::AccelSensorPortHandler(
00216     RTC::DataFlowComponentBase *i_rtc, 
00217     const char *i_portName,
00218     AccelSensor *i_sensor) : 
00219     SensorPortHandler<AccelSensor, RTC::TimedAcceleration3D>(i_rtc, i_portName, i_sensor)
00220 {
00221 }
00222 
00223 void AccelSensorPortHandler::update(double time)
00224 {
00225     m_data.data.ax = m_sensor->dv[0];
00226     m_data.data.ay = m_sensor->dv[1];
00227     m_data.data.az = m_sensor->dv[2];
00228     write(time);
00229 }
00230 
00231 RangeSensorPortHandler::RangeSensorPortHandler(
00232     RTC::DataFlowComponentBase *i_rtc, 
00233     const char *i_portName,
00234     RangeSensor *i_sensor) : 
00235     SensorPortHandler<RangeSensor, RTC::RangeData>(i_rtc, i_portName, i_sensor)
00236 {
00237     i_sensor->isEnabled = true;
00238     m_data.config.minAngle = -i_sensor->scanAngle/2;
00239     m_data.config.maxAngle =  i_sensor->scanAngle/2;
00240     m_data.config.angularRes = i_sensor->scanStep;
00241     m_data.config.minRange = 0;
00242     m_data.config.maxRange = i_sensor->maxDistance;
00243     m_data.config.rangeRes = 0;
00244     m_data.config.frequency = i_sensor->scanRate;
00245 }
00246 
00247 void RangeSensorPortHandler::update(double time)
00248 {
00249     if (m_sensor->isUpdated){
00250         if (m_data.ranges.length() != m_sensor->distances.size()){
00251             m_data.ranges.length(m_sensor->distances.size());
00252         }
00253         memcpy(m_data.ranges.get_buffer(), &(m_sensor->distances[0]), 
00254                sizeof(double)*m_sensor->distances.size());
00255         write(time);
00256         m_sensor->isUpdated = false;
00257     }
00258 }
00259 
00260 
00261 VisionSensorPortHandler::VisionSensorPortHandler(
00262     RTC::DataFlowComponentBase *i_rtc, 
00263     const char *i_portName,
00264     VisionSensor *i_sensor) : 
00265     SensorPortHandler<VisionSensor, Img::TimedCameraImage>(i_rtc, i_portName, i_sensor)
00266 {
00267     i_sensor->isEnabled = true;
00268     if (m_sensor->imageType == VisionSensor::COLOR 
00269         || m_sensor->imageType == VisionSensor::COLOR_DEPTH){
00270         m_data.data.image.width = m_sensor->width;
00271         m_data.data.image.height = m_sensor->height;
00272         m_data.data.image.format = Img::CF_RGB;
00273         int len = m_sensor->width*m_sensor->height*3;
00274         m_data.data.image.raw_data.length(len);
00275         m_data.data.intrinsic.distortion_coefficient.length(5);
00276         for(int i = 0; i < 5; i++){
00277             m_data.data.intrinsic.distortion_coefficient[i] = 0;
00278         }
00279         double fovx = m_sensor->width/m_sensor->height*m_sensor->fovy;
00280         m_data.data.intrinsic.matrix_element[0]=0.5 * m_sensor->width/tan(fovx/2.0);
00281         m_data.data.intrinsic.matrix_element[1]=0.0;
00282         m_data.data.intrinsic.matrix_element[2]=m_sensor->width/2;
00283         m_data.data.intrinsic.matrix_element[3]=0.5 * m_sensor->height/tan(m_sensor->fovy/2.0);
00284         m_data.data.intrinsic.matrix_element[4]=m_sensor->height/2;
00285     }else if(m_sensor->imageType == VisionSensor::MONO
00286              || m_sensor->imageType == VisionSensor::MONO_DEPTH){
00287         m_data.data.image.width = m_sensor->width;
00288         m_data.data.image.height = m_sensor->height;
00289         m_data.data.image.format = Img::CF_GRAY;
00290         int len = m_sensor->width*m_sensor->height;
00291         m_data.data.image.raw_data.length(len);
00292         m_data.data.intrinsic.distortion_coefficient.length(5);
00293         for(int i = 0; i < 5; i++){
00294             m_data.data.intrinsic.distortion_coefficient[i] = 0;
00295         }
00296         double fovx = m_sensor->width/m_sensor->height*m_sensor->fovy;
00297         m_data.data.intrinsic.matrix_element[0]=0.5 * m_sensor->width/tan(fovx/2.0);
00298         m_data.data.intrinsic.matrix_element[1]=0.0;
00299         m_data.data.intrinsic.matrix_element[2]=m_sensor->width/2;
00300         m_data.data.intrinsic.matrix_element[3]=0.5 * m_sensor->height/tan(m_sensor->fovy/2.0);
00301         m_data.data.intrinsic.matrix_element[4]=m_sensor->height/2;
00302     }
00303 }
00304 
00305 void VisionSensorPortHandler::update(double time)
00306 {
00307     if (m_sensor->isUpdated){
00308         if (m_sensor->imageType == VisionSensor::COLOR 
00309             || m_sensor->imageType == VisionSensor::MONO
00310             || m_sensor->imageType == VisionSensor::COLOR_DEPTH 
00311             || m_sensor->imageType == VisionSensor::MONO_DEPTH){
00312             if (m_data.data.image.raw_data.length() != m_sensor->image.size()){
00313                 std::cerr << "BodyRTC: mismatch image length " 
00314                           << m_data.data.image.raw_data.length()
00315                           << "<->" << m_sensor->image.size() << std::endl;
00316             }else{
00317                 memcpy(m_data.data.image.raw_data.get_buffer(), 
00318                        &m_sensor->image[0], m_sensor->image.size());
00319                 write(time);
00320 #if 0
00321                 char filename[20];
00322                 sprintf(filename, "camera%d.ppm", m_sensor->id);
00323                 std::ofstream ofs(filename, std::ios::out | std::ios::trunc | std::ios::binary );
00324                 char buf[10];
00325                 unsigned char *pixels = &m_sensor->image[0];
00326                 sprintf(buf, "%d %d", m_sensor->width, m_sensor->height);
00327                 if (m_sensor->imageType == VisionSensor::COLOR
00328                     || m_sensor->imageType == VisionSensor::COLOR_DEPTH){
00329                     ofs << "P6";
00330                 }else{ 
00331                     ofs << "P5";
00332                 }
00333                 ofs << std::endl << buf << std::endl << "255" << std::endl;
00334                 ofs.write((char *)pixels, m_sensor->image.size());
00335 #endif    
00336             }
00337         }
00338         m_sensor->isUpdated = false;
00339     }
00340 }
00341 
00342 PointCloudPortHandler::PointCloudPortHandler(
00343     RTC::DataFlowComponentBase *i_rtc, 
00344     const char *i_portName,
00345     VisionSensor *i_sensor) : 
00346     SensorPortHandler<VisionSensor, PointCloudTypes::PointCloud>(i_rtc, i_portName, i_sensor)
00347 {
00348     i_sensor->isEnabled = true;
00349     switch(m_sensor->imageType){
00350     case VisionSensor::DEPTH:
00351         m_pcFormat = "xyz"; break;
00352     case VisionSensor::COLOR_DEPTH:
00353         m_pcFormat = "xyzrgb"; break;
00354     case VisionSensor::MONO_DEPTH:
00355         m_pcFormat = "xyz"; break;
00356     default:
00357         std::cout << "VisionSensor " << m_sensor->name
00358                   << " doesn't have distance measuring function" << std::endl;
00359         break;
00360     }
00361     m_data.width = m_sensor->width;
00362     m_data.height = m_sensor->height;
00363     m_data.type = m_pcFormat.c_str();
00364 
00365     bool colored = false;
00366     if (m_pcFormat == "xyz"){
00367         m_data.fields.length(3);
00368     }else if (m_pcFormat == "xyzrgb"){
00369         m_data.fields.length(6);
00370         colored = true;
00371     }else{
00372         std::cerr << "unknown point cloud format:[" << m_pcFormat << "]" << std::endl;
00373     }
00374     m_data.fields[0].name = "x";
00375     m_data.fields[0].offset = 0;
00376     m_data.fields[0].data_type = PointCloudTypes::FLOAT32;
00377     m_data.fields[0].count = 4;
00378     m_data.fields[1].name = "y";
00379     m_data.fields[1].offset = 4;
00380     m_data.fields[1].data_type = PointCloudTypes::FLOAT32;
00381     m_data.fields[1].count = 4;
00382     m_data.fields[2].name = "z";
00383     m_data.fields[2].offset = 8;
00384     m_data.fields[2].data_type = PointCloudTypes::FLOAT32;
00385     m_data.fields[2].count = 4;
00386     if (m_pcFormat == "xyzrgb"){
00387         m_data.fields[3].name = "r";
00388         m_data.fields[3].offset = 12;
00389         m_data.fields[3].data_type = PointCloudTypes::UINT8;
00390         m_data.fields[3].count = 1;
00391         m_data.fields[4].name = "g";
00392         m_data.fields[4].offset = 13;
00393         m_data.fields[4].data_type = PointCloudTypes::UINT8;
00394         m_data.fields[4].count = 1;
00395         m_data.fields[5].name = "b";
00396         m_data.fields[5].offset = 14;
00397         m_data.fields[5].data_type = PointCloudTypes::UINT8;
00398         m_data.fields[5].count = 1;
00399     }
00400     m_data.is_bigendian = false;
00401     m_data.point_step = 16;
00402     m_data.is_dense = true;
00403     m_data.row_step = m_data.point_step*m_sensor->width;
00404 }
00405 
00406 void PointCloudPortHandler::update(double time)
00407 {
00408     if (m_sensor->isUpdated){
00409         m_data.data.length(m_sensor->depth.size());
00410         memcpy(m_data.data.get_buffer(), &m_sensor->depth[0],
00411                m_sensor->depth.size());
00412         write(time);
00413     }
00414     m_sensor->isUpdated = false;
00415 }
00416 
00417 AbsTransformInPortHandler::AbsTransformInPortHandler(
00418     RTC::DataFlowComponentBase *i_rtc,
00419     const char *i_portName,
00420     hrp::Link *i_link) :
00421     InPortHandler<RTC::TimedPose3D>(i_rtc, i_portName),
00422     m_link(i_link)
00423 {
00424 }
00425 
00426 void AbsTransformInPortHandler::update()
00427 {
00428     if (m_port.isNew()){
00429         do{
00430             m_port.read();
00431         }while(m_port.isNew());
00432         m_link->p << 
00433             m_data.data.position.x, 
00434             m_data.data.position.y, 
00435             m_data.data.position.z;
00436         hrp::Matrix33 R = hrp::rotFromRpy(m_data.data.orientation.r,
00437                                           m_data.data.orientation.p,
00438                                           m_data.data.orientation.y);
00439         m_link->setSegmentAttitude(R);
00440     }
00441 }
00442 
00443 AbsVelocityInPortHandler::AbsVelocityInPortHandler(
00444     RTC::DataFlowComponentBase *i_rtc,
00445     const char *i_portName,
00446     hrp::Link *i_link) :
00447     InPortHandler<RTC::TimedDoubleSeq>(i_rtc, i_portName),
00448     m_link(i_link)
00449 {
00450 }
00451 
00452 void AbsVelocityInPortHandler::update()
00453 {
00454     if (m_port.isNew()){
00455         do{
00456             m_port.read();
00457         }while(m_port.isNew());
00458         m_link->v << m_data.data[0], m_data.data[1], m_data.data[2];
00459         m_link->w << m_data.data[3], m_data.data[4], m_data.data[5];
00460         m_link->vo = m_link->v - m_link->w.cross(m_link->p);
00461     }
00462 }
00463 
00464 AbsAccelerationInPortHandler::AbsAccelerationInPortHandler(
00465     RTC::DataFlowComponentBase *i_rtc,
00466     const char *i_portName,
00467     hrp::Link *i_link) :
00468     InPortHandler<RTC::TimedDoubleSeq>(i_rtc, i_portName),
00469     m_link(i_link)
00470 {
00471 }
00472 
00473 void AbsAccelerationInPortHandler::update()
00474 {
00475     if (m_port.isNew()){
00476         do{
00477             m_port.read();
00478         }while(m_port.isNew());
00479         m_link->dv << m_data.data[0], m_data.data[1], m_data.data[2];
00480         m_link->dw << m_data.data[3], m_data.data[4], m_data.data[5];
00481     }
00482 }
00483 
00484 FrameRateInPortHandler::FrameRateInPortHandler(
00485     RTC::DataFlowComponentBase *i_rtc,
00486     const char *i_portName,
00487     hrp::VisionSensor *i_sensor) :
00488     InPortHandler<RTC::TimedDouble>(i_rtc, i_portName),
00489     m_sensor(i_sensor)
00490 {
00491 }
00492 
00493 void FrameRateInPortHandler::update()
00494 {
00495     if (m_port.isNew()){
00496         do {
00497             m_port.read();
00498         }while(m_port.isNew());
00499         m_sensor->frameRate = m_data.data;
00500     }
00501 }
00502 
00503 LightSwitchInPortHandler::LightSwitchInPortHandler(
00504     RTC::DataFlowComponentBase *i_rtc,
00505     const char *i_portName,
00506     hrp::Light *i_light) :
00507     InPortHandler<RTC::TimedBoolean>(i_rtc, i_portName),
00508     m_light(i_light)
00509 {
00510 }
00511 
00512 void LightSwitchInPortHandler::update()
00513 {
00514     if (m_port.isNew()){
00515         do {
00516             m_port.read();
00517         }while(m_port.isNew());
00518         m_light->on = m_data.data;
00519     }
00520 }
00521 
00522 AbsTransformOutPortHandler::AbsTransformOutPortHandler(
00523     RTC::DataFlowComponentBase *i_rtc,
00524     const char *i_portName,
00525     hrp::Link *i_link) :
00526     OutPortHandler<RTC::TimedPose3D>(i_rtc, i_portName),
00527     m_link(i_link), m_sensor(NULL)
00528 {
00529 }
00530 
00531 AbsTransformOutPortHandler::AbsTransformOutPortHandler(
00532     RTC::DataFlowComponentBase *i_rtc,
00533     const char *i_portName,
00534     hrp::Sensor *i_sensor) :
00535     OutPortHandler<RTC::TimedPose3D>(i_rtc, i_portName),
00536     m_link(NULL), m_sensor(i_sensor)
00537 {
00538 }
00539 
00540 void AbsTransformOutPortHandler::update(double time)
00541 {
00542     hrp::Vector3 p;
00543     hrp::Matrix33 R;
00544     if (m_link){
00545         p = m_link->p;
00546         R = m_link->attitude();
00547     }else{
00548         hrp::Link *parent = m_sensor->link;
00549         p = parent->R*m_sensor->localPos+parent->p;
00550         R = parent->R*m_sensor->localR;
00551     }
00552     m_data.data.position.x = p[0];
00553     m_data.data.position.y = p[1];
00554     m_data.data.position.z = p[2];
00555     hrp::Vector3 rpy = rpyFromRot(R);
00556     m_data.data.orientation.r = rpy[0];
00557     m_data.data.orientation.p = rpy[1];
00558     m_data.data.orientation.y = rpy[2];
00559     write(time);
00560 }
00561 
00562 
00563 AbsVelocityOutPortHandler::AbsVelocityOutPortHandler(
00564     RTC::DataFlowComponentBase *i_rtc,
00565     const char *i_portName,
00566     hrp::Link *i_link) :
00567     OutPortHandler<RTC::TimedDoubleSeq>(i_rtc, i_portName),
00568     m_link(i_link)
00569 {
00570     m_data.data.length(6);
00571 }
00572 
00573 void AbsVelocityOutPortHandler::update(double time){
00574     m_data.data[0] = m_link->v(0);
00575     m_data.data[1] = m_link->v(1);
00576     m_data.data[2] = m_link->v(2);
00577     m_data.data[3] = m_link->w(0);
00578     m_data.data[4] = m_link->w(1);
00579     m_data.data[5] = m_link->w(2);
00580 }
00581 
00582 AbsAccelerationOutPortHandler::AbsAccelerationOutPortHandler(
00583     RTC::DataFlowComponentBase *i_rtc,
00584     const char *i_portName,
00585     hrp::Link *i_link) :
00586     OutPortHandler<RTC::TimedDoubleSeq>(i_rtc, i_portName),
00587     m_link(i_link)
00588 {
00589     m_data.data.length(6);
00590 }
00591 
00592 void AbsAccelerationOutPortHandler::update(double time)
00593 {
00594     m_data.data[0] = m_link->dv(0);
00595     m_data.data[1] = m_link->dv(1);
00596     m_data.data[2] = m_link->dv(2);
00597     m_data.data[3] = m_link->dw(0);
00598     m_data.data[4] = m_link->dw(1);
00599     m_data.data[5] = m_link->dw(2);
00600 }
00601 
00602 EmergencySignalPortHandler::EmergencySignalPortHandler(
00603     RTC::DataFlowComponentBase *i_rtc,
00604     const char *i_portName,
00605     BodyRTC *i_body) :
00606     OutPortHandler<RTC::TimedLong>(i_rtc, i_portName),
00607     m_body(i_body)
00608 {
00609 }
00610 
00611 void EmergencySignalPortHandler::update(double time)
00612 {
00613     if (m_body->m_emergencyReason != BodyRTC::EMG_NONE){
00614         m_data.data = m_body->m_emergencyReason;
00615         write(time);
00616     }
00617 }
00618 
00619 ServoStatePortHandler::ServoStatePortHandler(
00620     RTC::DataFlowComponentBase *i_rtc,
00621     const char *i_portName,
00622     BodyRTC *i_body) :
00623     OutPortHandler<OpenHRP::TimedLongSeqSeq>(i_rtc, i_portName),
00624     m_body(i_body)
00625 {
00626     rs = new OpenHRP::RobotHardwareService::RobotState();
00627 }
00628 
00629 void ServoStatePortHandler::update(double time)
00630 {
00631     m_body->getStatus(rs);
00632     m_data.data.length(rs->servoState.length());
00633     for (size_t i=0; i < rs->servoState.length(); i++) {
00634         m_data.data[i].length(rs->servoState[i].length());
00635         for (size_t j=0; j < rs->servoState[i].length(); j++) {
00636             m_data.data[i][j] = rs->servoState[i][j];
00637         }
00638     }
00639     write(time);
00640 }


hrpsys
Author(s): AIST, Fumio Kanehiro
autogenerated on Wed May 15 2019 05:02:18