BodyRTC.h
Go to the documentation of this file.
1 #ifndef BODY_EXT_H_INCLUDED
2 #define BODY_EXT_H_INCLUDED
3 
4 #include <rtm/idl/BasicDataType.hh>
5 #include <rtm/idl/ExtendedDataTypes.hh>
6 #include "hrpsys/idl/Img.hh"
7 #include "hrpsys/idl/RobotHardwareService.hh"
8 #include <hrpModel/Body.h>
9 #include <hrpCorba/OpenHRPCommon.hh>
10 #include <rtm/Manager.h>
11 #include <rtm/DataFlowComponentBase.h>
12 #include <rtm/CorbaPort.h>
13 #include <rtm/DataInPort.h>
14 #include <rtm/DataOutPort.h>
15 #include <rtm/idl/BasicDataTypeSkel.h>
16 #include <rtm/idl/ExtendedDataTypesSkel.h>
17 
18 class InPortHandlerBase;
19 class OutPortHandlerBase;
21 class BodyRTC;
22 
24  : public virtual POA_OpenHRP::RobotHardwareService,
25  public virtual PortableServer::RefCountServantBase
26 {
27 public:
30  void getStatus(OpenHRP::RobotHardwareService::RobotState_out rs);
31  void getStatus2(OpenHRP::RobotHardwareService::RobotState2_out rs);
32  CORBA::Boolean power(const char* jname, OpenHRP::RobotHardwareService::SwitchStatus ss);
33  CORBA::Boolean servo(const char* jname, OpenHRP::RobotHardwareService::SwitchStatus ss);
34  void setServoGainPercentage(const char *jname, double limit);
35  void setServoTorqueGainPercentage(const char *jname, double limit);
36  void setServoErrorLimit(const char *jname, double limit);
37  void setJointControlMode(const char *jname, OpenHRP::RobotHardwareService::JointControlMode jcm);
40  void initializeJointAngle(const char* name, const char* option);
41  CORBA::Boolean addJointGroup(const char* gname, const OpenHRP::RobotHardwareService::StrSequence& jnames);
42  CORBA::Boolean readDigitalInput(::OpenHRP::RobotHardwareService::OctSequence_out din);
43  CORBA::Long lengthDigitalInput();
44  CORBA::Boolean writeDigitalOutput(const ::OpenHRP::RobotHardwareService::OctSequence& dout);
45  CORBA::Boolean writeDigitalOutputWithMask(const ::OpenHRP::RobotHardwareService::OctSequence& dout, const ::OpenHRP::RobotHardwareService::OctSequence& mask);
46  CORBA::Long lengthDigitalOutput();
47  CORBA::Boolean readDigitalOutput(::OpenHRP::RobotHardwareService::OctSequence_out dout);
48  CORBA::Boolean setJointInertia(const char* name, ::CORBA::Double mn);
49  void setJointInertias(const ::OpenHRP::RobotHardwareService::DblSequence& mns);
52  void setDisturbanceObserverGain(::CORBA::Double gain);
53  void setRobot(BodyRTC *i_robot);
54 private:
56 };
57 
58 //
59 
60 class BodyRTC : virtual public hrp::Body, public RTC::DataFlowComponentBase
61 {
62 public:
64  virtual ~BodyRTC(void);
65 
66  RTC::ReturnCode_t setup();
67 
68  RTC::ReturnCode_t onActivated(RTC::UniqueId ec_id){
69  std::cout << "BodyRTC::onActivated(" << ec_id << ")" << std::endl;
70  return RTC::RTC_OK;
71  }
72  RTC::ReturnCode_t onDeactivated(RTC::UniqueId ec_id){
73  std::cout << "BodyRTC::onDeactivated(" << ec_id << ")" << std::endl;
74  return RTC::RTC_OK;
75  }
76 
77  void createInPort(const std::string &config);
78  void createOutPort(const std::string &config);
79  void writeDataPorts(double time);
80  void readDataPorts();
81  static void moduleInit(RTC::Manager*);
82 
83  void getStatus(OpenHRP::RobotHardwareService::RobotState* rs);
84  void getStatus2(OpenHRP::RobotHardwareService::RobotState2* rs);
85 
86  bool preOneStep();
87  bool postOneStep();
88  bool names2ids(const std::vector<std::string> &i_names, std::vector<int> &o_ids);
89  std::vector<int> getJointGroup(const char* gname) {return m_jointGroups[gname]; }
90  int addJointGroup(const char* gname, const std::vector<int>jids) { m_jointGroups[gname] = jids; return 0;}
91 
92  // API to be compatible with robot.h
93  bool power(int jid, bool turnon) {power_status[jid] = turnon?OpenHRP::RobotHardwareService::SWITCH_ON:OpenHRP::RobotHardwareService::SWITCH_OFF; return true; }
94  bool servo(const char *jname, bool turnon);
95  bool servo(int jid, bool turnon) {servo_status[jid] = turnon?OpenHRP::RobotHardwareService::SWITCH_ON:OpenHRP::RobotHardwareService::SWITCH_OFF; return true; }
96  bool power(const char *jname, bool turnon);
97 
98  //void removeForceSensorOffset();
99  //bool loadGain();
100  //void startInertiaSensorCalibration();
101  //void startForceSensorCalibration();
102  //void initializeJointAngle(const char *name, const char *option);
103  //void oneStep();
104  int readCalibState(const int i) { return (calib_status[i] == OpenHRP::RobotHardwareService::SWITCH_ON); }
105  int readPowerState(const int i) { return (power_status[i] == OpenHRP::RobotHardwareService::SWITCH_ON); }
106  int readServoState(const int i) { return (servo_status[i] == OpenHRP::RobotHardwareService::SWITCH_ON); }
107  //int readServoAlarm(int i);
108  //int readDriverTemperature(int i);
109  //void readPowerStatus(double &o_voltage, double &o_current);
110  //void readJointAngles(double *o_angles);
111  //void readJointVelocities(double *o_velocities);
112  //int readJointTorques(double *o_torques);
113  //void readGyroSensor(unsigned int i_rank, double *o_rates);
114  //void readAccelerometer(unsigned int i_rank, double *o_accs);
115  //void readForceSensor(unsigned int i_rank, double *o_forces);
116  //void writeJointCommands(const double *i_commands);
117  //void readJointCommands(double *o_commands);
118  //void writeTorqueCommands(const double *i_commands);
119  //void writeVelocityCommands(const double *i_commands);
120  //size_t lengthOfExtraServoState(int id);
121  //void readExtraServoState(int id, int *state);
122  typedef enum {EMG_NONE, EMG_SERVO_ERROR, EMG_FZ} emg_reason;
123  bool checkEmergency(emg_reason &o_reason, int &o_id);
124  //bool setServoGainPercentage(const char *i_jname, double i_percentage);
125  bool setServoErrorLimit(const char *i_jname, double i_limit);
126  //void setProperty(const char *key, const char *value);
127  //bool addJointGroup(const char *gname, const std::vector<std::string>& jnames);
128  std::vector<double> m_servoErrorLimit;
129  //double m_fzLimitRatio;
130  //double m_maxZmpError;
131 
132  bool readDigitalInput(char *o_din);
133  int lengthDigitalInput();
134  bool writeDigitalOutput(const char *i_dout);
135  bool writeDigitalOutputWithMask(const char *i_dout, const char *i_mask);
136  int lengthDigitalOutput();
137  bool readDigitalOutput(char *o_dout);
138 
139  bool resetPosition() { m_resetPosition = true; return true; }
140  //
143 
144 private:
145  static const char* bodyrtc_spec[];
146  // DataInPort
147  std::vector<InPortHandlerBase *> m_inports;
148 
149  // DataOutPort
150  std::vector<OutPortHandlerBase *> m_outports;
151 
152  // Corba Port
155 
156  // robot status
157  std::vector<double> angles;
158  std::vector<double> commands;
159  std::vector<hrp::Vector3> accels;
160  std::vector<hrp::Vector3> gyros;
161  std::vector<hrp::dvector6> forces;
162  std::vector<OpenHRP::RobotHardwareService::SwitchStatus> calib_status;
163  std::vector<OpenHRP::RobotHardwareService::SwitchStatus> servo_status;
164  std::vector<OpenHRP::RobotHardwareService::SwitchStatus> power_status;
165  std::map<std::string, std::vector<int> > m_jointGroups;
166 
167  // pinned position for servo off
171 
172  int dummy;
173 };
174 
175 typedef boost::intrusive_ptr<BodyRTC> BodyRTCPtr;
176 
177 #endif
std::vector< OpenHRP::RobotHardwareService::SwitchStatus > servo_status
Definition: BodyRTC.h:163
hrp::Vector3 m_lastServoOn_p
Definition: BodyRTC.h:169
void setJointControlMode(const char *jname, OpenHRP::RobotHardwareService::JointControlMode jcm)
Definition: BodyRTC.cpp:672
std::vector< hrp::dvector6 > forces
Definition: BodyRTC.h:161
BodyRTC::emg_reason m_emergencyReason
Definition: BodyRTC.h:141
emg_reason
Definition: BodyRTC.h:122
void setServoErrorLimit(const char *jname, double limit)
Definition: BodyRTC.cpp:669
void setServoTorqueGainPercentage(const char *jname, double limit)
Definition: BodyRTC.cpp:667
std::vector< OpenHRP::RobotHardwareService::SwitchStatus > calib_status
Definition: BodyRTC.h:162
void setDisturbanceObserverGain(::CORBA::Double gain)
Definition: BodyRTC.cpp:722
CORBA::Long lengthDigitalInput()
Definition: BodyRTC.cpp:696
RobotHardwareServicePort m_service0
Definition: BodyRTC.h:154
void setJointInertias(const ::OpenHRP::RobotHardwareService::DblSequence &mns)
Definition: BodyRTC.cpp:717
std::vector< int > getJointGroup(const char *gname)
Definition: BodyRTC.h:89
hrp::Matrix33 m_lastServoOn_R
Definition: BodyRTC.h:170
int m_emergencyId
Definition: BodyRTC.h:142
bool power(int jid, bool turnon)
Definition: BodyRTC.h:93
boost::intrusive_ptr< BodyRTC > BodyRTCPtr
Definition: BodyRTC.h:175
png_infop png_charpp name
std::vector< InPortHandlerBase * > m_inports
Definition: BodyRTC.h:147
RTC::ReturnCode_t onDeactivated(RTC::UniqueId ec_id)
Definition: BodyRTC.h:72
RTC::CorbaPort m_RobotHardwareServicePort
Definition: BodyRTC.h:153
std::vector< hrp::Vector3 > gyros
Definition: BodyRTC.h:160
int readPowerState(const int i)
Definition: BodyRTC.h:105
manager
CORBA::Boolean readDigitalInput(::OpenHRP::RobotHardwareService::OctSequence_out din)
Definition: BodyRTC.cpp:693
std::vector< double > commands
Definition: BodyRTC.h:158
JCOPY_OPTION option
static Manager & instance()
bool servo(int jid, bool turnon)
Definition: BodyRTC.h:95
void setRobot(BodyRTC *i_robot)
Definition: BodyRTC.cpp:724
void setServoGainPercentage(const char *jname, double limit)
Definition: BodyRTC.cpp:665
int readServoState(const int i)
Definition: BodyRTC.h:106
std::map< std::string, std::vector< int > > m_jointGroups
Definition: BodyRTC.h:165
int addJointGroup(const char *gname, const std::vector< int >jids)
Definition: BodyRTC.h:90
Eigen::Vector3d Vector3
CORBA::Boolean addJointGroup(const char *gname, const OpenHRP::RobotHardwareService::StrSequence &jnames)
Definition: BodyRTC.cpp:680
Eigen::Matrix3d Matrix33
CORBA::Long lengthDigitalOutput()
Definition: BodyRTC.cpp:705
bool m_resetPosition
Definition: BodyRTC.h:168
CORBA::Boolean writeDigitalOutput(const ::OpenHRP::RobotHardwareService::OctSequence &dout)
Definition: BodyRTC.cpp:699
CORBA::Boolean readDigitalOutput(::OpenHRP::RobotHardwareService::OctSequence_out dout)
Definition: BodyRTC.cpp:708
ExecutionContextHandle_t UniqueId
png_infop int png_uint_32 mask
void enableDisturbanceObserver()
Definition: BodyRTC.cpp:720
CORBA::Boolean writeDigitalOutputWithMask(const ::OpenHRP::RobotHardwareService::OctSequence &dout, const ::OpenHRP::RobotHardwareService::OctSequence &mask)
Definition: BodyRTC.cpp:702
bool resetPosition()
Definition: BodyRTC.h:139
int dummy
Definition: BodyRTC.h:172
std::vector< OutPortHandlerBase * > m_outports
Definition: BodyRTC.h:150
void getStatus2(OpenHRP::RobotHardwareService::RobotState2_out rs)
Definition: BodyRTC.cpp:653
CORBA::Boolean servo(const char *jname, OpenHRP::RobotHardwareService::SwitchStatus ss)
Definition: BodyRTC.cpp:662
CORBA::Boolean power(const char *jname, OpenHRP::RobotHardwareService::SwitchStatus ss)
Definition: BodyRTC.cpp:658
std::vector< double > m_servoErrorLimit
Definition: BodyRTC.h:128
void initializeJointAngle(const char *name, const char *option)
Definition: BodyRTC.cpp:678
void disableDisturbanceObserver()
Definition: BodyRTC.cpp:721
std::vector< hrp::Vector3 > accels
Definition: BodyRTC.h:159
void getStatus(OpenHRP::RobotHardwareService::RobotState_out rs)
Definition: BodyRTC.cpp:648
std::vector< double > angles
Definition: BodyRTC.h:157
std::vector< OpenHRP::RobotHardwareService::SwitchStatus > power_status
Definition: BodyRTC.h:164
CORBA::Boolean setJointInertia(const char *name,::CORBA::Double mn)
Definition: BodyRTC.cpp:712
RTC::ReturnCode_t onActivated(RTC::UniqueId ec_id)
Definition: BodyRTC.h:68
int readCalibState(const int i)
Definition: BodyRTC.h:104


hrpsys
Author(s): AIST, Fumio Kanehiro
autogenerated on Thu May 6 2021 02:41:49