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 setServoErrorLimit(const char *jname, double limit);
00036     void calibrateInertiaSensor();
00037     void removeForceSensorOffset();
00038     void initializeJointAngle(const char* name, const char* option);
00039     CORBA::Boolean addJointGroup(const char* gname, const OpenHRP::RobotHardwareService::StrSequence& jnames);
00040     CORBA::Boolean readDigitalInput(::OpenHRP::RobotHardwareService::OctSequence_out din);
00041     CORBA::Long lengthDigitalInput();
00042     CORBA::Boolean writeDigitalOutput(const ::OpenHRP::RobotHardwareService::OctSequence& dout);
00043     CORBA::Boolean writeDigitalOutputWithMask(const ::OpenHRP::RobotHardwareService::OctSequence& dout, const ::OpenHRP::RobotHardwareService::OctSequence& mask);
00044     CORBA::Long lengthDigitalOutput();
00045     CORBA::Boolean readDigitalOutput(::OpenHRP::RobotHardwareService::OctSequence_out dout);
00046     void setRobot(BodyRTC *i_robot);
00047 private:
00048     BodyRTC *m_robot;
00049 };
00050 
00051 //
00052 
00053 class BodyRTC : virtual public hrp::Body, public RTC::DataFlowComponentBase
00054 {
00055 public:
00056     BodyRTC(RTC::Manager* manager = &RTC::Manager::instance());
00057     virtual ~BodyRTC(void);
00058 
00059     RTC::ReturnCode_t setup();
00060 
00061     RTC::ReturnCode_t onActivated(RTC::UniqueId ec_id){
00062         std::cout << "BodyRTC::onActivated(" << ec_id << ")" << std::endl;
00063         return RTC::RTC_OK;
00064     }
00065     RTC::ReturnCode_t onDeactivated(RTC::UniqueId ec_id){
00066         std::cout << "BodyRTC::onDeactivated(" << ec_id << ")" << std::endl;
00067         return RTC::RTC_OK;
00068     }
00069 
00070     void createInPort(const std::string &config);
00071     void createOutPort(const std::string &config);
00072     void writeDataPorts(double time);
00073     void readDataPorts();
00074     static void moduleInit(RTC::Manager*);
00075 
00076     void getStatus(OpenHRP::RobotHardwareService::RobotState* rs);
00077     void getStatus2(OpenHRP::RobotHardwareService::RobotState2* rs);
00078 
00079     bool preOneStep();
00080     bool postOneStep();
00081     bool names2ids(const std::vector<std::string> &i_names, std::vector<int> &o_ids);
00082     std::vector<int> getJointGroup(const char* gname) {return  m_jointGroups[gname]; }
00083     int addJointGroup(const char* gname, const std::vector<int>jids) { m_jointGroups[gname] = jids; }
00084 
00085     // API to be compatible with robot.h
00086     bool power(int jid, bool turnon) {power_status[jid] = turnon?OpenHRP::RobotHardwareService::SWITCH_ON:OpenHRP::RobotHardwareService::SWITCH_OFF; }
00087     bool servo(const char *jname, bool turnon);
00088     bool servo(int jid, bool turnon) {servo_status[jid] = turnon?OpenHRP::RobotHardwareService::SWITCH_ON:OpenHRP::RobotHardwareService::SWITCH_OFF; }
00089     bool power(const char *jname, bool turnon);
00090 
00091     //void removeForceSensorOffset();
00092     //bool loadGain();
00093     //void startInertiaSensorCalibration();
00094     //void startForceSensorCalibration();
00095     //void initializeJointAngle(const char *name, const char *option);
00096     //void oneStep();
00097     int readCalibState(const int i) { return (calib_status[i] == OpenHRP::RobotHardwareService::SWITCH_ON); }
00098     int readPowerState(const int i) { return (power_status[i] == OpenHRP::RobotHardwareService::SWITCH_ON); }
00099     int readServoState(const int i) { return (servo_status[i] == OpenHRP::RobotHardwareService::SWITCH_ON); }
00100     //int readServoAlarm(int i);
00101     //int readDriverTemperature(int i);
00102     //void readPowerStatus(double &o_voltage, double &o_current);
00103     //void readJointAngles(double *o_angles);
00104     //void readJointVelocities(double *o_velocities);
00105     //int readJointTorques(double *o_torques);
00106     //void readGyroSensor(unsigned int i_rank, double *o_rates);
00107     //void readAccelerometer(unsigned int i_rank, double *o_accs);
00108     //void readForceSensor(unsigned int i_rank, double *o_forces);
00109     //void writeJointCommands(const double *i_commands);
00110     //void readJointCommands(double *o_commands);
00111     //void writeTorqueCommands(const double *i_commands);
00112     //void writeVelocityCommands(const double *i_commands);
00113     //size_t lengthOfExtraServoState(int id);
00114     //void readExtraServoState(int id, int *state);
00115     typedef enum {EMG_NONE, EMG_SERVO_ERROR, EMG_FZ} emg_reason;
00116     bool checkEmergency(emg_reason &o_reason, int &o_id);
00117     //bool setServoGainPercentage(const char *i_jname, double i_percentage);
00118     bool setServoErrorLimit(const char *i_jname, double i_limit);
00119     //void setProperty(const char *key, const char *value);
00120     //bool addJointGroup(const char *gname, const std::vector<std::string>& jnames);
00121     std::vector<double> m_servoErrorLimit;
00122     //double m_fzLimitRatio;
00123     //double m_maxZmpError;
00124 
00125     bool readDigitalInput(char *o_din);
00126     int lengthDigitalInput();
00127     bool writeDigitalOutput(const char *i_dout);
00128     bool writeDigitalOutputWithMask(const char *i_dout, const char *i_mask);
00129     int lengthDigitalOutput();
00130     bool readDigitalOutput(char *o_dout);
00131 
00132     bool resetPosition() { m_resetPosition = true; }
00133     //
00134     BodyRTC::emg_reason m_emergencyReason;
00135     int m_emergencyId;
00136 
00137 private:
00138     static const char* bodyrtc_spec[];
00139     // DataInPort
00140     std::vector<InPortHandlerBase *> m_inports;
00141 
00142     // DataOutPort
00143     std::vector<OutPortHandlerBase *> m_outports;
00144 
00145     // Corba Port
00146     RTC::CorbaPort m_RobotHardwareServicePort;
00147     RobotHardwareServicePort m_service0;
00148 
00149     // robot status
00150     std::vector<double> angles;
00151     std::vector<double> commands;
00152     std::vector<hrp::Vector3> accels;
00153     std::vector<hrp::Vector3> gyros;
00154     std::vector<hrp::dvector6> forces;
00155     std::vector<OpenHRP::RobotHardwareService::SwitchStatus> calib_status;
00156     std::vector<OpenHRP::RobotHardwareService::SwitchStatus> servo_status;
00157     std::vector<OpenHRP::RobotHardwareService::SwitchStatus> power_status;
00158     std::map<std::string, std::vector<int> > m_jointGroups;
00159 
00160     // pinned position for servo off
00161     bool m_resetPosition;
00162     hrp::Vector3  m_lastServoOn_p;
00163     hrp::Matrix33 m_lastServoOn_R;
00164 
00165     int dummy;
00166 };
00167 
00168 typedef boost::intrusive_ptr<BodyRTC> BodyRTCPtr;
00169 
00170 #endif


hrpsys
Author(s): AIST, Fumio Kanehiro
autogenerated on Wed Sep 6 2017 02:35:54