@@ -76,58 +76,61 @@ public void reasoningCycleStarting() {
76
76
public List <Literal > perceive () {
77
77
jason_ros_msgs .Perception perception = rosNode .getPerception ();
78
78
while (perception != null ) {
79
- TransitionSystem ts = getTS ();
80
- Literal bel = createLiteral (perception .getPerceptionName ());
81
- bel .addAnnot (ts .getAg ().getBB ().TPercept );
79
+ String agent_name = perception .getAgentName ();
80
+ if (agent_name .equals (this .getAgName ())){
81
+ TransitionSystem ts = getTS ();
82
+ Literal bel = createLiteral (perception .getPerceptionName ());
83
+ bel .addAnnot (ts .getAg ().getBB ().TPercept );
82
84
83
- for (String param : perception .getParameters ()) {
85
+ for (String param : perception .getParameters ()) {
84
86
try {
85
- Term p = parseTerm (param );
86
- if (p .isVar ()) {
87
- p = new StringTermImpl (param );
88
- }
89
- bel .addTerm (p );
87
+ Term p = parseTerm (param );
88
+ if (p .isVar ()) {
89
+ p = new StringTermImpl (param );
90
+ }
91
+ bel .addTerm (p );
90
92
} catch (ParseException e ) {
91
- bel .addTerm (new StringTermImpl (param ));
93
+ bel .addTerm (new StringTermImpl (param ));
92
94
}
93
- }
95
+ }
94
96
95
- boolean bufUpdate = perception .getUpdate ();
96
- if (bufUpdate ) {
97
+ boolean bufUpdate = perception .getUpdate ();
98
+ if (bufUpdate ) {
97
99
Iterator <Literal > ibb =
98
- ts .getAg ().getBB ().getCandidateBeliefs (new PredicateIndicator (
99
- perception .getPerceptionName (), perception .getParameters ().size ()));
100
+ ts .getAg ().getBB ().getCandidateBeliefs (new PredicateIndicator (
101
+ perception .getPerceptionName (), perception .getParameters ().size ()));
100
102
boolean addBelief = true ;
101
103
while (ibb != null && ibb .hasNext ()) {
102
- Literal l = ibb .next ();
103
- if (l .equals (bel )) {
104
- addBelief = false ;
105
- } else {
106
- ibb .remove (); // remove l as perception from BB
107
-
108
- // only produce -bel event if the agent has plans for the event
109
- Trigger te = new Trigger (TEOperator .del , TEType .belief , l );
110
- if (ts .getC ().hasListener () || ts .getAg ().getPL ().hasCandidatePlan (te )) {
111
- l = ASSyntax .createLiteral (l .getFunctor (), l .getTermsArray ());
112
- l .addAnnot (ts .getAg ().getBB ().TPercept );
113
- te .setLiteral (l );
114
- ts .getC ().addEvent (new Event (te , Intention .EmptyInt ));
115
- }
104
+ Literal l = ibb .next ();
105
+ if (l .equals (bel )) {
106
+ addBelief = false ;
107
+ } else {
108
+ ibb .remove (); // remove l as perception from BB
109
+
110
+ // only produce -bel event if the agent has plans for the event
111
+ Trigger te = new Trigger (TEOperator .del , TEType .belief , l );
112
+ if (ts .getC ().hasListener () || ts .getAg ().getPL ().hasCandidatePlan (te )) {
113
+ l = ASSyntax .createLiteral (l .getFunctor (), l .getTermsArray ());
114
+ l .addAnnot (ts .getAg ().getBB ().TPercept );
115
+ te .setLiteral (l );
116
+ ts .getC ().addEvent (new Event (te , Intention .EmptyInt ));
116
117
}
118
+ }
117
119
}
118
120
if (addBelief ) {
119
- try {
120
- ts .getAg ().addBel (bel );
121
- } catch (RevisionFailedException e ) {
122
- System .out .println ("Error adding new belief" );
123
- }
121
+ try {
122
+ ts .getAg ().addBel (bel );
123
+ } catch (RevisionFailedException e ) {
124
+ System .out .println ("Error adding new belief" );
125
+ }
124
126
}
125
- } else {
127
+ } else {
126
128
try {
127
- getTS ().getAg ().addBel (bel );
129
+ getTS ().getAg ().addBel (bel );
128
130
} catch (RevisionFailedException e ) {
129
- System .out .println ("Error adding new belief" );
131
+ System .out .println ("Error adding new belief" );
130
132
}
133
+ }
131
134
}
132
135
perception = rosNode .getPerception ();
133
136
}
@@ -142,17 +145,20 @@ public void act(ActionExec action) {
142
145
}
143
146
144
147
public void actionsStatus (jason_ros_msgs .ActionStatus data ) {
145
- int id = data .getId ();
146
- boolean result = data .getResult ();
148
+ String agent_name = data .getAgentName ();
149
+ if (agent_name .equals (this .getAgName ())){
150
+ int id = data .getId ();
151
+ boolean result = data .getResult ();
147
152
148
- ActionExec action = actionsWaiting .get (id );
153
+ ActionExec action = actionsWaiting .get (id );
149
154
150
- if (action != null ) {
155
+ if (action != null ) {
151
156
action .setResult (result );
152
157
actionExecuted (action );
153
158
actionsWaiting .remove (id );
154
- } else {
159
+ } else {
155
160
System .out .println ("Action not found." );
161
+ }
156
162
}
157
163
}
158
164
0 commit comments