Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added flag to get instances service to include constants or not, default is not. #286

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 41 additions & 14 deletions rosplan_knowledge_base/src/KnowledgeBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -429,16 +429,39 @@ namespace KCL_rosplan {
}

// check if function already exists
bool function_exists = false;
std::vector<rosplan_knowledge_msgs::KnowledgeItem>::iterator pit;
for(pit=model_functions.begin(); pit!=model_functions.end(); pit++) {
if(KnowledgeComparitor::containsKnowledge(msg, *pit)) {
ROS_INFO("KCL: (%s) Updating function (= (%s%s) %f)", ros::this_node::getName().c_str(), msg.attribute_name.c_str(), param_str.c_str(), msg.function_value);
pit->function_value = msg.function_value;
return;
switch(msg.assign_op) {
case rosplan_knowledge_msgs::KnowledgeItem::AP_ASSIGN:
ROS_INFO("KCL: (%s) Updating function (= (%s%s) %f)", ros::this_node::getName().c_str(), msg.attribute_name.c_str(), param_str.c_str(), msg.function_value);
pit->function_value = msg.function_value;
break;
case rosplan_knowledge_msgs::KnowledgeItem::AP_SCALE_UP:
case rosplan_knowledge_msgs::KnowledgeItem::AP_INCREASE:
pit->function_value = pit->function_value + msg.function_value;
ROS_INFO("KCL: (%s) Increasing function (= (%s%s) %f)", ros::this_node::getName().c_str(), msg.attribute_name.c_str(), param_str.c_str(), pit->function_value);
break;
case rosplan_knowledge_msgs::KnowledgeItem::AP_SCALE_DOWN:
case rosplan_knowledge_msgs::KnowledgeItem::AP_DECREASE:
pit->function_value = pit->function_value - msg.function_value;
ROS_INFO("KCL: (%s) Decreasing function (= (%s%s) %f)", ros::this_node::getName().c_str(), msg.attribute_name.c_str(), param_str.c_str(), pit->function_value);
break;
case rosplan_knowledge_msgs::KnowledgeItem::AP_ASSIGN_CTS:
ROS_WARN("KCL: (%s) Continuous numeric effects not implemented in function updating.", ros::this_node::getName().c_str());
break;
}
function_exists = true;
break;
}
}
ROS_INFO("KCL: (%s) Adding function (= (%s%s) %f)", ros::this_node::getName().c_str(), msg.attribute_name.c_str(), param_str.c_str(), msg.function_value);
model_functions.push_back(msg);
if (!function_exists && msg.assign_op==rosplan_knowledge_msgs::KnowledgeItem::AP_ASSIGN) {
ROS_INFO("KCL: (%s) Adding function (= (%s%s) %f)", ros::this_node::getName().c_str(), msg.attribute_name.c_str(), param_str.c_str(), msg.function_value);
model_functions.push_back(msg);
} else if (!function_exists) {
ROS_INFO("KCL: (%s) Ignoring function update (%s%s) function does not exist", ros::this_node::getName().c_str(), msg.attribute_name.c_str(), param_str.c_str());
}
}
break;

Expand Down Expand Up @@ -493,10 +516,12 @@ namespace KCL_rosplan {
res.instances.push_back(iit->second[j]);
}
// constants
for(iit=domain_constants.begin(); iit != domain_constants.end(); iit++) {
for(size_t j=0; j<iit->second.size(); j++)
res.instances.push_back(iit->second[j]);
}
if (req.include_constants) {
for(iit=domain_constants.begin(); iit != domain_constants.end(); iit++) {
for(size_t j=0; j<iit->second.size(); j++)
res.instances.push_back(iit->second[j]);
}
}
} else {
std::map<std::string,std::vector<std::string> >::iterator iit;
// objects
Expand All @@ -506,11 +531,13 @@ namespace KCL_rosplan {
res.instances.push_back(iit->second[j]);
}
// constants
iit = domain_constants.find(req.type_name);
if(iit != domain_constants.end()) {
for(size_t j=0; j<iit->second.size(); j++)
res.instances.push_back(iit->second[j]);
}
if (req.include_constants) {
iit = domain_constants.find(req.type_name);
if(iit != domain_constants.end()) {
for(size_t j=0; j<iit->second.size(); j++)
res.instances.push_back(iit->second[j]);
}
}
}

return true;
Expand Down
10 changes: 10 additions & 0 deletions rosplan_knowledge_msgs/msg/KnowledgeItem.msg
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,16 @@ diagnostic_msgs/KeyValue[] values
# function value
float64 function_value

# assignment operator
uint8 AP_ASSIGN = 0
uint8 AP_INCREASE = 1
uint8 AP_DECREASE = 2
uint8 AP_SCALE_UP = 3
uint8 AP_SCALE_DOWN = 4
uint8 AP_ASSIGN_CTS = 5

uint8 assign_op

#-----------
# EXPRESSION
#-----------
Expand Down
1 change: 1 addition & 0 deletions rosplan_knowledge_msgs/srv/GetInstanceService.srv
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# PDDL problem generation; service(1/3):
# Get all instances of the type with the name 'typeName'.
string type_name
bool include_constants
---
string[] instances