Skip to content

Commit e69a206

Browse files
author
Michael Neumann
committed
update interface
1 parent 1560ea3 commit e69a206

File tree

1 file changed

+65
-70
lines changed

1 file changed

+65
-70
lines changed

neem-interface.pl

Lines changed: 65 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -4,31 +4,29 @@
44

55
mem_clear_memory() :-
66
drop_graph(user),
7-
tf_mem_clear, mng_drop(roslog, tf),
8-
wrench_mem_clear, wrench_mng_drop.
7+
tf_mem_clear,
8+
mng_drop(roslog, tf).
99

10-
mem_episode_start(Action, TaskType, EnvOwl, EnvOwlIndiName, EnvUrdf, AgentOwl, AgentOwlIndiName, AgentUrdf) :-
10+
mem_episode_start(Action, EnvOwl, EnvOwlIndiName, EnvUrdf, EnvUrdfPrefix, AgentOwl, AgentOwlIndiName, AgentUrdf) :-
1111
get_time(StartTime),
12-
mem_episode_start(Action, TaskType, EnvOwl, EnvOwlIndiName, EnvUrdf, AgentOwl, AgentOwlIndiName, AgentUrdf, StartTime).
12+
mem_episode_start(Action, EnvOwl, EnvOwlIndiName, EnvUrdf, EnvUrdfPrefix, AgentOwl, AgentOwlIndiName, AgentUrdf, StartTime).
1313

14-
mem_episode_start(Action, TaskType, EnvOwl, EnvOwlIndiName, EnvUrdf, AgentOwl, AgentOwlIndiName, AgentUrdf,
15-
StartTime) :-
14+
mem_episode_start(Action, EnvOwl, EnvOwlIndiName, EnvUrdf, EnvUrdfPrefix, AgentOwl, AgentOwlIndiName, AgentUrdf, StartTime) :-
1615
retractall(execution_agent(_)),
17-
tf_logger_disable, wrench_logger_disable,
16+
tf_logger_disable,
1817
mem_clear_memory,
19-
tf_logger_enable, wrench_logger_enable,
20-
% load_owl('package://knowrob/owl/knowrob.owl',[namespace(knowrob)]), % Is always loaded when knowrob starts
18+
tf_logger_enable,
2119
load_owl(EnvOwl),
2220
load_owl(AgentOwl),
2321
urdf_load(AgentOwlIndiName, AgentUrdf, [load_rdf]),
24-
urdf_load(EnvOwlIndiName, EnvUrdf, [load_rdf]),
22+
urdf_load(EnvOwlIndiName, EnvUrdf, [load_rdf,prefix(EnvUrdfPrefix)]),
2523
assertz(execution_agent(AgentOwlIndiName)),
2624
execution_agent(Agent),
2725
kb_project([
2826
new_iri(Episode, soma:'Episode'), is_episode(Episode), % Using new_iri here and below is a hideous workaround for a KnowRob bug, see https://github.com/knowrob/knowrob/issues/299
2927
new_iri(Action, dul:'Action'), is_action(Action),
3028
new_iri(TimeInterval, dul:'TimeInterval'), holds(Action, dul:'hasTimeInterval', TimeInterval), holds(TimeInterval, soma:'hasIntervalBegin', StartTime),
31-
new_iri(Task, dul:'Task'), instance_of(Task,TaskType), executes_task(Action,Task),
29+
new_iri(Task, dul:'Task'), has_type(Task,soma:'PhysicalTask'), executes_task(Action,Task),
3230
is_setting_for(Episode,Action),
3331
is_performed_by(Action,Agent),
3432
new_iri(Role, soma:'AgentRole'), has_type(Role, soma:'AgentRole'), has_role(Agent,Role)
@@ -48,6 +46,7 @@
4846
is_episode(Episode), is_action(Action), is_setting_for(Episode,Action),
4947
holds(Action, dul:'hasTimeInterval', TimeInterval)
5048
]),
49+
ignore(kb_unproject(triple(TimeInterval, soma:'hasIntervalEnd', double('Infinity')))),
5150
kb_project([
5251
holds(TimeInterval, soma:'hasIntervalEnd', EndTime)
5352
]),
@@ -59,78 +58,78 @@
5958

6059
mem_event_add_diagnosis(Situation, Diagnosis) :- kb_project(satisfies(Situation, Diagnosis)).
6160

62-
mem_add_subaction_with_task(ParentAction,SubActionType,TaskType,SubAction) :-
61+
add_subaction_with_task(ParentAction,SubAction,TaskType) :-
6362
execution_agent(Agent),
6463
kb_project([
65-
new_iri(SubAction, SubActionType), is_individual(SubAction), instance_of(SubAction,SubActionType),
66-
new_iri(Task, TaskType), is_individual(Task), instance_of(Task,TaskType), executes_task(SubAction,Task),
67-
% % has_subevent(ParentAction,SubAction), <-- has_subevent is currently broken in KnowRob (https://github.com/knowrob/knowrob/issues/300)
64+
new_iri(SubAction, dul:'Action'), has_type(SubAction,soma:'Action'),
65+
new_iri(Task, TaskType), has_type(Task,TaskType), executes_task(SubAction,Task),
6866
holds(ParentAction,dul:hasConstituent,SubAction), % replacement for has_subevent
6967
is_performed_by(SubAction,Agent)
7068
]),!.
7169

72-
% mem_event_end(Event) :- execution_agent(Agent), get_time(CurrentTime), kb_call([triple(Event,dul:'hasTimeInterval',TimeInterval), triple(TimeInterval,soma:'hasIntervalBegin', Start), executes_task(Event,Task)]),kb_unproject(TimeInterval, soma:'hasIntervalEnd', _),kb_project([holds(TimeInterval, soma:'hasIntervalEnd', CurrentTime),has_type(Role, soma:'AgentRole'), has_role(Agent,Role) during Event,task_role(Task, Role)]),!.
73-
74-
% mem_event_begin(Event) :- get_time(CurrentTime),kb_project(occurs(Event) since CurrentTime),!.
70+
mem_event_end(Event) :- execution_agent(Agent),
71+
get_time(CurrentTime),
72+
kb_call([
73+
triple(Event,dul:'hasTimeInterval',TimeInterval),
74+
triple(TimeInterval,soma:'hasIntervalBegin', Start), executes_task(Event,Task)]),
75+
ignore(kb_unproject(triple(TimeInterval, soma:'hasIntervalEnd', double('Infinity')))),
76+
kb_project([holds(TimeInterval, soma:'hasIntervalEnd', CurrentTime),new_iri(Role, soma:'AgentRole'),has_type(Role, soma:'AgentRole')]),
77+
kb_project([has_role(Agent,Role) during Event, task_role(Task, Role)]),!.
78+
mem_event_begin(Event) :- get_time(CurrentTime),kb_project(occurs(Event) since CurrentTime),!.
7579

7680
%belief_perceived_at(ObjectType, Frame, Object) :- get_time(CurrentTime),execution_agent(Agent),kb_project([has_type(Object,ObjectType),is_at(Object,Frame) since CurrentTime]).
7781

78-
belief_perceived_at(ObjectType, Mesh, Rotation, Object) :- kb_project([has_type(Object,ObjectType),has_type(ShapeRegion, soma:'MeshShape'), has_type(Shape, soma:'Shape'), triple(Object, soma:'hasShape', Shape), triple(Shape, dul:'hasRegion', ShapeRegion), triple(ShapeRegion, soma:'hasFilePath', Mesh),has_type(Origin,soma:'Origin'),triple(ShapeRegion,'http://knowrob.org/kb/urdf.owl#hasOrigin',Origin),triple(Origin, 'http://www.ease-crc.org/ont/SOMA.owl#hasPositionVector', term([0.0,0.0,0.0])),triple(Origin, 'http://www.ease-crc.org/ont/SOMA.owl#hasOrientationVector',term(Rotation))]).
82+
belief_perceived_at(ObjectType, Mesh, Rotation, Object) :- kb_project([
83+
has_type(Object,ObjectType),
84+
new_iri(ShapeRegion,soma:'MeshShape'), has_type(ShapeRegion, soma:'MeshShape'),
85+
new_iri(Shape, soma:'Shape'), has_type(Shape, soma:'Shape'),
86+
triple(Object, soma:'hasShape', Shape),
87+
triple(Shape, dul:'hasRegion', ShapeRegion),
88+
triple(ShapeRegion, soma:'hasFilePath', Mesh),
89+
new_iri(Origin, soma:'Origin'), has_type(Origin,soma:'Origin'),
90+
triple(ShapeRegion,'http://knowrob.org/kb/urdf.owl#hasOrigin',Origin),
91+
triple(Origin, 'http://www.ease-crc.org/ont/SOMA.owl#hasPositionVector', term([0.0,0.0,0.0])),
92+
triple(Origin, 'http://www.ease-crc.org/ont/SOMA.owl#hasOrientationVector', term(Rotation))]).
7993

8094
belief_perceived_at(ObjectType, Object) :- kb_project([has_type(Object,ObjectType)]).
8195

82-
mem_tf_set(Object, Pose, Timestamp) :-
96+
mem_tf_set(Object, ReferenceFrame, Position, Rotation, Timestamp) :-
8397
time_scope(=(Timestamp), =<('Infinity'), FScope),
84-
tf_set_pose(Object, Pose, FScope).
98+
tf_set_pose(Object, [ReferenceFrame, Position, Rotation], FScope).
8599

86-
mem_tf_get(Object, Pose) :-
100+
mem_tf_get(Object, ReferenceFrame, Position, Rotation) :-
87101
current_scope(QScope),
88-
tf_get_pose(Object, Pose, QScope, _).
102+
tf_get_pose(Object, [ReferenceFrame, Position, Rotation], QScope, _).
89103

90-
mem_tf_get(Object, Pose, Timestamp) :-
104+
mem_tf_get(Object, ReferenceFrame, Position, Rotation, Timestamp) :-
91105
time_scope(=(Timestamp), =(Timestamp), QScope),
92-
tf_get_pose(Object, Pose, QScope, _).
93-
94-
mem_wrench_set(Object, Force, Torque, Timestamp) :-
95-
write('mem_wrench_set, object: '),
96-
write(Object),
97-
write('\n'),
98-
time_scope(=(Timestamp), =<('Infinity'), FScope),
99-
wrench_set(Object, [Force, Torque], FScope),
100-
write('wrench_set succeeded\n').
101-
102-
mem_add_participant_with_role(Action, ObjectId, RoleType) :-
103-
kb_call(executes_task(Action, Task)),
104-
kb_project([
105-
has_participant(Action,ObjectId),
106-
new_iri(Role, dul:'Role'), is_individual(Role), instance_of(Role, RoleType),
107-
has_task_role(Task, Role),
108-
has_role(ObjectId, Role)
109-
]).
110-
111-
add_parameter(Task, ParameterType, RegionType, Parameter) :-
112-
kb_project([
113-
new_iri(Parameter, dul:Parameter),
114-
has_type(Parameter, ParameterType),
115-
has_parameter(Task, Parameter),
116-
new_iri(Region, dul:Region),
117-
has_type(Region, RegionType),
118-
has_assignment(Parameter, Region)
119-
]).
120-
121-
add_named_parameter(Task, ParameterType, ParameterName, RegionType, Parameter) :-
122-
add_parameter(Task, ParameterType, RegionType, Parameter),
123-
kb_project(holds(Parameter, soma:hasNameString, ParameterName)).
124-
125-
% set_parameter_value_during_interval(Parameter, ParameterValue, Begin, End) :-
126-
% has_assignment(Parameter, Region),
127-
% kb_project(holds(Region, dul:hasRegionDataValue, ParameterValue) during [Begin, End]).
128-
129-
set_parameter_value(Parameter, ParameterValue) :-
130-
has_assignment(Parameter, Region),
131-
kb_project(holds(Region, dul:hasRegionDataValue, ParameterValue)).
132-
133-
add_grasping_parameter(Action,GraspingOrientationType) :- kb_call(executes_task(Action, Task)), kb_project([has_type(GraspingOrientation,GraspingOrientationType), has_type(GraspingOrientationConcept,'http://www.ease-crc.org/ont/SOMA.owl#GraspingOrientation'), has_parameter(Task,GraspingOrientationConcept),holds(GraspingOrientationConcept, dul:classifies, GraspingOrientation),has_region(Action,GraspingOrientation)]),!.
106+
tf_get_pose(Object, [ReferenceFrame, Position, Rotation], QScope, _).
107+
108+
add_participant_with_role(Action, ObjectId, RoleType) :-
109+
kb_call([executes_task(Action, Task),
110+
triple(Event,dul:'hasTimeInterval',TimeInterval),
111+
triple(TimeInterval,soma:'hasIntervalBegin',Start),
112+
triple(TimeInterval,soma:'hasIntervalEnd',End)]),
113+
kb_project([has_participant(Action,ObjectId),
114+
has_type(Role, RoleType),
115+
has_role(ObjectId,Role) during Action,task_role(Task, Role)]).
116+
%kb_project([holds(TimeInterval, soma:'hasIntervalEnd', CurrentTime),new_iri(Role, soma:'AgentRole'),has_type(Role, soma:'AgentRole')]),
117+
%kb_project([has_role(Agent,Role) during Event, task_role(Task, Role)]),!.
118+
119+
%add_participant_with_role(Action, ObjectId, RoleType) :- kb_call(executes_task(Action, Task)), kb_project([has_participant(Action,ObjectId), has_type(Role, RoleType), has_role(ObjectId,Role) during [0.0,0.0]]).
120+
121+
add_parameter(Task,ParameterType,RegionType) :- kb_project([new_iri(Parameter, ParameterType), has_type(Parameter, ParameterType),
122+
new_iri(Region,RegionType),has_type(Region,RegionType),
123+
has_assignment(Parameter,Region) during [0.0,0.1],
124+
has_parameter(Task, Parameter)]).
125+
126+
add_grasping_parameter(Action,GraspingOrientationType) :- kb_call(executes_task(Action, Task)),
127+
kb_project([new_iri(GraspingOrientation,GraspingOrientationType), has_type(GraspingOrientation,GraspingOrientationType),
128+
new_iri(GraspingOrientationConcept,'http://www.ease-crc.org/ont/SOMA.owl#GraspingOrientation'),
129+
has_type(GraspingOrientationConcept,'http://www.ease-crc.org/ont/SOMA.owl#GraspingOrientation'),
130+
has_parameter(Task,GraspingOrientationConcept),
131+
holds(GraspingOrientationConcept, dul:classifies, GraspingOrientation),
132+
has_region(Action,GraspingOrientation)]),!.
134133

135134
add_comment(Entity,Comment) :- kb_project(triple(Entity, 'http://www.w3.org/2000/01/rdf-schema#comment', Comment)).
136135
ros_logger_start :- process_create(path('rosrun'),['mongodb_log', 'mongodb_log.py','__name:=topic_logger', '--mongodb-name', 'roslog', '/tf_projection', '/tf'],[process(PID)]),asserta(ros_logger_pid(PID)).
@@ -143,7 +142,3 @@
143142
[stdin(pipe(In)), detached(true), process(TLPID)]),
144143
writeln(In,'y'),flush_output(In), process_wait(TLPID, _),
145144
print_message(informational,'Topic Logger stopped').
146-
147-
148-
149-
% test_tf_query :- kb_call([triple('http://www.ontologydesignpatterns.org/ont/dul/DUL.owl#Action_DCJBWPIE',dul:'hasTimeInterval',_O), triple(_O, soma:'hasIntervalBegin', _T2)]),time_scope(=<(_T2), >=(_T2), QScope),writeln(_T2),tf_get_pose('base_footprint', ['map',Position,Orientation], QScope, _),!.

0 commit comments

Comments
 (0)