Revision: 8608 http://playerstage.svn.sourceforge.net/playerstage/?rev=8608&view=rev Author: natepak Date: 2010-04-10 21:11:32 +0000 (Sat, 10 Apr 2010)
Log Message: ----------- Added a gazebomodel command line tool Added Paths: ----------- code/gazebo/trunk/libgazebo/FactoryIface.cc code/gazebo/trunk/tools/ code/gazebo/trunk/tools/CMakeLists.txt code/gazebo/trunk/tools/gazebomodel.cc Added: code/gazebo/trunk/libgazebo/FactoryIface.cc =================================================================== --- code/gazebo/trunk/libgazebo/FactoryIface.cc (rev 0) +++ code/gazebo/trunk/libgazebo/FactoryIface.cc 2010-04-10 21:11:32 UTC (rev 8608) @@ -0,0 +1,14 @@ +#include <stdio.h> + +#include "gz.h" + +using namespace gazebo; + +/// \brief Delete a model by name +bool FactoryIface::DeleteModel(const std::string &model_name) +{ + this->Lock(1); + strcpy((char*)this->data->deleteModel, model_name.c_str()); + this->Unlock(); + return true; +} Added: code/gazebo/trunk/tools/CMakeLists.txt =================================================================== --- code/gazebo/trunk/tools/CMakeLists.txt (rev 0) +++ code/gazebo/trunk/tools/CMakeLists.txt 2010-04-10 21:11:32 UTC (rev 8608) @@ -0,0 +1,11 @@ + +link_directories(../libgazebo) +include_directories(../libgazebo) + +set (sources gazebomodel.cc) + +set_source_files_properties(${sources} PROPERTIES COMPILE_FLAGS "-ggdb -g2 -Wall") + +add_executable(gazebomodel gazebomodel.cc) + +target_link_libraries(gazebomodel gazebo boost_program_options) Added: code/gazebo/trunk/tools/gazebomodel.cc =================================================================== --- code/gazebo/trunk/tools/gazebomodel.cc (rev 0) +++ code/gazebo/trunk/tools/gazebomodel.cc 2010-04-10 21:11:32 UTC (rev 8608) @@ -0,0 +1,152 @@ +#include <iostream> +//#include <gazebo/gazebo.h> +#include "libgazebo/gz.h" + +gazebo::Client *client = NULL; +gazebo::SimulationIface *simIface = NULL; +gazebo::FactoryIface *factoryIface = NULL; + + +//////////////////////////////////////////////////////////////////////////////// +// Print out info for one model. Recurses through all child models +void print_model(std::string name, std::string prefix) +{ + std::string type; + gazebo::Pose pose; + + if (!simIface->GetPose3d(name, pose)) + std::cerr << "Unable to get model[" << name << "] pose\n"; + if (!simIface->GetModelType(name, type)) + std::cerr << "Unable to get model[" << name << "] type\n"; + + std::cout << prefix << "Model[" << name << "]\n"; + std::cout << prefix << " Type: " << type << "\n"; + std::cout << prefix << " XYZ: " << pose.pos.x << " " << pose.pos.y + << " " << pose.pos.z << "\n"; + std::cout << prefix << " RPY: " << pose.roll << " " << pose.pitch + << " " << pose.yaw << "\n"; + + /*unsigned int children; + if (!simIface->GetNumChildren(name, children)) + std::cerr << "Unable to get the number of children for model[" + << name << "]\n"; + + for (unsigned int i=0; i < children; i++) + { + std::string childName; + if (!simIface->GetChildName(name, i, childName)) + std::cerr << "Unable to get model[" << name << "] child name.\n"; + else + info(childName, prefix + " "); + }*/ +} + +//////////////////////////////////////////////////////////////////////////////// +// Print out a list of all the models +void list(int argc, char **argv) +{ + unsigned int numModels = 0; + + if (!simIface->GetNumModels(numModels)) + std::cerr << "Unable to get the model count\n"; + + for (unsigned int i=0; i < numModels; i++) + { + std::string name; + if (!simIface->GetModelName(i, name)) + std::cerr << "Unable to get model[" << i << "]\n"; + + print_model(name, ""); + } +} + +//////////////////////////////////////////////////////////////////////////////// +// Show info for a model +void show(int argc, char **argv) +{ + if (argc < 3) + std::cerr << "Missing model name\n"; + else + print_model(argv[2], ""); +} + +//////////////////////////////////////////////////////////////////////////////// +// Remove a model from the world +void kill(int argc, char **argv) +{ + if (argc < 3) + std::cerr << "Missing model name\n"; + else + { + factoryIface->DeleteModel( argv[2] ); + } +} + +void help() +{ + std::cout << "gazebomodel is a command-line tool for printing out information about models in a gazebo world.\n"; + std::cout << "\n"; + std::cout << "Usage: gazebomodel <command> <option_1> ... <option_n>\n"; + std::cout << "\n"; + + std::cout << "Commands:\n"; + std::cout << "\tgazebomodel list \t List all the models\n"; + std::cout << "\tgazebomodel show \t Show info about a model\n"; +} + +int main(int argc, char **argv) +{ + + if (argc == 1 || std::string(argv[1]) == "help") + { + help(); + return 1; + } + + client = new gazebo::Client(); + simIface = new gazebo::SimulationIface(); + factoryIface = new gazebo::FactoryIface(); + + try + { + client->ConnectWait(0, GZ_CLIENT_ID_USER_FIRST); + } + catch(std::string e) + { + std::cerr << "Gazebo Error: Unable to connect: " << e << "\n"; + return -1; + } + + /// Open the sim iface + try + { + simIface->Open(client, "default"); + } + catch (std::string e) + { + std::cerr << "Gazebo error: Unable to connect to sim iface:" << e << "\n"; + return -1; + } + + // Open the factory iface + try + { + factoryIface->Open(client, "default"); + } + catch( std::string e) + { + std::cerr << "Gazebo error: Unable to connect to the factory Iface:" + << e << "\n"; + return -1; + } + + std::string cmd = argv[1]; + if (cmd == "list") + list(argc, argv); + else if (cmd == "show") + show(argc, argv); + else if (cmd == "kill") + kill(argc, argv); + else + std::cerr << "Unknown command[" << cmd << "]\n"; +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. ------------------------------------------------------------------------------ Download Intel® Parallel Studio Eval Try the new software tools for yourself. Speed compiling, find bugs proactively, and fine-tune applications for parallel performance. See why Intel Parallel Studio got high marks during beta. http://p.sf.net/sfu/intel-sw-dev _______________________________________________ Playerstage-commit mailing list Playerstage-commit@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/playerstage-commit