11 #include "hrpsys/util/VectorConvert.h" 13 #include <hrpModel/ModelLoaderUtil.h> 14 #include "hrpsys/idl/RobotHardwareService.hh" 19 #define deg2rad(x)((x)*M_PI/180) 20 #define min(a,b) ((a)<(b)?(a):(b)) 21 #define max(a,b) ((a)>(b)?(a):(b)) 27 "implementation_id",
"GraspController",
28 "type_name",
"GraspController",
29 "description",
"soft error limiter",
30 "version", HRPSYS_PACKAGE_VERSION,
32 "category",
"example",
33 "activity_type",
"DataFlowComponent",
36 "lang_type",
"compile",
38 "conf.default.debugLevel",
"0",
46 m_qRefIn(
"qRef", m_qRef),
47 m_qCurrentIn(
"qCurrent", m_qCurrent),
50 m_GraspControllerServicePort(
"GraspControllerService"),
66 std::cout <<
"[" <<
m_profile.instance_name <<
"] : onInitialize()" << std::endl;
98 std::string nameServer = rtcManager.
getConfig()[
"corba.nameservers"];
99 int comPos = nameServer.find(
",");
101 comPos = nameServer.length();
103 nameServer = nameServer.substr(0, comPos);
106 CosNaming::NamingContext::_duplicate(
naming.getRootContext())
108 std::cerr <<
"[" <<
m_profile.instance_name <<
"] failed to load model[" << prop[
"model"] <<
"]" 110 return RTC::RTC_ERROR;
115 std::string grasp_name;
117 std::vector<GraspJoint> grasp_joints;
118 std::cerr <<
"[" <<
m_profile.instance_name <<
"] Parse joint group setting..." << std::endl;
119 for(
unsigned int i = 0,
f = 0;
i < grasp_joint_params.size();
i++ ){
121 if ( grasp_joint_group_names.size() > 1 ) {
122 if ( grasp_name !=
"" ) {
124 grasp_param.
time = 0;
125 grasp_param.
joints = grasp_joints;
126 grasp_param.
time = 1;
128 grasp_joints.clear();
131 grasp_name = grasp_joint_group_names[0];
132 if ( !!
m_robot->link(grasp_joint_group_names[1]) ) {
133 grasp_joint.
id =
m_robot->link(std::string(grasp_joint_group_names[1].c_str()))->jointId;
135 std::cerr <<
"[" <<
m_profile.instance_name <<
"] No such grasp joint name " << grasp_joint_group_names[1] << std::endl;
140 std::cerr <<
"[" <<
m_profile.instance_name <<
"] Invalid joint group setting (length " << grasp_joint_group_names.size() <<
" should be > 1" << std::endl;
144 grasp_joints.push_back(grasp_joint);
147 if ( !!
m_robot->link(grasp_joint_params[i]) ) {
148 grasp_joint.
id =
m_robot->link(grasp_joint_params[i])->jointId;
150 std::cerr <<
"[" <<
m_profile.instance_name <<
"] No such grasp joint name " << grasp_joint_params[i] << std::endl;
156 if ( grasp_name !=
"" ) {
158 grasp_param.
time = 0;
159 grasp_param.
joints = grasp_joints;
160 grasp_param.
time = 1;
164 std::cerr <<
"[" <<
m_profile.instance_name <<
"] Joint group setting results." << std::endl;
165 std::map<std::string, GraspParam >::iterator it =
m_grasp_param.begin();
167 std::cerr <<
"[" <<
m_profile.instance_name <<
"] " << it->first <<
" : ";
168 for (
unsigned int i = 0 ;
i < it->second.joints.size();
i++ ) {
169 std::cerr <<
"id = " << it->second.joints[
i].id <<
", dir = " << it->second.joints[
i].dir <<
", ";
171 std::cerr << std::endl;
202 std::cout <<
"[" <<
m_profile.instance_name<<
"] : onActivated(" << ec_id <<
")" << std::endl;
208 std::cout <<
"[" <<
m_profile.instance_name<<
"] : onDeactivated(" << ec_id <<
")" << std::endl;
211 it->second.target_error = 0;
230 m_qRef.data.length() ==
m_q.data.length() ) {
232 std::map<std::string, GraspParam >::iterator it =
m_grasp_param.begin();
235 if ( grasp_param.
time < 0 ) {
237 }
else if ( grasp_param.
time == 0 ) {
239 for (
unsigned int j= 0;
j < grasp_param.
joints.size();
j++ ) {
241 if ( 0 <= i && (
unsigned int)i <
m_qRef.data.length() ) {
243 double diff = fabs(error);
244 if ( error > 0 )
m_q.data[i] =
m_qRef.data[i] + diff;
245 if ( error < 0 )
m_q.data[i] =
m_qRef.data[i] - diff;
248 if (
m_debugLevel==1) std::cerr <<
"GraspController is not working..., id = " << i << std::endl;
251 }
else if ( grasp_param.
time > 1 ) {
253 for (
unsigned int j= 0;
j < grasp_param.
joints.size();
j++ ) {
255 if ( 0 <= i && (
unsigned int)i <
m_qRef.data.length() ) {
258 if ( diff > 0 ) diff =
min(diff, 0.034907);
259 if ( diff < 0 ) diff =
max(diff,-0.034907);
264 }
else if ( grasp_param.
time == 1 ) {
271 if (
m_debugLevel==1) std::cerr <<
"GraspController in pass through mode..." << std::endl;
274 std::cerr <<
"GraspController is not working..." << std::endl;
275 std::cerr <<
" m_qIn " <<
m_q.data.length() << std::endl;
276 std::cerr <<
" m_qRef " <<
m_qRef.data.length() << std::endl;
277 std::cerr <<
" m_qCurrent " <<
m_qCurrent.data.length() << std::endl;
325 std::cerr <<
"[" <<
m_profile.instance_name <<
"] Could not found grasp controller " << name << std::endl;
328 std::cerr <<
"[" <<
m_profile.instance_name <<
"] Start Grasp " << name << std::endl;
336 std::cerr <<
"[" <<
m_profile.instance_name <<
"] Could not found grasp controller " << name << std::endl;
339 std::cerr <<
"[" <<
m_profile.instance_name <<
"] Stop Grasp " << name << std::endl;
353 RTC::Create<GraspController>,
354 RTC::Delete<GraspController>);
ComponentProfile m_profile
png_infop png_charpp int png_charpp profile
std::vector< GraspJoint > joints
bool stringTo(To &val, const char *str)
InPort< TimedDoubleSeq > m_qIn
InPort< TimedDoubleSeq > m_qRefIn
vstring split(const std::string &input, const std::string &delimiter, bool ignore_empty)
void error(char *msg) const
void GraspControllerInit(RTC::Manager *manager)
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()
unsigned int m_debugLevel
ExecutionContextHandle_t UniqueId
bool bindParameter(const char *param_name, VarType &var, const char *def_val, bool(*trans)(VarType &, const char *)=coil::stringTo)
def j(str, encoding="cp932")
const std::string & name()
int loadBodyFromModelLoader(::World *world, const char *name, const char *url, CosNaming::NamingContext_var cxt)
void grasp(GraspController *i_grasp)
OutPort< TimedDoubleSeq > m_qOut
static const char * softerrorlimiter_spec[]
virtual RTC::ReturnCode_t onInitialize()
virtual RTC::ReturnCode_t onDeactivated(RTC::UniqueId ec_id)
bool startGrasp(const char *name, double target_error)
RTC::CorbaPort m_GraspControllerServicePort
TimedDoubleSeq m_qCurrent
virtual ~GraspController()
Destructor.
virtual RTC::ReturnCode_t onExecute(RTC::UniqueId ec_id)
bool addPort(PortBase &port)
std::map< std::string, GraspParam > m_grasp_param
virtual bool write(DataType &value)
InPort< TimedDoubleSeq > m_qCurrentIn
bool addInPort(const char *name, InPortBase &inport)
virtual RTC::ReturnCode_t onActivated(RTC::UniqueId ec_id)
bool registerFactory(coil::Properties &profile, RtcNewFunc new_func, RtcDeleteFunc delete_func)
bool stopGrasp(const char *name)
GraspController(RTC::Manager *manager)
Constructor.
bool registerProvider(const char *instance_name, const char *type_name, PortableServer::RefCountServantBase &provider)
GraspControllerService_impl m_service0