20 #include <boost/program_options.hpp>    23 #include <dynamic-graph/pool.h>    28 namespace po = boost::program_options;
    44   po::options_description desc(
"Allowed options");
    45   desc.add_options()(
"help", 
"produce help message")(
    46       "sot-dynamic-library", po::value<std::string>(), 
"Library to load");
    47   desc.add_options()(
"help", 
"produce help message")(
    48       "input-file", po::value<std::string>(), 
"Library to load");
    52   po::store(po::parse_command_line(argc, argv, desc), vm);
    55   if (vm.count(
"help")) {
    56     std::cout << desc << 
"\n";
    59   if (vm.count(
"sot-dynamic-library")) {
    61   } 
else if (vm.count(
"input-file")) {
    64     std::cout << 
"No filename specified\n";
    75     std::cerr << 
"Cannot load library: " << dlerror() << 
'\n';
    86   const char *dlsym_error = dlerror();
    88     std::cerr << 
"Cannot load symbol create: " << dlsym_error << 
'\n';
    99   std::string result, out, 
err;
   106   runPythonCommand(
"print(\"python version:\", sys.version)", result, out, err);
   107   runPythonCommand(
"pythonpath = os.environ.get('PYTHONPATH', '')", result, out,
   111       "for p in pythonpath.split(':'):\n"   112       "  if p not in sys.path:\n"   119       "if not hasattr(sys, \'argv\'):\n"   120       "    sys.argv  = ['sot']",
   125   runPythonCommand(
"print(\"Executing python interpreter prologue... Done\")",
   148             reinterpret_cast<long>(
   150     const char *dlsym_error = dlerror();
   152       std::cerr << 
"Cannot load symbol destroy: " << dlsym_error << 
'\n';
   166                                  std::string &result, std::string &out,
   172     std::map<std::string, SensorValues> &sensors_in,
   173     std::map<std::string, ControlValues> &control_values,
   174     const double &period) {
   179     } 
catch (std::exception &e) {
   180       std::cout << 
"Exception while running the graph:\n"   181                 << e.what() << std::endl;
   188   std::string result, out, 
err;
   190   runPythonCommand(
"print(\"Load device from C++ to Python...\")", result, out,
   198   runPythonCommand(
"loaded_device_name = \"" + device_name + 
"\"", result, out,
 void deregisterEntity(const std::string &entname)
void * sot_dynamic_library_
Handle on the SoT library. 
void loadDeviceInPython(const std::string &device_name)
Load the Device entity in the python global scope. 
void destroySotExternalInterface(dynamicgraph::sot::AbstractSotExternalInterface *p)
bool initialization()
Prepare the SoT framework. 
virtual void nominalSetSensors(std::map< std::string, SensorValues > &sensorsIn)=0
~SotLoader()
Default destructor. 
void oneIteration(std::map< std::string, SensorValues > &sensors_in, std::map< std::string, ControlValues > &control_values, const double &period)
Compute one iteration of control. Basically executes fillSensors, the SoT and the readControl...
std::string device_name_
Device entity created and loaded, so we deregister it as the Pool is not responsible for it's life ti...
std::string python(const std::string &command)
void cleanUp()
Unload the library which handles the robot device. 
static PoolStorage * getInstance()
SotLoader()
Default constructor. 
python::Interpreter embeded_python_interpreter_
Embeded python interpreter. 
AbstractSotExternalInterface * sot_external_interface_
The interface between the device and the robot driver. 
dynamicgraph::sot::AbstractSotExternalInterface * createSotExternalInterface_t()
void runPythonCommand(const std::string &command, std::string &result, std::string &out, std::string &err)
Run a python command inside the embeded python interpreter. 
dynamicgraph::sot::AbstractSotExternalInterface * createSotExternalInterface()
std::string sot_dynamic_library_filename_
Name of the dynamic library containing the dgs::AbstractSotExternalInterface object. 
void destroySotExternalInterface_t(dynamicgraph::sot::AbstractSotExternalInterface *)
virtual void getControl(std::map< std::string, ControlValues > &, const double &period=0)=0
int parseOptions(int argc, char *argv[])
Read user input to extract the path of the SoT dynamic library. 
bool dynamic_graph_stopped_
Check if the dynamic graph is running or not.