par implementation details

52
1 PAR Implementation Details PAR Implementation Details Jan M. Allbeck 11/6/2008

Upload: others

Post on 22-May-2022

2 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: PAR Implementation Details

1

PAR Implementation DetailsPAR Implementation Details

Jan M. Allbeck

11/6/2008

Page 2: PAR Implementation Details

2

OutlineOutline

• Creating Objects (and Agents)• Creating an Environment• Creating Actions• Processing Actions• Projects and Future Work

Page 3: PAR Implementation Details

3

• Model them• Convert them to obj format• Find location in• Add Parent (instances are automatic)• Edit parameters• Enter sites• Agents—roles, groups

Creating ObjectsCreating Objects

Actionary

Page 4: PAR Implementation Details

4

Creating an EnvironmentCreating an Environment

• ASCII Environment File• Room layout -> Cell and Portal Graph• Textures• Objects

• ASCII Map File• Navigate from any room to any room

Page 5: PAR Implementation Details

5

• Object name (relates to parent in Actionary)• Room name (relates to parent in Actionary)• Obj file name• Check for collisions? (0 = no, 1 = yes)• X, Y, Z position• X, Y, Z orientation• Scale factor• Used to be bounding radius (no longer used)

ASCII Environment FileASCII Environment File

Page 6: PAR Implementation Details

6

• Create animations (key framed or procedural)

• uPARs vs. iPARs• .• Python code• C++ code: register MGs

Creating ActionsCreating Actions

Actionary

Page 7: PAR Implementation Details

7

uPARsuPARs vs. vs. iPARsiPARs

• uPARs are uninstantiated or general PARs• uPARs are the semantics of the action• iPARs are an implementation of those

semantics (fill in the required blanks)• iPARs are uPARs that have been instantiated

with an agent and objects, etc. • iPARs are ready to be processed• iPARs can override parameters of the uPARs

they are created from.

Page 8: PAR Implementation Details

8

Adding a Adding a uPARuPAR to the Actionaryto the Actionary

• Determine new id and a name• Add Python file names• Determine proper placement in the hierarchy

(parent id)• Specify duration?• Specify a default priority• Specify the number of object participants• Specify a site type• Add capability for the agents

Actionary

Page 9: PAR Implementation Details

9

Python FilesPython Files

• Conditionals• Termination conditions• Applicability conditions• Preparatory specifications• Execution steps---------------------------------------------• Post assertions• During condition• Purpose achieve

Page 10: PAR Implementation Details

10

InspectCul.pyInspectCul.py

def culmination_condition(self, agent, obj):return 0

Page 11: PAR Implementation Details

11

InspectApp.pyInspectApp.py

def applicability_condition(self, agent, obj):if checkCapability(agent, self.name, [obj]):

return 1else:

return 0

Page 12: PAR Implementation Details

12

InspectPre.pyInspectPre.py

def preparatory_spec(self, agent, obj1):radius = getBoundingRadius(obj1);distnce = dist(agent, obj1);if(distnce > radius):

actions = {'PRIMITIVE':("Walk",{'agents':agent, 'objects':obj1})};return actions

else:return 1

Page 13: PAR Implementation Details

13

InspectExec.pyInspectExec.py

def execution_steps(self, agent, obj):actions = {'PRIMITIVE':("Inspect",{'agents':agent, 'objects':obj})};return actions

Page 14: PAR Implementation Details

14

C++ Code: PredicatesC++ Code: Predicatesstatic PyMethodDef prop_methods[] = {

{"getIntProperty", prop_getIntProperty, METH_VARARGS},{"setIntProperty", prop_setIntProperty, METH_VARARGS},{"checkCapability", agent_checkCapability, METH_VARARGS},{"contain", object_contain, METH_VARARGS},{"findObject", prop_findObject, METH_VARARGS},{"getVector", prop_getVector, METH_VARARGS},{"setVector", prop_setVector, METH_VARARGS},{"getPosture", prop_getPosture, METH_VARARGS},{"getStatus", prop_getStatus, METH_VARARGS},{"getLocation", prop_getLocation, METH_VARARGS},{"dist", prop_dist, METH_VARARGS}, //distance between two objects{"getBoundingRadius", prop_getBoundingRadius, METH_VARARGS},{"inFront", prop_inFront, METH_VARARGS}, //is obj1 in front of obj2{"testAppCond", prop_testAppCond, METH_VARARGS},{"testCulCond", prop_testCulCond, METH_VARARGS},{"testPreSpec", prop_testPreSpec, METH_VARARGS},{"nullCheck", prop_nullCheck, METH_VARARGS},

…{NULL, NULL}

};

Page 15: PAR Implementation Details

15

C++ Code: Register C++ Code: Register MGsMGs

• actionTable.addFunctions("Inspect", &DoInspect, &CheckInspect);

• DoInspect = function that starts the execution• CheckInspect = function that indicates

whether or not the action is completed

Page 16: PAR Implementation Details

16

Adding an Adding an iPARiPAR to the Actionaryto the Actionary

• Determine the corresponding uPAR• Create new action id• Fill in name• Fill in purpose to enable action?• Fill in act_parent_act_id = uPAR id• Fill in start time• Fill in duration if desired• Alter priority?

Page 17: PAR Implementation Details

17

Assigning an Assigning an iPARiPAR to an Agentto an Agentchar* objNames[] = {obj->getObjectName()};

iPAR* ipar = new iPAR(act->getActionName(), agent->getObjectName(), objNames);

ipar->setStartTime(partime->getCurrentTime());ipar->setPriority(11);

// add to agent's queueagt->addAction(ipar);

Page 18: PAR Implementation Details

18

System DiagramSystem Diagram

Page 19: PAR Implementation Details

19

Start

Exit

Curraction Preempt popaction paraction

nonemptyQ

activeAction

EmptyQnoFailAction

defaultCond finished

poperror

defaultcond

AgentNet

Page 20: PAR Implementation Details

20

AgentNet::AgentNet(list<iPAR*> *IParQ, AgentProc *ap):LWNet(NUMNODES)

{

iparQ = IParQ;agentproc = ap;

ipar = 0;popError = 0;

defnormalnode(START, (ACTFUNC)&AgentNet::actfunc_start);deftrans(START, (CONDFUNC) &AgentNet::nonemptyQ, CURRACTION);

defnormalnode(CURRACTION, (ACTFUNC)&AgentNet::actfunc_curraction);deftrans(CURRACTION,(CONDFUNC)&AgentNet::emptyQ, START);deftrans(CURRACTION,(CONDFUNC)&AgentNet::activeAction, PREEMPT);deftrans(CURRACTION,(CONDFUNC)&AgentNet::noFailAction, POPACTION);

defnormalnode(PREEMPT, (ACTFUNC)&AgentNet::actfunc_preempt);deftrans(PREEMPT,(CONDFUNC)&LWNet::defaultcond, START);

defnormalnode(POPACTION, (ACTFUNC)&AgentNet::actfunc_popaction);deftrans(POPACTION,(CONDFUNC)&AgentNet::condfunc_poperror, EXITNODE);deftrans(POPACTION, (CONDFUNC)&LWNet::finishcond, PARACTION);

defnormalnode(PARACTION, (ACTFUNC)&AgentNet::actfunc_paraction);deftrans(PARACTION,(CONDFUNC)&LWNet::defaultcond, START);

defexitnode(EXITNODE);} AgentNet

Page 21: PAR Implementation Details

21

Exit

Start

failExitNode

applicability

primitive

newsubparnode

preparatory coreexec

newparnode

complex

defaultcond

culminate

applicable

Applic_dict

Defaultcond

ready

Prep_dict

error

finishcond

error

finishcond

iscomplex

defaultcond

error

finish

errorfinish

PARNet

Page 22: PAR Implementation Details

22

defnormalnode(START, (ACTFUNC)&ParNet::actfunc_start);deftrans(START, (CONDFUNC)&ParNet::condfunc_culminate, EXITNODE);deftrans(START, (CONDFUNC)&LWNet::defaultcond, APPLICABILITY);

defnormalnode(APPLICABILITY, (ACTFUNC)&ParNet::actfunc_applicability);deftrans(APPLICABILITY, (CONDFUNC)&ParNet::condfunc_isapplicdictionary, NEWPARNODE);deftrans(APPLICABILITY, (CONDFUNC)&ParNet::condfunc_applicable, PREPARATORY);deftrans(APPLICABILITY, (CONDFUNC)&LWNet::defaultcond, EXITNODE);

defnormalnode(PREPARATORY, (ACTFUNC)&ParNet::actfunc_preparatory);deftrans(PREPARATORY, (CONDFUNC)&ParNet::condfunc_isprepdictionary, NEWSUBPARNODE);deftrans(PREPARATORY, (CONDFUNC)&ParNet::condfunc_ready, COREEXEC);

defcallnode(NEWPARNODE, (LWNEW)&ParNet::newpar, NULL, NULL, (void *)app_result);deftrans(NEWPARNODE,(CONDFUNC)&LWNet::errorcond,FAILEXITNODE);deftrans(NEWPARNODE, (CONDFUNC)&LWNet::finishcond, EXITNODE);

defcallnode(NEWSUBPARNODE, (LWNEW)&ParNet::newpar,NULL,NULL,&prep_result);deftrans(NEWSUBPARNODE,(CONDFUNC)&LWNet::errorcond,FAILEXITNODE);deftrans(NEWSUBPARNODE, (CONDFUNC)&LWNet::finishcond, COREEXEC);

defnormalnode(COREEXEC, (ACTFUNC)&ParNet::actfunc_coreexecution);deftrans(COREEXEC, (CONDFUNC)&ParNet::condfunc_iscomplex, COMPLEX);deftrans(COREEXEC, (CONDFUNC)&LWNet::defaultcond, PRIMITIVE);

defcallnode(COMPLEX,(LWNEW)&ParNet::newpar, NULL, (ACTFUNC)&ParNet::postactfunc_complex, &complexobj);deftrans(COMPLEX,(CONDFUNC)&LWNet::errorcond,FAILEXITNODE);deftrans(COMPLEX, (CONDFUNC)&LWNet::finishcond, EXITNODE);

defnormalnode(PRIMITIVE, (ACTFUNC)&ParNet::actfunc_primitive, (ACTFUNC)&ParNet::preactfunc_primitive,(ACTFUNC)&ParNet::postactfunc_primitive);deftrans(PRIMITIVE,(CONDFUNC)&LWNet::errorcond,FAILEXITNODE);deftrans(PRIMITIVE, (CONDFUNC)&LWNet::finishcond, EXITNODE);

defexitnode(EXITNODE); deffailexitnode(FAILEXITNODE); PARNet

Page 23: PAR Implementation Details

23

System DiagramSystem Diagram

Page 24: PAR Implementation Details

24

Agent ProcessAgent Process

• Inform: message passing• Perceive: objects that are sensed• Update:

• positions, locations, etc• Action choices

• Add action: start new performance

Page 25: PAR Implementation Details

25

Projects/Future WorkProjects/Future Work

• GUIs• Tools and checkers• Agents• Different action types• Quantifiers• Properties• Spatial reasoner• Maya plug-in for object creating and db

Page 26: PAR Implementation Details

26

The EndThe End

Page 27: PAR Implementation Details

27

voidAgentNet::actfunc_start(void){}

Back

Page 28: PAR Implementation Details

28

voidAgentNet::actfunc_curraction(void){}

Back

Page 29: PAR Implementation Details

29

voidAgentNet::actfunc_preempt(void){iPAR* cfipar = this->getFirstAction();if (ipar != NULL

&& this->readyToGo(cfipar))agentproc->ipt->

preempt(cfipar->getPriority()); }

Back

Page 30: PAR Implementation Details

30

voidAgentNet::actfunc_popaction(void){

iPAR *cfipar = getFirstAction();if (cfipar == NULL)

return;

if (readyToGo(cfipar)){

ipar = cfipar;iparQ->remove(cfipar);markfinished();

}}

Back

Page 31: PAR Implementation Details

31

voidAgentNet::actfunc_paraction(void){

ComplexObj *complexobj = new ComplexObj(ipar,0);

LWNetList::addnet(new ParNet(complexobj));}

Back

Page 32: PAR Implementation Details

32

boolAgentNet::nonemptyQ(void){return (!(iparQ->empty()));

}

Back

Page 33: PAR Implementation Details

33

boolAgentNet::emptyQ(void){return iparQ->empty();

}

Back

Page 34: PAR Implementation Details

34

boolAgentNet::condfunc_poperror(void){return popError;

}

Back

Page 35: PAR Implementation Details

35

boolAgentNet::activeAction(void){

return agentproc->ipt->activeAction();}

Back

Page 36: PAR Implementation Details

36

boolAgentNet::noFailAction(void){

return !(agentproc->ipt->failAction());}

Back

Page 37: PAR Implementation Details

37

IPAR TableIPAR Table• List of all IPARs for the agent• Status:

• notfound, • onqueue, • preproc, • prepspec, • exec, • completed, • aborted, • failure, // set when failure has been detected • failed // set after failure recovery

Page 38: PAR Implementation Details

38

voidParNet::actfunc_start(void){ap->ipt->setStatus(ipar,preproc);

}

Back

Page 39: PAR Implementation Details

39

BoolParNet::condfunc_culminate(void){

timer.startTimer("ParNet::condfunc_culminate");Bool result;PyObject* res;

res = actionary->testCulminationCond(ipar); assert(res);

if (result = fromPyObjectToBool(res))ap->ipt->setStatus(ipar,completed);

timer.stopTimer("ParNet::condfunc_culminate");return result;

}

Back

Page 40: PAR Implementation Details

40

voidParNet::actfunc_applicability(void){

timer.startTimer("ParNet::act_func_applicability");app_result = actionary->testApplicabilityCond(ipar);assert(app_result);

if(PyDict_Check(app_result)){

app_dict = 1;AgentProc *ap = agentTable.getAgent(ipar->par->getAgent()->getObjectName());assert(ap);ap->ipt->setStatus(ipar,aborted);

}else if (fromPyObjectToBool(app_result)){

app_status = 1;}else

{app_status = 0;AgentProc *ap = agentTable.getAgent(ipar->par->getAgent()->getObjectName());assert(ap);ap->ipt->setStatus(ipar,aborted);

}timer.stopTimer("ParNet::act_func_applicability");

}

Back

Page 41: PAR Implementation Details

41

BoolParNet::condfunc_applicable(void){return app_status;

}

Back

Page 42: PAR Implementation Details

42

BoolParNet::condfunc_isapplicdictionary(void){

return app_dict;}

Back

Page 43: PAR Implementation Details

43

LWNet *ParNet::newpar(void *args){

timer.startTimer("ParNet::newpar");

ComplexObj **cobj = (ComplexObj **)args;assert(cobj);

ActionNet *actionnet = new ActionNet(*cobj);assert(actionnet);

timer.stopTimer("ParNet::newpar");return actionnet;

}

Back

Page 44: PAR Implementation Details

44

voidParNet::actfunc_preparatory(void){

timer.startTimer("ParNet::actfunc_preparatory");

ap->ipt->setStatus(ipar,prepspec);prep_result = actionary->testPreparatorySpec(ipar);assert(prep_result);

if(PyDict_Check(prep_result)) {prep_dict = 1; }

else if (fromPyObjectToBool(prep_result)) {prep_status = 1; }

else { prep_status = 0; }

timer.stopTimer("ParNet::actfunc_preparatory");}

Back

Page 45: PAR Implementation Details

45

BoolParNet::condfunc_ready(void){return prep_status;

}

Back

Page 46: PAR Implementation Details

46

BoolParNet::condfunc_isprepdictionary(void){

return prep_dict;}

Back

Page 47: PAR Implementation Details

47

voidParNet::actfunc_coreexecution(void){

timer.startTimer("ParNet::actfunc_coreexecution");ap->ipt->setStatus(ipar,exec);PyObject *complexpar = actionary->testExecutionSteps(ipar); assert(complexpar);complexobj->pyobj = complexpar;complexobj->complexParent = ipar;

if(PyDict_Check(complexpar)) {prep_dict = 1; }

if(PyDict_GetItemString(complexpar,"COMPLEX")) {complex = 1; }

else if (PyDict_GetItemString(complexpar,"PRIMITIVE")) {complex = 0; }

timer.stopTimer("ParNet::actfunc_coreexecution");}

Back

Page 48: PAR Implementation Details

48

BoolParNet::condfunc_iscomplex(void){return complex;

}

Back

Page 49: PAR Implementation Details

49

voidParNet::preactfunc_primitive(void){if(!(callback = actionTable.getFunctions(ipar->par->getActionName())))printf("ERROR: No execution function found for action

%s\n",ipar->par->getActionName());elsecallback->func(ipar);

}

Back

Page 50: PAR Implementation Details

50

voidParNet::actfunc_primitive(void){

FailData *failData = new FailData;if(callback){switch(callback->finished(ipar, &failData)) {case SUCCESS:

markfinished();break;

case FAILURE:markerror(); // flag this node as errorif(ipar->complexParent) {

ap->ipt->setStatus(ipar->complexParent,failure);failData->complexIPAR = ipar->complexParent; }

ap->inform("Failure",(void *)failData); break;

default:break;

}}else markfinished();

}

Back

Page 51: PAR Implementation Details

51

voidParNet::postactfunc_primitive(void){

if((ap->ipt->getStatus(ipar) != failure) && \(ap->ipt->getStatus(ipar) != failed) &&

(ap->ipt->getStatus(ipar) != aborted)){ap->ipt->setStatus(ipar,completed); }

}

Back

Page 52: PAR Implementation Details

52

voidParNet::postactfunc_complex(void){

if(!errorcond()){

ap->ipt->setStatus(ipar,completed);}

}

Back