Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added emergency nortification for temperature and torque to ThermoLimiter #229

Merged
merged 15 commits into from
Oct 10, 2014
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Added isDebug method which is alternative of DEBUGP
  • Loading branch information
orikuma committed May 21, 2014
commit 29d21757c6456890f9a2f37596ce9664dd5cf83c
25 changes: 14 additions & 11 deletions rtc/ThermoLimiter/ThermoLimiter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
#include <hrpUtil/MatrixSolvers.h>
#include <cmath>

#define DEBUGP ((m_debugLevel==1 && loop%200==0) || m_debugLevel > 1 )
#define DQ_MAX 1.0

// Module specification
Expand Down Expand Up @@ -193,10 +192,9 @@ RTC::ReturnCode_t ThermoLimiter::onDeactivated(RTC::UniqueId ec_id)
RTC::ReturnCode_t ThermoLimiter::onExecute(RTC::UniqueId ec_id)
{
// std::cout << m_profile.instance_name<< ": onExecute(" << ec_id << "), data = " << m_data.data << std::endl;
static long long loop = 0;
loop ++;
m_loop++;

if (DEBUGP) {
if (isDebug()) {
std::cerr << "[" << m_profile.instance_name << "]" << std::endl;
}

Expand Down Expand Up @@ -224,7 +222,7 @@ RTC::ReturnCode_t ThermoLimiter::onExecute(RTC::UniqueId ec_id)
m_qCurrentInIn.read();
}

if (DEBUGP) {
if (isDebug()) {
std::cerr << "temperature: ";
for (int i = 0; i < m_tempIn.data.length(); i++) {
std::cerr << " " << m_tempIn.data[i];
Expand All @@ -247,7 +245,7 @@ RTC::ReturnCode_t ThermoLimiter::onExecute(RTC::UniqueId ec_id)
}
}

if (DEBUGP) {
if (isDebug()) {
std::cerr << "tauMax: ";
for (int i = 0; i < tauMax.size(); i++) {
std::cerr << tauMax[i] << " ";
Expand All @@ -263,8 +261,8 @@ RTC::ReturnCode_t ThermoLimiter::onExecute(RTC::UniqueId ec_id)
torqueLimitRatio = calcEmergencyRatio(m_tauIn, tauMax, alarmRatio, torqueLimitPrefix);
}

// call beep
callBeep(3136, std::max(thermoLimitRatio, torqueLimitRatio), alarmRatio);
// call beep (3136/0.8=3920)
callBeep(3920, std::max(thermoLimitRatio, torqueLimitRatio), alarmRatio);

// output restricted tauMax
for (int i = 0; i < m_robot->numJoints(); i++) {
Expand Down Expand Up @@ -316,8 +314,8 @@ void ThermoLimiter::calcMaxTorqueFromTemperature(hrp::dvector &tauMax)
double temp, tempLimit;
hrp::dvector squareTauMax(numJoints);

if ( m_tempIn.data.length() == m_robot->numJoints()
&& m_tauIn.data.length() == m_robot->numJoints() ) {
if (m_tempIn.data.length() == m_robot->numJoints()
&& m_tauIn.data.length() == m_robot->numJoints()) {

for (int i = 0; i < numJoints; i++) {
temp = m_tempIn.data[i];
Expand Down Expand Up @@ -346,7 +344,7 @@ double ThermoLimiter::calcEmergencyRatio(RTC::TimedDoubleSeq &current, hrp::dvec
for (int i = 0; i < current.data.length(); i++) {
double tmpEmergencyRatio = std::abs(current.data[i] / max[i]);
if (tmpEmergencyRatio > alarmRatio) {
std::cerr << prefix << "[" << i << "]" << " is over " << alarmRatio << "of the limit.";
std::cerr << prefix << "[" << m_robot->joint(i)->name << "]" << " is over " << alarmRatio << " of the limit.";
if (m_debugLevel > 0) {
std::cerr << ": " << current.data[i] << ">" << max[i];
}
Expand All @@ -371,6 +369,11 @@ void ThermoLimiter::callBeep(int maxFreq, double ratio, double alarmRatio)
return;
}

bool ThermoLimiter::isDebug(int cycle)
{
return ((m_debugLevel==1 && m_loop%cycle==0) || m_debugLevel > 1);
}

extern "C"
{

Expand Down
2 changes: 2 additions & 0 deletions rtc/ThermoLimiter/ThermoLimiter.h
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ class ThermoLimiter

private:
double m_dt;
long long m_loop;
unsigned int m_debugLevel;
hrp::dvector m_motorTemperatureLimit;
hrp::BodyPtr m_robot;
Expand All @@ -153,6 +154,7 @@ class ThermoLimiter
void calcMaxTorqueFromTemperature(hrp::dvector &tauMax);
double calcEmergencyRatio(RTC::TimedDoubleSeq &current, hrp::dvector &max, double alarmRatio, std::string &prefix);
void callBeep(int maxFreq, double ratio, double alarmRatio);
bool isDebug(int cycle = 200);
};


Expand Down