#include <Factory.hpp>
Public Types | |
typedef std::vector < boost::shared_ptr< Task > > | task_table_t |
typedef std::vector < boost::shared_ptr< Skill > > | skill_table_t |
Public Member Functions | |
Status | parseString (std::string const &yaml_string) |
Parse a YAML document contained in a string. | |
Status | parseFile (std::string const &yaml_filename) |
Parse a YAML file, specified as a filename. | |
Status | parseStream (std::istream &yaml_istream) |
Parse a YAML file from a stream. | |
task_table_t const & | getTaskTable () const |
The task table contains pointers to all task instances ever created by this Factory, in the order that they were encountered in the YAML documents. | |
skill_table_t const & | getSkillTable () const |
The skill table contains pointers to all skill instances ever created by this Factory, in the order that they were encountered in the YAML documents. | |
boost::shared_ptr< Task > | findTask (std::string const &name) const |
boost::shared_ptr< Skill > | findSkill (std::string const &name) const |
ReflectionRegistry * | createRegistry () |
Create a ReflectionRegistry and populate it with the currently registered task and skill instances. | |
void | dump (std::ostream &os, std::string const &title, std::string const &prefix) const |
Write a human-readable (hopefully, anyway) description of all skills and tasks contained in the tables. | |
Static Public Member Functions | |
static void | setDebugStream (std::ostream *dbg) |
template<typename task_subtype> | |
static void | addTaskType (std::string const &type) |
template<typename skill_subtype> | |
static void | addSkillType (std::string const &type) |
static Task * | createTask (std::string const &type, std::string const &name) |
static Skill * | createSkill (std::string const &type, std::string const &name) |
Protected Types | |
typedef std::map< std::string, boost::shared_ptr< ShopAPI < Task > > > | task_shop_t |
typedef std::map< std::string, boost::shared_ptr< ShopAPI < Skill > > > | skill_shop_t |
Protected Attributes | |
task_table_t | task_table_ |
skill_table_t | skill_table_ |
Static Protected Attributes | |
static std::ostream * | dbg__ |
static task_shop_t | task_shop__ |
static skill_shop_t | skill_shop__ |
For the moment, we use a hardcoded mapping from type names to subclasses, but it will be really easy to extend this with some sort of plugin approach.
The idea is to call the parseFoo() methods to feed it with task and skill specifications, and then retrieve them using getTaskTable() and/or getSkillTable().
The YAML format is quite simple: you specify a list of dictionaries. When the key is `tasks', then it parses a list of tasks. Similarly, it parses skills when the dictionary key is `skills'. You can mix and match, but beware that tasks referenced by a skill must be defined before they can be used.
For tasks, the specification is again a list of dictionaries. Each one specifies a task. The required dictionary keys are `type' and `name'. All the others get looked up via Task::lookupParameter() and directly specify task parameters.
Skills are very similar, except that dictionary values are handled differently depending on whether they are lists or dictionaries: if they are dictionaries, they are treated as state definitions which define which task goes where in the slots provided by the skill. Otherwise, they are treated as parameter definitions.
An example task YAML file is:
- tasks: - type: opspace::PositionTask name: eepos dt_seconds: 0.002 kp: [ 100.0 ] kd: [ 20.0 ] maxvel: [ 0.5 ] maxacc: [ 1.5 ] - type: opspace::PostureTask name: posture dt_seconds: 0.002 kp: [ 400.0, 400.0, 400.0, 100.0, 100.0, 100.0, 100.0 ] kd: [ 40.0, 40.0, 40.0, 20.0, 20.0, 20.0, 20.0 ] maxvel: [ 3.1416 ] maxacc: [ 6.2832 ] - skills: - type: opspace::TPSkill name: task_posture # dictionaries define task slots default: eepos: eepos posture: posture # key-value pairs define parameters some_param_name: some_param_value
Definition at line 113 of file Factory.hpp.
typedef std::vector<boost::shared_ptr<Task> > opspace::Factory::task_table_t |
Definition at line 116 of file Factory.hpp.
typedef std::vector<boost::shared_ptr<Skill> > opspace::Factory::skill_table_t |
Definition at line 117 of file Factory.hpp.
typedef std::map<std::string, boost::shared_ptr<ShopAPI<Task> > > opspace::Factory::task_shop_t [protected] |
Definition at line 185 of file Factory.hpp.
typedef std::map<std::string, boost::shared_ptr<ShopAPI<Skill> > > opspace::Factory::skill_shop_t [protected] |
Definition at line 186 of file Factory.hpp.
void opspace::Factory::setDebugStream | ( | std::ostream * | dbg | ) | [static] |
static void opspace::Factory::addTaskType | ( | std::string const & | type | ) | [inline, static] |
static void opspace::Factory::addSkillType | ( | std::string const & | type | ) | [inline, static] |
Task * opspace::Factory::createTask | ( | std::string const & | type, | |
std::string const & | name | |||
) | [static] |
Definition at line 72 of file Factory.cpp.
References dbg__, opspace::init_shops(), and task_shop__.
Referenced by opspace::operator>>().
Skill * opspace::Factory::createSkill | ( | std::string const & | type, | |
std::string const & | name | |||
) | [static] |
Definition at line 91 of file Factory.cpp.
References dbg__, opspace::init_shops(), and skill_shop__.
Referenced by opspace::operator>>().
Status opspace::Factory::parseString | ( | std::string const & | yaml_string | ) |
Parse a YAML document contained in a string.
Retrieve the result using getTaskTable().
Definition at line 110 of file Factory.cpp.
References parseStream().
Status opspace::Factory::parseFile | ( | std::string const & | yaml_filename | ) |
Parse a YAML file, specified as a filename.
Retrieve the result using getTaskTable().
Definition at line 118 of file Factory.cpp.
References parseStream().
Status opspace::Factory::parseStream | ( | std::istream & | yaml_istream | ) |
Parse a YAML file from a stream.
Retrieve the result using getTaskTable().
Definition at line 129 of file Factory.cpp.
References dbg__, jspace::Status::errstr, jspace::Status::ok, skill_table_, and task_table_.
Referenced by parseFile(), and parseString().
Factory::task_table_t const & opspace::Factory::getTaskTable | ( | ) | const |
The task table contains pointers to all task instances ever created by this Factory, in the order that they were encountered in the YAML documents.
Definition at line 183 of file Factory.cpp.
References task_table_.
Factory::skill_table_t const & opspace::Factory::getSkillTable | ( | ) | const |
The skill table contains pointers to all skill instances ever created by this Factory, in the order that they were encountered in the YAML documents.
Definition at line 190 of file Factory.cpp.
References skill_table_.
boost::shared_ptr< Task > opspace::Factory::findTask | ( | std::string const & | name | ) | const |
Definition at line 218 of file Factory.cpp.
References task_table_.
Referenced by opspace::operator>>().
boost::shared_ptr< Skill > opspace::Factory::findSkill | ( | std::string const & | name | ) | const |
ReflectionRegistry * opspace::Factory::createRegistry | ( | ) |
Create a ReflectionRegistry and populate it with the currently registered task and skill instances.
Definition at line 244 of file Factory.cpp.
References opspace::ReflectionRegistry::add(), skill_table_, and task_table_.
void opspace::Factory::dump | ( | std::ostream & | os, | |
std::string const & | title, | |||
std::string const & | prefix | |||
) | const |
Write a human-readable (hopefully, anyway) description of all skills and tasks contained in the tables.
Definition at line 197 of file Factory.cpp.
References skill_table_, and task_table_.
std::ostream * opspace::Factory::dbg__ [static, protected] |
Definition at line 188 of file Factory.hpp.
Referenced by createSkill(), createTask(), parseStream(), and setDebugStream().
Factory::task_shop_t opspace::Factory::task_shop__ [static, protected] |
Factory::skill_shop_t opspace::Factory::skill_shop__ [static, protected] |
task_table_t opspace::Factory::task_table_ [protected] |
Definition at line 192 of file Factory.hpp.
Referenced by createRegistry(), dump(), findTask(), getTaskTable(), and parseStream().
skill_table_t opspace::Factory::skill_table_ [protected] |
Definition at line 193 of file Factory.hpp.
Referenced by createRegistry(), dump(), findSkill(), getSkillTable(), and parseStream().