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
41 changes: 39 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,11 @@ find_package(catkin REQUIRED COMPONENTS
knowrob
)
find_package(spdlog REQUIRED)
find_package(rostest REQUIRED)

## =============================
## ROS message generation
## =============================
add_message_files(
DIRECTORY msg
FILES
Expand All @@ -29,7 +33,6 @@ add_message_files(
TellMessage.msg
GraphQueryMessage.msg
GraphAnswerMessage.msg
EventToken.msg
)
add_action_files(
DIRECTORY action
Expand All @@ -50,7 +53,10 @@ generate_messages(DEPENDENCIES
actionlib_msgs
)

catkin_package(CATKIN_DEPENDS roscpp roslib knowrob message_runtime)
## =============================
## Catkin package
## =============================
catkin_package(CATKIN_DEPENDS roscpp roslib rospy knowrob message_runtime)

include_directories(include ${catkin_INCLUDE_DIRS})

Expand All @@ -65,4 +71,35 @@ add_dependencies(knowrob-ros

target_link_libraries(knowrob-ros ${catkin_LIBRARIES} spdlog::spdlog)

## =============================
## Python library installation
## =============================

# Install Python library (e.g., knowrob_ros_lib.py)
# With this:
file (COPY
${CMAKE_CURRENT_SOURCE_DIR}/src/knowrob_ros_lib/knowrob_ros_lib.py
DESTINATION ${CATKIN_DEVEL_PREFIX}/lib/python3/dist-packages/knowrob_ros/
)

catkin_install_python(PROGRAMS
scripts/test_knowrob_ros_lib.py
DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION}
)

## =============================
## Install binaries
## =============================

install(TARGETS knowrob-ros RUNTIME DESTINATION bin)

## =============================
## Install test files
## =============================

if (CATKIN_ENABLE_TESTING)
catkin_add_nosetests(
test/test_knowrob_ros_lib.test
DEPENDENCIES ${catkin_EXPORTED_TARGETS}
)
endif()
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ WORKDIR /catkin_ws
RUN /usr/bin/catkin init
RUN . /opt/ros/noetic/setup.sh && /usr/bin/catkin build

RUN echo "aaaa"
# Build workspace with knowrob_ros
WORKDIR /catkin_ws/src
ADD . /catkin_ws/src/knowrob_ros
Expand Down
21 changes: 13 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,18 +74,23 @@ Then run a query on another terminal:
```bash
rostopic pub /knowrob/askone/goal knowrob_ros/AskOneActionGoal "header:
seq: 0
stamp:
secs: 0
nsecs: 0
stamp: {secs: 0, nsecs: 0}
frame_id: ''
goal_id:
stamp:
secs: 0
nsecs: 0
stamp: {secs: 0, nsecs: 0}
id: ''
goal:
query: {lang: '', queryString: 'lpn:jealous(lpn:vincent, X)', epistemicOperator: 0, aboutAgentIRI: '', aboutSimulationIRI: '',
temporalOperator: 0, minPastTimestamp: 0.0, maxPastTimestamp: 0.0, confidence: 0.0}"
query:
lang: ''
queryString: 'lpn:jealous(lpn:vincent, X)'
frame:
epistemicOperator: 0
aboutAgentIRI: ''
aboutSimulationIRI: ''
temporalOperator: 0
minPastTimestamp: 0.0
maxPastTimestamp: 0.0
confidence: 0.0"
```

You should now see an answer on the first terminal.
2 changes: 1 addition & 1 deletion action/AskAll.action
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ byte FALSE = 0
byte TRUE = 1
byte QUERY_FAILED = 2

GraphAnswerMessage[] answer
GraphAnswerMessage[] answers
byte status
---
uint32 numberOfSolutions
8 changes: 0 additions & 8 deletions msg/EventToken.msg

This file was deleted.

2 changes: 1 addition & 1 deletion msg/GraphQueryMessage.msg
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Languages in which graph queries can be encoded.
uint8 LANG_FOL=0 # Prolog-like syntax, @see ....
string LANG_FOL="LANG_FOL" # Prolog-like syntax, @see ....

# Configure the language in which the graph query is encoded.
string lang # Default: LANG_FOL
Expand Down
3 changes: 3 additions & 0 deletions package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,14 @@
<build_depend>visualization_msgs</build_depend>
<exec_depend>message_runtime</exec_depend>
<exec_depend>actionlib</exec_depend>
<test_depend>rostest</test_depend>
<test_depend>python3</test_depend>

<depend>roslib</depend>
<depend>roscpp</depend>
<depend>knowrob</depend>
<depend>spdlog</depend>
<depend>rospy</depend>
<depend>libmongoc-dev</depend>
<depend>fmt</depend>
</package>
76 changes: 76 additions & 0 deletions scripts/test_knowrob_ros_lib.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
from knowrob_ros.knowrob_ros_lib import KnowRobRosLib, graph_answer_to_dict, get_default_modalframe, graph_answers_to_list
import unittest
import rosunit
from knowrob_ros.msg import (
KeyValuePair,
AskOneAction,
AskOneGoal,
AskOneResult,
AskAllAction,
AskAllGoal,
AskAllResult,
GraphQueryMessage,
GraphAnswerMessage,
)

class TestKnowrobRosLib(unittest.TestCase):
def test_ask_all(self):
# Test the ask_one function
ask_all_result = self.knowrob_ros.ask_all("lpn:jealous(lpn:vincent, X)", get_default_modalframe())
self.assertTrue(ask_all_result.status == AskAllResult.TRUE)
result_dict = graph_answers_to_list(ask_all_result.answers)
print("Result dict:", str(result_dict))
self.assertEqual(result_dict, [{
'X': 'http://knowrob.org/kb/lpn#marsellus'
}])

def test_ask_one(self):
# Test the ask_one function
ask_one_result = self.knowrob_ros.ask_one("lpn:jealous(lpn:vincent, X)", get_default_modalframe())
self.assertTrue(ask_one_result.status == AskOneResult.TRUE)
result_dict = graph_answer_to_dict(ask_one_result.answer)
print("Result dict:", str(result_dict))
self.assertEqual(result_dict, {
'X': 'http://knowrob.org/kb/lpn#marsellus'
})

# def test_tell(self):
# # Create the triples to be added
# builder = knowrob_ros_lib.TripleQueryBuilder()
# builder.add("alice", "knows", "bob")
# builder.add("bob", "likes", "pizza")
# query_str = builder.build_query_string()

# # Test the tell function
# result = knowrob_ros.tell(query_str)
# self.assertTrue(result.success)
# result = knowrob_ros.ask_all("lpn:jelous(alice, X)")
# self.assertEqual(result.bindings, [{
# 'X': 'pizza'
# }])

# Init the test class
@classmethod
def setUpClass(cls):
# Initialize the knowrob_ros_lib
cls.knowrob_ros = KnowRobRosLib()
# Initialize the ROS node
cls.knowrob_ros.init_node("test_knowrob_ros_lib")

@classmethod
def tearDownClass(cls):
# Shutdown the ROS node
cls.knowrob_ros.shutdown_node()

@classmethod
def setUpClass(cls):
cls.knowrob_ros = KnowRobRosLib()
cls.knowrob_ros.init_node("test_knowrob_ros_lib")


if __name__ == '__main__':
rosunit.unitrun(
'knowrob_ros', # your package
'test_knowrob_ros_lib', # test name
TestKnowrobRosLib # your TestCase
)
2 changes: 1 addition & 1 deletion src/ROSInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ void ROSInterface::executeAskAllCB(const AskAllGoalConstPtr &goal) {
} else {
// Push one answer
GraphAnswerMessage graphAns = createGraphAnswer(positiveAnswer);
result.answer.push_back(graphAns);
result.answers.push_back(graphAns);
numSolutions_ += 1;
// publish feedback
AskAllFeedback feedback;
Expand Down
67 changes: 0 additions & 67 deletions src/action_streamer.py

This file was deleted.

File renamed without changes.
Loading