BodyRTC.h
Go to the documentation of this file.
00001 #ifndef BODY_EXT_H_INCLUDED
00002 #define BODY_EXT_H_INCLUDED
00003 
00004 #include <rtm/idl/BasicDataType.hh>
00005 #include <rtm/idl/ExtendedDataTypes.hh>
00006 #include "hrpsys/idl/Img.hh"
00007 #include "hrpsys/idl/RobotHardwareService.hh"
00008 #include <hrpModel/Body.h>
00009 #include <hrpCorba/OpenHRPCommon.hh>
00010 #include <rtm/Manager.h>
00011 #include <rtm/DataFlowComponentBase.h>
00012 #include <rtm/CorbaPort.h>
00013 #include <rtm/DataInPort.h>
00014 #include <rtm/DataOutPort.h>
00015 #include <rtm/idl/BasicDataTypeSkel.h>
00016 #include <rtm/idl/ExtendedDataTypesSkel.h>
00017 
00018 class InPortHandlerBase;
00019 class OutPortHandlerBase;
00020 class EmergencySignalPortHandler;
00021 class BodyRTC;
00022 
00023 class RobotHardwareServicePort
00024     : public virtual POA_OpenHRP::RobotHardwareService,
00025       public virtual PortableServer::RefCountServantBase
00026 {
00027 public:
00028     RobotHardwareServicePort();
00029     ~RobotHardwareServicePort();
00030     void getStatus(OpenHRP::RobotHardwareService::RobotState_out rs);
00031     void getStatus2(OpenHRP::RobotHardwareService::RobotState2_out rs);
00032     CORBA::Boolean power(const char* jname, OpenHRP::RobotHardwareService::SwitchStatus ss);
00033     CORBA::Boolean servo(const char* jname, OpenHRP::RobotHardwareService::SwitchStatus ss);
00034     void setServoGainPercentage(const char *jname, double limit);
00035     void setServoTorqueGainPercentage(const char *jname, double limit);
00036     void setServoErrorLimit(const char *jname, double limit);
00037     void setJointControlMode(const char *jname, OpenHRP::RobotHardwareService::JointControlMode jcm);
00038     void calibrateInertiaSensor();
00039     void removeForceSensorOffset();
00040     void initializeJointAngle(const char* name, const char* option);
00041     CORBA::Boolean addJointGroup(const char* gname, const OpenHRP::RobotHardwareService::StrSequence& jnames);
00042     CORBA::Boolean readDigitalInput(::OpenHRP::RobotHardwareService::OctSequence_out din);
00043     CORBA::Long lengthDigitalInput();
00044     CORBA::Boolean writeDigitalOutput(const ::OpenHRP::RobotHardwareService::OctSequence& dout);
00045     CORBA::Boolean writeDigitalOutputWithMask(const ::OpenHRP::RobotHardwareService::OctSequence& dout, const ::OpenHRP::RobotHardwareService::OctSequence& mask);
00046     CORBA::Long lengthDigitalOutput();
00047     CORBA::Boolean readDigitalOutput(::OpenHRP::RobotHardwareService::OctSequence_out dout);
00048     CORBA::Boolean setJointInertia(const char* name, ::CORBA::Double mn);
00049     void setJointInertias(const ::OpenHRP::RobotHardwareService::DblSequence& mns);
00050     void enableDisturbanceObserver();
00051     void disableDisturbanceObserver();
00052     void setDisturbanceObserverGain(::CORBA::Double gain);
00053     void setRobot(BodyRTC *i_robot);
00054 private:
00055     BodyRTC *m_robot;
00056 };
00057 
00058 //
00059 
00060 class BodyRTC : virtual public hrp::Body, public RTC::DataFlowComponentBase
00061 {
00062 public:
00063     BodyRTC(RTC::Manager* manager = &RTC::Manager::instance());
00064     virtual ~BodyRTC(void);
00065 
00066     RTC::ReturnCode_t setup();
00067 
00068     RTC::ReturnCode_t onActivated(RTC::UniqueId ec_id){
00069         std::cout << "BodyRTC::onActivated(" << ec_id << ")" << std::endl;
00070         return RTC::RTC_OK;
00071     }
00072     RTC::ReturnCode_t onDeactivated(RTC::UniqueId ec_id){
00073         std::cout << "BodyRTC::onDeactivated(" << ec_id << ")" << std::endl;
00074         return RTC::RTC_OK;
00075     }
00076 
00077     void createInPort(const std::string &config);
00078     void createOutPort(const std::string &config);
00079     void writeDataPorts(double time);
00080     void readDataPorts();
00081     static void moduleInit(RTC::Manager*);
00082 
00083     void getStatus(OpenHRP::RobotHardwareService::RobotState* rs);
00084     void getStatus2(OpenHRP::RobotHardwareService::RobotState2* rs);
00085 
00086     bool preOneStep();
00087     bool postOneStep();
00088     bool names2ids(const std::vector<std::string> &i_names, std::vector<int> &o_ids);
00089     std::vector<int> getJointGroup(const char* gname) {return  m_jointGroups[gname]; }
00090     int addJointGroup(const char* gname, const std::vector<int>jids) { m_jointGroups[gname] = jids; return 0;}
00091 
00092     // API to be compatible with robot.h
00093     bool power(int jid, bool turnon) {power_status[jid] = turnon?OpenHRP::RobotHardwareService::SWITCH_ON:OpenHRP::RobotHardwareService::SWITCH_OFF; return true; }
00094     bool servo(const char *jname, bool turnon);
00095     bool servo(int jid, bool turnon) {servo_status[jid] = turnon?OpenHRP::RobotHardwareService::SWITCH_ON:OpenHRP::RobotHardwareService::SWITCH_OFF; return true; }
00096     bool power(const char *jname, bool turnon);
00097 
00098     //void removeForceSensorOffset();
00099     //bool loadGain();
00100     //void startInertiaSensorCalibration();
00101     //void startForceSensorCalibration();
00102     //void initializeJointAngle(const char *name, const char *option);
00103     //void oneStep();
00104     int readCalibState(const int i) { return (calib_status[i] == OpenHRP::RobotHardwareService::SWITCH_ON); }
00105     int readPowerState(const int i) { return (power_status[i] == OpenHRP::RobotHardwareService::SWITCH_ON); }
00106     int readServoState(const int i) { return (servo_status[i] == OpenHRP::RobotHardwareService::SWITCH_ON); }
00107     //int readServoAlarm(int i);
00108     //int readDriverTemperature(int i);
00109     //void readPowerStatus(double &o_voltage, double &o_current);
00110     //void readJointAngles(double *o_angles);
00111     //void readJointVelocities(double *o_velocities);
00112     //int readJointTorques(double *o_torques);
00113     //void readGyroSensor(unsigned int i_rank, double *o_rates);
00114     //void readAccelerometer(unsigned int i_rank, double *o_accs);
00115     //void readForceSensor(unsigned int i_rank, double *o_forces);
00116     //void writeJointCommands(const double *i_commands);
00117     //void readJointCommands(double *o_commands);
00118     //void writeTorqueCommands(const double *i_commands);
00119     //void writeVelocityCommands(const double *i_commands);
00120     //size_t lengthOfExtraServoState(int id);
00121     //void readExtraServoState(int id, int *state);
00122     typedef enum {EMG_NONE, EMG_SERVO_ERROR, EMG_FZ} emg_reason;
00123     bool checkEmergency(emg_reason &o_reason, int &o_id);
00124     //bool setServoGainPercentage(const char *i_jname, double i_percentage);
00125     bool setServoErrorLimit(const char *i_jname, double i_limit);
00126     //void setProperty(const char *key, const char *value);
00127     //bool addJointGroup(const char *gname, const std::vector<std::string>& jnames);
00128     std::vector<double> m_servoErrorLimit;
00129     //double m_fzLimitRatio;
00130     //double m_maxZmpError;
00131 
00132     bool readDigitalInput(char *o_din);
00133     int lengthDigitalInput();
00134     bool writeDigitalOutput(const char *i_dout);
00135     bool writeDigitalOutputWithMask(const char *i_dout, const char *i_mask);
00136     int lengthDigitalOutput();
00137     bool readDigitalOutput(char *o_dout);
00138 
00139     bool resetPosition() { m_resetPosition = true; return true; }
00140     //
00141     BodyRTC::emg_reason m_emergencyReason;
00142     int m_emergencyId;
00143 
00144 private:
00145     static const char* bodyrtc_spec[];
00146     // DataInPort
00147     std::vector<InPortHandlerBase *> m_inports;
00148 
00149     // DataOutPort
00150     std::vector<OutPortHandlerBase *> m_outports;
00151 
00152     // Corba Port
00153     RTC::CorbaPort m_RobotHardwareServicePort;
00154     RobotHardwareServicePort m_service0;
00155 
00156     // robot status
00157     std::vector<double> angles;
00158     std::vector<double> commands;
00159     std::vector<hrp::Vector3> accels;
00160     std::vector<hrp::Vector3> gyros;
00161     std::vector<hrp::dvector6> forces;
00162     std::vector<OpenHRP::RobotHardwareService::SwitchStatus> calib_status;
00163     std::vector<OpenHRP::RobotHardwareService::SwitchStatus> servo_status;
00164     std::vector<OpenHRP::RobotHardwareService::SwitchStatus> power_status;
00165     std::map<std::string, std::vector<int> > m_jointGroups;
00166 
00167     // pinned position for servo off
00168     bool m_resetPosition;
00169     hrp::Vector3  m_lastServoOn_p;
00170     hrp::Matrix33 m_lastServoOn_R;
00171 
00172     int dummy;
00173 };
00174 
00175 typedef boost::intrusive_ptr<BodyRTC> BodyRTCPtr;
00176 
00177 #endif


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