CLASS kb_tools
See also
see also NODE kb_interface which is an application of the services offered by this class.
Header
basic tools for dealng with the ROSPLan knowledge base.
- Authors
- Francesco Ganci 
- Version
- v1.0.0 
Defines
- 
__H_KB_TOOLS__
- 
DEBUG_MODE_ENABLED
- 
SERVICE_QUERY
- 
TIMEOUT_QUERY
- 
SERVICE_QUERY_2
- 
TIMEOUT_QUERY_2
- 
SERVICE_KB_UPDATE
- 
TIMEOUT_KB_UPDATE
- 
SERVICE_KB_GET_FLUENT
- 
TIMEOUT_KB_GET_FLUENT
- 
KB_ADD_KNOWLEDGE
- 
KB_DEL_KNOWLEDGE
- 
KB_ADD_GOAL
- 
KB_DEL_GOAL
- 
KB_KTYPE_FLUENT
- 
KB_KTYPE_PREDICATE
- 
class kb_tools
- #include <kb_tools.h>base interface with the ROS plan knowledge base this interface can be considered a abstraction of the ROS plan knowledge base. the knowledge base is seen as a database containing predicates and fluents, which can be obtaine by GET methods, and set using SET methods. Moreover, the class opens and manages all the services needed to perform such communication with the database, hence the node using this kind of functonality doesn’t need to manually open the required interfaces. Subclassed by kb_interface Public Functions - 
kb_tools()
- class constructor 
 - 
~kb_tools()
- class destructor 
 - 
bool ok()
- check if the last action succeeded or not - Note - this function should be called every time you perform a call to any service. 
 - 
void set_debug_mode(bool dbmode)
- set the log verbosity level - with the debug mode disabled, the class will notify only the opening of the services; otherwise, each method contains a lot of printable messages. - Parameters
- dbmode – if true, the class will print on the log/shell every operations the system will perform. 
 
 - 
bool get_predicate(const std::string &pname, std::map<std::string, std::string> params)
- get value of a predicate - Todo:
- the method assumes that only one result is returned, which is true for fully defined queries, but what about partial queries? 
 - Note - the boolean ‘false’ is returned also when the call fails, so remember to check the valdity of the value using ok - Parameters
- pname – the name of the predicate to get 
- params – the map of the parameters of the predicate to check 
 
- Returns
- true if the predicate is true (and the call succeeded) 
- false if the predicate is false OR if the service call failed, see ok 
 
 
 - 
bool set_predicate(const std::string &pname, std::map<std::string, std::string> params, bool pvalue)
- set the truth value of a predicate - Note - no need here to check the success of the call using ok: the return value is sufficient to understand what’s going on. - Parameters
- pname – the name of the predicate to get 
- params – the map of the parameters of the predicate to check 
- pvalue – the boolean value to set for that predicate 
 
- Returns
- (bool) true if the operation has gone well, false otherwise. 
 
 - 
bool set_goal(const std::string &pname, std::map<std::string, std::string> params, bool pvalue)
- set the truth value of a goal predicate - Note - no need here to check the success of the call using ok: the return value is sufficient to understand what’s going on. - Parameters
- pname – the name of the goal predicate to get 
- params – the map of the parameters of the goal predicate to check 
- pvalue – the boolean value to set for that goal predicate 
 
- Returns
- (bool) true if the operation has gone well, false otherwise. 
 
 Protected Functions - 
rosplan_knowledge_msgs::KnowledgeQueryService request_query(const std::string &pname, std::map<std::string, std::string> ¶ms)
- build a query message (predicates only) - the method returns a message ready for a simple predicate query. just give the name of the predicate you’re searching, and its parameters. - Parameters
- pname – (string) the name of the predicate 
- params – (std::map<std::string, std::string>&) the map of parameters for the predicate 
 
- Returns
- a copy of the message rosplan_knowledge_msgs::KnowledgeQueryService, with the .request field ready for the service request. 
 
 - 
rosplan_knowledge_msgs::KnowledgeUpdateService request_update(const std::string pname, std::map<std::string, std::string> ¶ms, bool value, bool is_goal = false)
- build a update message for predicates - Parameters
- pname – (string) the name of the predicate 
- params – (std::map<std::string, std::string>&) the map of parameters for the predicate 
- value – (bool) the new value of the predicate 
 
- Returns
- a copy of the message rosplan_knowledge_msgs::KnowledgeUpdateService, with the .request field ready for the service request. 
 
 - 
std::map<std::string, std::string> keyvalue2map(const std::vector<diagnostic_msgs::KeyValue> &kv)
- cast a KeyValue message into a simple map - this function is often useful, since the messages of the knowledge base use a lot the message type diagnostic_msgs::KeyValue. - Parameters
- kv – the vector of messages diagnostic_msgs::KeyValue 
- Returns
- a map from that vector 
 
 Protected Attributes - 
ros::NodeHandle nh
- node handle reference 
 - 
bool debug_mode
- debug mode status, - See also 
 Private Functions - 
void open_services()
- open the services with the knowledge base - here is the list of the services opened by this function: - SERVICE_QUERY : rosplan_knowledge_msgs::KnowledgeQueryService> 
- SERVICE_KB_UPDATE : rosplan_knowledge_msgs::KnowledgeUpdateService 
- ??? : ??? 
 
 
- 
kb_tools()