-
Notifications
You must be signed in to change notification settings - Fork 1
action task method_model
RAE will use lisp code that will be executed as operationnal model, which will then be used for planning. To define tasks, methods and actions, we will create macros.
A RAE domain is composed of primitive-actions, tasks and associated methods.
We define a macro to declare a new state function such as :
(def-state-function robot.battery ?r)
-> (lambda (?r) (rae-get-state-variable robot.battery ?r))
(defmacro def-state-function (lambda args
(let ((label (car args))
(params (cdr args)))
(quasiquote (rae-add-to-env (unquote label)
(lambda (unquote params)
(unquote (cons rae-get-state-variable (cons label params)))))))))
We would like to define an action as following:
(defaction move ?r ?x ?y)
The macro defaction has the form :
(defmacro defaction (lambda args
(let ((label (car args))
(params (cdr args)))
(rae-add-action label (lambda params
((rae-get-exec-command) label params))))
defaction could directly be a lambda:
(define defaction (lambda (label param)
(quasiquote (rae-add-action (unquote label) (lambda (unquote param)
(unquote ((rae-get-exec-command) label param)))))))
Here is an example:
(defaction pick ?r)
-> (rae-add-action pick (lambda (?r) (exec-godot pick ?r)))
Note: exec-godot returns an action id to handle status
For the moment we use a simplified way to define tasks without preconditions and effects annotations:
The skeleton of the definition would be as follow:
(deftask <task-label> <params>)
Here is an example:
(deftask pick ?r)
=> (((lambda (?r) (get-best-method pick ?r))?r))
We would use a macro to define tasks:
(deftask task-label ((:params <params>) (:preconditions <conditions>) (:effects <effects>)))
The macro has the following form:
(defmacro deftask (lambda (l body)
(rae-add-task l (lambda (cadr body)
(if (caadr body)
(caddr body)
(error (quote (task is not applicable in the given state))))))))
Here is an example:
(deftask pick ((:params ?r) (:preconditions nil) (:effects nil)))
-> (rae-add-task pick (lambda (?r)
(if nil
nil
(error (quote (task is not applicable in the given state))))))
A method is the operationnal code to execute a task. A task can have 1+ methods.
(defmethod <method-label> ((:task <task-label>)
(:params <params>)
(:body <body>)))
macro defmethod:
(defmacro defmethod (lambda (l body)
(let ((task-label (cadar body))
(params (cdadr body))
(body (cadaddr body))) -> #the method cadaddr is the concatenation of (car (cdr (car (cdr (cdr x)))))
(rae-add-method l (lambda params
body)))))
Here is an example:
(defmethod m1-pick ((:task pick)
(:params ?r)
(:body (begin
(seq (pick ?r))))))
-> (rae-add-method m1-pick pick (lambda (?r)
(begin (seq (pick ?r)))))
Note: seq executes sequentially tasks
For methods with more parameters than the task, we need to find the set of parameters that are applicable to the task. To do that we need to define the way RAE will check in real time the applicability of some parameters.
(def-method-parameters (quote ((<instances-to-test>) ((<params names of lambda>) (<conds>)))))
Def-method is using the macro enumerate_params that is defined in rae_env.
(defmacro enumerate_params (lambda args
(let ((p_enum (car args))
(p_labels (caadr args))
(conds (cadadr args)))
(quasiquote
(begin
(define eval_params (lambda args
(let ((params (car args)))
(if (not (null? params))
(if (eval (cons (lambda (unquote p_labels) (unquote conds)) params))
(cons params (eval_params (cdr args)))
(eval_params (cdr args)))
nil))))
(eval_params (unquote (cons enumerate p_enum))))))))
Here is a long example to use enumerate_params:
>> (begin
(define robots (list r1 r2))
(define machines (list m1 m2))
(define robot.is_available (lambda (?r) (if (= ?r r1) true)))
(define machine.is_ready (lambda (?r) true))
(enumerate_params
(robots machines) ((?r ?m)
(and (robot.is_available ?r) (machine.is_ready ?m)))))
LI>> ((r1 m1) (r1 m2))
(def-method-parameters <method-label> <intances> <body>)
Example:
(def-method-parameters m_pick (robots) ((?r) (robot.is_empty ?r)))
(defmacro generate-method-parameter (lambda args
(let ((label (car args))
(args_enumerate (cdr args)))
(quasiquote (quote (unquote (list label (cons (quote enumerate_params) args_enumerate))))))))
Sometimes we want to explicitely modify the state.
-
(rae-add-action \ \): add an action in its environment
-
(rae-add-task \ \) : add a task in the environment of rae
-
(rae-add-method \ ): add a method for a already defined task
-
(rae-set-exec-command ) : set the exec command to execute
(rae-set-exec-command exec-godot) #to use godo as execution environment
-
(rae-get-exec-command) : returns the function used to execute commands -(rae-add-action label )
-
Acting methods: Cf arthur's document about real-time primitives.