12 #include <hrpModel/ModelLoaderUtil.h> 24 "implementation_id",
"ThermoLimiter",
25 "type_name",
"ThermoLimiter",
26 "description",
"thermo limiter",
27 "version", HRPSYS_PACKAGE_VERSION,
29 "category",
"example",
30 "activity_type",
"DataFlowComponent",
33 "lang_type",
"compile",
35 "conf.default.debugLevel",
"0",
43 m_tempInIn(
"tempIn", m_tempIn),
44 m_tauMaxOutOut(
"tauMax", m_tauMaxOut),
45 m_beepCommandOutOut(
"beepCommand", m_beepCommandOut),
46 m_ThermoLimiterServicePort(
"ThermoLimiterService"),
58 std::cerr <<
"[" <<
m_profile.instance_name <<
"] : onInitialize()" << std::endl;
90 std::string nameServer = rtcManager.
getConfig()[
"corba.nameservers"];
91 int comPos = nameServer.find(
",");
93 comPos = nameServer.length();
95 nameServer = nameServer.substr(0, comPos);
98 CosNaming::NamingContext::_duplicate(
naming.getRootContext())
100 std::cerr <<
"[" <<
m_profile.instance_name <<
"] failed to load model[" << prop[
"model"] <<
"]" 106 if (motorTemperatureLimitFromConf.size() !=
m_robot->numJoints()) {
107 std::cerr <<
"[" <<
m_profile.instance_name <<
"] [WARN]: size of motor_temperature_limit is " << motorTemperatureLimitFromConf.size() <<
", not equal to " <<
m_robot->numJoints() << std::endl;
108 for (
unsigned int i = 0;
i <
m_robot->numJoints();
i++) {
112 for (
unsigned int i = 0;
i <
m_robot->numJoints();
i++) {
117 std::cerr <<
"motor_temperature_limit: ";
121 std::cerr << std::endl;
125 double ambientTemp = 25.0;
126 if (prop[
"ambient_tmp"] !=
"") {
129 std::cerr <<
"[" <<
m_profile.instance_name <<
"] : ambient temperature: " << ambientTemp << std::endl;
134 if (motorHeatParamsFromConf.size() != 2 *
m_robot->numJoints()) {
135 std::cerr <<
"[" <<
m_profile.instance_name <<
"] [WARN]: size of motor_heat_param is " << motorHeatParamsFromConf.size() <<
", not equal to 2 * " <<
m_robot->numJoints() << std::endl;
136 for (
unsigned int i = 0;
i <
m_robot->numJoints();
i++) {
142 for (
unsigned int i = 0;
i <
m_robot->numJoints();
i++) {
150 std::cerr <<
"motor_heat_param: ";
152 std::cerr << (*it).temperature <<
"," << (*it).currentCoeffs <<
"," << (*it).thermoCoeffs <<
", ";
154 std::cerr << std::endl;
155 std::cerr <<
"default torque limit from model:" << std::endl;
156 for (
unsigned int i = 0;
i <
m_robot->numJoints();
i++) {
163 if (prop[
"alarm_ratio"] !=
"") {
167 std::cerr <<
"alarmRatio: " <<
m_alarmRatio << std::endl;
201 std::cerr <<
"[" <<
m_profile.instance_name <<
"] : onActivated(" << ec_id <<
")" << std::endl;
207 std::cerr <<
"[" <<
m_profile.instance_name <<
"] : onDeactivated(" << ec_id <<
")" << std::endl;
217 std::cerr <<
"[" <<
m_profile.instance_name <<
"]" << std::endl;
222 tm.sec = coiltm.
sec();
223 tm.nsec = coiltm.
usec()*1000;
225 tauMax.resize(
m_robot->numJoints());
227 double thermoLimitRatio = 0.0;
228 std::string thermoLimitPrefix =
"ThermoLimit";
237 std::cerr <<
"temperature: ";
238 for (
unsigned int i = 0;
i <
m_tempIn.data.length();
i++) {
241 std::cerr << std::endl;
248 for (
unsigned int i = 0;
i <
m_robot->numJoints();
i++) {
254 std::cerr <<
"tauMax: ";
255 for (
int i = 0;
i < tauMax.size();
i++) {
256 std::cerr << tauMax[
i] <<
" ";
258 std::cerr << std::endl;
270 for (
unsigned int i = 0;
i <
m_robot->numJoints();
i++) {
317 unsigned int numJoints =
m_robot->numJoints();
318 double temp, tempLimit;
323 for (
unsigned int i = 0;
i < numJoints;
i++) {
332 if (squareTauMax[
i] < 0) {
334 std::cerr <<
"[WARN] tauMax ** 2 = " << squareTauMax[
i] <<
" < 0 in Joint " <<
i << std::endl;
338 tauMax[
i] = std::sqrt(squareTauMax[
i]);
347 double maxEmergencyRatio = 0.0;
348 if (current.data.length() == max.size()) {
349 for (
unsigned int i = 0;
i < current.data.length();
i++) {
350 double tmpEmergencyRatio = std::abs(current.data[
i] / max[
i]);
352 std::cerr << prefix <<
"[" <<
m_robot->joint(i)->name <<
"]" <<
" is over " << alarmRatio <<
" of the limit (" << current.data[i] <<
"/" << max[i] <<
")" << std::endl;
354 if (maxEmergencyRatio < tmpEmergencyRatio) {
355 maxEmergencyRatio = tmpEmergencyRatio;
359 return maxEmergencyRatio;
364 const int maxFreq = 3136;
365 const int minFreq = 2794;
368 const int emergency_beep_cycle = 200;
369 int current_emergency_beep_cycle =
m_loop % emergency_beep_cycle;
370 if (current_emergency_beep_cycle <= (emergency_beep_cycle / 2)) {
375 }
else if (ratio > alarmRatio) {
376 int freq = minFreq + (maxFreq - minFreq) * ((ratio - alarmRatio) / (1.0 - alarmRatio));
393 std::cerr <<
"[" <<
m_profile.instance_name <<
"] setThermoLimiterParam" << std::endl;
415 RTC::Create<ThermoLimiter>,
416 RTC::Delete<ThermoLimiter>);
ComponentProfile m_profile
png_infop png_charpp int png_charpp profile
bool isDebug(int cycle=200)
OutPort< TimedDoubleSeq > m_tauMaxOutOut
coil::Guard< coil::Mutex > Guard
bool getParameter(OpenHRP::ThermoLimiterService::tlParam &i_tlp)
virtual RTC::ReturnCode_t onInitialize()
unsigned int m_debug_print_freq
bool stringTo(To &val, const char *str)
virtual ~ThermoLimiter()
Destructor.
vstring split(const std::string &input, const std::string &delimiter, bool ignore_empty)
ThermoLimiter(RTC::Manager *manager)
Constructor.
TimedDoubleSeq m_tauMaxOut
coil::Properties & getProperties()
static Manager & instance()
bool addOutPort(const char *name, OutPortBase &outport)
void setDataPort(RTC::TimedLongSeq &out_data)
virtual RTC::ReturnCode_t onDeactivated(RTC::UniqueId ec_id)
boost::shared_ptr< Body > BodyPtr
std::vector< std::string > vstring
int gettimeofday(struct timeval *tv, struct timezone *tz)
coil::Properties & getConfig()
unsigned int m_debugLevel
OutPort< TimedLongSeq > m_beepCommandOutOut
void startBeep(const int _freq, const int _length=50)
hrp::dvector m_motorTemperatureLimit
ExecutionContextHandle_t UniqueId
std::vector< MotorHeatParam > m_motorHeatParams
bool bindParameter(const char *param_name, VarType &var, const char *def_val, bool(*trans)(VarType &, const char *)=coil::stringTo)
static const char * thermolimiter_spec[]
int loadBodyFromModelLoader(::World *world, const char *name, const char *url, CosNaming::NamingContext_var cxt)
virtual RTC::ReturnCode_t onActivated(RTC::UniqueId ec_id)
TimedLongSeq m_beepCommandOut
void thermolimiter(ThermoLimiter *i_thermolimiter)
virtual RTC::ReturnCode_t onExecute(RTC::UniqueId ec_id)
void callBeep(double ratio, double alarmRatio)
bool addPort(PortBase &port)
virtual bool write(DataType &value)
void ThermoLimiterInit(RTC::Manager *manager)
InPort< TimedDoubleSeq > m_tempInIn
int get_num_beep_info() const
ThermoLimiterService_impl m_ThermoLimiterService
bool addInPort(const char *name, InPortBase &inport)
bool setParameter(const OpenHRP::ThermoLimiterService::tlParam &i_tlp)
RTC::CorbaPort m_ThermoLimiterServicePort
bool registerFactory(coil::Properties &profile, RtcNewFunc new_func, RtcDeleteFunc delete_func)
void calcMaxTorqueFromTemperature(hrp::dvector &tauMax)
double calcEmergencyRatio(RTC::TimedDoubleSeq ¤t, hrp::dvector &max, double alarmRatio, std::string &prefix)
bool registerProvider(const char *instance_name, const char *type_name, PortableServer::RefCountServantBase &provider)