16 #include "hrpsys/idl/RobotHardwareService.hh" 18 #include <hrpModel/ModelLoaderUtil.h> 25 "implementation_id",
"ThermoEstimator",
26 "type_name",
"ThermoEstimator",
27 "description",
"null component",
28 "version", HRPSYS_PACKAGE_VERSION,
30 "category",
"example",
31 "activity_type",
"DataFlowComponent",
34 "lang_type",
"compile",
36 "conf.default.debugLevel",
"0",
45 m_tauInIn(
"tauIn", m_tauIn),
46 m_qRefInIn(
"qRefIn", m_qRefIn),
47 m_qCurrentInIn(
"qCurrentIn", m_qCurrentIn),
48 m_servoStateInIn(
"servoStateIn", m_servoStateIn),
49 m_tempOutOut(
"tempOut", m_tempOut),
50 m_servoStateOutOut(
"servoStateOut", m_servoStateOut),
62 std::cerr <<
"[" <<
m_profile.instance_name <<
"] : onInitialize()" << std::endl;
96 std::string nameServer = rtcManager.
getConfig()[
"corba.nameservers"];
97 int comPos = nameServer.find(
",");
99 comPos = nameServer.length();
101 nameServer = nameServer.substr(0, comPos);
104 CosNaming::NamingContext::_duplicate(
naming.getRootContext())
106 std::cerr <<
"[" <<
m_profile.instance_name <<
"] failed to load model[" << prop[
"model"] <<
"]" 116 if (prop[
"ambient_tmp"] !=
"") {
126 if (motorHeatParamsFromConf.size() != 2 *
m_robot->numJoints()) {
127 std::cerr <<
"[" <<
m_profile.instance_name <<
"] [WARN]: size of motorHeatParams is " << motorHeatParamsFromConf.size() <<
", not equal to 2 * " <<
m_robot->numJoints() << std::endl;
130 for (
unsigned int i = 0;
i <
m_robot->numJoints();
i++) {
136 std::cerr <<
"motorHeatParams is " << std::endl;
137 for (
unsigned int i = 0;
i <
m_robot->numJoints();
i++) {
145 if (error2tauFromConf.size() !=
m_robot->numJoints()) {
146 std::cerr <<
"[" <<
m_profile.instance_name <<
"] [WARN]: size of error2tau is " << error2tauFromConf.size() <<
", not equal to " <<
m_robot->numJoints() << std::endl;
150 for (
unsigned int i = 0;
i <
m_robot->numJoints();
i++) {
154 std::cerr <<
"motorHeatParams:" << std::endl;
155 for (
unsigned int i = 0;
i <
m_robot->numJoints();
i++) {
158 std::cerr << std::endl;
190 std::cerr <<
"[" <<
m_profile.instance_name <<
"] : onActivated(" << ec_id <<
")" << std::endl;
196 std::cerr <<
"[" <<
m_profile.instance_name <<
"] : onDeactivated(" << ec_id <<
")" << std::endl;
203 unsigned int numJoints =
m_robot->numJoints();
208 tm.sec = coiltm.
sec();
209 tm.nsec = coiltm.
usec()*1000;
226 if (
m_tauIn.data.length() == numJoints) {
227 jointTorque.resize(numJoints);
228 for (
unsigned int i = 0;
i < numJoints;
i++) {
232 std::cerr <<
"raw torque: ";
233 for (
unsigned int i = 0;
i < numJoints;
i++) {
234 std::cerr <<
" " <<
m_tauIn.data[
i] ;
236 std::cerr << std::endl;
238 }
else if (
m_qRefIn.data.length() == numJoints
240 jointTorque.resize(numJoints);
242 for (
unsigned int i = 0;
i < numJoints;
i++) {
247 std::cerr <<
"qRef: ";
248 for (
unsigned int i = 0;
i < numJoints;
i++) {
251 std::cerr << std::endl;
252 std::cerr <<
"qCurrent: ";
253 for (
unsigned int i = 0;
i < numJoints;
i++) {
256 std::cerr << std::endl;
259 jointTorque.resize(0);
263 if (jointTorque.size() ==
m_robot->numJoints()) {
264 for (
unsigned int i = 0;
i < numJoints;
i++) {
271 std::cerr << std::endl <<
"temperature : ";
272 for (
unsigned int i = 0;
i < numJoints;
i++) {
275 std::cerr << std::endl;
281 if (jointTorque.size() ==
m_robot->numJoints()
286 for (
unsigned int j = 0;
j < len;
j++) {
291 std::memcpy(&(
m_servoStateOut.data[
i][len]), &tmp_temperature,
sizeof(
float));
341 if (error.size() ==
m_robot->numJoints()
343 tau.resize(
m_robot->numJoints());
344 for (
unsigned int i = 0;
i <
m_robot->numJoints();
i++) {
348 std::cerr <<
"estimated torque: ";
349 for (
unsigned int i = 0;
i <
m_robot->numJoints();
i++) {
350 std::cerr <<
" " << tau[
i] ;
352 std::cerr << std::endl;
357 std::cerr <<
"Invalid size of values:" << std::endl;
358 std::cerr <<
"num joints: " <<
m_robot->numJoints() << std::endl;
359 std::cerr <<
"joint error: " << error.size() << std::endl;
360 std::cerr <<
"error2tau: " <<
m_error2tau.size() << std::endl;
371 double currentHeat, radiation;
390 RTC::Create<ThermoEstimator>,
391 RTC::Delete<ThermoEstimator>);
ComponentProfile m_profile
png_infop png_charpp int png_charpp profile
virtual RTC::ReturnCode_t onInitialize()
bool stringTo(To &val, const char *str)
virtual ~ThermoEstimator()
Destructor.
void calculateJointTemperature(double tau, MotorHeatParam ¶m)
bool isDebug(int cycle=200)
vstring split(const std::string &input, const std::string &delimiter, bool ignore_empty)
coil::Properties & getProperties()
static Manager & instance()
bool addOutPort(const char *name, OutPortBase &outport)
boost::shared_ptr< Body > BodyPtr
unsigned int m_debugLevel
void estimateJointTorqueFromJointError(hrp::dvector &error, hrp::dvector &tau)
std::vector< std::string > vstring
int gettimeofday(struct timeval *tv, struct timezone *tz)
coil::Properties & getConfig()
virtual RTC::ReturnCode_t onExecute(RTC::UniqueId ec_id)
InPort< OpenHRP::TimedLongSeqSeq > m_servoStateInIn
ExecutionContextHandle_t UniqueId
OpenHRP::TimedLongSeqSeq m_servoStateIn
bool bindParameter(const char *param_name, VarType &var, const char *def_val, bool(*trans)(VarType &, const char *)=coil::stringTo)
def j(str, encoding="cp932")
std::vector< MotorHeatParam > m_motorHeatParams
InPort< TimedDoubleSeq > m_qCurrentInIn
TimedDoubleSeq m_qCurrentIn
int loadBodyFromModelLoader(::World *world, const char *name, const char *url, CosNaming::NamingContext_var cxt)
void ThermoEstimatorInit(RTC::Manager *manager)
InPort< TimedDoubleSeq > m_qRefInIn
OutPort< OpenHRP::TimedLongSeqSeq > m_servoStateOutOut
InPort< TimedDoubleSeq > m_tauInIn
virtual bool write(DataType &value)
OpenHRP::TimedLongSeqSeq m_servoStateOut
static const char * thermoestimator_spec[]
virtual RTC::ReturnCode_t onActivated(RTC::UniqueId ec_id)
virtual RTC::ReturnCode_t onDeactivated(RTC::UniqueId ec_id)
bool addInPort(const char *name, InPortBase &inport)
ThermoEstimator(RTC::Manager *manager)
Constructor.
bool registerFactory(coil::Properties &profile, RtcNewFunc new_func, RtcDeleteFunc delete_func)
OutPort< TimedDoubleSeq > m_tempOutOut