14 #include <hrpModel/Sensor.h> 15 #include <hrpModel/ModelLoaderUtil.h> 16 #include <libxml/encoding.h> 17 #include <libxml/xmlwriter.h> 23 xmlTextWriterStartElement(writer, BAD_CAST
"property");
24 xmlTextWriterWriteAttribute(writer, BAD_CAST
"name", BAD_CAST name.c_str());
25 xmlTextWriterWriteAttribute(writer, BAD_CAST
"value", BAD_CAST value.c_str());
26 xmlTextWriterEndElement(writer);
30 std::string
ret = name.substr(name.find_last_of(
'/')+1);
31 return ret.substr(0,ret.find_last_of(
'.'));
34 int main (
int argc,
char** argv)
37 std::vector<std::string> inputs, filenames;
38 std::string conf_file_option, robothardware_conf_file_option, integrate(
"true"), dt(
"0.005"), timeStep(dt), joint_properties;
39 bool use_highgain_mode(
true);
42 std::vector<char *> rtmargv;
43 rtmargv.push_back(argv[0]);
45 for (
int i = 1;
i < argc; ++
i) {
46 std::string
arg(argv[
i]);
48 if ( arg ==
"--output" ) {
49 if (++i < argc) output = argv[i];
50 }
else if ( arg ==
"--integrate" ) {
51 if (++i < argc) integrate = argv[i];
52 }
else if ( arg ==
"--dt" ) {
53 if (++i < argc) dt = argv[i];
54 }
else if ( arg ==
"--timestep" ) {
55 if (++i < argc) timeStep = argv[i];
56 }
else if ( arg ==
"--conf-file-option" ) {
57 if (++i < argc) conf_file_option += std::string(
"\n") + argv[i];
58 }
else if ( arg ==
"--robothardware-conf-file-option" ) {
59 if (++i < argc) robothardware_conf_file_option += std::string(
"\n") + argv[i];
60 }
else if ( arg ==
"--joint-properties" ) {
61 if (++i < argc) joint_properties = argv[i];
62 }
else if ( arg ==
"--use-highgain-mode" ) {
63 if (++i < argc) use_highgain_mode = (std::string(argv[i])==std::string(
"true")?
true:
false);
64 }
else if ( arg.find(
"--gtest_output") == 0 ||arg.find(
"--text") == 0 || arg.find(
"__log") == 0 || arg.find(
"__name") == 0 ) {
65 }
else if ( arg[0] ==
'-' ) {
66 rtmargv.push_back(argv[i]);
67 rtmargv.push_back(argv[i+1]);
71 inputs.push_back(argv[i]);
78 std::string nameServer = manager->
getConfig()[
"corba.nameservers"];
79 int comPos = nameServer.find(
",");
81 comPos = nameServer.length();
83 nameServer = nameServer.substr(0, comPos);
87 writer = xmlNewTextWriterFilename(output.c_str(), 0);
88 xmlTextWriterSetIndent(writer, 4);
89 xmlTextWriterStartElement(writer, BAD_CAST
"grxui");
91 xmlTextWriterStartElement(writer, BAD_CAST
"mode");
92 xmlTextWriterWriteAttribute(writer, BAD_CAST
"name", BAD_CAST
"Simulation");
94 xmlTextWriterStartElement(writer, BAD_CAST
"item");
95 xmlTextWriterWriteAttribute(writer, BAD_CAST
"class", BAD_CAST
"com.generalrobotix.ui.item.GrxSimulationItem");
96 xmlTextWriterWriteAttribute(writer, BAD_CAST
"name", BAD_CAST
"simulationItem");
103 xmlTextWriterEndElement(writer);
106 Eigen::AngleAxis<double> WAIST_offset_rot = Eigen::AngleAxis<double>(0,
hrp::Vector3(0,0,1));
107 for (std::vector<std::string>::iterator it = inputs.begin();
117 std::string
filename = filename_arg_str[0];
118 filenames.push_back(filename);
119 if ( filename_arg_str.size () > 1 ){
120 for (
size_t i = 0;
i < 3;
i++) {
122 coil::stringTo(WAIST_offset_rot.axis()(
i), filename_arg_str[
i+1+3].c_str());
124 coil::stringTo(WAIST_offset_rot.angle(), filename_arg_str[1+3+3].c_str());
128 CosNaming::NamingContext::_duplicate(
naming.getRootContext()),
130 std::cerr <<
"failed to load model[" << filename <<
"]" << std::endl;
133 std::string
name = body->name();
135 xmlTextWriterStartElement(writer, BAD_CAST
"item");
136 xmlTextWriterWriteAttribute(writer, BAD_CAST
"class", BAD_CAST
"com.generalrobotix.ui.item.GrxRTSItem");
137 xmlTextWriterWriteAttribute(writer, BAD_CAST
"name", BAD_CAST name.c_str());
138 xmlTextWriterWriteAttribute(writer, BAD_CAST
"select", BAD_CAST
"true");
141 if (use_highgain_mode) {
144 if (it==inputs.begin()) {
152 if (it==inputs.begin()) {
157 xmlTextWriterEndElement(writer);
160 xmlTextWriterStartElement(writer, BAD_CAST
"item");
161 xmlTextWriterWriteAttribute(writer, BAD_CAST
"class", BAD_CAST
"com.generalrobotix.ui.item.GrxModelItem");
162 xmlTextWriterWriteAttribute(writer, BAD_CAST
"name", BAD_CAST (
basename(*it).c_str()));
163 xmlTextWriterWriteAttribute(writer, BAD_CAST
"url", BAD_CAST filename.c_str());
166 if (use_highgain_mode) {
170 if (integrate ==
"false") {
181 if ( nforce > 0 ) std::cerr <<
"hrp::Sensor::FORCE";
182 for (
unsigned int i=0;
i<nforce;
i++){
186 std::cerr <<
" " << s->
name;
188 if ( nforce > 0 ) std::cerr << std::endl;
190 if ( ngyro > 0 ) std::cerr <<
"hrp::Sensor::GYRO";
195 std::cerr <<
" " << s->
name;
197 for (
unsigned int i=0;
i<ngyro;
i++){
199 std::stringstream str_strm;
200 str_strm << s->
name <<
i <<
":" + s->
name <<
":RATE_GYRO_SENSOR";
202 std::cerr <<
" " << s->
name;
205 if ( ngyro > 0 ) std::cerr << std::endl;
207 if ( nacc > 0 ) std::cerr <<
"hrp::Sensor::ACCELERATION";
212 std::cerr <<
" " << s->
name;
214 for (
unsigned int i=0;
i<nacc;
i++){
216 std::stringstream str_strm;
217 str_strm << s->
name <<
i <<
":" << s->
name <<
":ACCELERATION_SENSOR";
219 std::cerr <<
" " << s->
name;
222 if ( nacc > 0 ) std::cerr << std::endl;
225 std::string root_name = body->rootLink()->name;
229 std::ostringstream os;
230 os << body->rootLink()->p[0] + WAIST_offset_pos(0) <<
" " 231 << body->rootLink()->p[1] + WAIST_offset_pos(1) <<
" " 232 << body->rootLink()->p[2] + WAIST_offset_pos(2);
235 Eigen::AngleAxis<double> tmpAA = Eigen::AngleAxis<double>(
hrp::Matrix33(body->rootLink()->R * WAIST_offset_rot.toRotationMatrix()));
236 os << tmpAA.axis()(0) <<
" " 237 << tmpAA.axis()(1) <<
" " 238 << tmpAA.axis()(2) <<
" " 242 if ( ! body->isStaticModel() ) {
251 std::map <std::string, std::string> joint_properties_map;
252 for (
size_t i = 0;
i < joint_properties_arg_str.size()/2;
i++) {
253 joint_properties_map.insert(std::pair<std::string, std::string>(joint_properties_arg_str[
i*2], joint_properties_arg_str[i*2+1]));
255 if ( body->numJoints() > 0 ) std::cerr <<
"hrp::Joint";
256 for(
unsigned int i = 0;
i < body->numJoints();
i++){
257 if ( body->joint(
i)->index > 0 ) {
258 std::cerr <<
" " << body->joint(
i)->name <<
"(" << body->joint(
i)->jointId <<
")";
259 std::string joint_name = body->joint(
i)->name;
260 std::string j_property = joint_name+
".angle";
262 (joint_properties_map.find(j_property) != joint_properties_map.end()) ? joint_properties_map[j_property] :
"0.0");
263 j_property = joint_name+
".mode";
265 (joint_properties_map.find(j_property) != joint_properties_map.end()) ? joint_properties_map[j_property] : (use_highgain_mode?
"HighGain":
"Torque"));
266 j_property = joint_name+
".NumOfAABB";
268 (joint_properties_map.find(j_property) != joint_properties_map.end()) ? joint_properties_map[j_property] :
"1");
271 xmlTextWriterEndElement(writer);
272 if ( body->numJoints() > 0 ) std::cerr << std::endl;
293 xmlTextWriterStartElement(writer, BAD_CAST
"view");
294 xmlTextWriterWriteAttribute(writer, BAD_CAST
"class", BAD_CAST
"com.generalrobotix.ui.view.GrxRobotHardwareClientView");
295 xmlTextWriterWriteAttribute(writer, BAD_CAST
"name", BAD_CAST
"RobotHardware RTC Client");
302 xmlTextWriterEndElement(writer);
304 xmlTextWriterStartElement(writer, BAD_CAST
"view");
305 xmlTextWriterWriteAttribute(writer, BAD_CAST
"class", BAD_CAST
"com.generalrobotix.ui.view.Grx3DView");
306 xmlTextWriterWriteAttribute(writer, BAD_CAST
"name", BAD_CAST
"3DView");
316 xmlTextWriterEndElement(writer);
320 for (std::vector<std::string>::iterator it1 = inputs.begin(); it1 != inputs.end(); it1++) {
322 for (std::vector<std::string>::iterator it2 = it1+1; it2 != inputs.end(); it2++) {
325 xmlTextWriterStartElement(writer, BAD_CAST
"item");
326 xmlTextWriterWriteAttribute(writer, BAD_CAST
"class", BAD_CAST
"com.generalrobotix.ui.item.GrxCollisionPairItem");
327 xmlTextWriterWriteAttribute(writer, BAD_CAST
"name", BAD_CAST std::string(
"CP#"+name2+
"_#"+name1+
"_").c_str());
339 xmlTextWriterEndElement(writer);
344 xmlTextWriterEndElement(writer);
346 xmlTextWriterEndElement(writer);
348 xmlFreeTextWriter(writer);
351 std::string conf_file = output.substr(0,output.find_last_of(
'.'))+
".conf";
352 std::fstream s(conf_file.c_str(), std::ios::out);
354 s <<
"model: file://" << filenames[0] << std::endl;
355 s <<
"dt: " << dt << std::endl;
356 s << conf_file_option << std::endl;
360 std::string conf_file = output.substr(0,output.find_last_of(
'.'))+
".RobotHardware.conf";
361 std::fstream s(conf_file.c_str(), std::ios::out);
363 s <<
"model: file://" << filenames[0] << std::endl;
364 s <<
"exec_cxt.periodic.type: hrpExecutionContext" << std::endl;
365 s <<
"exec_cxt.periodic.rate: " <<
static_cast<size_t>(1/atof(dt.c_str())+0.5) << std::endl;
366 s << robothardware_conf_file_option << std::endl;
368 std::cerr <<
"\033[1;31mProjectGenerator in hrpsys-base is old, so please use projectGenerator in openhrp3.\033[0m" << std::endl;
std::string normalize(std::string &str)
bool stringTo(To &val, const char *str)
png_infop png_charpp name
RTC::ReturnCode_t ret(RTC::Local::ReturnCode_t r)
vstring split(const std::string &input, const std::string &delimiter, bool ignore_empty)
std::string basename(const std::string name)
std::vector< std::string > vstring
coil::Properties & getConfig()
static Manager * init(int argc, char **argv)
int loadBodyFromModelLoader(::World *world, const char *name, const char *url, CosNaming::NamingContext_var cxt)
void xmlTextWriterWriteProperty(const xmlTextWriterPtr writer, const std::string name, const std::string value)
int main(int argc, char **argv)
output(gif_dest_ptr dinfo, int code)