Go to the documentation of this file.00001 #ifndef __ROBOT_H__
00002 #define __ROBOT_H__
00003
00004 #include <boost/array.hpp>
00005 #include <semaphore.h>
00006 #include <hrpModel/Body.h>
00007 #include "hrpsys/io/iob.h"
00008
00012 class robot : public hrp::Body
00013 {
00014 public:
00019 robot(double dt);
00020
00024 ~robot();
00025
00029 bool init();
00030
00036 bool servo(int jid, bool turnon);
00037
00043 bool servo(const char *jname, bool turnon);
00044
00050 bool power(int jid, bool turnon);
00051
00057 bool power(const char *jname, bool turnon);
00058
00062 void removeForceSensorOffset();
00063
00069 bool loadGain();
00070
00074 void startInertiaSensorCalibration();
00075
00079 void startForceSensorCalibration();
00080
00086 void initializeJointAngle(const char *name, const char *option);
00087
00091 void oneStep();
00092
00098 int readCalibState(int i);
00099
00105 int readPowerState(int i);
00106
00112 int readServoState(int i);
00113
00119 int readServoAlarm(int i);
00120
00126 int readDriverTemperature(int i);
00127
00134 void readPowerStatus(double &o_voltage, double &o_current);
00135
00143 void readBatteryState(unsigned int i_rank, double &o_voltage,
00144 double &o_current, double &o_soc);
00145
00151 void readThermometer(unsigned int i_rank, double &o_temp);
00152
00157 void readJointAngles(double *o_angles);
00158
00163 void readJointVelocities(double *o_velocities);
00164
00170 int readJointTorques(double *o_torques);
00171
00177 int readJointCommandTorques(double *o_torques);
00178
00184 void readGyroSensor(unsigned int i_rank, double *o_rates);
00185
00191 void readAccelerometer(unsigned int i_rank, double *o_accs);
00192
00198 void readForceSensor(unsigned int i_rank, double *o_forces);
00199
00204 void writeJointCommands(const double *i_commands);
00205
00210 void readJointCommands(double *o_commands);
00211
00216 void writeTorqueCommands(const double *i_commands);
00217
00222 void writeVelocityCommands(const double *i_commands);
00223
00228 void writeAccelerationCommands(const double *i_commands);
00229
00235 int readPDControllerTorques(double *o_torques);
00236
00242 size_t lengthOfExtraServoState(int id);
00243
00249 void readExtraServoState(int id, int *state);
00250
00254 typedef enum {EMG_SERVO_ERROR, EMG_FZ, EMG_SERVO_ALARM, EMG_POWER_OFF} emg_reason;
00255
00262 bool checkEmergency(emg_reason &o_reason, int &o_id);
00263
00264
00269 bool checkJointCommands(const double *i_commands);
00270
00277 bool setServoGainPercentage(const char *i_jname, double i_percentage);
00278
00285 bool setServoTorqueGainPercentage(const char *i_jname, double i_percentage);
00286
00293 bool setServoErrorLimit(const char *i_jname, double i_limit);
00294
00301 bool setJointInertia(const char *i_jname, double i_mn);
00302
00307 void setJointInertias(const double *i_mn);
00308
00312 void enableDisturbanceObserver();
00313
00317 void disableDisturbanceObserver();
00318
00323 void setDisturbanceObserverGain(double gain);
00324
00325 void setProperty(const char *key, const char *value);
00326 bool addJointGroup(const char *gname, const std::vector<std::string>& jnames);
00327 std::vector<double> m_servoErrorLimit;
00328 double m_fzLimitRatio;
00329 double m_maxZmpError;
00330 double m_accLimit;
00331 double m_servoOnDelay;
00332
00333 bool readDigitalInput(char *o_din);
00334 int lengthDigitalInput();
00335 bool writeDigitalOutput(const char *i_dout);
00336 bool writeDigitalOutputWithMask(const char *i_dout, const char *i_mask);
00337 int lengthDigitalOutput();
00338 bool readDigitalOutput(char *o_dout);
00339
00344 int numBatteries();
00345
00350 int numThermometers();
00351
00358 bool setJointControlMode(const char *i_jname, joint_control_mode mode);
00359 private:
00363 void calibrateInertiaSensorOneStep();
00364
00368 void calibrateForceSensorOneStep();
00369
00374 bool isBusy() const;
00375
00376 bool names2ids(const std::vector<std::string> &i_names,
00377 std::vector<int> &o_ids);
00378
00379 void gain_control();
00380 void gain_control(int id);
00381
00382 int inertia_calib_counter, force_calib_counter;
00383 std::vector<double> gain_counter;
00384
00385 std::vector< boost::array<double,3> > gyro_sum;
00386 std::vector< boost::array<double,3> > accel_sum;
00387 std::vector< boost::array<double,3> > att_sum;
00388 std::vector< boost::array<double,6> > force_sum;
00389
00390 std::vector<double> pgain, old_pgain, default_pgain;
00391 std::vector<double> dgain, old_dgain, default_dgain;
00392 std::vector<double> tqpgain, old_tqpgain, default_tqpgain;
00393 std::vector<double> tqdgain, old_tqdgain, default_tqdgain;
00394
00395 int m_lLegForceSensorId, m_rLegForceSensorId;
00396 std::map<std::string, std::vector<int> > m_jointGroups;
00397 bool m_calibRequested;
00398 std::string m_calibJointName, m_calibOptions;
00399 std::string m_pdgainsFilename;
00400 bool m_reportedEmergency;
00401 sem_t wait_sem;
00402 double m_dt;
00403 std::vector<double> m_commandOld, m_velocityOld;
00404 hrp::Vector3 G;
00405 bool m_enable_poweroff_check;
00406 };
00407
00408 #endif