perception);
+
+}
diff --git a/src/main/java/br/unicamp/meca/system1/codelets/ActionFromPerceptionCodelet.java b/src/main/java/br/unicamp/meca/system1/codelets/ActionFromPerceptionCodelet.java
deleted file mode 100644
index 2223336..0000000
--- a/src/main/java/br/unicamp/meca/system1/codelets/ActionFromPerceptionCodelet.java
+++ /dev/null
@@ -1,261 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2019 DCA-FEEC-UNICAMP and Ericsson Research *
- * All rights reserved. This program and the accompanying materials *
- * are made available under the terms of the GNU Lesser Public License v3 *
- * which accompanies this distribution, and is available at *
- * http://www.gnu.org/licenses/lgpl.html *
- * *
- * Contributors: *
- * R. R. Gudwin, A. L. O. Paraense, E. Froes, W. Gibaut, *
- * and K. Raizer. *
- * *
- ******************************************************************************/
-package br.unicamp.meca.system1.codelets;
-
-import java.util.ArrayList;
-
-import br.unicamp.cst.core.entities.Codelet;
-import br.unicamp.cst.core.entities.Memory;
-import br.unicamp.cst.core.exceptions.CodeletActivationBoundsException;
-
-/**
- * This class represents the MECA Action From Perception Codelet. This Action From Perception
- * Codelet allows inputs from one or more of the PerceptualCodelets and
- * inputs from one or more of the MotivationalCodelets. It outputs
- * necessarily to a MotorCodelet. As the name suggests, the idea behind this
- * action from perception codelet is to provide an action as a purely reaction to the environment in System 1.
- *
- * Usually, Action From Perception Codelets are application-specific, and the MECA
- * software implementation just provides basic template class, which is a
- * wrapper to CST's {@link Codelet}, to be reused while building an application
- * using MECA.
- *
- * @author A. L. O. Paraense
- *
- */
-public abstract class ActionFromPerceptionCodelet extends Codelet {
-
- protected String id;
-
- protected ArrayList perceptualCodeletsIds;
- protected ArrayList perceptualMemories;
-
- protected ArrayList motivationalCodeletsIds;
- protected ArrayList driveMemories;
-
- protected String soarCodeletId;
- protected Memory broadcastMemory;
-
- protected String motorCodeletId;
- protected Memory motorMemory;
-
- /**
- *
- * Creates a MECA Action From Perception Codelet.
- *
- * @param id
- * the id of the Action From Perception Codelet. Must be unique per
- * Action From Perception Codelet.
- * @param perceptualCodeletsIds
- * the list of ids of the Perceptual Codelets whose outputs will
- * be read by this Action From Perception Codelet.
- * @param motivationalCodeletsIds
- * the list of ids of the Motivational Codelets whose outputs will
- * be read by this Action From Perception Codelet.
- * @param motorCodeletId
- * the id of the Motor Codelet which will read the outputs of
- * this Action From Perception Codelet.
- * @param soarCodeletId
- * the id of the Soar Codelet whose outputs will be read by this
- * Action From Perception Codelet.
- */
- public ActionFromPerceptionCodelet(String id, ArrayList perceptualCodeletsIds, ArrayList motivationalCodeletsIds, String motorCodeletId,
- String soarCodeletId) {
- super();
- setName(id);
- this.id = id;
- this.motorCodeletId = motorCodeletId;
- this.perceptualCodeletsIds = perceptualCodeletsIds;
- this.soarCodeletId = soarCodeletId;
- this.motivationalCodeletsIds = motivationalCodeletsIds;
- }
-
- @Override
- public void accessMemoryObjects() {
-
- int index=0;
-
- if(perceptualMemories == null || perceptualMemories.size() == 0) {
-
- perceptualMemories = new ArrayList<>();
-
- if(perceptualCodeletsIds != null) {
-
- for(String perceptualCodeletId : perceptualCodeletsIds) {
- Memory perceptualMemory = this.getInput(perceptualCodeletId, index);
- perceptualMemories.add(perceptualMemory);
- }
- }
- }
-
- if(driveMemories == null || driveMemories.size() == 0)
- {
- driveMemories = new ArrayList<>();
-
- if(motivationalCodeletsIds!=null){
-
- for(String motivationalCodeletsId : motivationalCodeletsIds)
- {
- Memory inputDrive = this.getInput(motivationalCodeletsId + "_DRIVE_MO");
- driveMemories.add(inputDrive);
- }
- }
- }
-
- if(broadcastMemory == null) {
- broadcastMemory = this.getBroadcast(soarCodeletId, index);
- }
-
-
- if(motorMemory==null && motorCodeletId!=null)
- motorMemory = this.getOutput(motorCodeletId, index);
- }
-
- @Override
- public void calculateActivation() {
-
- double activation = 0;
-
- if (driveMemories!=null && driveMemories.size() > 0){
-
- for (Memory driveMO: driveMemories) {
- activation += driveMO.getEvaluation();
- }
-
- activation /= driveMemories.size();
-
- }
-
- try {
-
- if(activation<0.0d)
- activation=0.0d;
-
- if(activation>1.0d)
- activation=1.0d;
-
- setActivation(activation);
-
- } catch (CodeletActivationBoundsException e) {
- e.printStackTrace();
- }
-
- }
-
- @Override
- public void proc() {
-
- proc(perceptualMemories, broadcastMemory, motorMemory);
- }
-
- /**
- * Main method of the Action From Perception Codelet called passing all input and output necessary memories.
- *
- * @param perceptualMemories
- * the input memories coming from perception.
- * @param broadcastMemory
- * the input memory coming from the conscious planner broadcast.
- * @param motorMemory
- * the output motor memory.
- */
- public abstract void proc(ArrayList perceptualMemories, Memory broadcastMemory, Memory motorMemory);
-
- /**
- * Returns the id of the Soar Codelet whose outputs will be read by this
- * Action From Perception Codelet.
- *
- * @return the soarCodeletId
- */
- public String getSoarCodeletId() {
- return soarCodeletId;
- }
-
- /**
- * Sets the id of the Soar Codelet whose outputs will be read by this
- * Action From Perception Codelet.
- *
- * @param soarCodeletId
- * the soarCodeletId to set
- */
- public void setSoarCodeletId(String soarCodeletId) {
- this.soarCodeletId = soarCodeletId;
- }
-
- /**
- * Returns the list of the Perceptual Codelet's ids whose outputs will be
- * read by this Action From Perception Codelet.
- *
- * @return the perceptualCodeletsIds
- */
- public ArrayList getPerceptualCodeletsIds() {
- return perceptualCodeletsIds;
- }
-
- /**
- * Sets the list of the Perceptual Codelet's ids whose outputs will be read
- * by this Action From Perception Codelet.
- *
- * @param perceptualCodeletsIds
- * the perceptualCodeletsIds to set
- */
- public void setPerceptualCodeletsIds(ArrayList perceptualCodeletsIds) {
- this.perceptualCodeletsIds = perceptualCodeletsIds;
- }
-
- /**
- * Returns the id of this Action From Perception Codelet.
- *
- * @return the id
- */
- public String getId() {
- return id;
- }
-
- /**
- * Sets the id of this Action From Perception Codelet.
- *
- * @param id
- * the id to set
- */
- public void setId(String id) {
- this.id = id;
- }
-
- /**
- * Returns the id of the Motor Codelet which will read the outputs of this
- * Action From Perception Codelet.
- *
- * @return the motorCodeletId
- */
- public String getMotorCodeletId() {
- return motorCodeletId;
- }
-
- /**
- * Sets the id of the Motor Codelet which will read the outputs of this
- * Action From Perception Codelet.
- *
- * @param motorCodeletId
- * the motorCodeletId to set
- */
- public void setMotorCodeletId(String motorCodeletId) {
- this.motorCodeletId = motorCodeletId;
- }
-
- /**
- * @return the motivationalCodeletsIds
- */
- public ArrayList getMotivationalCodeletsIds() {
- return motivationalCodeletsIds;
- }
-}
diff --git a/src/main/java/br/unicamp/meca/system1/codelets/ActionFromPlanningCodelet.java b/src/main/java/br/unicamp/meca/system1/codelets/ActionFromPlanningCodelet.java
deleted file mode 100644
index 242ce85..0000000
--- a/src/main/java/br/unicamp/meca/system1/codelets/ActionFromPlanningCodelet.java
+++ /dev/null
@@ -1,237 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2018 DCA-FEEC-UNICAMP and Ericsson Research *
- * All rights reserved. This program and the accompanying materials *
- * are made available under the terms of the GNU Lesser Public License v3 *
- * which accompanies this distribution, and is available at *
- * http://www.gnu.org/licenses/lgpl.html *
- * *
- * Contributors: *
- * R. R. Gudwin, A. L. O. Paraense, E. Froes, W. Gibaut, S. de Paula, *
- * E. Castro, V. Figueredo and K. Raizer *
- * *
- ******************************************************************************/
-package br.unicamp.meca.system1.codelets;
-
-import java.util.ArrayList;
-
-import br.unicamp.cst.core.entities.Codelet;
-import br.unicamp.cst.core.entities.Memory;
-import br.unicamp.cst.core.exceptions.CodeletActivationBoundsException;
-import br.unicamp.meca.mind.MecaMind;
-import br.unicamp.meca.models.ActionSequencePlan;
-
-/**
- * This class represents the MECA Action From Planning Codelet. This Action From Planning
- * Codelet allows inputs from one or more of the PerceptualCodelets and the ActionSequencePlan
- * with greatest activation. It outputs
- * necessarily to a MotorCodelet. As the name suggests, the idea behind this
- * action from planning codelet is to provide an action following a specific plan from the behavior generator in System 1.
- *
- * Usually, Action From Planning Codelets are application-specific, and the MECA
- * software implementation just provides basic template class, which is a
- * wrapper to CST's {@link Codelet}, to be reused while building an application
- * using MECA.
- *
- * @author A. L. O. Paraense
- *
- */
-public abstract class ActionFromPlanningCodelet extends Codelet {
-
- protected String id;
-
- protected ArrayList perceptualCodeletsIds;
- protected ArrayList perceptualMemories;
-
- protected String soarCodeletId;
- protected Memory broadcastMemory;
-
- protected Memory actionSequencePlanMemoryContainer;
-
- protected String motorCodeletId;
- protected Memory motorMemory;
-
- /**
- * Creates a MECA Action From Planning Codelet.
- *
- * @param id
- * the id of the Action From Planning Codelet. Must be unique per
- * Reactive Behavioral Codelet.
- * @param perceptualCodeletsIds
- * the list of ids of the Perceptual Codelets whose outputs will
- * be read by this Action From Planning Codelet.
- * @param motorCodeletId
- * the id of the Motor Codelet which will read the outputs of
- * this Action From Planning Codelet.
- * @param soarCodeletId
- * the id of the Soar Codelet whose outputs will be read by this
- * Action From Planning Codelet.
- */
- public ActionFromPlanningCodelet(String id, ArrayList perceptualCodeletsIds, String motorCodeletId,
- String soarCodeletId) {
- super();
- setName(id);
- this.id = id;
- this.motorCodeletId = motorCodeletId;
- this.perceptualCodeletsIds = perceptualCodeletsIds;
- this.soarCodeletId = soarCodeletId;
- }
-
- @Override
- public void accessMemoryObjects() {
-
- int index=0;
-
- if(perceptualMemories == null || perceptualMemories.size() == 0) {
-
- perceptualMemories = new ArrayList<>();
-
- if(perceptualCodeletsIds != null) {
-
- for(String perceptualCodeletId : perceptualCodeletsIds) {
- Memory perceptualMemory = this.getInput(perceptualCodeletId, index);
- perceptualMemories.add(perceptualMemory);
- }
- }
- }
-
- if(broadcastMemory == null) {
- broadcastMemory = this.getBroadcast(soarCodeletId, index);
- }
-
- if(actionSequencePlanMemoryContainer == null)
- actionSequencePlanMemoryContainer = this.getInput(MecaMind.ACTION_SEQUENCE_PLAN_ID, index);
-
- if(motorMemory==null && motorCodeletId!=null)
- motorMemory = this.getOutput(motorCodeletId, index);
-
- }
-
- @Override
- public void calculateActivation() {
-
- try {
- if(actionSequencePlanMemoryContainer != null && actionSequencePlanMemoryContainer.getI() != null && actionSequencePlanMemoryContainer.getI() instanceof ActionSequencePlan) {
-
- ActionSequencePlan actionSequencePlan = (ActionSequencePlan) actionSequencePlanMemoryContainer.getI();
- String currentActionId = actionSequencePlan.getCurrentActionId();
-
- if(currentActionId != null && currentActionId.equalsIgnoreCase(id)) {
- setActivation(actionSequencePlanMemoryContainer.getEvaluation());
- }else {
- setActivation(0.0d);
- }
- }
-
- } catch (CodeletActivationBoundsException e) {
- e.printStackTrace();
- }
- }
-
- @Override
- public void proc() {
-
- if(actionSequencePlanMemoryContainer != null && actionSequencePlanMemoryContainer.getI() != null && actionSequencePlanMemoryContainer.getI() instanceof ActionSequencePlan) {
-
- ActionSequencePlan actionSequencePlan = (ActionSequencePlan) actionSequencePlanMemoryContainer.getI();
- String currentActionId = actionSequencePlan.getCurrentActionId();
-
- if(currentActionId != null && currentActionId.equalsIgnoreCase(id)) {
- proc(perceptualMemories, broadcastMemory, motorMemory);
- }
- }
- }
-
- /**
- * Main method of this Action From Planning Codelet called passing all the input and output memories necessary.
- *
- * @param perceptualMemories
- * the input memories coming from perception.
- * @param broadcastMemory
- * the input memories coming from the conscious broadcast of the planner.
- * @param motorMemory
- * the output motor memory to be dispatched to the actuators.
- */
- public abstract void proc(ArrayList perceptualMemories, Memory broadcastMemory, Memory motorMemory);
-
- /**
- * Returns the id of the Soar Codelet whose outputs will be read by this
- * Action From Planning Codelet.
- *
- * @return the soarCodeletId
- */
- public String getSoarCodeletId() {
- return soarCodeletId;
- }
-
- /**
- * Sets the id of the Soar Codelet whose outputs will be read by this
- * Action From Planning Codelet.
- *
- * @param soarCodeletId
- * the soarCodeletId to set
- */
- public void setSoarCodeletId(String soarCodeletId) {
- this.soarCodeletId = soarCodeletId;
- }
-
- /**
- * Returns the list of the Perceptual Codelet's ids whose outputs will be
- * read by this Action From Planning Codelet.
- *
- * @return the perceptualCodeletsIds
- */
- public ArrayList getPerceptualCodeletsIds() {
- return perceptualCodeletsIds;
- }
-
- /**
- * Sets the list of the Perceptual Codelet's ids whose outputs will be read
- * by this Action From Planning Codelet.
- *
- * @param perceptualCodeletsIds
- * the perceptualCodeletsIds to set
- */
- public void setPerceptualCodeletsIds(ArrayList perceptualCodeletsIds) {
- this.perceptualCodeletsIds = perceptualCodeletsIds;
- }
-
- /**
- * Returns the id of this Action From Planning Codelet.
- *
- * @return the id
- */
- public String getId() {
- return id;
- }
-
- /**
- * Sets the id of this Action From Planning Codelet.
- *
- * @param id
- * the id to set
- */
- public void setId(String id) {
- this.id = id;
- }
-
- /**
- * Returns the id of the Motor Codelet which will read the outputs of this
- * Action From Planning Codelet.
- *
- * @return the motorCodeletId
- */
- public String getMotorCodeletId() {
- return motorCodeletId;
- }
-
- /**
- * Sets the id of the Motor Codelet which will read the outputs of this
- * Action From Planning Codelet.
- *
- * @param motorCodeletId
- * the motorCodeletId to set
- */
- public void setMotorCodeletId(String motorCodeletId) {
- this.motorCodeletId = motorCodeletId;
- }
-}
diff --git a/src/main/java/br/unicamp/meca/system1/codelets/ActivityCodelet.java b/src/main/java/br/unicamp/meca/system1/codelets/ActivityCodelet.java
new file mode 100644
index 0000000..05570fe
--- /dev/null
+++ b/src/main/java/br/unicamp/meca/system1/codelets/ActivityCodelet.java
@@ -0,0 +1,329 @@
+/**
+ *
+ */
+package br.unicamp.meca.system1.codelets;
+
+import java.util.ArrayList;
+
+import br.unicamp.cst.core.entities.Codelet;
+import br.unicamp.cst.core.entities.Memory;
+import br.unicamp.cst.core.exceptions.CodeletActivationBoundsException;
+import br.unicamp.meca.mind.MecaMind;
+import br.unicamp.meca.models.ActionSequencePlan;
+import br.unicamp.meca.models.ActionStep;
+
+/**
+ * This class represents the MECA Activity Codelet. This Activity
+ * Codelet allows inputs from one or more of the PerceptualCodelets,
+ * inputs from one or more of the MotivationalCodelets and the ActionSequencePlan
+ * with greatest activation. It outputs
+ * necessarily to a MotorCodelet. As the name suggests, the idea behind this
+ * activity codelet is to provide an action as a purely reaction to the environment
+ * or else based on a plan in System 1.
+ *
+ * Usually, Activity Codelets are application-specific, and the MECA
+ * software implementation just provides basic template class, which is a
+ * wrapper to CST's {@link Codelet}, to be reused while building an application
+ * using MECA.
+ *
+ * @author A. L. O. Paraense
+ *
+ */
+public abstract class ActivityCodelet extends Codelet {
+
+ protected String id;
+
+ protected ArrayList perceptualCodeletsIds;
+ protected ArrayList perceptualMemories;
+
+ protected ArrayList motivationalCodeletsIds;
+ protected ArrayList driveMemories;
+
+ protected String planningCodeletId;
+ protected Memory broadcastMemory;
+
+ protected Memory actionSequencePlanMemoryContainer;
+
+ protected String motorCodeletId;
+ protected Memory motorMemory;
+
+ /**
+ *
+ * Creates a MECA Activity Codelet.
+ *
+ * @param id
+ * the id of the Activity Codelet. Must be unique per
+ * Activity Codelet.
+ * @param perceptualCodeletsIds
+ * the list of ids of the Perceptual Codelets whose outputs will
+ * be read by this Activity Codelet.
+ * @param motivationalCodeletsIds
+ * the list of ids of the Motivational Codelets whose outputs will
+ * be read by this Activity Codelet.
+ * @param motorCodeletId
+ * the id of the Motor Codelet which will read the outputs of
+ * this Activity Codelet.
+ * @param planningCodeletId
+ * the id of the Planning Codelet whose outputs will be read by this
+ * Activity Codelet.
+ */
+ public ActivityCodelet(
+ String id,
+ ArrayList perceptualCodeletsIds,
+ ArrayList motivationalCodeletsIds,
+ String motorCodeletId,
+ String planningCodeletId) {
+ setName(id);
+ this.id = id;
+ this.motorCodeletId = motorCodeletId;
+ this.perceptualCodeletsIds = perceptualCodeletsIds;
+ this.planningCodeletId = planningCodeletId;
+ this.motivationalCodeletsIds = motivationalCodeletsIds;
+ }
+
+ @Override
+ public void accessMemoryObjects() {
+ int index=0;
+
+ if(perceptualMemories == null || perceptualMemories.size() == 0) {
+
+ perceptualMemories = new ArrayList<>();
+
+ if(perceptualCodeletsIds != null) {
+
+ for(String perceptualCodeletId : perceptualCodeletsIds) {
+ Memory perceptualMemory = this.getInput(perceptualCodeletId, index);
+ if (perceptualMemory != null)
+ perceptualMemories.add(perceptualMemory);
+ }
+ }
+ }
+
+ if(driveMemories == null || driveMemories.size() == 0)
+ {
+ driveMemories = new ArrayList<>();
+
+ if(motivationalCodeletsIds!=null){
+
+ for(String motivationalCodeletsId : motivationalCodeletsIds)
+ {
+ Memory inputDrive = this.getInput(motivationalCodeletsId + "Drive");
+ if (inputDrive != null)
+ driveMemories.add(inputDrive);
+ }
+ }
+ }
+
+ if(broadcastMemory == null) {
+ broadcastMemory = this.getBroadcast(planningCodeletId, index);
+ }
+
+
+ if(motorMemory==null && motorCodeletId!=null)
+ motorMemory = this.getOutput(motorCodeletId, index);
+
+ if(actionSequencePlanMemoryContainer == null)
+ actionSequencePlanMemoryContainer = this.getInput(MecaMind.ACTION_SEQUENCE_PLAN_ID, index);
+ }
+
+ @Override
+ public void calculateActivation() {
+ double activation = 0;
+
+ if(actionSequencePlanMemoryContainer != null && actionSequencePlanMemoryContainer.getI() != null && actionSequencePlanMemoryContainer.getI() instanceof ActionSequencePlan) {
+
+ ActionSequencePlan actionSequencePlan = (ActionSequencePlan) actionSequencePlanMemoryContainer.getI();
+ ActionStep currentActionId = actionSequencePlan.getCurrentActionStep();
+
+ if(currentActionId != null && currentActionId.getActionId().equalsIgnoreCase(id)) {
+ activation = actionSequencePlanMemoryContainer.getEvaluation();
+ }else {
+ activation = 0.0d;
+ }
+ }else if (driveMemories!=null && driveMemories.size() > 0){
+
+ for (Memory driveMO: driveMemories) {
+ activation += driveMO.getEvaluation();
+ }
+
+ activation /= driveMemories.size();
+
+ }
+
+ try {
+
+ if(activation<0.0d)
+ activation=0.0d;
+
+ if(activation>1.0d)
+ activation=1.0d;
+
+ setActivation(activation);
+
+ } catch (CodeletActivationBoundsException e) {
+ e.printStackTrace();
+ }
+
+ }
+
+ @Override
+ public void proc() {
+ // This is the case when this ActivityCodelet is following a plan - there is a plan available
+ if(actionSequencePlanMemoryContainer != null && actionSequencePlanMemoryContainer.getI() != null && actionSequencePlanMemoryContainer.getI() instanceof ActionSequencePlan) {
+ ActionSequencePlan actionSequencePlan = (ActionSequencePlan) actionSequencePlanMemoryContainer.getI();
+ ActionStep currentAction = actionSequencePlan.getCurrentActionStep();
+ ActionStep lastActionStep = actionSequencePlan.getLastExecutedActionStep();
+ String lastActionId;
+ if (lastActionStep != null) {
+ lastActionId = lastActionStep.getActionId();
+ if (lastActionId != null && lastActionId.equalsIgnoreCase(id) && lastActionStep.needsConclusion) {
+ doConclusion(perceptualMemories, broadcastMemory, motorMemory);
+ lastActionStep.needsConclusion = false;
+ }
+ }
+ String currentActionId;
+ if (currentAction != null) {
+ currentActionId = currentAction.getActionId();
+ if(currentActionId != null && currentActionId.equalsIgnoreCase(id) && currentAction.executed == false) {
+ proc(perceptualMemories, broadcastMemory, motorMemory);
+ }
+ }
+ }else { // This is the case when there is NO plan available, and the ActivityCodelet should be run only with Perception
+ proc(perceptualMemories, broadcastMemory, motorMemory);
+ }
+ }
+
+ /**
+ * Main method of the Activity Codelet called passing all input and output necessary memories.
+ *
+ * @param perceptualMemories
+ * the input memories coming from perception.
+ * @param broadcastMemory
+ * the input memory coming from the conscious planner broadcast.
+ * @param motorMemory
+ * the output motor memory.
+ */
+ public abstract void proc(ArrayList perceptualMemories, Memory broadcastMemory, Memory motorMemory);
+
+ /**
+ * Method to be called to do the Conclusion of an ActionStep, after its activities are over.
+ * Similar to the proc method, but to be called one last time to clean whatever needs to be cleaned at the motorMemory
+ *
+ * @param perceptualMemories
+ * the input memories coming from perception.
+ * @param broadcastMemory
+ * the input memory coming from the conscious planner broadcast.
+ * @param motorMemory
+ * the output motor memory.
+ */
+ public abstract void doConclusion(ArrayList perceptualMemories, Memory broadcastMemory, Memory motorMemory);
+
+ /**
+ * Returns the id of the Planning Codelet whose outputs will be read by this
+ * Activity Codelet.
+ *
+ * @return the planningCodeletId
+ */
+ public String getPlanningCodeletId() {
+ return planningCodeletId;
+ }
+
+ /**
+ * Sets the id of the Planning Codelet whose outputs will be read by this
+ * Activity Codelet.
+ *
+ * @param planningCodeletId
+ * the planningCodeletId to set
+ */
+ public void setPlanningCodeletId(String planningCodeletId) {
+ this.planningCodeletId = planningCodeletId;
+ }
+
+ /**
+ * Returns the list of the Perceptual Codelet's ids whose outputs will be
+ * read by this Activity Codelet.
+ *
+ * @return the perceptualCodeletsIds
+ */
+ public ArrayList getPerceptualCodeletsIds() {
+ return perceptualCodeletsIds;
+ }
+
+ /**
+ * Sets the list of the Perceptual Codelet's ids whose outputs will be read
+ * by this Activity Codelet.
+ *
+ * @param perceptualCodeletsIds
+ * the perceptualCodeletsIds to set
+ */
+ public void setPerceptualCodeletsIds(ArrayList perceptualCodeletsIds) {
+ this.perceptualCodeletsIds = perceptualCodeletsIds;
+ }
+
+ /**
+ * Returns the id of this Activity Codelet.
+ *
+ * @return the id
+ */
+ public String getId() {
+ return id;
+ }
+
+ /**
+ * Sets the id of this Activity Codelet.
+ *
+ * @param id
+ * the id to set
+ */
+ public void setId(String id) {
+ this.id = id;
+ }
+
+ /**
+ * Returns the id of the Motor Codelet which will read the outputs of this
+ * Activity Codelet.
+ *
+ * @return the motorCodeletId
+ */
+ public String getMotorCodeletId() {
+ return motorCodeletId;
+ }
+
+ /**
+ * Sets the id of the Motor Codelet which will read the outputs of this
+ * Activity Codelet.
+ *
+ * @param motorCodeletId
+ * the motorCodeletId to set
+ */
+ public void setMotorCodeletId(String motorCodeletId) {
+ this.motorCodeletId = motorCodeletId;
+ }
+
+ /**
+ * @return the motivationalCodeletsIds
+ */
+ public ArrayList getMotivationalCodeletsIds() {
+ return motivationalCodeletsIds;
+ }
+
+ public ArrayList getPerceptionMemories() {
+ return(perceptualMemories);
+ }
+
+ public ArrayList getDriveMemories() {
+ return(driveMemories);
+ }
+
+ public Memory getBroadcastMemory() {
+ return(broadcastMemory);
+ }
+
+ public Memory getActionSequencePlanMemoryContainer() {
+ return(actionSequencePlanMemoryContainer);
+ }
+
+ public Memory getMotorMemory() {
+ return(motorMemory);
+ }
+}
diff --git a/src/main/java/br/unicamp/meca/system1/codelets/ActivityTrackingCodelet.java b/src/main/java/br/unicamp/meca/system1/codelets/ActivityTrackingCodelet.java
new file mode 100644
index 0000000..d3a3858
--- /dev/null
+++ b/src/main/java/br/unicamp/meca/system1/codelets/ActivityTrackingCodelet.java
@@ -0,0 +1,164 @@
+/**
+ *
+ */
+package br.unicamp.meca.system1.codelets;
+
+import java.util.ArrayList;
+
+import br.unicamp.cst.core.entities.Codelet;
+import br.unicamp.cst.core.entities.Memory;
+import br.unicamp.cst.core.exceptions.CodeletActivationBoundsException;
+import br.unicamp.meca.mind.MecaMind;
+import br.unicamp.meca.models.ActionSequencePlan;
+import br.unicamp.meca.models.ActionStep;
+
+/**
+ * This class represents the MECA Activity Tracking Codelet. This
+ * Activity Tracking Codelet allows inputs from one or more of the Perceptual Codelets. The idea behind
+ * this codelet is to track the steps of an Action Sequence Plan in System 1.
+ *
+ * Usually, Activity Tracking Codelets are application-specific, and the
+ * MECA software implementation just provides basic template class, which is a
+ * wrapper to CST's {@link Codelet}, to be reused while building an application
+ * using MECA.
+ *
+ * @author A. L. O. Paraense
+ *
+ */
+public class ActivityTrackingCodelet extends Codelet {
+
+ protected String id;
+
+ protected ArrayList perceptualCodeletsIds;
+ protected ArrayList perceptualMemories;
+
+ protected Memory actionSequencePlanMemoryContainer;
+
+ protected ActionSequencePlan actionSequencePlan;
+
+ /**
+ * Creates a MECA Activity Tracking Codelet.
+ *
+ * @param id
+ * the id of the Activity Tracking. Must be unique
+ * per Activity Tracking.
+ * @param perceptualCodeletsIds
+ * the list of ids of the Perceptual Codelets whose outputs
+ * will be read by this Activity Tracking.
+ * @see Codelet
+ * @see ActionSequencePlan
+ */
+ public ActivityTrackingCodelet(String id, ArrayList perceptualCodeletsIds) {
+ super();
+ setName(id);
+ this.id = id;
+ this.perceptualCodeletsIds = perceptualCodeletsIds;
+ }
+
+ @Override
+ public void accessMemoryObjects() {
+ int index=0;
+
+ if(perceptualMemories == null || perceptualMemories.size() == 0) {
+
+ perceptualMemories = new ArrayList<>();
+
+ if(perceptualCodeletsIds != null) {
+
+ for(String perceptualCodeletId : perceptualCodeletsIds) {
+ Memory perceptualMemory = this.getInput(perceptualCodeletId, index);
+ perceptualMemories.add(perceptualMemory);
+ }
+ }
+ }
+
+ if(actionSequencePlanMemoryContainer == null)
+ actionSequencePlanMemoryContainer = this.getInput(MecaMind.ACTION_SEQUENCE_PLAN_ID, index);
+
+ }
+
+ @Override
+ public void calculateActivation() {
+ try {
+ setActivation(0.0d);
+ } catch (CodeletActivationBoundsException e) {
+ e.printStackTrace();
+ }
+ }
+
+ /**
+ * Track and advance actions in the sequence plan.
+ *
+ * @param actionSequencePlan
+ * the ActionSequencePlan.
+ * @param perceptualMemories
+ * the list Perceptual Memories coming from Perceptual Codelets.
+ */
+ public void trackActionSequencePlan(ArrayList perceptualMemories, ActionSequencePlan actionSequencePlan) {
+ if(actionSequencePlan != null &&
+ actionSequencePlan.getActionStepSequence() != null &&
+ perceptualMemories != null &&
+ perceptualMemories.size() > 0) {
+ ActionStep currentActionStep = actionSequencePlan.getCurrentActionStep();
+ ActionStep lastActionStep = actionSequencePlan.getLastExecutedActionStep();
+ if ((actionSequencePlan.getCurrentActionIdIndex() == 0
+ || lastActionStep.needsConclusion == false) // you can go to next step if it is the first step of the plan or if the last step is clear
+ && (currentActionStep != null // then just check if current ActionStep is not null to avoid breaking the next tests
+ && currentActionStep.executed == false // the ActionStep was not already executed
+ && currentActionStep.stopCondition(perceptualMemories)) ) { // and the ActionStep reached its final destination
+ currentActionStep.needsConclusion = true;
+ actionSequencePlan.gotoNextAction();
+ }
+ }
+ }
+
+ @Override
+ public void proc() {
+ if (actionSequencePlanMemoryContainer != null) {
+ actionSequencePlan = (ActionSequencePlan) actionSequencePlanMemoryContainer.getI();
+ trackActionSequencePlan(perceptualMemories, actionSequencePlan);
+ }
+ }
+
+ /**
+ * @return the id
+ */
+ public String getId() {
+ return id;
+ }
+
+ /**
+ * @param id the id to set
+ */
+ public void setId(String id) {
+ this.id = id;
+ }
+
+ /**
+ * @return the perceptualCodeletsIds
+ */
+ public ArrayList getPerceptualCodeletsIds() {
+ return perceptualCodeletsIds;
+ }
+
+ /**
+ * @param perceptualCodeletsIds the perceptualCodeletsIds to set
+ */
+ public void setPerceptualCodeletsIds(ArrayList perceptualCodeletsIds) {
+ this.perceptualCodeletsIds = perceptualCodeletsIds;
+ }
+
+ /**
+ * @return the actionSequencePlanMemoryContainer
+ */
+ public Memory getActionSequencePlanMemoryContainer() {
+ return actionSequencePlanMemoryContainer;
+ }
+
+ /**
+ * @param actionSequencePlanMemoryContainer the actionSequencePlanMemoryContainer to set
+ */
+ public void setActionSequencePlanMemoryContainer(Memory actionSequencePlanMemoryContainer) {
+ this.actionSequencePlanMemoryContainer = actionSequencePlanMemoryContainer;
+ }
+}
diff --git a/src/main/java/br/unicamp/meca/system1/codelets/AttentionCodelet.java b/src/main/java/br/unicamp/meca/system1/codelets/AttentionCodelet.java
index 157892d..c1d34ea 100644
--- a/src/main/java/br/unicamp/meca/system1/codelets/AttentionCodelet.java
+++ b/src/main/java/br/unicamp/meca/system1/codelets/AttentionCodelet.java
@@ -18,7 +18,7 @@
import br.unicamp.cst.core.entities.Codelet;
import br.unicamp.cst.core.entities.Memory;
import br.unicamp.cst.core.exceptions.CodeletActivationBoundsException;
-import br.unicamp.cst.representation.owrl.AbstractObject;
+import br.unicamp.cst.representation.idea.Idea;
/**
* This class represents a MECA Attention Codelet in System 1. Attention
@@ -44,8 +44,8 @@ public abstract class AttentionCodelet extends Codelet {
private Memory inputPerceptsMO;
private Memory outputFilteredPerceptsMO;
- private List inputPercepts;
- private AbstractObject outputFilteredPercepts;
+ private List inputPercepts;
+ private Idea outputFilteredPercepts;
private List perceptualCodeletsIds;
/**
@@ -62,7 +62,7 @@ public AttentionCodelet(String id, ArrayList perceptualCodeletsIds) {
setName(id);
setId(id);
setPerceptualCodeletsIds(perceptualCodeletsIds);
- setInputPercepts(new ArrayList());
+ setInputPercepts(new ArrayList());
}
@Override
@@ -70,7 +70,7 @@ public void accessMemoryObjects() {
if (getInputPerceptsMO() == null) {
for (Memory perceptualMO : this.getInputs()) {
- getInputPercepts().add((AbstractObject) perceptualMO.getI());
+ getInputPercepts().add((Idea) perceptualMO.getI());
}
}
@@ -96,13 +96,13 @@ public void proc() {
}
/**
- * Generates a filtered percept as an AbstractObject.
+ * Generates a filtered percept as an Idea.
*
* @param inputPercepts
* the list of input percepts.
- * @return filtered percept as an AbstractObject.
+ * @return filtered percept as an Idea.
*/
- public abstract AbstractObject generateFilteredPercepts(List inputPercepts);
+ public abstract Idea generateFilteredPercepts(List inputPercepts);
/**
* Gets the input Percept as a Memory Object.
@@ -147,7 +147,7 @@ public void setOutputFilteredPerceptsMO(Memory outputFilteredPerceptsMO) {
*
* @return the list of input percepts.
*/
- public List getInputPercepts() {
+ public List getInputPercepts() {
return inputPercepts;
}
@@ -157,7 +157,7 @@ public List getInputPercepts() {
* @param inputPercepts
* the list of input percepts.
*/
- public void setInputPercepts(List inputPercepts) {
+ public void setInputPercepts(List inputPercepts) {
this.inputPercepts = inputPercepts;
}
@@ -166,7 +166,7 @@ public void setInputPercepts(List inputPercepts) {
*
* @return the output filtered percepts.
*/
- public AbstractObject getOutputFilteredPercepts() {
+ public Idea getOutputFilteredPercepts() {
return outputFilteredPercepts;
}
@@ -176,7 +176,7 @@ public AbstractObject getOutputFilteredPercepts() {
* @param outputFilteredPercepts
* the output filtered percepts.
*/
- public void setOutputFilteredPercepts(AbstractObject outputFilteredPercepts) {
+ public void setOutputFilteredPercepts(Idea outputFilteredPercepts) {
this.outputFilteredPercepts = outputFilteredPercepts;
}
diff --git a/src/main/java/br/unicamp/meca/system1/codelets/BehaviorCodelet.java b/src/main/java/br/unicamp/meca/system1/codelets/BehaviorCodelet.java
index 366337a..3728a80 100644
--- a/src/main/java/br/unicamp/meca/system1/codelets/BehaviorCodelet.java
+++ b/src/main/java/br/unicamp/meca/system1/codelets/BehaviorCodelet.java
@@ -46,7 +46,7 @@ public abstract class BehaviorCodelet extends Codelet {
protected ArrayList motivationalCodeletsIds;
protected ArrayList driveMemories;
- protected String soarCodeletId;
+ protected String planningCodeletId;
protected Memory broadcastMemory;
protected ActionSequencePlan actionSequencePlan;
@@ -67,36 +67,21 @@ public abstract class BehaviorCodelet extends Codelet {
* @param motivationalCodeletsIds
* the list of ids of the Motivational Codelets whose outputs
* will be read by this Behavior Codelet.
- * @param soarCodeletId
- * the id of the Soar Codelet whose outputs will be read by this
+ * @param planningCodeletId
+ * the id of the Planning Codelet whose outputs will be read by this
* Behavior Codelet.
- * @param actionSequencePlan
- * the ActionSequencePlan that this Behavior Codelet will provide
* @see Codelet
- * @see ActionSequencePlan
*/
public BehaviorCodelet(String id, ArrayList perceptualCodeletsIds, ArrayList motivationalCodeletsIds,
- String soarCodeletId, ActionSequencePlan actionSequencePlan) {
+ String planningCodeletId) {
super();
setName(id);
this.id = id;
this.perceptualCodeletsIds = perceptualCodeletsIds;
this.motivationalCodeletsIds = motivationalCodeletsIds;
- this.soarCodeletId = soarCodeletId;
- this.actionSequencePlan = actionSequencePlan;
+ this.planningCodeletId = planningCodeletId;
}
-
- /**
- * Track and advance actions in the sequence plan. To be implemented in each object of this class,
- * according to its action sequence plan.
- *
- * @param actionSequencePlan
- * the ActionSequencePlan that this Behavior Codelet provides.
- * @param perceptualMemories
- * the list Perceptual Memories coming from Perceptual Codelets.
- */
- public abstract void trackActionSequencePlan(ArrayList perceptualMemories, ActionSequencePlan actionSequencePlan);
-
+
@Override
public void accessMemoryObjects() {
@@ -123,14 +108,14 @@ public void accessMemoryObjects() {
for(String motivationalCodeletsId : motivationalCodeletsIds)
{
- Memory inputDrive = this.getInput(motivationalCodeletsId + "_DRIVE_MO");
+ Memory inputDrive = this.getInput(motivationalCodeletsId + "Drive");
driveMemories.add(inputDrive);
}
}
}
if(broadcastMemory == null) {
- broadcastMemory = this.getBroadcast(soarCodeletId, index);
+ broadcastMemory = this.getBroadcast(planningCodeletId, index);
}
if(actionSequencePlanMemoryContainer == null)
@@ -172,39 +157,51 @@ public void calculateActivation() {
}
+ /**
+ * Builds the action sequence plan to be outputed by this BehaviorCodelet
+ *
+ * @param perceptualMemories the Perceptual Memories coming from Perceptual Codelets.
+ * @return the action sequence plan to be followed.
+ */
+ protected abstract ActionSequencePlan buildActionSequencePlan(ArrayList perceptualMemories);
+
@Override
public void proc() {
- trackActionSequencePlan(perceptualMemories,actionSequencePlan);
+ actionSequencePlan = buildActionSequencePlan(perceptualMemories);
+
+ if(broadcastMemory != null && broadcastMemory.getI()!= null && broadcastMemory.getI() instanceof ActionSequencePlan)
+ actionSequencePlan = (ActionSequencePlan) broadcastMemory.getI();
if(actionSequencePlan != null) {
((MemoryContainer) actionSequencePlanMemoryContainer).setI(actionSequencePlan,getActivation(),id);
- ((MemoryContainer) actionSequencePlanRequestMemoryContainer).setI(null,0.0d,id);
+ ((MemoryContainer) actionSequencePlanRequestMemoryContainer).setI(null,0.0d,"R_"+id);
}else {
((MemoryContainer) actionSequencePlanMemoryContainer).setI(null,0.0d,id);
- ((MemoryContainer) actionSequencePlanRequestMemoryContainer).setI(id,getActivation(),id);
+ ((MemoryContainer) actionSequencePlanRequestMemoryContainer).setI(id,getActivation(),"R_"+id);
}
}
+
/**
- * Returns the id of the Soar Codelet whose outputs will be read by this
+ * Returns the id of the Planning Codelet whose outputs will be read by this
* Behavior Codelet.
*
- * @return the soarCodeletId
+ * @return the planningCodeletId
*/
- public String getSoarCodeletId() {
- return soarCodeletId;
+ public String getPlanningCodeletId() {
+ return planningCodeletId;
}
/**
- * Sets the id of the Soar Codelet whose outputs will be read by this
+ * Sets the id of the Planning Codelet whose outputs will be read by this
* Behavior Codelet.
*
- * @param soarCodeletId
- * the soarCodeletId to set
+ * @param planningCodeletId
+ * the planningCodeletId to set
*/
- public void setSoarCodeletId(String soarCodeletId) {
- this.soarCodeletId = soarCodeletId;
+ public void setPlanningCodeletId(String planningCodeletId) {
+ this.planningCodeletId = planningCodeletId;
}
/**
diff --git a/src/main/java/br/unicamp/meca/system1/codelets/MotivationalCodelet.java b/src/main/java/br/unicamp/meca/system1/codelets/MotivationalCodelet.java
index ec55198..6307783 100644
--- a/src/main/java/br/unicamp/meca/system1/codelets/MotivationalCodelet.java
+++ b/src/main/java/br/unicamp/meca/system1/codelets/MotivationalCodelet.java
@@ -73,14 +73,14 @@ public void accessMemoryObjects() {
if (getSensoryVariables().size() == 0) {
for (Memory sensoryMO : getInputs()) {
- if (!sensoryMO.getName().contains("DRIVE"))
+ if (!sensoryMO.getName().contains("Drive"))
getSensoryVariables().add(sensoryMO);
}
}
if (getDrivesRelevance().size() == 0) {
for (Memory driveMO : getInputs()) {
- if (driveMO.getName().contains("DRIVE")) {
+ if (driveMO.getName().contains("Drive")) {
getDrivesRelevance().putAll((Map extends Memory, ? extends Double>) driveMO.getI());
}
}
diff --git a/src/main/java/br/unicamp/meca/system1/codelets/MotorCodelet.java b/src/main/java/br/unicamp/meca/system1/codelets/MotorCodelet.java
index c92f7e3..a22d794 100644
--- a/src/main/java/br/unicamp/meca/system1/codelets/MotorCodelet.java
+++ b/src/main/java/br/unicamp/meca/system1/codelets/MotorCodelet.java
@@ -34,7 +34,7 @@ public abstract class MotorCodelet extends Codelet implements IMotorCodelet{
protected String id;
- protected Memory motorMemory;
+ protected volatile Memory motorMemory;
/**
* Creates a MECA Motor Codelet.
diff --git a/src/main/java/br/unicamp/meca/system1/codelets/RosTopicOneShotPublisherMotorCodelet.java b/src/main/java/br/unicamp/meca/system1/codelets/RosTopicOneShotPublisherMotorCodelet.java
new file mode 100644
index 0000000..2f9d27a
--- /dev/null
+++ b/src/main/java/br/unicamp/meca/system1/codelets/RosTopicOneShotPublisherMotorCodelet.java
@@ -0,0 +1,54 @@
+/**
+ *
+ */
+package br.unicamp.meca.system1.codelets;
+
+import br.unicamp.cst.bindings.rosjava.RosTopicOneShotPublisherCodelet;
+import java.net.URI;
+
+
+/**
+ * A Wrapper of the CST's RosTopicPublisherCodelet implementing the IMotorCodelet interface,
+ * in order to be able to be mounted on the MecaMind.
+ *
+ * @author andre
+ *
+ * @param The ROS Message Type - Ex: std_msgs.String from ROS standard messages
+ */
+public abstract class RosTopicOneShotPublisherMotorCodelet extends RosTopicOneShotPublisherCodelet implements IMotorCodelet{
+
+ protected String id;
+
+ /**
+ * Constructor for the RosTopicPublisherMotorCodelet.
+ *
+ * @param id the id of this Motor Codelet, to be used in mounting MECA Mind. Also the name of this ROS node.
+ * @param topic the name of the ROS topic this node will be publishing to.
+ * @param messageType the ROS message type. Ex: "std_msgs.String".
+ * @param host the host IP where to run. Ex: "127.0.0.1".
+ * @param masterURI the URI of the master ROS node. Ex: new URI("http://127.0.0.1:11311").
+ */
+ public RosTopicOneShotPublisherMotorCodelet(String id, String topic, String messageType, String host, URI masterURI) {
+ super(id, topic, messageType, host, masterURI);
+ this.id = id;
+ }
+
+ /**
+ * Returns the id of this RosTopicPublisherMotorCodelet.
+ *
+ * @return the id
+ */
+ public String getId() {
+ return id;
+ }
+
+ /**
+ * Sets the id of this RosTopicPublisherMotorCodelet.
+ *
+ * @param id
+ * the id to set
+ */
+ public void setId(String id) {
+ this.id = id;
+ }
+}
diff --git a/src/main/java/br/unicamp/meca/system2/codelets/GoalCodelet.java b/src/main/java/br/unicamp/meca/system2/codelets/GoalCodelet.java
index 1935283..4bd6a7f 100644
--- a/src/main/java/br/unicamp/meca/system2/codelets/GoalCodelet.java
+++ b/src/main/java/br/unicamp/meca/system2/codelets/GoalCodelet.java
@@ -12,6 +12,11 @@
******************************************************************************/
package br.unicamp.meca.system2.codelets;
+import br.unicamp.cst.core.entities.Memory;
+import br.unicamp.cst.core.entities.MemoryContainer;
+import br.unicamp.cst.representation.idea.Idea;
+import br.unicamp.meca.memory.WorkingMemory;
+
/**
* This class represents MECA's Goal Codelet. Goals are created in MECA by the
* Goal Codelet. The Goal Codelet uses the Current Perception in order to
@@ -25,6 +30,9 @@
*/
public abstract class GoalCodelet extends br.unicamp.cst.motivational.GoalCodelet {
+ private Memory actionSequencePlanRequestMemoryContainer;
+ private WorkingMemory wm;
+
/**
* Creates a MECA's Goal Codelet.
*
@@ -33,5 +41,47 @@ public abstract class GoalCodelet extends br.unicamp.cst.motivational.GoalCodele
*/
public GoalCodelet(String id) {
super(id);
+ setName(id);
}
+
+ @Override
+ public void proc() {
+ if (isInit()) {
+ setHypotheticalSituation((Idea) getInputHypotheticalSituationsMO().getI());
+ setGoal(goalGeneration(getHypotheticalSituation()));
+ ((MemoryContainer)getGoalMO()).setI(getGoal(),getActivation(),getId());
+ }
+
+ setInit(true);
+ }
+
+ /**
+ * @return the actionSequencePlanRequestMemoryContainer
+ */
+ public Memory getActionSequencePlanRequestMemoryContainer() {
+ return actionSequencePlanRequestMemoryContainer;
+ }
+
+ /**
+ * @param actionSequencePlanRequestMemoryContainer the actionSequencePlanRequestMemoryContainer to set
+ */
+ public void setActionSequencePlanRequestMemoryContainer(Memory actionSequencePlanRequestMemoryContainer) {
+ this.actionSequencePlanRequestMemoryContainer = actionSequencePlanRequestMemoryContainer;
+ }
+
+ /**
+ * @return the wm
+ */
+ public WorkingMemory getWm() {
+ return wm;
+ }
+
+ /**
+ * @param wm the wm to set
+ */
+ public void setWm(WorkingMemory wm) {
+ this.wm = wm;
+ }
+
+
}
diff --git a/src/main/java/br/unicamp/meca/system2/codelets/IPlanningCodelet.java b/src/main/java/br/unicamp/meca/system2/codelets/IPlanningCodelet.java
new file mode 100644
index 0000000..1931e3a
--- /dev/null
+++ b/src/main/java/br/unicamp/meca/system2/codelets/IPlanningCodelet.java
@@ -0,0 +1,53 @@
+/**
+ *
+ */
+package br.unicamp.meca.system2.codelets;
+
+import java.util.List;
+
+import br.unicamp.cst.core.entities.Memory;
+
+/**
+ * @author andre
+ *
+ */
+public interface IPlanningCodelet {
+
+ /**
+ * Returns the id of this Planning Codelet.
+ *
+ * @return the id
+ */
+ String getId();
+
+ /**
+ * Gets the list of output memories.
+ *
+ * @return the outputs.
+ */
+ List getOutputs();
+
+ /**
+ * Add a memory to the output list.
+ *
+ * @param memory
+ * one output to set.
+ */
+ void addOutput(Memory memory);
+
+ /**
+ * Gets the input memories list.
+ *
+ * @return the inputs.
+ */
+ List getInputs();
+
+ /**
+ * Add one memory to the input list.
+ *
+ * @param memory
+ * one input to set.
+ */
+ void addInput(Memory memory);
+
+}
diff --git a/src/main/java/br/unicamp/meca/system2/codelets/SoarCodelet.java b/src/main/java/br/unicamp/meca/system2/codelets/SoarCodelet.java
index 4dd8dd1..7907250 100644
--- a/src/main/java/br/unicamp/meca/system2/codelets/SoarCodelet.java
+++ b/src/main/java/br/unicamp/meca/system2/codelets/SoarCodelet.java
@@ -18,9 +18,7 @@
import java.util.List;
import br.unicamp.cst.core.entities.Memory;
-import br.unicamp.cst.motivational.Goal;
-import br.unicamp.cst.representation.owrl.AbstractObject;
-import br.unicamp.cst.representation.owrl.Property;
+import br.unicamp.cst.representation.idea.Idea;
import br.unicamp.meca.memory.WorkingMemory;
/**
@@ -32,7 +30,7 @@
* @author W. Gibaut
* @see br.unicamp.cst.bindings.soar.JSoarCodelet
*/
-public abstract class SoarCodelet extends br.unicamp.cst.bindings.soar.JSoarCodelet {
+public abstract class SoarCodelet extends br.unicamp.cst.bindings.soar.JSoarCodelet implements IPlanningCodelet {
private String id;
@@ -110,11 +108,11 @@ public void accessMemoryObjects() {
@Override
public void proc() {
- AbstractObject il = processWorkingMemoryInput();
- if (il.getCompositeList().size() == 0)
+ Idea il = processWorkingMemoryInput();
+ if (il.getL().size() == 0)
return;
- setInputLinkAO(il);
+ this.setInputLinkIdea(il);
if (getDebugState() == 0)
getJsoar().step();
@@ -124,7 +122,8 @@ public void proc() {
if (commandList != null) {
Collections.addAll(rawPlan, commandList);
- workingMemory.getPlansMemory().setI(rawPlan);
+ //workingMemory.getPlansMemory().setI(rawPlan);
+ workingMemory.getInternalMemory("PlansMemory").setI(rawPlan);
workingMemoryOutputMO.setI(workingMemory);
@@ -147,44 +146,49 @@ public void proc() {
*
* @return an abstract object represent an Input link.
*/
- public AbstractObject processWorkingMemoryInput() {
+ public Idea processWorkingMemoryInput() {
- AbstractObject il = new AbstractObject("InputLink");
+ Idea il = Idea.createIdea("InputLink","",0);
- AbstractObject currentPerceptionWO = (AbstractObject) workingMemory.getCurrentPerceptionMemory().getI() != null
- ? convertToAbstractObject((AbstractObject) workingMemory.getCurrentPerceptionMemory().getI(),
+ //AbstractObject currentPerceptionWO = (AbstractObject) workingMemory.getCurrentPerceptionMemory().getI() != null
+ Idea currentPerceptionWO = (Idea) workingMemory.getInternalMemory("CurrentPerceptionMemory").getI() != null
+ ? convertToIdea((Idea) workingMemory.getInternalMemory("CurrentPerceptionMemory").getI(),
"CURRENT_PERCEPTION")
: null;
- AbstractObject imaginationsWO = (List) workingMemory.getImaginationsMemory().getI() != null
- ? convertToAbstractObject((List) workingMemory.getImaginationsMemory().getI(),
+ //AbstractObject imaginationsWO = (List) workingMemory.getImaginationsMemory().getI() != null
+ Idea imaginationsWO = (List) workingMemory.getInternalMemory("ImaginationsMemory").getI() != null
+ ? convertToIdea((List) workingMemory.getInternalMemory("ImaginationsMemory").getI(),
"IMAGINATION")
: null;
- AbstractObject goalsWO = (List) workingMemory.getGoalsMemory().getI() != null
- ? goalToAbstractObject((List) workingMemory.getGoalsMemory().getI()) : null;
+ //AbstractObject goalsWO = (List) workingMemory.getGoalsMemory().getI() != null
+ Idea goalsWO = (List) workingMemory.getInternalMemory("GoalsMemory").getI() != null
+ ? goalToIdea((List) workingMemory.getInternalMemory("GoalsMemory").getI()) : null;
- AbstractObject globalWO = (List) workingMemory.getGlobalWorkspaceMemory().getI() != null
- ? globalWorkspaceToAbstractObject((List) workingMemory.getGlobalWorkspaceMemory().getI())
+ //AbstractObject globalWO = (List) workingMemory.getGlobalWorkspaceMemory().getI() != null
+ Idea globalWO = (List) workingMemory.getInternalMemory("GlobalWorkspaceMemory").getI() != null
+ ? globalWorkspaceToIdea((List) workingMemory.getInternalMemory("GlobalWorkspaceMemory").getI())
: null;
- AbstractObject epRecallWO = (List) workingMemory.getEpisodicRecallMemory().getI() != null
- ? epRecallToAbstractObject((List) workingMemory.getEpisodicRecallMemory().getI()) : null;
+ //AbstractObject epRecallWO = (List) workingMemory.getEpisodicRecallMemory().getI() != null
+ Idea epRecallWO = (List) workingMemory.getInternalMemory("EpisodicRecallMemory").getI() != null
+ ? epRecallToIdea((List) workingMemory.getInternalMemory("EpisodicRecallMemory").getI()) : null;
if (currentPerceptionWO != null)
- il.addCompositePart(currentPerceptionWO);
+ il.add(currentPerceptionWO);
if (imaginationsWO != null)
- il.addCompositePart(imaginationsWO);
+ il.add(imaginationsWO);
if (goalsWO != null)
- il.addCompositePart(goalsWO);
+ il.add(goalsWO);
if (globalWO != null)
- il.addCompositePart(globalWO);
+ il.add(globalWO);
if (epRecallWO != null)
- il.addCompositePart(epRecallWO);
+ il.add(epRecallWO);
return il;
}
@@ -198,11 +202,11 @@ public AbstractObject processWorkingMemoryInput() {
* the node name.
* @return the abstract object.
*/
- public AbstractObject convertToAbstractObject(AbstractObject abstractObject, String nodeName) {
+ public Idea convertToIdea(Idea abstractObject, String nodeName) {
- AbstractObject abs = new AbstractObject(nodeName);
+ Idea abs = Idea.createIdea(nodeName,"",0);
- abs.addCompositePart(abstractObject);
+ abs.add(abstractObject);
return abs;
}
@@ -210,18 +214,18 @@ public AbstractObject convertToAbstractObject(AbstractObject abstractObject, Str
/**
* Converts to abstract object.
*
- * @param abstractObjects
+ * @param ideas
* the list of input abstract objects.
* @param nodeNameTemplate
* the node name template.
* @return the abstract object.
*/
- public AbstractObject convertToAbstractObject(List abstractObjects, String nodeNameTemplate) {
+ public Idea convertToIdea(List ideas, String nodeNameTemplate) {
- AbstractObject configs = new AbstractObject(abstractObjects.toString());
+ Idea configs = Idea.createIdea(ideas.toString(),"",0);
- for (AbstractObject abs : abstractObjects) {
- configs.addAggregatePart(convertToAbstractObject(abs, nodeNameTemplate));
+ for (Idea abs : ideas) {
+ configs.add(convertToIdea(abs, nodeNameTemplate));
}
return configs;
}
@@ -233,15 +237,16 @@ public AbstractObject convertToAbstractObject(List abstractObjec
* the list of goals.
* @return the Abstract Object representing the Goals.
*/
- public AbstractObject goalToAbstractObject(List goals) {
+ public Idea goalToIdea(List goals) {
- AbstractObject go = new AbstractObject("Goals");
+ Idea go = Idea.createIdea("Goals","",0);
- for (Goal goal : goals) {
+ for (Idea goal : goals) {
- AbstractObject temp = convertToAbstractObject(goal.getGoalAbstractObjects(), "GOAL");
- temp.addProperty(new Property(goal.getId()));
- go.addAggregatePart(temp);
+ //Idea temp = convertToIdea(goal.getGoalIdeas(), "GOAL");
+ //temp.add(new Idea(goal.getId()));
+ //go.add(temp);
+ go.add(goal);
}
return go;
}
@@ -253,17 +258,17 @@ public AbstractObject goalToAbstractObject(List goals) {
* the list of memories
* @return the abstract object representing global workspace
*/
- public AbstractObject globalWorkspaceToAbstractObject(List global) {
+ public Idea globalWorkspaceToIdea(List global) {
- List globalAbstractObjects = null;
+ List globalIdeass = null;
List globalStrings = null;
for (Memory mem : global) {
- if (isAbstractObject(mem.getI())) {
+ if (isIdea(mem.getI())) {
- globalAbstractObjects.add((AbstractObject) mem.getI());
+ globalIdeass.add((Idea) mem.getI());
}
}
@@ -275,11 +280,11 @@ public AbstractObject globalWorkspaceToAbstractObject(List global) {
}
}
- AbstractObject gAbs = convertToAbstractObject(globalAbstractObjects, "GLOBAL_WORKSPACE");
+ Idea gAbs = convertToIdea(globalIdeass, "GLOBAL_WORKSPACE");
for (String st : globalStrings) {
- gAbs.addAggregatePart(new AbstractObject(st));
+ gAbs.add(Idea.createIdea(st,"",0));
}
return gAbs;
@@ -292,19 +297,19 @@ public AbstractObject globalWorkspaceToAbstractObject(List global) {
* the list of memories representing the episodic recall.
* @return the Abstract Object representing an episodic recall.
*/
- public AbstractObject epRecallToAbstractObject(List episodicRecall) {
+ public Idea epRecallToIdea(List episodicRecall) {
- List epConfigurations = null;
+ List epConfigurations = null;
for (Memory mem : episodicRecall) {
- if (isAbstractObject(mem.getI())) {
+ if (isIdea(mem.getI())) {
- epConfigurations.add((AbstractObject) mem.getI());
+ epConfigurations.add((Idea) mem.getI());
}
}
- AbstractObject gConf = convertToAbstractObject(epConfigurations, "EPISODIC_RECALL_MEMORY");
+ Idea gConf = convertToIdea(epConfigurations, "EPISODIC_RECALL_MEMORY");
return gConf;
}
@@ -316,9 +321,9 @@ public AbstractObject epRecallToAbstractObject(List episodicRecall) {
* the object to be tested
* @return true if the obj is an abstract object.
*/
- public boolean isAbstractObject(Object obj) {
+ public boolean isIdea(Object obj) {
- if (obj.getClass() == AbstractObject.class)
+ if (obj.getClass() == Idea.class)
return true;
else
return false;
diff --git a/src/test/java/br/unicamp/meca/mind/MecaMindTest.java b/src/test/java/br/unicamp/meca/mind/MecaMindTest.java
index 4e789c2..2662225 100644
--- a/src/test/java/br/unicamp/meca/mind/MecaMindTest.java
+++ b/src/test/java/br/unicamp/meca/mind/MecaMindTest.java
@@ -14,27 +14,30 @@
import org.junit.Test;
import br.unicamp.cst.core.entities.Codelet;
+import br.unicamp.cst.core.entities.Memory;
import br.unicamp.cst.core.entities.MemoryContainer;
import br.unicamp.cst.core.exceptions.CodeletActivationBoundsException;
-import br.unicamp.cst.util.MindViewer;
-import br.unicamp.meca.mind.action.Test1ActionFromPerceptionCodelet;
-import br.unicamp.meca.mind.action.Test1ActionFromPlanningCodelet;
-import br.unicamp.meca.mind.action.Test2ActionFromPlanningCodelets;
+import br.unicamp.cst.util.viewer.MindViewer;
+import br.unicamp.meca.mind.action.Test1ActivityCodelet;
+import br.unicamp.meca.mind.action.Test2ActivityCodelet;
+import br.unicamp.meca.mind.action.Test3ActivityCodelet;
import br.unicamp.meca.mind.behavior.Test1AndTest2BehaviorCodelet;
import br.unicamp.meca.mind.motivational.TestMotivationalFromPerceptionCodelet;
import br.unicamp.meca.mind.motivational.TestMotivationalFromPlanningCodelet;
import br.unicamp.meca.mind.motor.TestMotorCodelet;
import br.unicamp.meca.mind.perceptual.TestPerceptualCodelet;
+import br.unicamp.meca.mind.planning.TestSoarCodelet;
import br.unicamp.meca.mind.sensory.TestPerceptionSensoryCodelet;
import br.unicamp.meca.mind.sensory.TestPlanningSensoryCodelet;
import br.unicamp.meca.models.ActionSequencePlan;
-import br.unicamp.meca.system1.codelets.ActionFromPerceptionCodelet;
-import br.unicamp.meca.system1.codelets.ActionFromPlanningCodelet;
+import br.unicamp.meca.system1.codelets.ActivityCodelet;
+import br.unicamp.meca.system1.codelets.ActivityTrackingCodelet;
import br.unicamp.meca.system1.codelets.BehaviorCodelet;
import br.unicamp.meca.system1.codelets.IMotorCodelet;
import br.unicamp.meca.system1.codelets.ISensoryCodelet;
import br.unicamp.meca.system1.codelets.MotivationalCodelet;
import br.unicamp.meca.system1.codelets.PerceptualCodelet;
+import br.unicamp.meca.system2.codelets.IPlanningCodelet;
/**
* @author andre
@@ -51,6 +54,16 @@ public class MecaMindTest {
private static TestPlanningSensoryCodelet testPlanningSensoryCodelet;
private static TestMotorCodelet testMotorCodelet;
+
+ private static List perceptualCodelets;
+
+ private static List sensoryCodelets;
+
+ private static List motivationalCodelets;
+
+ private static List activityCodelets;
+
+ private static IPlanningCodelet planningCodelet;
@BeforeClass
public static void setup() throws InterruptedException {
@@ -58,21 +71,18 @@ public static void setup() throws InterruptedException {
mecaMind = new MecaMind("MecaMind");
/* Sensory codelets we are about to create for this Meca mind*/
- List sensoryCodelets = new ArrayList<>();
+ sensoryCodelets = new ArrayList<>();
/* Lists that will hold the codelets ids. This is important
* for the MECA mind mounting algorithm be able to glue the
* codelets according to the reference architecture
* */
- ArrayList sensoryCodeletsIds = new ArrayList<>();
-
+ ArrayList sensoryPerceptionCodeletsIds = new ArrayList<>();
+
testPerceptionSensoryCodelet = new TestPerceptionSensoryCodelet("TestPerceptionSensoryCodelet");
sensoryCodelets.add(testPerceptionSensoryCodelet);
- sensoryCodeletsIds.add(testPerceptionSensoryCodelet.getId());
+ sensoryPerceptionCodeletsIds.add(testPerceptionSensoryCodelet.getId());
- testPlanningSensoryCodelet = new TestPlanningSensoryCodelet("TestPlanningSensoryCodelet");
- sensoryCodelets.add(testPlanningSensoryCodelet);
- sensoryCodeletsIds.add(testPlanningSensoryCodelet.getId());
/*
* Now it is a good time to create the motor codelets, before the Behavioral ones,
@@ -90,26 +100,27 @@ public static void setup() throws InterruptedException {
* This codelet must receive the ids of the sensory codelets,
* in order to be glued to them, receiving their inputs.
*/
- List perceptualCodelets = new ArrayList<>();
- ArrayList perceptualCodeletsIds = new ArrayList<>();
+ perceptualCodelets = new ArrayList<>();
+ ArrayList perceptualPerceptionCodeletsIds = new ArrayList<>();
- TestPerceptualCodelet testPerceptualCodelet = new TestPerceptualCodelet("TestPerceptualCodelet", sensoryCodeletsIds);
- perceptualCodeletsIds.add(testPerceptualCodelet.getId());
+ TestPerceptualCodelet testPerceptualCodelet = new TestPerceptualCodelet("TestPerceptualCodelet", sensoryPerceptionCodeletsIds);
+ perceptualPerceptionCodeletsIds.add(testPerceptualCodelet.getId());
perceptualCodelets.add(testPerceptualCodelet);
+
/*
* Next step is to create the motivational codelets.
* This codelets must receive the ids of the sensory codelets,
* in order to be glued to them, receiving their inputs.
*/
- List motivationalCodelets = new ArrayList<>();
+ motivationalCodelets = new ArrayList<>();
ArrayList testMotivationalFromPerceptionCodeletIds = new ArrayList<>();
TestMotivationalFromPerceptionCodelet testMotivationalFromPerceptionCodelet;
try {
- testMotivationalFromPerceptionCodelet = new TestMotivationalFromPerceptionCodelet("TestMotivationalFromPerceptionCodelet", 0, 0.45, 0.9, sensoryCodeletsIds, new HashMap());
+ testMotivationalFromPerceptionCodelet = new TestMotivationalFromPerceptionCodelet("TestMotivationalFromPerceptionCodelet", 0, 0.45, 0.9, sensoryPerceptionCodeletsIds, new HashMap());
testMotivationalFromPerceptionCodeletIds.add(testMotivationalFromPerceptionCodelet.getId());
motivationalCodelets.add(testMotivationalFromPerceptionCodelet);
@@ -117,45 +128,20 @@ public static void setup() throws InterruptedException {
e.printStackTrace();
}
- ArrayList testMotivationalFromPlanningCodeletIds = new ArrayList<>();
-
- TestMotivationalFromPlanningCodelet testMotivationalFromPlanningCodelet;
-
- try {
-
- testMotivationalFromPlanningCodelet = new TestMotivationalFromPlanningCodelet("TestMotivationalFromPlanningCodelet", 0, 0.5, 0.9, sensoryCodeletsIds, new HashMap());
- testMotivationalFromPlanningCodeletIds.add(testMotivationalFromPlanningCodelet.getId());
- motivationalCodelets.add(testMotivationalFromPlanningCodelet);
- } catch (CodeletActivationBoundsException e) {
- e.printStackTrace();
- }
-
/*
* Last step is to create the behavioral codelets,
* They receive the ids of the perceptual codelets and
* motor codelets, in order to be glued to them, according
* to the reference architecture.
*/
+
+ activityCodelets = new ArrayList<>();
- List actionFromPerceptionCodelets = new ArrayList<>();
-
- Test1ActionFromPerceptionCodelet test1ActionFromPerceptionCodelet = new Test1ActionFromPerceptionCodelet("Test1ActionFromPerceptionCodelet", perceptualCodeletsIds, testMotivationalFromPerceptionCodeletIds, testMotorCodelet.getId(), null);
- actionFromPerceptionCodelets.add(test1ActionFromPerceptionCodelet);
-
- List actionFromPlanningCodelets = new ArrayList<>();
-
- Test1ActionFromPlanningCodelet test1ActionFromPlanningCodelet = new Test1ActionFromPlanningCodelet("Test1ActionFromPlanningCodelet", perceptualCodeletsIds, testMotorCodelet.getId(), null);
- actionFromPlanningCodelets.add(test1ActionFromPlanningCodelet);
-
- Test2ActionFromPlanningCodelets test2ActionFromPlanningCodelets = new Test2ActionFromPlanningCodelets("Test2ActionFromPlanningCodelets", perceptualCodeletsIds, testMotorCodelet.getId(), null);
- actionFromPlanningCodelets.add(test2ActionFromPlanningCodelets);
-
- List behaviorCodelets = new ArrayList<>();
-
- ActionSequencePlan test1Test2ActionSequence = new ActionSequencePlan(new String[] {"Test1ActionFromPlanningCodelet","Test2ActionFromPlanningCodelets"});
-
- Test1AndTest2BehaviorCodelet test1AndTest2BehaviorCodelet = new Test1AndTest2BehaviorCodelet("Test1AndTest2BehaviorCodelet", perceptualCodeletsIds, testMotivationalFromPlanningCodeletIds, null, test1Test2ActionSequence);
- behaviorCodelets.add(test1AndTest2BehaviorCodelet);
+ Test1ActivityCodelet test1ActivityCodelet = new Test1ActivityCodelet("Test1Activity", perceptualPerceptionCodeletsIds, testMotivationalFromPerceptionCodeletIds, testMotorCodelet.getId(), null);
+ activityCodelets.add(test1ActivityCodelet);
+
+ planningCodelet = new TestSoarCodelet("soar");
+
/*
* Inserting the System 1 codelets inside MECA mind
@@ -164,10 +150,22 @@ public static void setup() throws InterruptedException {
mecaMind.setIMotorCodelets(motorCodelets);
mecaMind.setPerceptualCodelets(perceptualCodelets);
mecaMind.setMotivationalCodelets(motivationalCodelets);
- mecaMind.setActionFromPerceptionCodelets(actionFromPerceptionCodelets);
- mecaMind.setActionFromPlanningCodelets(actionFromPlanningCodelets);
- mecaMind.setBehaviorCodelets(behaviorCodelets);
+ mecaMind.setActivityCodelets(activityCodelets);
+ mecaMind.setPlanningCodelet(planningCodelet);
+
+
+ }
+
+ @AfterClass
+ public static void tearDown() {
+ mv.setVisible(false);
+ mecaMind.shutDown();
+ }
+
+ @Test
+ public void testMecaMindMountActivityReactWin() throws InterruptedException {
+
/*
* After passing references to the codelets, we call the method 'MecaMind.mountMecaMind()', which
* is responsible for wiring the MecaMind altogether according to the reference architecture, including
@@ -190,40 +188,24 @@ public static void setup() throws InterruptedException {
* codelets, which activation has a pivotal role.
*/
List listOfCodelets = new ArrayList<>();
- listOfCodelets.addAll(mecaMind.getActionFromPerceptionCodelets());
- listOfCodelets.addAll(mecaMind.getActionFromPlanningCodelets());
- listOfCodelets.addAll(mecaMind.getBehaviorCodelets());
+ listOfCodelets.addAll(mecaMind.getActivityCodelets());
mv = new MindViewer(mecaMind, "MECA Mind Inspection - "+mecaMind.getId(), listOfCodelets);
mv.setVisible(true);
Thread.sleep(1000);
- }
-
- @AfterClass
- public static void tearDown() {
-
- mv.setVisible(false);
- mecaMind.shutDown();
- }
-
- @Test
- public void testMecaMindMountActionFromPerceptionWin() throws InterruptedException {
-
//do something
String contentInTheEnvironment = "Something";
testPerceptionSensoryCodelet.setSensoryContents(contentInTheEnvironment);
- testPlanningSensoryCodelet.setSensoryContents(null);
-
Thread.sleep(1000);
//test something
- String messageExpected = "Test1ActionFromPerception - A black dog";
+ String messageExpected = "Test1Activity - A black dog";
MemoryContainer motorMemory = (MemoryContainer) testMotorCodelet.getInput("TestMotorCodelet");
@@ -235,8 +217,92 @@ public void testMecaMindMountActionFromPerceptionWin() throws InterruptedExcepti
}
@Test
- public void testMecaMindMountActionFromPlanningWin() throws InterruptedException {
+ public void testMecaMindMountActivityFromPlanningWin() throws InterruptedException {
+
+ ArrayList sensoryPlanningCodeletsIds = new ArrayList<>();
+ testPlanningSensoryCodelet = new TestPlanningSensoryCodelet("TestPlanningSensoryCodelet");
+ sensoryCodelets.add(testPlanningSensoryCodelet);
+ sensoryPlanningCodeletsIds.add(testPlanningSensoryCodelet.getId());
+
+ ArrayList perceptualPlanningCodeletsIds = new ArrayList<>();
+ TestPerceptualCodelet testPlanningCodelet = new TestPerceptualCodelet("TestPlanningCodelet", sensoryPlanningCodeletsIds);
+ perceptualPlanningCodeletsIds.add(testPlanningCodelet.getId());
+ perceptualCodelets.add(testPlanningCodelet);
+
+ ArrayList testMotivationalFromPlanningCodeletIds = new ArrayList<>();
+
+ TestMotivationalFromPlanningCodelet testMotivationalFromPlanningCodelet;
+
+ try {
+
+ testMotivationalFromPlanningCodelet = new TestMotivationalFromPlanningCodelet("TestMotivationalFromPlanningCodelet", 0, 0.5, 0.9, sensoryPlanningCodeletsIds, new HashMap());
+ testMotivationalFromPlanningCodeletIds.add(testMotivationalFromPlanningCodelet.getId());
+ motivationalCodelets.add(testMotivationalFromPlanningCodelet);
+ } catch (CodeletActivationBoundsException e) {
+ e.printStackTrace();
+ }
+
+ Test2ActivityCodelet test2ActivityCodelet = new Test2ActivityCodelet("Test2Activity", perceptualPlanningCodeletsIds, testMotivationalFromPlanningCodeletIds, testMotorCodelet.getId(), null);
+ activityCodelets.add(test2ActivityCodelet);
+
+ Test3ActivityCodelet test3ActivityCodelets = new Test3ActivityCodelet("Test3Activity", perceptualPlanningCodeletsIds, testMotivationalFromPlanningCodeletIds, testMotorCodelet.getId(), null);
+ activityCodelets.add(test3ActivityCodelets);
+
+ ActivityTrackingCodelet activityTrackingCodelet = new ActivityTrackingCodelet("ActivityTrackingCodelet", perceptualPlanningCodeletsIds) {
+
+ @Override
+ public void trackActionSequencePlan(ArrayList perceptualMemories, ActionSequencePlan actionSequencePlan) {
+
+ if(actionSequencePlan == null || actionSequencePlan.getActionStepSequence() == null) {
+ return;
+ }
+
+ actionSequencePlan.setCurrentActionIdIndex(0);
+
+ //In this test, will never go on to the second action. We could have limit on perceptual memory to move on, though.
+ }
+ };
+
+
+ List behaviorCodelets = new ArrayList<>();
+
+ Test1AndTest2BehaviorCodelet test1AndTest2BehaviorCodelet = new Test1AndTest2BehaviorCodelet("Test1AndTest2BehaviorCodelet", perceptualPlanningCodeletsIds, testMotivationalFromPlanningCodeletIds, null);
+ behaviorCodelets.add(test1AndTest2BehaviorCodelet);
+
+ mecaMind.setBehaviorCodelets(behaviorCodelets);
+ mecaMind.setActivityTrackingCodelet(activityTrackingCodelet);
+
+ /*
+ * After passing references to the codelets, we call the method 'MecaMind.mountMecaMind()', which
+ * is responsible for wiring the MecaMind altogether according to the reference architecture, including
+ * the creation of memory objects and containers which glue them together. This method is of pivotal
+ * importance and inside it resides all the value from the reference architecture created - the idea is
+ * that the user only has to create the codelets, put them inside lists of differente types and call
+ * this method, which transparently glue the codelets together accordingly to the MECA reference
+ * architecture.
+ */
+ mecaMind.mountMecaMind();
+
+ /*
+ * Starting the mind
+ */
+ mecaMind.start();
+
+ /*
+ * Instead of inserting the sensory codelets in the
+ * CST visualization tool, let's insert the behaviroal
+ * codelets, which activation has a pivotal role.
+ */
+ List listOfCodelets = new ArrayList<>();
+ listOfCodelets.addAll(mecaMind.getActivityCodelets());
+ listOfCodelets.addAll(mecaMind.getBehaviorCodelets());
+
+ mv = new MindViewer(mecaMind, "MECA Mind Inspection - "+mecaMind.getId(), listOfCodelets);
+ mv.setVisible(true);
+
+ Thread.sleep(1000);
+
//do something
String contentInTheEnvironment = "Something";
@@ -249,7 +315,7 @@ public void testMecaMindMountActionFromPlanningWin() throws InterruptedException
//test something
- String messageExpected = "Test1ActionFromPlanning - A black dog";
+ String messageExpected = "Test2Activity - A black dog";
MemoryContainer motorMemory = (MemoryContainer) testMotorCodelet.getInput("TestMotorCodelet");
diff --git a/src/test/java/br/unicamp/meca/mind/action/Test1ActionFromPlanningCodelet.java b/src/test/java/br/unicamp/meca/mind/action/Test1ActionFromPlanningCodelet.java
deleted file mode 100644
index 1ed9c58..0000000
--- a/src/test/java/br/unicamp/meca/mind/action/Test1ActionFromPlanningCodelet.java
+++ /dev/null
@@ -1,39 +0,0 @@
-/**
- *
- */
-package br.unicamp.meca.mind.action;
-
-import java.util.ArrayList;
-
-import br.unicamp.cst.core.entities.Memory;
-import br.unicamp.cst.core.entities.MemoryContainer;
-import br.unicamp.meca.system1.codelets.ActionFromPlanningCodelet;
-
-/**
- * @author andre
- *
- */
-public class Test1ActionFromPlanningCodelet extends ActionFromPlanningCodelet {
-
- public Test1ActionFromPlanningCodelet(String id, ArrayList perceptualCodeletsIds, String motorCodeletId,
- String soarCodeletId) {
- super(id, perceptualCodeletsIds, motorCodeletId, soarCodeletId);
- }
-
- @Override
- public void proc(ArrayList perceptualMemories, Memory broadcastMemory, Memory motorMemory) {
- if(perceptualMemories == null || perceptualMemories.size() == 0) {
- return;
- }
-
- motorMemory.setI(null);
-
- for(Memory memory: perceptualMemories) {
- if(memory.getI()!=null && memory.getI() instanceof String) {
- String perceptualContent = (String) memory.getI();
-
- ((MemoryContainer) motorMemory).setI("Test1ActionFromPlanning - "+perceptualContent,getActivation(),id);
- }
- }
- }
-}
diff --git a/src/test/java/br/unicamp/meca/mind/action/Test1ActivityCodelet.java b/src/test/java/br/unicamp/meca/mind/action/Test1ActivityCodelet.java
new file mode 100644
index 0000000..89b2d77
--- /dev/null
+++ b/src/test/java/br/unicamp/meca/mind/action/Test1ActivityCodelet.java
@@ -0,0 +1,52 @@
+/**
+ *
+ */
+package br.unicamp.meca.mind.action;
+
+import java.util.ArrayList;
+
+import br.unicamp.cst.core.entities.Memory;
+import br.unicamp.cst.core.entities.MemoryContainer;
+import br.unicamp.meca.system1.codelets.ActivityCodelet;
+
+/**
+ * @author andre
+ *
+ */
+public class Test1ActivityCodelet extends ActivityCodelet {
+
+ /**
+ * @param id
+ * @param perceptualCodeletsIds
+ * @param motivationalCodeletsIds
+ * @param motorCodeletId
+ * @param soarCodeletId
+ */
+ public Test1ActivityCodelet(String id, ArrayList perceptualCodeletsIds,
+ ArrayList motivationalCodeletsIds, String motorCodeletId, String soarCodeletId) {
+ super(id, perceptualCodeletsIds, motivationalCodeletsIds, motorCodeletId, soarCodeletId);
+ }
+
+ @Override
+ public void doConclusion(ArrayList perceptualMemories, Memory broadcastMemory, Memory motorMemory) {
+ System.out.println("Concluding "+id);
+ ((MemoryContainer) motorMemory).setI(id+" - concluded",getActivation(),id);
+ }
+
+ @Override
+ public void proc(ArrayList perceptualMemories, Memory broadcastMemory, Memory motorMemory) {
+ if(perceptualMemories == null || perceptualMemories.size() == 0) {
+ return;
+ }
+
+ ((MemoryContainer) motorMemory).setI(null,0.0,id);
+
+ for(Memory memory: perceptualMemories) {
+ if(memory.getI()!=null && memory.getI() instanceof String) {
+ String perceptualContent = (String) memory.getI();
+
+ ((MemoryContainer) motorMemory).setI(id+" - "+perceptualContent,getActivation(),id);
+ }
+ }
+ }
+}
diff --git a/src/test/java/br/unicamp/meca/mind/action/Test2ActionFromPlanningCodelets.java b/src/test/java/br/unicamp/meca/mind/action/Test2ActionFromPlanningCodelets.java
deleted file mode 100644
index ece7ea5..0000000
--- a/src/test/java/br/unicamp/meca/mind/action/Test2ActionFromPlanningCodelets.java
+++ /dev/null
@@ -1,41 +0,0 @@
-/**
- *
- */
-package br.unicamp.meca.mind.action;
-
-import java.util.ArrayList;
-
-import br.unicamp.cst.core.entities.Memory;
-import br.unicamp.cst.core.entities.MemoryContainer;
-import br.unicamp.meca.system1.codelets.ActionFromPlanningCodelet;
-
-/**
- * @author andre
- *
- */
-public class Test2ActionFromPlanningCodelets extends ActionFromPlanningCodelet {
-
- public Test2ActionFromPlanningCodelets(String id, ArrayList perceptualCodeletsIds, String motorCodeletId,
- String soarCodeletId) {
- super(id, perceptualCodeletsIds, motorCodeletId, soarCodeletId);
- }
-
- @Override
- public void proc(ArrayList perceptualMemories, Memory broadcastMemory, Memory motorMemory) {
- if(perceptualMemories == null || perceptualMemories.size() == 0) {
- return;
- }
-
- motorMemory.setI(null);
-
- for(Memory memory: perceptualMemories) {
- if(memory.getI()!=null && memory.getI() instanceof String) {
- String perceptualContent = (String) memory.getI();
-
- ((MemoryContainer) motorMemory).setI("Test2ActionFromPlanning - "+perceptualContent,getActivation(),id);
- }
- }
-
- }
-
-}
diff --git a/src/test/java/br/unicamp/meca/mind/action/Test2ActivityCodelet.java b/src/test/java/br/unicamp/meca/mind/action/Test2ActivityCodelet.java
new file mode 100644
index 0000000..22ad0bc
--- /dev/null
+++ b/src/test/java/br/unicamp/meca/mind/action/Test2ActivityCodelet.java
@@ -0,0 +1,51 @@
+/**
+ *
+ */
+package br.unicamp.meca.mind.action;
+
+import java.util.ArrayList;
+
+import br.unicamp.cst.core.entities.Memory;
+import br.unicamp.cst.core.entities.MemoryContainer;
+import br.unicamp.meca.system1.codelets.ActivityCodelet;
+
+/**
+ * @author andre
+ *
+ */
+public class Test2ActivityCodelet extends ActivityCodelet {
+
+ /**
+ * @param id
+ * @param perceptualCodeletsIds
+ * @param motivationalCodeletsIds
+ * @param motorCodeletId
+ * @param soarCodeletId
+ */
+ public Test2ActivityCodelet(String id, ArrayList perceptualCodeletsIds,
+ ArrayList motivationalCodeletsIds, String motorCodeletId, String soarCodeletId) {
+ super(id, perceptualCodeletsIds, motivationalCodeletsIds, motorCodeletId, soarCodeletId);
+ }
+
+ @Override
+ public void doConclusion(ArrayList perceptualMemories, Memory broadcastMemory, Memory motorMemory) {
+ System.out.println("Concluding Test2Activity");
+ }
+
+ @Override
+ public void proc(ArrayList perceptualMemories, Memory broadcastMemory, Memory motorMemory) {
+ if(perceptualMemories == null || perceptualMemories.size() == 0) {
+ return;
+ }
+
+ ((MemoryContainer) motorMemory).setI(null,0.0,id);
+
+ for(Memory memory: perceptualMemories) {
+ if(memory.getI()!=null && memory.getI() instanceof String) {
+ String perceptualContent = (String) memory.getI();
+
+ ((MemoryContainer) motorMemory).setI("Test2Activity - "+perceptualContent,getActivation(),id);
+ }
+ }
+ }
+}
diff --git a/src/test/java/br/unicamp/meca/mind/action/Test1ActionFromPerceptionCodelet.java b/src/test/java/br/unicamp/meca/mind/action/Test3ActivityCodelet.java
similarity index 52%
rename from src/test/java/br/unicamp/meca/mind/action/Test1ActionFromPerceptionCodelet.java
rename to src/test/java/br/unicamp/meca/mind/action/Test3ActivityCodelet.java
index 6262a3a..01ba847 100644
--- a/src/test/java/br/unicamp/meca/mind/action/Test1ActionFromPerceptionCodelet.java
+++ b/src/test/java/br/unicamp/meca/mind/action/Test3ActivityCodelet.java
@@ -7,35 +7,45 @@
import br.unicamp.cst.core.entities.Memory;
import br.unicamp.cst.core.entities.MemoryContainer;
-import br.unicamp.meca.system1.codelets.ActionFromPerceptionCodelet;
+import br.unicamp.meca.system1.codelets.ActivityCodelet;
/**
* @author andre
*
*/
-public class Test1ActionFromPerceptionCodelet extends ActionFromPerceptionCodelet {
+public class Test3ActivityCodelet extends ActivityCodelet {
- public Test1ActionFromPerceptionCodelet(String id, ArrayList perceptualCodeletsIds,
+ /**
+ * @param id
+ * @param perceptualCodeletsIds
+ * @param motivationalCodeletsIds
+ * @param motorCodeletId
+ * @param soarCodeletId
+ */
+ public Test3ActivityCodelet(String id, ArrayList perceptualCodeletsIds,
ArrayList motivationalCodeletsIds, String motorCodeletId, String soarCodeletId) {
super(id, perceptualCodeletsIds, motivationalCodeletsIds, motorCodeletId, soarCodeletId);
}
+
+ @Override
+ public void doConclusion(ArrayList perceptualMemories, Memory broadcastMemory, Memory motorMemory) {
+ System.out.println("Concluding Test3Activity");
+ }
@Override
public void proc(ArrayList perceptualMemories, Memory broadcastMemory, Memory motorMemory) {
-
if(perceptualMemories == null || perceptualMemories.size() == 0) {
return;
}
- motorMemory.setI(null);
+ ((MemoryContainer) motorMemory).setI(null,0.0,id);
for(Memory memory: perceptualMemories) {
if(memory.getI()!=null && memory.getI() instanceof String) {
String perceptualContent = (String) memory.getI();
- ((MemoryContainer) motorMemory).setI("Test1ActionFromPerception - "+perceptualContent,getActivation(),id);
+ ((MemoryContainer) motorMemory).setI("Test3Activity - "+perceptualContent,getActivation(),id);
}
}
}
-
}
diff --git a/src/test/java/br/unicamp/meca/mind/action/TestActivityCodelet.java b/src/test/java/br/unicamp/meca/mind/action/TestActivityCodelet.java
new file mode 100644
index 0000000..51a724c
--- /dev/null
+++ b/src/test/java/br/unicamp/meca/mind/action/TestActivityCodelet.java
@@ -0,0 +1,152 @@
+/*
+ * To change this license header, choose License Headers in Project Properties.
+ * To change this template file, choose Tools | Templates
+ * and open the template in the editor.
+ */
+package br.unicamp.meca.mind.action;
+
+import br.unicamp.cst.core.entities.MemoryContainer;
+import br.unicamp.cst.core.entities.MemoryObject;
+import br.unicamp.meca.mind.MecaMind;
+import br.unicamp.meca.mind.motor.TestMotorCodelet;
+import br.unicamp.meca.mind.perceptual.TestPerceptualCodelet;
+import br.unicamp.meca.mind.sensory.TestPerceptionSensoryCodelet;
+import br.unicamp.meca.models.ActionSequencePlan;
+import br.unicamp.meca.models.ActionStep;
+import br.unicamp.meca.models.ActionStepTest;
+import br.unicamp.meca.system1.codelets.ActivityCodelet;
+import br.unicamp.meca.system1.codelets.MotorCodelet;
+import br.unicamp.meca.system1.codelets.PerceptualCodelet;
+import br.unicamp.meca.system1.codelets.SensoryCodelet;
+import java.util.ArrayList;
+import static org.junit.Assert.assertEquals;
+import org.junit.Test;
+
+/**
+ *
+ * @author rgudwin
+ */
+public class TestActivityCodelet {
+
+ SensoryCodelet sc;
+ PerceptualCodelet pc;
+ ActivityCodelet ac;
+
+ @Test
+ public void testAccessMemoryObjects() {
+ ArrayList lsc = new ArrayList();
+ lsc.add("m1");
+ lsc.add("m2");
+ lsc.add("m3");
+ ac = new Test1ActivityCodelet("teste",lsc,lsc,null,null);
+ ac.accessMemoryObjects();
+ assertEquals(ac.getPerceptionMemories().size(),0);
+ MemoryObject mo = new MemoryObject();
+ mo.setType("m1");
+ ac.addInput(mo);
+ mo = new MemoryObject();
+ mo.setType("m2");
+ ac.addInput(mo);
+ mo = new MemoryObject();
+ mo.setType("m3");
+ ac.addInput(mo);
+ ac.accessMemoryObjects();
+ assertEquals(ac.getPerceptionMemories().size(),3);
+ mo = new MemoryObject();
+ mo.setType("m1Drive");
+ ac.addInput(mo);
+ mo = new MemoryObject();
+ mo.setType("m2Drive");
+ ac.addInput(mo);
+ mo = new MemoryObject();
+ mo.setType("m3Drive");
+ ac.addInput(mo);
+ ac.accessMemoryObjects();
+ assertEquals(ac.getDriveMemories().size(),3);
+ ac = new Test1ActivityCodelet("teste",null,null,"motor","soar");
+ mo = new MemoryObject();
+ mo.setType("motor");
+ ac.addOutput(mo);
+ ac.accessMemoryObjects();
+ assertEquals(ac.getMotorMemory(),mo);
+ mo = new MemoryObject();
+ mo.setType("soar");
+ ac.addBroadcast(mo);
+ ac.accessMemoryObjects();
+ assertEquals(ac.getBroadcastMemory(),mo);
+ MemoryContainer mc = new MemoryContainer();
+ mc.setType(MecaMind.ACTION_SEQUENCE_PLAN_ID);
+ ac.addInput(mc);
+ ac.accessMemoryObjects();
+ assertEquals(ac.getActionSequencePlanMemoryContainer(),mc);
+ }
+
+ @Test
+ public void testActivityCodelet() {
+ sc = new TestPerceptionSensoryCodelet("sensory");
+ ArrayList lsc = new ArrayList();
+ lsc.add("sensory");
+ pc = new TestPerceptualCodelet("perception",lsc);
+ lsc = new ArrayList();
+ ac = new Test1ActivityCodelet("teste",null,null,null,null);
+ ac.accessMemoryObjects();
+ ac.proc();
+ ac.calculateActivation();
+
+ ac = new Test1ActivityCodelet("teste",lsc,lsc,null,null);
+ ac.accessMemoryObjects();
+ ac.proc();
+ ac.calculateActivation();
+
+ ac = new Test1ActivityCodelet("teste",lsc,lsc,"motor",null);
+ ac.accessMemoryObjects();
+ ac.proc();
+ ac.calculateActivation();
+
+ MotorCodelet mc = new TestMotorCodelet("motor");
+ ac.accessMemoryObjects();
+ ac.proc();
+ ac.calculateActivation();
+
+ }
+
+ @Test
+ public void testCalculateActivation() {
+ ArrayList lsc = new ArrayList();
+ lsc.add("m1");
+ lsc.add("m2");
+ lsc.add("m3");
+ ac = new Test1ActivityCodelet("teste",null,lsc,null,null);
+ MemoryObject mo = new MemoryObject();
+ mo.setType("m1Drive");
+ mo.setEvaluation(0.5);
+ ac.addInput(mo);
+ mo = new MemoryObject();
+ mo.setType("m2Drive");
+ mo.setEvaluation(0.6);
+ ac.addInput(mo);
+ mo = new MemoryObject();
+ mo.setType("m3Drive");
+ ac.addInput(mo);
+ mo.setEvaluation(0.8);
+ ac.accessMemoryObjects();
+ ac.calculateActivation();
+ double presumedActivation = (0.5+0.6+0.8)/3;
+ assertEquals(ac.getActivation(),presumedActivation,0);
+ MemoryContainer mc = new MemoryContainer();
+ mc.setType(MecaMind.ACTION_SEQUENCE_PLAN_ID);
+ ActionStep as[] = new ActionStep[1];
+ ActionSequencePlan asp = new ActionSequencePlan(as);
+ mc.setI(asp,0.2);
+ ac.addInput(mc);
+ ac.accessMemoryObjects();
+ ac.calculateActivation();
+ // Because the ActionStep is null, the evaluation is 0
+ assertEquals(ac.getActivation(),0,0);
+ as[0] = new ActionStepTest("teste");
+ // Now that there is an action step with the same name as the ActivityCodelet, it should be 0.2
+ ac.calculateActivation();
+ assertEquals(ac.getActivation(),0.2,0);
+ }
+
+}
diff --git a/src/test/java/br/unicamp/meca/mind/behavior/Test1AndTest2BehaviorCodelet.java b/src/test/java/br/unicamp/meca/mind/behavior/Test1AndTest2BehaviorCodelet.java
index e522225..13b88a0 100644
--- a/src/test/java/br/unicamp/meca/mind/behavior/Test1AndTest2BehaviorCodelet.java
+++ b/src/test/java/br/unicamp/meca/mind/behavior/Test1AndTest2BehaviorCodelet.java
@@ -7,6 +7,8 @@
import br.unicamp.cst.core.entities.Memory;
import br.unicamp.meca.models.ActionSequencePlan;
+import br.unicamp.meca.models.ActionStep;
+import br.unicamp.meca.models.ActionStepTest;
import br.unicamp.meca.system1.codelets.BehaviorCodelet;
/**
@@ -14,22 +16,24 @@
*
*/
public class Test1AndTest2BehaviorCodelet extends BehaviorCodelet {
+
+ private ActionSequencePlan actionSequencePlan;
public Test1AndTest2BehaviorCodelet(String id, ArrayList perceptualCodeletsIds,
- ArrayList motivationalCodeletsIds, String soarCodeletId, ActionSequencePlan actionSequencePlan) {
- super(id, perceptualCodeletsIds, motivationalCodeletsIds, soarCodeletId, actionSequencePlan);
+ ArrayList motivationalCodeletsIds, String soarCodeletId) {
+ super(id, perceptualCodeletsIds, motivationalCodeletsIds, soarCodeletId);
}
@Override
- public void trackActionSequencePlan(ArrayList perceptualMemories, ActionSequencePlan actionSequencePlan) {
+ protected ActionSequencePlan buildActionSequencePlan(ArrayList perceptualMemories) {
- if(actionSequencePlan == null || actionSequencePlan.getActionIdSequence() == null) {
- return;
+ if(actionSequencePlan == null) {
+ ActionStep as1 = new ActionStepTest("Test2Activity");
+ ActionStep as2 = new ActionStepTest("Test3Activity");
+ actionSequencePlan = new ActionSequencePlan(new ActionStep[] {as1,as2});
}
-
- actionSequencePlan.setCurrentActionIdIndex(0);
-
- //In this test, will never go on to the second action. We could have limit on perceptual memory to move on, though.
+
+ return actionSequencePlan;
}
}
diff --git a/src/test/java/br/unicamp/meca/mind/planning/TestSoarCodelet.java b/src/test/java/br/unicamp/meca/mind/planning/TestSoarCodelet.java
new file mode 100644
index 0000000..dc6dfe7
--- /dev/null
+++ b/src/test/java/br/unicamp/meca/mind/planning/TestSoarCodelet.java
@@ -0,0 +1,49 @@
+/**
+ *
+ */
+package br.unicamp.meca.mind.planning;
+
+import java.io.File;
+
+import br.unicamp.meca.system2.codelets.SoarCodelet;
+
+/**
+ * @author andre
+ *
+ */
+public class TestSoarCodelet extends SoarCodelet {
+
+ /**
+ * @param id
+ */
+ public TestSoarCodelet(String id) {
+ super(id);
+ // TODO Auto-generated constructor stub
+ }
+
+ /**
+ * @param id
+ * @param path_to_commands
+ * @param _agentName
+ * @param _productionPath
+ * @param startSOARDebugger
+ */
+ public TestSoarCodelet(String id, String path_to_commands, String _agentName, File _productionPath,
+ Boolean startSOARDebugger) {
+ super(id, path_to_commands, _agentName, _productionPath, startSOARDebugger);
+ // TODO Auto-generated constructor stub
+ }
+
+ @Override
+ public void fromPlanToAction() {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void calculateActivation() {
+ // TODO Auto-generated method stub
+
+ }
+
+}
diff --git a/src/test/java/br/unicamp/meca/mind/tracking/testActivityTrackingCodelet.java b/src/test/java/br/unicamp/meca/mind/tracking/testActivityTrackingCodelet.java
new file mode 100644
index 0000000..135cb4f
--- /dev/null
+++ b/src/test/java/br/unicamp/meca/mind/tracking/testActivityTrackingCodelet.java
@@ -0,0 +1,259 @@
+/*
+ * To change this license header, choose License Headers in Project Properties.
+ * To change this template file, choose Tools | Templates
+ * and open the template in the editor.
+ */
+package br.unicamp.meca.mind.tracking;
+
+import br.unicamp.cst.core.entities.MemoryContainer;
+import br.unicamp.cst.core.entities.MemoryObject;
+import br.unicamp.meca.mind.MecaMind;
+import br.unicamp.meca.mind.action.Test1ActivityCodelet;
+import br.unicamp.meca.models.ActionSequencePlan;
+import br.unicamp.meca.models.ActionStep;
+import br.unicamp.meca.models.ActionStepTest;
+import br.unicamp.meca.system1.codelets.ActivityCodelet;
+import br.unicamp.meca.system1.codelets.ActivityTrackingCodelet;
+import java.util.ArrayList;
+import static org.junit.Assert.assertEquals;
+import org.junit.Test;
+
+/**
+ *
+ * @author rgudwin
+ */
+public class testActivityTrackingCodelet {
+ ActivityTrackingCodelet atc;
+ ActivityCodelet actc1;
+ ActivityCodelet actc2;
+
+ @Test
+ public void testActivityTrackingCodelet() {
+ atc = new ActivityTrackingCodelet("tracking",null);
+ atc.accessMemoryObjects();
+ atc.calculateActivation();
+ // This tests the case when there is still no sequence plan to be tracked
+ atc.proc();
+ // Now let's introduce an empty perception list
+ ArrayList lop = new ArrayList();
+ atc = new ActivityTrackingCodelet("tracking",lop);
+ atc.accessMemoryObjects();
+ atc.calculateActivation();
+ atc.proc();
+ // Now let's define an inexistent perception
+ lop.add("perception");
+ atc.accessMemoryObjects();
+ atc.calculateActivation();
+ atc.proc();
+ // Now, still without perception, let's introduce a sequence plan
+ MemoryContainer mc = new MemoryContainer();
+ mc.setType(MecaMind.ACTION_SEQUENCE_PLAN_ID);
+ atc.addInput(mc);
+ atc.accessMemoryObjects();
+ // Now there is a memory object, but still no sequence plan
+ atc.accessMemoryObjects();
+ atc.calculateActivation();
+ atc.proc();
+ // Now let's include a plan, but still without any action step
+ ActionStep as[] = new ActionStep[3];
+ ActionSequencePlan asp = new ActionSequencePlan(as);
+ mc.setI(asp,0.2);
+ atc.accessMemoryObjects();
+ atc.calculateActivation();
+ atc.proc();
+ // Finally, let's include the action steps
+ ActionStep as1 = new ActionStepTest("tracking");
+ as[0] = as1;
+ ActionStep as2 = new ActionStepTest("tracking");
+ as[1] = as2;
+ ActionStep as3 = new ActionStepTest("tracking");
+ as[2] = as3;
+ atc.accessMemoryObjects();
+ atc.calculateActivation();
+ atc.proc();
+ assertEquals(asp.getCurrentActionIdIndex(),0);
+ // Now let's introduce a Perception Memory to track
+ // And now finally let's provide an existent perception, still without info
+ MemoryObject per = new MemoryObject();
+ per.setType("perception");
+ atc = new ActivityTrackingCodelet("tracking",lop);
+ atc.addInput(per);
+ atc.addInput(mc);
+ atc.accessMemoryObjects();
+ atc.calculateActivation();
+ atc.proc();
+ assertEquals(asp.getCurrentActionIdIndex(),0);
+ // Now, let's create the conditions for the codelet decide to move to its 2nd step
+ per.setEvaluation(1.0);
+ atc.addInput(per);
+ //as[0].needsConclusion = true;
+ atc.accessMemoryObjects();
+ atc.calculateActivation();
+ assertEquals(as[0].executed,false);
+ atc.proc();
+ // Now, because there are conditions for move to the second step of the plan, the index should be 1
+ assertEquals(as[0].executed,true);
+ // Because the ActionStep 0 was executed, now it needs conclusion
+ assertEquals(as[0].needsConclusion,true);
+ assertEquals(asp.getCurrentActionIdIndex(),1);
+ assertEquals(as[1].executed,false);
+ atc.proc();
+ // Now let's play a little ... because the conclusion didn't come, this proc will not move to the 3rd action step
+ assertEquals(as[1].executed,false);
+ // Let's then conclude the action step 0 e see what happens
+ as[0].needsConclusion = false;
+ atc.proc();
+ // Now, this allows the execution of action step 1
+ assertEquals(as[1].executed,true);
+ assertEquals(asp.getCurrentActionIdIndex(),2);
+ assertEquals(as[2].executed,false);
+ assertEquals(as[1].needsConclusion,true);
+ as[1].needsConclusion = false;
+ atc.proc();
+ assertEquals(as[2].needsConclusion,true);
+ assertEquals(asp.getCurrentActionIdIndex(),0);
+ assertEquals(as[2].executed,true);
+ }
+
+ @Test
+ public void testDoConclusion() {
+ // Creation of the Perception Memory
+ ArrayList lop = new ArrayList();
+ MemoryObject per = new MemoryObject();
+ per.setType("perception");
+ per.setI("perception");
+ lop.add("perception");
+ atc = new ActivityTrackingCodelet("tracking",lop);
+ atc.addInput(per);
+ // Creation of the ActionSequencePlan
+ MemoryContainer planContainer = new MemoryContainer();
+ planContainer.setType(MecaMind.ACTION_SEQUENCE_PLAN_ID);
+ ActionStep as1 = new ActionStepTest("activity1");
+ ActionStep as2 = new ActionStepTest("activity2");
+ ActionSequencePlan asp = new ActionSequencePlan(new ActionStep[] {as1,as2});
+ planContainer.setI(asp,0.2,"plan");
+ atc.addInput(planContainer);
+ // Creation of the MotorMemory
+ MemoryContainer motorMemory = new MemoryContainer();
+ motorMemory.setType("motor");
+ // Now creating the ActivityCodelets which will serve the ActionStep
+ actc1 = new Test1ActivityCodelet("activity1",lop,null,"motor",null);
+ actc1.addInput(per);
+ actc1.addInput(planContainer);
+ actc1.addOutput(motorMemory);
+ actc2 = new Test1ActivityCodelet("activity2",lop,null,"motor",null);
+ actc2.addInput(per);
+ actc2.addInput(planContainer);
+ actc2.addOutput(motorMemory);
+ // Execute the 1st time step
+ step();
+ // Verifying if the activity1 modified the motor codelet
+ assertEquals(motorMemory.getI(),"activity1 - perception");
+ // now let's cause the ActivityTrackingCodelet to conclude step 1 and move to step 2
+ per.setEvaluation(1.0);
+ // And change the activation to a lower value than activity1 ...
+ // if activity1 is not concluded by doConclusion, it will stay at the motor codelet and ruin the output of motorCodelet
+ planContainer.setI(asp,0.1,"plan");
+ step();
+ // Let's first verify if the plan was advanced to step 2
+ assertEquals(asp.getCurrentActionIdIndex(),1);
+ // Let's verify if activity2 modified the motor codelet
+ assertEquals(motorMemory.getI(),"activity2 - perception");
+ // Let's verify if activity1 was concluded
+ assertEquals(motorMemory.getI(0),"activity1 - concluded");
+ // Now let's do one more step to conclude the plan
+ step();
+ // And verify the plan is back to step 1 and executed
+ assertEquals(asp.getCurrentActionIdIndex(),0);
+ assertEquals(asp.getCurrentActionStep().executed,true);
+ assertEquals(asp.getLastExecutedActionStep().executed,true);
+ // Let's do a final step and check if everything remains the same
+ step();
+ assertEquals(asp.getCurrentActionIdIndex(),0);
+ assertEquals(asp.getCurrentActionStep().executed,true);
+ assertEquals(asp.getLastExecutedActionStep().executed,true);
+
+ }
+
+ @Test
+ public void testTwoActionStepsOfSameType() {
+ // Creation of the Perception Memory
+ ArrayList lop = new ArrayList();
+ MemoryObject per = new MemoryObject();
+ per.setType("perception");
+ per.setI("perception");
+ lop.add("perception");
+ atc = new ActivityTrackingCodelet("tracking",lop);
+ atc.addInput(per);
+ // Creation of the ActionSequencePlan
+ MemoryContainer planContainer = new MemoryContainer();
+ planContainer.setType(MecaMind.ACTION_SEQUENCE_PLAN_ID);
+ ActionStep as1 = new ActionStepTest("activity1");
+ ActionStep as2 = new ActionStepTest("activity1"); // The 2nd actionstep is treated by the same ActivityCodelet
+ ActionSequencePlan asp = new ActionSequencePlan(new ActionStep[] {as1,as2});
+ planContainer.setI(asp,0.2,"plan");
+ atc.addInput(planContainer);
+ // Creation of the MotorMemory
+ MemoryContainer motorMemory = new MemoryContainer();
+ motorMemory.setType("motor");
+ // Now creating the ActivityCodelet which will serve the ActionStep
+ actc1 = new Test1ActivityCodelet("activity1",lop,null,"motor",null);
+ actc1.addInput(per);
+ actc1.addInput(planContainer);
+ actc1.addOutput(motorMemory);
+ // Execute the 1st time step
+ step2();
+ // Verifying if the activity1 modified the motor codelet
+ assertEquals(motorMemory.getI(),"activity1 - perception");
+ // now let's cause the ActivityTrackingCodelet to conclude step 1 and move to step 2
+ per.setEvaluation(1.0);
+ // And change the activation to a lower value than activity1 ...
+ // if activity1 is not concluded by doConclusion, it will stay at the motor codelet and ruin the output of motorCodelet
+ planContainer.setI(asp,0.1,"plan");
+ step2();
+ // Let's first verify if the plan was advanced to step 2
+ assertEquals(asp.getCurrentActionIdIndex(),1);
+ // The conclusion of step1 can only be verified by the log, as the motorMemory is immediately rewritten by step2
+ // A "Concluding activity1" message should have appeared in the log
+ // But we can still check the needsConclusion flag, which should be cleared
+ assertEquals(asp.getLastExecutedActionStep().needsConclusion,false);
+ // Now let's do one more step to conclude the plan
+ step2();
+ // And verify the plan is back to step 1 and executed
+ assertEquals(asp.getCurrentActionIdIndex(),0);
+ assertEquals(asp.getCurrentActionStep().needsConclusion,false);
+ assertEquals(asp.getCurrentActionStep().executed,true);
+ assertEquals(asp.getLastExecutedActionStep().needsConclusion,false);
+ assertEquals(asp.getLastExecutedActionStep().executed,true);
+ // Let's do a final step and check if everything remains the same
+ step2();
+ assertEquals(asp.getCurrentActionIdIndex(),0);
+ assertEquals(asp.getCurrentActionStep().needsConclusion,false);
+ assertEquals(asp.getCurrentActionStep().executed,true);
+ assertEquals(asp.getLastExecutedActionStep().needsConclusion,false);
+ assertEquals(asp.getLastExecutedActionStep().executed,true);
+ }
+
+ private void step() {
+ atc.accessMemoryObjects();
+ atc.calculateActivation();
+ atc.proc();
+ actc1.accessMemoryObjects();
+ actc1.calculateActivation();
+ actc1.proc();
+ actc2.accessMemoryObjects();
+ actc2.calculateActivation();
+ actc2.proc();
+ }
+
+
+ private void step2() {
+ atc.accessMemoryObjects();
+ atc.calculateActivation();
+ atc.proc();
+ actc1.accessMemoryObjects();
+ actc1.calculateActivation();
+ actc1.proc();
+ }
+
+}
diff --git a/src/test/java/br/unicamp/meca/models/ActionSequencePlanTest.java b/src/test/java/br/unicamp/meca/models/ActionSequencePlanTest.java
index 3a20afc..63c876e 100644
--- a/src/test/java/br/unicamp/meca/models/ActionSequencePlanTest.java
+++ b/src/test/java/br/unicamp/meca/models/ActionSequencePlanTest.java
@@ -12,20 +12,91 @@
*
*/
public class ActionSequencePlanTest {
+
+ ActionStep as1 = new ActionStepTest("Land");
+ ActionStep as2 = new ActionStepTest("Stop");
+ ActionSequencePlan landAndStopSequencePlan = new ActionSequencePlan(new ActionStep[] {as1,as2});
public void setUp() {
System.out.println("########## Action Sequence Plan TESTS ##########");
}
+
+ @Test
+ public void testGetCurrentActionIdIndex() {
+ landAndStopSequencePlan.setCurrentActionIdIndex(0);
+ int currentStep = landAndStopSequencePlan.getCurrentActionIdIndex();
+ assertEquals(currentStep,0);
+ landAndStopSequencePlan.setCurrentActionIdIndex(1);
+ currentStep = landAndStopSequencePlan.getCurrentActionIdIndex();
+ assertEquals(currentStep,1);
+ }
@Test
public void testGetCurrentActionId() {
-
- ActionSequencePlan landAndStopSequencePlan = new ActionSequencePlan(new String[] {"Land","Stop"});
-
- assertEquals(landAndStopSequencePlan.getCurrentActionId(), "Land");
-
+ landAndStopSequencePlan.setCurrentActionIdIndex(0);
+ assertEquals(landAndStopSequencePlan.getCurrentActionStep().getActionId(), "Land");
+
landAndStopSequencePlan.setCurrentActionIdIndex(1);
-
- assertEquals(landAndStopSequencePlan.getCurrentActionId(), "Stop");
+ assertEquals(landAndStopSequencePlan.getCurrentActionStep().getActionId(), "Stop");
+ }
+
+ @Test
+ public void testGetCurrentActionStep() {
+ landAndStopSequencePlan.setCurrentActionIdIndex(0);
+ ActionStep as = landAndStopSequencePlan.getCurrentActionStep();
+ assertEquals(as,as1);
+ landAndStopSequencePlan.setCurrentActionIdIndex(1);
+ as = landAndStopSequencePlan.getCurrentActionStep();
+ assertEquals(as,as2);
+ }
+
+ @Test
+ public void testLastActionStep() {
+ landAndStopSequencePlan.setCurrentActionIdIndex(0);
+ ActionStep lastAS = landAndStopSequencePlan.getLastExecutedActionStep();
+ assertEquals(lastAS,as2);
+ assertEquals(lastAS.executed,false);
+ assertEquals(lastAS.needsConclusion,false);
+
+ landAndStopSequencePlan.setCurrentActionIdIndex(1);
+ lastAS = landAndStopSequencePlan.getLastExecutedActionStep();
+ assertEquals(lastAS,as1);
+ assertEquals(lastAS.executed,false);
+ assertEquals(lastAS.needsConclusion,false);
+ }
+
+ @Test
+ public void testGoToNextAction() {
+ landAndStopSequencePlan.setCurrentActionIdIndex(0);
+ ActionStep as = landAndStopSequencePlan.getCurrentActionStep();
+ assertEquals(as,as1);
+ assertEquals(as1.executed,false);
+
+ landAndStopSequencePlan.gotoNextAction();
+ as = landAndStopSequencePlan.getCurrentActionStep();
+ assertEquals(as,as2);
+ assertEquals(as1.executed,true);
+ assertEquals(as2.executed,false);
+ landAndStopSequencePlan.gotoNextAction();
+ as = landAndStopSequencePlan.getCurrentActionStep();
+ assertEquals(as,as1);
+ assertEquals(as2.executed,true);
+ }
+
+ @Test
+ public void testResetPlan() {
+ as1.executed = true;
+ as2.executed = true;
+ landAndStopSequencePlan.resetPlan();
+ for (ActionStep ass : landAndStopSequencePlan.getActionStepSequence()) {
+ assertEquals(ass.executed,false);
+ assertEquals(ass.needsConclusion,false);
+ }
+ }
+
+ @Test
+ public void testToString() {
+ String s = landAndStopSequencePlan.toString();
+ assertEquals(s,"{Land, Stop}");
}
}
diff --git a/src/test/java/br/unicamp/meca/models/ActionStepTest.java b/src/test/java/br/unicamp/meca/models/ActionStepTest.java
new file mode 100644
index 0000000..488e3f1
--- /dev/null
+++ b/src/test/java/br/unicamp/meca/models/ActionStepTest.java
@@ -0,0 +1,36 @@
+package br.unicamp.meca.models;
+
+import br.unicamp.cst.core.entities.Memory;
+import br.unicamp.meca.models.ActionStep;
+import java.util.List;
+
+/*
+ * To change this license header, choose License Headers in Project Properties.
+ * To change this template file, choose Tools | Templates
+ * and open the template in the editor.
+ */
+public class ActionStepTest extends ActionStep {
+
+ public ActionStepTest() {
+
+ }
+
+ public ActionStepTest(String s) {
+ super(s);
+ }
+
+ public void setUp() {
+ System.out.println("########## ActionStep TESTS ##########");
+ }
+
+ @Override
+ public boolean stopCondition(List perceptions) {
+ if (perceptions != null && perceptions.size() > 0) {
+ Memory perceptionMemory = perceptions.get(0);
+ if (perceptionMemory != null && perceptionMemory.getEvaluation() > 0.5) return(true);
+ else return(false);
+ }
+ return(false);
+ }
+
+}
\ No newline at end of file
diff --git a/src/test/java/br/unicamp/meca/models/ActionStepTester.java b/src/test/java/br/unicamp/meca/models/ActionStepTester.java
new file mode 100644
index 0000000..aae2313
--- /dev/null
+++ b/src/test/java/br/unicamp/meca/models/ActionStepTester.java
@@ -0,0 +1,38 @@
+/*
+ * To change this license header, choose License Headers in Project Properties.
+ * To change this template file, choose Tools | Templates
+ * and open the template in the editor.
+ */
+package br.unicamp.meca.models;
+import static org.junit.Assert.assertEquals;
+import org.junit.Test;
+
+/**
+ *
+ * @author rgudwin
+ */
+public class ActionStepTester {
+
+ public void setUp() {
+ System.out.println("########## ActionStep TESTS ##########");
+ }
+
+ @Test
+ public void testActionStepTester() {
+ ActionStep as1 = new ActionStepTest();
+ assertEquals(as1.getNumberOfParameters(),0);
+ ActionStep as2 = new ActionStepTest("TestAction");
+ assertEquals(as2.getNumberOfParameters(),0);
+ assertEquals(as2.getActionId(),"TestAction");
+ as2.setParameter("param", "value");
+ assertEquals(as2.getNumberOfParameters(),1);
+ assertEquals(as2.getParameter("param"),"value");
+ as2.setParameter("param", "value2");
+ assertEquals(as2.getParameter("param"),"value2");
+ as2.unsetParameter("param");
+ assertEquals(as2.getNumberOfParameters(),0);
+ }
+
+
+
+}
diff --git a/src/test/java/br/unicamp/meca/system1/codelets/rosservice/AddTwoIntServiceClient.java b/src/test/java/br/unicamp/meca/system1/codelets/rosservice/AddTwoIntServiceClient.java
index f87cc34..088826c 100644
--- a/src/test/java/br/unicamp/meca/system1/codelets/rosservice/AddTwoIntServiceClient.java
+++ b/src/test/java/br/unicamp/meca/system1/codelets/rosservice/AddTwoIntServiceClient.java
@@ -6,6 +6,7 @@
import java.net.URI;
import br.unicamp.cst.core.entities.Memory;
+import br.unicamp.cst.support.TimeStamp;
import br.unicamp.meca.system1.codelets.RosServiceClientMotorCodelet;
import rosjava_test_msgs.AddTwoIntsRequest;
import rosjava_test_msgs.AddTwoIntsResponse;
@@ -16,32 +17,59 @@
*/
public class AddTwoIntServiceClient extends RosServiceClientMotorCodelet {
- private Integer sum;
+ private volatile Integer a,b;
+ private volatile Integer sum;
+ private volatile long tsreq=0, tsresp=0;
public AddTwoIntServiceClient(String host, URI masterURI) {
super("AddTwoIntServiceClient", "add_two_ints", rosjava_test_msgs.AddTwoInts._TYPE, host, masterURI);
}
@Override
- public void formatServiceRequest(Memory motorMemory, AddTwoIntsRequest serviceMessageRequest) {
- if(motorMemory != null && motorMemory.getI() != null) {
- Integer[] numsToSum = (Integer[]) motorMemory.getI();
- serviceMessageRequest.setA(numsToSum[0]);
- serviceMessageRequest.setB(numsToSum[1]);
+ public boolean formatServiceRequest(Memory motorMemory, AddTwoIntsRequest serviceMessageRequest) {
+ if(motorMemory == null || motorMemory.getI() == null) {
+ return false;
}
+
+ Integer[] numsToSum = (Integer[]) motorMemory.getI();
+ a = numsToSum[0];
+ b = numsToSum[1];
+ serviceMessageRequest.setA(numsToSum[0]);
+ serviceMessageRequest.setB(numsToSum[1]);
+ tsreq = System.currentTimeMillis();
+ System.out.println("REQUEST a = "+a+" b = "+b+" at "+TimeStamp.getStringTimeStamp(tsreq)+" with data from "+TimeStamp.getStringTimeStamp(motorMemory.getTimestamp()));
+
+ return true;
}
@Override
public void processServiceResponse(AddTwoIntsResponse serviceMessageResponse) {
sum = (int) serviceMessageResponse.getSum();
- System.out.println("Sum = "+sum);
+ tsresp = System.currentTimeMillis();
+ System.out.println("RESPONSE Sum = "+sum+" at "+TimeStamp.getStringTimeStamp(tsresp));
}
/**
* @return the sum
*/
- public Integer getSum() {
+ public synchronized Integer getSum() {
return sum;
}
+
+ /**
+ *
+ * @return timestamp
+ */
+ public synchronized long getTSReq() {
+ return tsreq;
+ }
+
+ /**
+ *
+ * @return timestamp
+ */
+ public synchronized long getTSResp() {
+ return tsresp;
+ }
}
diff --git a/src/test/java/br/unicamp/meca/system1/codelets/rosservice/RosServiceClientTest.java b/src/test/java/br/unicamp/meca/system1/codelets/rosservice/RosServiceClientTest.java
index a6bd043..363326a 100644
--- a/src/test/java/br/unicamp/meca/system1/codelets/rosservice/RosServiceClientTest.java
+++ b/src/test/java/br/unicamp/meca/system1/codelets/rosservice/RosServiceClientTest.java
@@ -19,8 +19,13 @@
import org.ros.node.NodeMainExecutor;
import br.unicamp.cst.core.entities.Memory;
+import br.unicamp.cst.core.entities.MemoryContainer;
+import br.unicamp.cst.support.TimeStamp;
import br.unicamp.meca.mind.MecaMind;
import br.unicamp.meca.system1.codelets.IMotorCodelet;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+import org.slf4j.LoggerFactory;
/**
* @author andre
@@ -29,11 +34,13 @@
public class RosServiceClientTest {
private static RosCore rosCore;
+ private volatile Memory motorMemory;
@BeforeClass
public static void beforeAllTestMethods() {
rosCore = RosCore.newPublic("127.0.0.1",11311);
rosCore.start();
+ try{Thread.sleep(1000);} catch(Exception e){e.printStackTrace();}
}
@AfterClass
@@ -41,6 +48,13 @@ public static void afterAllTestMethods() {
rosCore.shutdown();
}
+ public void SilenceLoggers() {
+ ((ch.qos.logback.classic.Logger) LoggerFactory.getLogger("httpclient")).setLevel(ch.qos.logback.classic.Level.OFF);
+ ((ch.qos.logback.classic.Logger) LoggerFactory.getLogger("org.apache")).setLevel(ch.qos.logback.classic.Level.OFF);
+ ((ch.qos.logback.classic.Logger) LoggerFactory.getLogger("org.ros")).setLevel(ch.qos.logback.classic.Level.OFF);
+ Logger.getLogger("Simulation").setLevel(Level.SEVERE);
+ }
+
@Test
public void testRosService() throws URISyntaxException, InterruptedException {
@@ -48,6 +62,7 @@ public void testRosService() throws URISyntaxException, InterruptedException {
NodeMainExecutor nodeMainExecutor = DefaultNodeMainExecutor.newDefault();
NodeConfiguration nodeConfiguration = NodeConfiguration.newPublic("127.0.0.1",new URI("http://127.0.0.1:11311"));
nodeMainExecutor.execute(addTwoIntService, nodeConfiguration);
+
Thread.sleep(2000);
@@ -59,19 +74,18 @@ public void testRosService() throws URISyntaxException, InterruptedException {
motorCodelets.add(addTwoIntServiceClient);
mecaMind.setIMotorCodelets(motorCodelets);
-
- mecaMind.mountMecaMind();
-
+ mecaMind.mountMecaMind();
mecaMind.start();
Thread.sleep(5000);
- Memory motorMemory = addTwoIntServiceClient.getInput(addTwoIntServiceClient.getId());
+ motorMemory = addTwoIntServiceClient.getInput(addTwoIntServiceClient.getId());
Integer expectedSum = 5;
Integer[] numsToSum = new Integer[] {2,3};
motorMemory.setI(numsToSum);
+ System.out.println("Nums to sum were changed to {2,3}");
Thread.sleep(2000);
@@ -86,7 +100,8 @@ public void testRosService() throws URISyntaxException, InterruptedException {
@Test
public void testRosServiceCallTwice() throws URISyntaxException, InterruptedException {
- AddTwoIntService addTwoIntService = new AddTwoIntService();
+ SilenceLoggers();
+ AddTwoIntService addTwoIntService = new AddTwoIntService();
NodeMainExecutor nodeMainExecutor = DefaultNodeMainExecutor.newDefault();
NodeConfiguration nodeConfiguration = NodeConfiguration.newPublic("127.0.0.1",new URI("http://127.0.0.1:11311"));
nodeMainExecutor.execute(addTwoIntService, nodeConfiguration);
@@ -101,32 +116,61 @@ public void testRosServiceCallTwice() throws URISyntaxException, InterruptedExce
motorCodelets.add(addTwoIntServiceClient);
mecaMind.setIMotorCodelets(motorCodelets);
-
- mecaMind.mountMecaMind();
-
+ mecaMind.mountMecaMind();
mecaMind.start();
Thread.sleep(5000);
- Memory motorMemory = addTwoIntServiceClient.getInput(addTwoIntServiceClient.getId());
-
- Integer expectedSum = 5;
+ MemoryContainer mc=null;
+ motorMemory = addTwoIntServiceClient.getInput(addTwoIntServiceClient.getId());
+ // Be careful ... at this point motorMemory is a MemoryContainer, and it is empty
+ if (motorMemory instanceof MemoryContainer)
+ mc = (MemoryContainer) motorMemory;
+ Integer expectedSum = 5;
Integer[] numsToSum = new Integer[] {2,3};
- motorMemory.setI(numsToSum);
-
- Thread.sleep(2000);
+ int id = motorMemory.setI(numsToSum);
+ // At this point, motorMemory has 1 internal MemoryObject and id should be 0
+ System.out.println("id: "+id);
+ System.out.println("\n\nNums to sum were changed to {2,3} at "+TimeStamp.getStringTimeStamp(motorMemory.getTimestamp()));
+ long tsstartreq = addTwoIntServiceClient.getTSReq();
+ long tsstopreq = tsstartreq;
+ long tsstartresp = addTwoIntServiceClient.getTSResp();
+ long tsstopresp = tsstartresp;
+ System.out.println("Service situation - req:"+TimeStamp.getStringTimeStamp(tsstartreq)+" resp:"+TimeStamp.getStringTimeStamp(tsstartresp));
+ while (tsstartreq == tsstopreq || tsstartresp == tsstopresp ) {
+ tsstopresp = addTwoIntServiceClient.getTSResp();
+ tsstopreq = addTwoIntServiceClient.getTSReq();
+ System.out.println("startreq: "+TimeStamp.getStringTimeStamp(tsstartreq)+" stopreq: "+TimeStamp.getStringTimeStamp(tsstopreq));
+ System.out.println("startresp: "+TimeStamp.getStringTimeStamp(tsstartresp)+" stopreq: "+TimeStamp.getStringTimeStamp(tsstopresp));
+ Thread.sleep(100);
+ }
+ System.out.println("Finished process - req:"+TimeStamp.getStringTimeStamp(tsstopreq)+" resp:"+TimeStamp.getStringTimeStamp(tsstopresp));
+ //Thread.sleep(5000);
assertEquals(expectedSum, addTwoIntServiceClient.getSum());
expectedSum = 6;
numsToSum = new Integer[] {3,3};
- motorMemory.setI(numsToSum);
-
- Thread.sleep(2000);
-
- assertEquals(expectedSum, addTwoIntServiceClient.getSum());
+ // This is the tricker part ... instead of calling setI from motorMemory, we should use its MemoryContainer counterpart
+ mc.setI(numsToSum,0);
+ System.out.println("\n\nNums to sum were changed to {3,3} at "+TimeStamp.getStringTimeStamp(motorMemory.getTimestamp()));
+ tsstartreq = addTwoIntServiceClient.getTSReq();
+ tsstopreq = tsstartreq;
+ tsstartresp = addTwoIntServiceClient.getTSResp();
+ tsstopresp = tsstartresp;
+ System.out.println("Service situation - req:"+TimeStamp.getStringTimeStamp(tsstartreq)+" resp:"+TimeStamp.getStringTimeStamp(tsstartresp));
+ while (tsstartreq == tsstopreq || tsstartresp == tsstopresp ) {
+ tsstopresp = addTwoIntServiceClient.getTSResp();
+ tsstopreq = addTwoIntServiceClient.getTSReq();
+ System.out.println("tsstartreq: "+TimeStamp.getStringTimeStamp(tsstartreq)+" tsstopreq: "+TimeStamp.getStringTimeStamp(tsstopreq));
+ System.out.println("tsstartresp: "+TimeStamp.getStringTimeStamp(tsstartresp)+" tsstopreq: "+TimeStamp.getStringTimeStamp(tsstopresp));
+ System.out.println("motorMemory: "+TimeStamp.getStringTimeStamp(motorMemory.getTimestamp()));
+ Thread.sleep(100);
+ }
+ System.out.println("Finished process - req:"+TimeStamp.getStringTimeStamp(tsstopreq)+" resp"+TimeStamp.getStringTimeStamp(tsstopresp));
+ assertEquals(expectedSum, addTwoIntServiceClient.getSum());
nodeMainExecutor.shutdownNodeMain(addTwoIntService);
diff --git a/src/test/java/br/unicamp/meca/system1/codelets/rostopic/RosTopicPublisherSubscriberTest.java b/src/test/java/br/unicamp/meca/system1/codelets/rostopic/RosTopicPublisherSubscriberTest.java
index 5c0cb83..731154f 100644
--- a/src/test/java/br/unicamp/meca/system1/codelets/rostopic/RosTopicPublisherSubscriberTest.java
+++ b/src/test/java/br/unicamp/meca/system1/codelets/rostopic/RosTopicPublisherSubscriberTest.java
@@ -32,6 +32,7 @@ public class RosTopicPublisherSubscriberTest {
public static void beforeAllTestMethods() {
rosCore = RosCore.newPublic("127.0.0.1",11311);
rosCore.start();
+ try{Thread.sleep(1000);} catch(Exception e){e.printStackTrace();}
}
@AfterClass