12 #include <coil/stringutil.h> 18 "implementation_id",
"PDcontroller",
19 "type_name",
"PDcontroller",
20 "description",
"PDcontroller component",
21 "version", HRPSYS_PACKAGE_VERSION,
23 "category",
"example",
24 "activity_type",
"DataFlowComponent",
27 "lang_type",
"compile",
29 "conf.default.pdgains_sim_file_name",
"",
30 "conf.default.debugLevel",
"0",
38 m_angleIn(
"angle", m_angle),
39 m_angleRefIn(
"angleRef", m_angleRef),
40 m_torqueOut(
"torque", m_torque),
56 std::cout <<
m_profile.instance_name <<
": onInitialize() " << std::endl;
68 std::string nameServer = rtcManager.
getConfig()[
"corba.nameservers"];
69 int comPos = nameServer.find(
",");
71 comPos = nameServer.length();
73 nameServer = nameServer.substr(0, comPos);
76 CosNaming::NamingContext::_duplicate(
naming.getRootContext())
78 std::cerr <<
"[" <<
m_profile.instance_name <<
"] failed to load model[" << prop[
"model"] <<
"]" 124 std::cout <<
m_profile.instance_name <<
": on Activated " << std::endl;
137 std::cout <<
m_profile.instance_name <<
": on Deactivated " << std::endl;
157 for(
size_t i=0;
i<
dof;
i++){
160 double dq = (q -
qold[
i]) /
dt;
170 if (
i == 0 &&
loop % 500 == 0) {
171 std::cerr <<
"[" <<
m_profile.instance_name <<
"] m_robot is not set properly!! Maybe ModelLoader is missing?" << std::endl;
175 std::cerr <<
"[" <<
m_profile.instance_name <<
"] joint = " 176 <<
i <<
", tq = " <<
m_torque.data[
i] <<
", q,qref = (" << q <<
", " << q_ref <<
"), dq,dqref = (" << dq <<
", " << dq_ref <<
"), pd = (" <<
Pgain[
i] <<
", " <<
Dgain[
i] <<
"), tlimit = " << tlimit << std::endl;
204 for (
unsigned int i=0;
i<
dof;
i++){
208 std::cerr <<
"[" <<
m_profile.instance_name <<
"] Gain file [" <<
gain_fname <<
"] is too short" << std::endl;
213 std::cerr <<
"[" <<
m_profile.instance_name <<
"] Gain file [" <<
gain_fname <<
"] is too short" << std::endl;
217 std::cerr <<
"[" <<
m_profile.instance_name <<
"] Gain file [" <<
gain_fname <<
"] opened" << std::endl;
219 std::cerr <<
"[" <<
m_profile.instance_name <<
"] Gain file [" <<
gain_fname <<
"] not opened" << std::endl;
224 if (prop[
"pdcontrol_tlimit_ratio"] !=
"") {
226 if (tlimit_ratio_str.size() ==
dof) {
227 for (
size_t i = 0;
i <
dof;
i++) {
230 std::cerr <<
"[" <<
m_profile.instance_name <<
"] tlimit_ratio is set to " << prop[
"pdcontrol_tlimit_ratio"] << std::endl;
232 for (
size_t i = 0;
i <
dof;
i++) {
235 std::cerr <<
"[" <<
m_profile.instance_name <<
"] pdcontrol_tlimit_ratio found, but invalid length (" << tlimit_ratio_str.size() <<
" != " << dof <<
")." << std::endl;
236 std::cerr <<
"[" <<
m_profile.instance_name <<
"] All tlimit_ratio are set to 1.0." << std::endl;
239 for (
size_t i = 0;
i <
dof;
i++) {
242 std::cerr <<
"[" <<
m_profile.instance_name <<
"] No pdcontrol_tlimit_ratio found." << std::endl;
243 std::cerr <<
"[" <<
m_profile.instance_name <<
"] All tlimit_ratio are set to 1.0." << std::endl;
247 for(
unsigned int i=0;
i <
dof; ++
i){
251 std::cerr <<
"[" <<
m_profile.instance_name <<
"] loadGain" << std::endl;
252 for (
unsigned int i=0;
i<
m_robot->numJoints();
i++) {
253 std::cerr <<
"[" <<
m_profile.instance_name <<
"] " <<
m_robot->joint(
i)->name <<
", pgain = " <<
Pgain[
i] <<
", dgain = " <<
Dgain[
i] << std::endl;
299 RTC::Create<PDcontroller>,
300 RTC::Delete<PDcontroller>);
ComponentProfile m_profile
png_infop png_charpp int png_charpp profile
OutPort< TimedDoubleSeq > m_torqueOut
bool stringTo(To &val, const char *str)
hrp::dvector tlimit_ratio
virtual RTC::ReturnCode_t onDeactivated(RTC::UniqueId ec_id)
InPort< TimedDoubleSeq > m_angleRefIn
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
std::vector< std::string > vstring
coil::Properties & getConfig()
InPort< TimedDoubleSeq > m_angleIn
ExecutionContextHandle_t UniqueId
PDcontroller(RTC::Manager *manager)
bool bindParameter(const char *param_name, VarType &var, const char *def_val, bool(*trans)(VarType &, const char *)=coil::stringTo)
static const char * PDcontroller_spec[]
void PDcontrollerInit(RTC::Manager *manager)
int loadBodyFromModelLoader(::World *world, const char *name, const char *url, CosNaming::NamingContext_var cxt)
virtual RTC::ReturnCode_t onActivated(RTC::UniqueId ec_id)
virtual bool write(DataType &value)
unsigned int m_debugLevel
virtual RTC::ReturnCode_t onInitialize()
bool addInPort(const char *name, InPortBase &inport)
virtual RTC::ReturnCode_t onExecute(RTC::UniqueId ec_id)
TimedDoubleSeq m_angleRef
bool registerFactory(coil::Properties &profile, RtcNewFunc new_func, RtcDeleteFunc delete_func)