13 #include <hrpCorba/OpenHRPCommon.hh> 14 #include <hrpModel/ModelLoaderUtil.h> 15 #include <hrpModel/OnlineViewerUtil.h> 17 #include "hrpsys/util/Project.h" 23 "implementation_id",
"Simulator",
24 "type_name",
"Simulator",
25 "description",
"dynamics simulator component",
26 "version", HRPSYS_PACKAGE_VERSION,
28 "category",
"example",
29 "activity_type",
"DataFlowComponent",
32 "lang_type",
"compile",
34 "conf.default.project",
"",
35 "conf.default.kinematics_only",
"0",
36 "conf.default.useOLV",
"0",
44 m_sceneStateOut(
"state", m_sceneState),
58 std::cout <<
m_profile.instance_name <<
": onInitialize()" << std::endl;
112 std::cout <<
m_profile.instance_name<<
": onActivated(" << ec_id <<
")" << std::endl;
115 std::cerr <<
"Project file is not specified." << std::endl;
116 return RTC::RTC_ERROR;
131 std::cout <<
"time step = " << prj.
timeStep() << std::endl;
139 std::string nameServer = rtcManager.
getConfig()[
"corba.nameservers"];
140 int comPos = nameServer.find(
",");
142 comPos = nameServer.length();
144 nameServer = nameServer.substr(0, comPos);
147 std::cout <<
"m_useOLV:" <<
m_useOLV << std::endl;
152 for (std::map<std::string, ModelItem>::iterator it=prj.
models().begin();
153 it != prj.
models().end(); it++){
156 CosNaming::NamingContext::_duplicate(
naming.getRootContext()),
158 std::cerr <<
"failed to load model[" << it->second.url <<
"]" << std::endl;
160 body->setName(it->first);
161 for (std::map<std::string, JointItem>::iterator it2=it->second.joint.begin();
162 it2 != it->second.joint.end(); it2++){
163 hrp::Link *link = body->link(it2->first);
167 body->createPorts(
this);
171 m_olv->load(it->first.c_str(), it->second.url.c_str());
185 if(bodyIndex1 >= 0 && bodyIndex2 >= 0){
189 std::vector<hrp::Link*> links1;
193 std::copy(traverse.
begin(), traverse.
end(), links1.begin());
195 links1.push_back(bodyPtr1->link(cpi.
jointName1));
198 std::vector<hrp::Link*> links2;
202 std::copy(traverse.
begin(), traverse.
end(), links2.begin());
204 links2.push_back(bodyPtr2->link(cpi.
jointName2));
207 for(
size_t j=0;
j < links1.size(); ++
j){
208 for(
size_t k=0; k < links2.size(); ++k){
212 if(link1 && link2 && link1 != link2){
214 (bodyIndex1, link1, bodyIndex2, link2,
225 for(
int i=0;
i < nBodies; ++
i){
227 bodyPtr->initializeConfiguration();
230 for (std::map<std::string, ModelItem>::iterator it=prj.
models().begin();
231 it != prj.
models().end(); it++){
233 for (std::map<std::string, JointItem>::iterator it2=it->second.joint.begin();
234 it2 != it->second.joint.end(); it2++){
235 hrp::Link *link = body->link(it2->first);
238 link->
p = it2->second.translation;
241 link->
q = it2->second.angle;
244 body->calcForwardKinematics();
263 std::cout <<
m_profile.instance_name<<
": onDeactivated(" << ec_id <<
")" << std::endl;
288 OpenHRP::CollisionSequence collision;
343 RTC::Create<Simulator>,
344 RTC::Delete<Simulator>);
ComponentProfile m_profile
png_infop png_charpp int png_charpp profile
virtual ~Simulator()
Destructor.
int bodyIndex(const std::string &name)
double timeStep(void) const
std::vector< Link * >::const_iterator end() const
bool parse(const std::string &filename)
int addBody(BodyPtr body)
void useBuiltinCollisionDetector(bool on)
virtual void initialize()
void clearCollisionCheckLinkPairs()
png_infop png_charpp name
void setCurrentTime(double tm)
Simulator(RTC::Manager *manager)
Constructor.
void setAttitude(const Matrix33 &R)
OpenHRP::SceneState m_sceneState
std::vector< Link * >::const_iterator begin() const
static Manager & instance()
void setRungeKuttaMethod()
bool addOutPort(const char *name, OutPortBase &outport)
void getWorldState(WorldState &state, WorldBase &world)
void enableConstraintForceOutput(bool on)
OpenHRP::WorldState m_state
void initWorldState(WorldState &state, WorldBase &world)
coil::Properties & getConfig()
unsigned int numLinks() const
ExecutionContextHandle_t UniqueId
void SimulatorInit(RTC::Manager *manager)
bool bindParameter(const char *param_name, VarType &var, const char *def_val, bool(*trans)(VarType &, const char *)=coil::stringTo)
def j(str, encoding="cp932")
std::vector< RTCBodyPtr > m_bodies
int loadBodyFromModelLoader(::World *world, const char *name, const char *url, CosNaming::NamingContext_var cxt)
std::map< std::string, ModelItem > & models()
bool addCollisionCheckLinkPair(int bodyIndex1, Link *link1, int bodyIndex2, Link *link2, double muStatic, double muDynamic, double culling_thresh, double restitution, double epsilon)
virtual RTC::ReturnCode_t onExecute(RTC::UniqueId ec_id)
OutPort< OpenHRP::SceneState > m_sceneStateOut
virtual RTC::ReturnCode_t onDeactivated(RTC::UniqueId ec_id)
virtual void calcNextState(OpenHRP::CollisionSequence &corbaCollisionSequence)
TConstraintForceSolver constraintForceSolver
void clearExternalForces()
virtual RTC::ReturnCode_t onInitialize()
static const char * component_spec[]
void setTimeStep(double dt)
hrp::World< hrp::ConstraintForceSolver > m_world
OpenHRP::OnlineViewer_var m_olv
HRP_UTIL_EXPORT OpenHRP::OnlineViewer_var getOnlineViewer(int argc, char **argv)
double currentTime(void) const
virtual RTC::ReturnCode_t onActivated(RTC::UniqueId ec_id)
bool registerFactory(coil::Properties &profile, RtcNewFunc new_func, RtcDeleteFunc delete_func)
void enableSensors(bool on)
std::vector< CollisionPairItem > & collisionPairs()