Skip to content
Merged
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
3 changes: 3 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ add_message_files(
DIRECTORY msg
FILES
KeyValuePair.msg
ModalFrame.msg
Triple.msg
TellMessage.msg
GraphQueryMessage.msg
GraphAnswerMessage.msg
EventToken.msg
Expand Down
12 changes: 7 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,19 @@ RUN apt install -y ros-noetic-tf2-geometry-msgs
RUN mkdir /catkin_ws
RUN mkdir /catkin_ws/src

# Build workspace with knowrob
WORKDIR /catkin_ws/src
# Clone the knowrob repository
RUN git clone https://github.com/knowrob/knowrob.git
# Add the knowrob-ros1 repository
ADD . /catkin_ws/src/knowrob_ros

WORKDIR /catkin_ws
# Build the catkin workspace
RUN /usr/bin/catkin init
RUN . /opt/ros/noetic/setup.sh && /usr/bin/catkin build

# Build workspace with knowrob_ros
WORKDIR /catkin_ws/src
ADD . /catkin_ws/src/knowrob_ros
WORKDIR /catkin_ws
RUN . /opt/ros/noetic/setup.sh && /usr/bin/catkin build

COPY run_knowrob.sh /run_knowrob.sh
COPY run_knowrob_local.sh /run_knowrob_local.sh

Expand Down
2 changes: 1 addition & 1 deletion action/Tell.action
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
GraphQueryMessage query
TellMessage tell
---
byte TRUE = 0
byte TELL_FAILED = 1
Expand Down
5 changes: 4 additions & 1 deletion include/ROSInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include "knowrob/KnowledgeBase.h"
#include "knowrob/queries/QueryParser.h"
#include "knowrob/formulas/ModalFormula.h"
#include "knowrob/terms/String.h"
// ROS
#include <ros/ros.h>
#include <ros/console.h>
Expand All @@ -28,7 +29,9 @@
#include <knowrob_ros/AskIncrementalNextSolutionAction.h>
#include <knowrob_ros/AskIncrementalFinish.h>
#include <knowrob_ros/TellAction.h>
#include <knowrob_ros/ModalFrame.h>
#include <actionlib/server/simple_action_server.h>

// std
#include <mutex>

Expand Down Expand Up @@ -114,7 +117,7 @@ namespace knowrob {
* @param query A GraphQueryMessage
* @return Map of key-value pairs
*/
std::unordered_map<std::string, boost::any> translateGraphQueryMessage(const GraphQueryMessage &query);
std::unordered_map<std::string, boost::any> translateModalityFrameMessage(const ModalFrame &frame);

/**
* Translate a answer into a GraphAnswerMessage
Expand Down
56 changes: 2 additions & 54 deletions msg/GraphQueryMessage.msg
Original file line number Diff line number Diff line change
@@ -1,21 +1,6 @@
# Languages in which graph queries can be encoded.
uint8 LANG_FOL=0 # Prolog-like syntax, @see ....

# Epistemic operators distinguishing knowledge and belief.
# Note that the operators can be indexed by an agent
# meaning that another agent has the knowledge or belief.
uint8 KNOWLEDGE=0 # "it is certain that ..."
uint8 BELIEF=1 # "it could be that ..."

# Temporal operators used to query truth
# of statements within time intervals.
uint8 CURRENTLY=0 # "it is now the case that ..."
uint8 ALL_PAST=1 # "it always was that ..."
uint8 SOME_PAST=2 # "it was the case that ..."

# Used to indicate that a timestamp remains unspecified.
float64 UNSPECIFIED_TIMESTAMP=-1.0

# Configure the language in which the graph query is encoded.
string lang # Default: LANG_FOL

Expand All @@ -26,42 +11,5 @@ string lang # Default: LANG_FOL
# via the "lang" field.
string queryString

# Determines the epistemic modality which is concerned
# with distinguishing knowledge (certain) from belief (uncertain).
# Defaults to KNOWLEDGE modality.
uint8 epistemicOperator # Default: KNOWLEDGE

# The IRI of another agent (i.e. not the controlled agent).
# Used to query whether another agent might has some knowledge
# or belief. This is thought to be used in HRI and multirobot
# scenarios where the robot estimates knowledge and belief of
# another agent.
# Defaults to empty string indicating that the query is about
# the agent's own knowledge or belief.
# Cannot be set in parallel with the aboutSimulationIRI parameter
string aboutAgentIRI # Default: ""

# The IRI to an KG of a mental simulation.
# The IRI will be returned as the output of an MentalSimulation
# Action. This is thought to be used in mental emulation
# and also visual anticipation tasks.
# Defaults to empty string indicating that the query is about
# the agen'ts own knowledge or beliefstate.
# Cannot be set in parallel with the aboutAgenIRI parameter
string aboutSimulationIRI # Default: ""

# Determines the temporal modality of the query.
# Temporal modalities are used to cope with characteristics
# that change over time.
uint8 temporalOperator # Default: CURRENTLY

# The time interval considered by the past operator can be constrained
# by min/max timestamp parameters.
# If minPastTimestamp>0, then statements are only considered that are
# true after the time indicated by minPastTimestamp. Similarly for maxPastTimestamp.
# It is also allowed to set only one of the fields to a positive value.
float64 minPastTimestamp # Default: UNSPECIFIED_TIMESTAMP
float64 maxPastTimestamp # Default: UNSPECIFIED_TIMESTAMP

# The minimal confidence of the statement
float64 confidence # Default: 0.0
# Determines the modal frame in which the triple is assumed to be true.
ModalFrame frame
54 changes: 54 additions & 0 deletions msg/ModalFrame.msg
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# Epistemic operators distinguishing knowledge and belief.
# Note that the operators can be indexed by an agent
# meaning that another agent has the knowledge or belief.
uint8 KNOWLEDGE=0 # "it is certain that ..."
uint8 BELIEF=1 # "it could be that ..."

# Temporal operators used to query truth
# of statements within time intervals.
uint8 CURRENTLY=0 # "it is now the case that ..."
uint8 ALL_PAST=1 # "it always was that ..."
uint8 SOME_PAST=2 # "it was the case that ..."

# Used to indicate that a timestamp remains unspecified.
float64 UNSPECIFIED_TIMESTAMP=-1.0

# Determines the epistemic modality which is concerned
# with distinguishing knowledge (certain) from belief (uncertain).
# Defaults to KNOWLEDGE modality.
uint8 epistemicOperator # Default: KNOWLEDGE

# The IRI of another agent (i.e. not the controlled agent).
# Used to query whether another agent might has some knowledge
# or belief. This is thought to be used in HRI and multirobot
# scenarios where the robot estimates knowledge and belief of
# another agent.
# Defaults to empty string indicating that the query is about
# the agent's own knowledge or belief.
# Cannot be set in parallel with the aboutSimulationIRI parameter
string aboutAgentIRI # Default: ""

# The IRI to an KG of a mental simulation.
# The IRI will be returned as the output of an MentalSimulation
# Action. This is thought to be used in mental emulation
# and also visual anticipation tasks.
# Defaults to empty string indicating that the query is about
# the agen'ts own knowledge or beliefstate.
# Cannot be set in parallel with the aboutAgenIRI parameter
string aboutSimulationIRI # Default: ""

# Determines the temporal modality of the query.
# Temporal modalities are used to cope with characteristics
# that change over time.
uint8 temporalOperator # Default: CURRENTLY

# The time interval considered by the past operator can be constrained
# by min/max timestamp parameters.
# If minPastTimestamp>0, then statements are only considered that are
# true after the time indicated by minPastTimestamp. Similarly for maxPastTimestamp.
# It is also allowed to set only one of the fields to a positive value.
float64 minPastTimestamp # Default: UNSPECIFIED_TIMESTAMP
float64 maxPastTimestamp # Default: UNSPECIFIED_TIMESTAMP

# The minimal confidence of the statement
float64 confidence # Default: 0.0
2 changes: 2 additions & 0 deletions msg/TellMessage.msg
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Triple[] triples
ModalFrame frame
3 changes: 3 additions & 0 deletions msg/Triple.msg
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
string subject
string predicate
string object
42 changes: 28 additions & 14 deletions src/ROSInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,15 @@ ROSInterface::ROSInterface(const boost::property_tree::ptree &config)
ROSInterface::~ROSInterface() = default;

// Function to convert GraphQueryMessage to std::unordered_map
std::unordered_map<std::string, boost::any> ROSInterface::translateGraphQueryMessage(const GraphQueryMessage &query) {
std::unordered_map<std::string, boost::any> ROSInterface::translateModalityFrameMessage(const ModalFrame &frame) {
std::unordered_map<std::string, boost::any> options;

options["epistemicOperator"] = int(query.epistemicOperator);
options["aboutAgentIRI"] = query.aboutAgentIRI;
options["confidence"] = query.confidence;
options["temporalOperator"] = int(query.temporalOperator);
options["minPastTimestamp"] = query.minPastTimestamp;
options["maxPastTimestamp"] = query.maxPastTimestamp;
options["epistemicOperator"] = int(frame.epistemicOperator);
options["aboutAgentIRI"] = frame.aboutAgentIRI;
options["confidence"] = frame.confidence;
options["temporalOperator"] = int(frame.temporalOperator);
options["minPastTimestamp"] = frame.minPastTimestamp;
options["maxPastTimestamp"] = frame.maxPastTimestamp;

return options;
}
Expand Down Expand Up @@ -130,10 +130,9 @@ GraphAnswerMessage ROSInterface::createGraphAnswer(std::shared_ptr<const AnswerY

void ROSInterface::executeAskAllCB(const AskAllGoalConstPtr &goal) {

// Implement your action here
FormulaPtr phi(QueryParser::parse(goal->query.queryString));

FormulaPtr mPhi = InterfaceUtils::applyModality(translateGraphQueryMessage(goal->query), phi);
FormulaPtr mPhi = InterfaceUtils::applyModality(translateModalityFrameMessage(goal->query.frame), phi);

auto ctx = std::make_shared<QueryContext>(QUERY_FLAG_ALL_SOLUTIONS);
auto resultStream = kb_->submitQuery(mPhi, ctx);
Expand Down Expand Up @@ -178,10 +177,9 @@ void ROSInterface::executeAskAllCB(const AskAllGoalConstPtr &goal) {
void ROSInterface::executeAskIncrementalCB(const AskIncrementalGoalConstPtr &goal) {
std::lock_guard<std::mutex> lock(query_mutex_);

// Implement your action here
FormulaPtr phi(QueryParser::parse(goal->query.queryString));

FormulaPtr mPhi = InterfaceUtils::applyModality(translateGraphQueryMessage(goal->query), phi);
FormulaPtr mPhi = InterfaceUtils::applyModality(translateModalityFrameMessage(goal->query.frame), phi);

auto ctx = std::make_shared<QueryContext>(QUERY_FLAG_ALL_SOLUTIONS);
auto resultStream = kb_->submitQuery(mPhi, ctx);
Expand Down Expand Up @@ -275,9 +273,10 @@ bool ROSInterface::handleAskIncrementalFinish(AskIncrementalFinish::Request &req
}

void ROSInterface::executeAskOneCB(const AskOneGoalConstPtr &goal) {

FormulaPtr phi(QueryParser::parse(goal->query.queryString));

FormulaPtr mPhi = InterfaceUtils::applyModality(translateGraphQueryMessage(goal->query), phi);
FormulaPtr mPhi = InterfaceUtils::applyModality(translateModalityFrameMessage(goal->query.frame), phi);

auto ctx = std::make_shared<QueryContext>(QUERY_FLAG_ALL_SOLUTIONS);
auto resultStream = kb_->submitQuery(mPhi, ctx);
Expand Down Expand Up @@ -307,9 +306,24 @@ void ROSInterface::executeAskOneCB(const AskOneGoalConstPtr &goal) {
}

void ROSInterface::executeTellCB(const TellGoalConstPtr &goal) {
FormulaPtr phi(QueryParser::parse(goal->query.queryString));

FormulaPtr mPhi = InterfaceUtils::applyModality(translateGraphQueryMessage(goal->query), phi);
// Create a vector of Formulas
std::vector<FormulaPtr> formulas;
// For each triple
for (const auto &triple: goal->tell.triples) {
// Create a vector of Terms for subject and object
std::vector<TermPtr> terms;
// Add subject
terms.push_back(std::make_shared<String>(triple.subject.data()));
// Add object
terms.push_back(std::make_shared<String>(triple.object.data()));
// Add to formulas
formulas.push_back(std::make_shared<Predicate>(triple.predicate, terms));
}
// Create conjunction of all formulas
FormulaPtr phi = std::make_shared<Conjunction>(formulas);

FormulaPtr mPhi = InterfaceUtils::applyModality(translateModalityFrameMessage(goal->tell.frame), phi);

bool success = InterfaceUtils::assertStatements(kb_, {mPhi});

Expand Down