3 #include <boost/bind.hpp> 4 #include <hrpModel/ModelLoaderUtil.h> 11 #include "hrpsys/util/ProjectUtil.h" 12 #include "hrpsys/util/GLbody.h" 13 #include "hrpsys/util/GLlink.h" 14 #include "hrpsys/util/GLutil.h" 15 #include "hrpsys/util/SDLUtil.h" 23 ModelLoader_ptr modelloader)
27 OpenHRP::ModelLoader::ModelLoadOption opt;
29 opt.AABBdata.length(0);
30 opt.AABBtype = OpenHRP::ModelLoader::AABB_NUM;
31 binfo = modelloader->getBodyInfoEx(mitem.
url.c_str(), opt);
32 }
catch(OpenHRP::ModelLoader::ModelLoaderException ex){
33 std::cerr << ex.description << std::endl;
44 int main(
int argc,
char* argv[])
47 std::cerr <<
"Usage:" << argv[0] <<
" project.xml [-rh RobotHardwareComponent] [-sh StateHolder component] [-size size] [-bg r g b] [-host localhost] [-port 2809] [-interval 100] [-nogui]" << std::endl;
52 if (!prj.
parse(argv[1])){
53 std::cerr <<
"failed to parse " << argv[1] << std::endl;
57 char *rhname = NULL, *shname = NULL, *hostname = NULL;
58 int wsize = 0, port=0, interval=0;
59 float bgColor[] = {0,0,0};
60 bool orbinitref =
false, gui =
true;
61 for (
int i = 2;
i<argc;
i++){
62 if (strcmp(argv[
i],
"-rh")==0){
64 }
else if(strcmp(argv[i],
"-sh")==0){
66 }
else if(strcmp(argv[i],
"-size")==0){
67 wsize = atoi(argv[++i]);
68 }
else if(strcmp(argv[i],
"-bg")==0){
69 bgColor[0] = atof(argv[++i]);
70 bgColor[1] = atof(argv[++i]);
71 bgColor[2] = atof(argv[++i]);
72 }
else if(strcmp(argv[i],
"-host")==0){
74 }
else if(strcmp(argv[i],
"-port")==0){
75 port = atoi(argv[++i]);
76 }
else if(strcmp(argv[i],
"-interval")==0){
77 interval = atoi(argv[++i]);
78 }
else if(strcmp(argv[i],
"-nogui")==0){
80 }
else if(strcmp(argv[i],
"-ORBInitRef")==0){
86 if(orbinitref ==
false){
87 nargv = (
char **)
malloc((argc+2)*
sizeof(
char *));
88 for(
int i = 0;
i < nargc;
i++) nargv[
i] = argv[
i];
89 char buf1[] =
"-ORBInitRef";
91 sprintf(buf2,
"NameService=corbaloc:iiop:%s:%d/NameService", hostname==NULL?
"localhost":hostname, port==0?2809:port);
92 nargv[nargc++] = buf1;
93 nargv[nargc++] = buf2;
97 for(
int i = 0;
i < nargc-1;
i++) {
98 if(strcmp(nargv[
i],
"-ORBInitRef")==0) {
99 std::cerr <<
"[monitor] Starting CORBA Client with " << nargv[i+1] << std::endl;
103 CosNaming::NamingContext_var namingContext;
106 orb = CORBA::ORB_init(nargc, nargv);
108 CORBA::Object_var
obj;
109 obj = orb->resolve_initial_references(
"RootPOA");
110 PortableServer::POA_var poa = PortableServer::POA::_narrow(obj);
111 if(CORBA::is_nil(poa)){
112 throw std::string(
"error: failed to narrow root POA.");
115 PortableServer::POAManager_var poaManager = poa->the_POAManager();
116 if(CORBA::is_nil(poaManager)){
117 throw std::string(
"error: failed to narrow root POA manager.");
120 obj = orb->resolve_initial_references(
"NameService");
121 namingContext = CosNaming::NamingContext::_narrow(obj);
122 if(CORBA::is_nil(namingContext)){
123 throw std::string(
"error: failed to narrow naming context.");
126 poaManager->activate();
127 }
catch (CORBA::SystemException& ex) {
128 std::cerr <<
"[monitor] Failed to initialize CORBA " << std::endl << ex._rep_id() << std::endl;
130 }
catch (
const std::string&
error){
131 std::cerr <<
"[monitor] Failed to initialize CORBA " << std::endl << error << std::endl;
141 if ( hostname != NULL ) rhview.
hostname = hostname;
142 if ( port != 0 ) rhview.
port = port;
143 if ( interval != 0 ) rhview.
interval = interval;
144 std::cerr <<
"[monitor] Monitor service with " << rhview.
hostname <<
"@" << rhview.
port <<
", " << 1000/rhview.
interval <<
"Hz" << std::endl;
164 SDLwindow window(&scene, &log, &monitor);
165 window.
init(wsize, wsize);
167 std::vector<hrp::ColdetLinkPairPtr> pairs;
169 if (CORBA::is_nil(modelloader)){
170 std::cerr <<
"openhrp-model-loader is not running" << std::endl;
185 std::vector<hrp::ColdetLinkPairPtr> pairs;
187 if (CORBA::is_nil(modelloader)){
188 std::cerr <<
"openhrp-model-loader is not running" << std::endl;
195 for (std::map<std::string, ModelItem>::iterator it=prj.
models().begin();
196 it != prj.
models().end(); it++){
197 const std::string
name 198 = it->second.rtcName ==
"" ? it->first : it->second.rtcName;
201 tmp_body->setName(name);
202 if(tmp_body->numJoints() > 0)
205 std::cerr <<
"[monitor] Skipping non-robot model (" << name <<
")" << std::endl;
209 std::cerr <<
"[monitor] Monitoring " << body->name() << std::endl;
void enableRingBuffer(int len)
HRPMODEL_API OpenHRP::ModelLoader_var getModelLoader(CosNaming::NamingContext_var cxt)
bool parse(const std::string &filename)
int main(int argc, char *argv[])
void setCollisionCheckPairs(const std::vector< hrp::ColdetLinkPairPtr > &i_pairs)
void setBackGroundColor(float rgb[3])
png_infop png_charpp name
bool init(int w=0, int h=0, bool resizable=true)
HRPMODEL_API bool loadBodyFromBodyInfo(BodyPtr body, OpenHRP::BodyInfo_ptr bodyInfo, bool loadGeometryForCollisionDetection=false, Link *(*f)()=NULL)
void showCoMonFloor(bool flag)
void error(char *msg) const
RobotHardwareClientView & RobotHardwareClient()
void loadShapeFromBodyInfo(GLbody *body, BodyInfo_var i_binfo, GLshape *(*shapeFactory)())
boost::shared_ptr< Body > BodyPtr
void setStateHolderName(const char *i_name)
void showStatus(hrp::BodyPtr &body)
hrp::Link * GLlinkFactory()
std::string RobotHardwareName
std::map< std::string, ModelItem > & models()
hrp::BodyPtr createBody(const std::string &name, const ModelItem &mitem, ModelLoader_ptr modelloader)
std::string sprintf(char const *__restrict fmt,...)
void setRobotHardwareName(const char *i_name)
boost::function2< hrp::BodyPtr, const std::string &, const ModelItem & > BodyFactory
void initWorld(Project &prj, BodyFactory &factory, hrp::World< hrp::ConstraintForceSolver > &world, std::vector< hrp::ColdetLinkPairPtr > &pairs)
std::string StateHolderName