Go to the documentation of this file.00001
00010 #include <math.h>
00011 #include <iomanip>
00012 #include <stdio.h>
00013 #include "AccelerationChecker.h"
00014
00015
00016
00017 static const char* spec[] =
00018 {
00019 "implementation_id", "AccelerationChecker",
00020 "type_name", "AccelerationChecker",
00021 "description", "Joint acceleration checker",
00022 "version", HRPSYS_PACKAGE_VERSION,
00023 "vendor", "AIST",
00024 "category", "example",
00025 "activity_type", "DataFlowComponent",
00026 "max_instance", "10",
00027 "language", "C++",
00028 "lang_type", "compile",
00029
00030 "conf.default.thd", "1000",
00031 "conf.default.print", "0",
00032
00033 ""
00034 };
00035
00036
00037 AccelerationChecker::AccelerationChecker(RTC::Manager* manager)
00038 : RTC::DataFlowComponentBase(manager),
00039
00040 m_qIn("qIn", m_q),
00041 m_qOut("qOut", m_q),
00042
00043 dummy(0)
00044 {
00045 }
00046
00047 AccelerationChecker::~AccelerationChecker()
00048 {
00049 }
00050
00051
00052
00053 RTC::ReturnCode_t AccelerationChecker::onInitialize()
00054 {
00055
00056
00057
00058 bindParameter("thd", m_thd, "1000");
00059 bindParameter("print", m_print, "0");
00060
00061
00062
00063
00064
00065
00066 addInPort("qIn", m_qIn);
00067
00068
00069 addOutPort("qOut", m_qOut);
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079 RTC::Properties& prop = getProperties();
00080 m_dt = 0;
00081 coil::stringTo(m_dt, prop["dt"].c_str());
00082 if (m_dt == 0){
00083 std::cerr << m_profile.instance_name << ": dt is not defined in the conf"
00084 << std::endl;
00085 return RTC::RTC_ERROR;
00086 }
00087
00088 return RTC::RTC_OK;
00089 }
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114 RTC::ReturnCode_t AccelerationChecker::onActivated(RTC::UniqueId ec_id)
00115 {
00116 std::cout << m_profile.instance_name<< ": onActivated(" << ec_id << ")" << std::endl;
00117 return RTC::RTC_OK;
00118 }
00119
00120 RTC::ReturnCode_t AccelerationChecker::onDeactivated(RTC::UniqueId ec_id)
00121 {
00122 std::cout << m_profile.instance_name<< ": onDeactivated(" << ec_id << ")" << std::endl;
00123 return RTC::RTC_OK;
00124 }
00125
00126 RTC::ReturnCode_t AccelerationChecker::onExecute(RTC::UniqueId ec_id)
00127 {
00128
00129
00130 if (m_qIn.isNew()){
00131 m_qIn.read();
00132 if (!m_dq.data.length()){
00133 m_qOld.data.length(m_q.data.length());
00134 m_qOld = m_q;
00135 m_dqOld.data.length(m_q.data.length());
00136 m_ddqMax.data.length(m_q.data.length());
00137 for (unsigned int i=0; i<m_dqOld.data.length(); i++){
00138 m_dqOld.data[i] = 0.0;
00139 m_ddqMax.data[i] = 0.0;
00140 }
00141 m_dq.data.length(m_q.data.length());
00142 }
00143 for (unsigned int i=0; i<m_q.data.length(); i++){
00144 m_dq.data[i] = (m_q.data[i] - m_qOld.data[i])/m_dt;
00145 double ddq = (m_dq.data[i] - m_dqOld.data[i])/m_dt;
00146 if (fabs(ddq) > m_ddqMax.data[i]) m_ddqMax.data[i] = fabs(ddq);
00147 if (fabs(ddq) > m_thd){
00148 std::cout << std::fixed << std::setprecision(3) << "["
00149 << (double)coil::gettimeofday()
00150 << "] Warning: too big joint acceleration for "
00151 << i << "th joint(" << ddq << "[rad/m^2])" << std::endl;
00152 }
00153 }
00154 m_qOld = m_q;
00155 m_dqOld = m_dq;
00156
00157 if (m_print){
00158 printf("jid: max acc[rad/m^2]\n");
00159 for (unsigned int i=0; i<m_ddqMax.data.length(); i++){
00160 printf("%2d: %8f\n", i, m_ddqMax.data[i]);
00161 }
00162 m_print = false;
00163 }
00164
00165 m_qOut.write();
00166 }
00167
00168 return RTC::RTC_OK;
00169 }
00170
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183
00184
00185
00186
00187
00188
00189
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205
00206
00207
00208 extern "C"
00209 {
00210
00211 void AccelerationCheckerInit(RTC::Manager* manager)
00212 {
00213 RTC::Properties profile(spec);
00214 manager->registerFactory(profile,
00215 RTC::Create<AccelerationChecker>,
00216 RTC::Delete<AccelerationChecker>);
00217 }
00218
00219 };
00220
00221