Projects/RCLL-SS2017: task2.clp

File task2.clp, 3.5 KB (added by thofmann, 6 months ago)

Solution of Agent Hands-On Task 2

Line 
1;---------------------------------------------------------------------------
2;  task1.clp - Summer school 2017 task1 rules for testing in the gazebo simulation
3;
4;  Created: Thu Aug 24, 2017
5;  Copyright  2017 Toshiya Maki
6;  Licensed under GPLv2+ license, cf. LICENSE file
7;---------------------------------------------------------------------------
8
9(defrule move-into-field
10 "recognize the arrival on the play field"
11 ?sf <- (state WAIT_START)
12 ?cf <- (change-state RUNNING)
13 (team-color ?team-color)
14 =>
15 (retract ?sf ?cf)
16 (assert (state MOVE_INTO_FIELD))
17
18 (skill-call drive_into_field team ?team-color wait 0)
19)
20
21(defrule move-into-field-done
22  "If the bot finished to move into the field, start the game."
23  ?sf     <- (state MOVE_INTO_FIELD)
24  ?final  <- (skill-done (name "drive_into_field") (status FINAL|FAILED))
25  =>
26  (retract ?sf ?final)
27  (assert (state RESTART))
28)
29
30(defrule pickup-base-with-cap
31 "pick up base with cap from cap station"
32 ?sf <- (state RESTART)
33 ?cf <- (change-phase PRODUCTION)
34 =>
35 (retract ?sf ?cf)
36 (assert (state PICKUP-BASE-WITH-CAP))
37 (assert (phase PRODUCTION))
38 (skill-call get_product_from place "C-CS1" shelf "RIGHT")
39)
40
41(defrule prepare-cap-station
42 "error check and move on"
43 ?sf <- (state PICKUP-BASE-WITH-CAP)
44 ?final <- (skill-done (name "get_product_from") (status FINAL|FAILED))
45 (skill-done (name "get_product_from") (status ?status))
46 (machine (name C-CS1) (state ?machinestate))
47  =>
48 (retract ?sf ?final)
49 (if (eq ?status FINAL) then
50  (if (eq ?machinestate IDLE) then
51   (assert (state PREPARE-CAP-STATION))
52   (assert (mps-instruction (machine C-CS1) (cs-operation RETRIEVE_CAP)))
53   else
54   (printout error "C-CS machine preparation failed" crlf)
55  )
56  else
57  (printout error "pickup base with cap failed" crlf)
58  (assert (state WORK-FAILED))
59 )
60)
61
62(defrule remove-cap
63 ?sf <- (state PREPARE-CAP-STATION)
64 (machine (name C-CS1) (state PREPARED))
65 =>
66 (retract ?sf)
67 (assert (state REMOVE-CAP))
68 (skill-call bring_product_to place C-CS1)
69 )
70
71(defrule pickup-processed-cap
72 ?sf <- (state REMOVE-CAP)
73 ?final <- (skill-done (name "bring_product_to") (status FINAL|FAILED))
74 (skill-done (name "bring_product_to") (status ?status))
75 =>
76 (retract ?sf)
77 (if (eq ?status FINAL) then
78  (assert (state PICKUP-PROCESSED-CAP))
79  (skill-call get_product_from place C-CS1 side output)
80  else
81  (printout error "bring base with cap to conveyer failed" crlf)
82 )
83)
84
85(defrule prepare-delivery-station
86 "error check and move on"
87 ?sf <- (state PICKUP-PROCESSED-CAP)
88 ?final <- (skill-done (name "get_product_from") (status FINAL|FAILED))
89 (skill-done (name "get_product_from") (status ?status))
90 (machine (name C-DS) (state ?machinestate))
91  =>
92 (retract ?sf ?final)
93 (if (eq ?status FINAL) then
94  (if (eq ?machinestate IDLE) then
95   (assert (state PREPARE-DELIVERY-STATION))
96   (assert (mps-instruction (machine C-DS) (gate 1)))
97   else
98   (printout error "C-DS machine preparation failed" crlf)
99  )
100  else
101  (printout error "pickup base without cap failed" crlf)
102  (assert (state WORK-FAILED))
103 )
104)
105
106(defrule deliver-base
107 ?sf <- (state PREPARE-DELIVERY-STATION)
108 (machine (name C-DS) (state PREPARED))
109 =>
110 (retract ?sf)
111 (assert (state DELIVER-BASE))
112 (skill-call bring_product_to place C-DS)
113 )
114
115
116(defrule delivery-confirmation
117 ?sf <- (state DELIVER-BASE)
118 ?final <- (skill-done (name "bring_product_to") (status FINAL|FAILED))
119 (skill-done (name "bring_product_to") (status ?status))
120 =>
121 (retract ?sf ?final)
122 (if (eq ?status FINAL) then
123  (assert (state DELIVERY-SUCCESS))
124  (printout t "delivered base successfully" crlf)
125  else
126  (printout error "deliver base failed" crlf)
127 )
128)
129