Skip to content

pami

Pami3Action #

Bases: Action

Action for PAMI 3.

Plan
  • BA: disable pantry
  • B1: wait initial_delay seconds (for PAMI 4, 5 and 6 to move)
  • B1: disable avoidance
  • P1: move to X=same Y=-1425 angle=180
  • A1: restore avoidance
  • B2: wait for pami_event (if wait==True)
  • B2: wait start_delay seconds (probably 0)
  • P2: go to PantryID.LocalSide
  • A2: enable flag motor
Source code in cogip/tools/planner/actions/pami.py
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
class Pami3Action(Action):
    """
    Action for PAMI 3.

    Plan:
        - BA: disable pantry
        - B1: wait initial_delay seconds (for PAMI 4, 5 and 6 to move)
        - B1: disable avoidance
        - P1: move to X=same Y=-1425 angle=180
        - A1: restore avoidance
        - B2: wait for pami_event (if wait==True)
        - B2: wait start_delay seconds (probably 0)
        - P2: go to PantryID.LocalSide
        - A2: enable flag motor
    """

    def __init__(self, planner: "Planner", strategy: Strategy, start_delay: int, wait: bool = True):
        super().__init__("PAMI 3 action", planner, strategy, interruptable=False)
        self.wait = wait
        self.before_action_func = self.before_action
        self.start_delay = start_delay
        self.initial_delay = 15
        self.pantry_id = PantryID.LocalSide

    def set_avoidance(self, new_strategy: AvoidanceStrategy):
        self.logger.info(f"{self.name}: set avoidance to {new_strategy.name}")
        self.planner.shared_properties.avoidance_strategy = new_strategy.val

    @property
    def pantry(self) -> Pantry:
        return self.planner.game_context.pantries[self.pantry_id]

    async def before_action(self):
        self.pantry.enabled = False
        if self.planner.shared_properties.table == TableEnum.Training:
            self.planner.game_context.pantries[PantryID.LocalSide].enabled = False

        self.start_pose = self.pose_current.model_copy()

        pose1 = AdaptedPose(
            x=self.start_pose.x,
            y=-1425,
            max_speed_linear=70,
            max_speed_angular=70,
            bypass_final_orientation=True,
            before_pose_func=self.before_pose1,
            after_pose_func=self.after_pose1,
        )
        self.poses.append(pose1)
        self.logger.info(f"{self.name}: pose1: x={pose1.x: 5.2f} y={pose1.y: 5.2f} O={pose1.O: 3.2f}°")

        pose2 = Pose(
            x=self.pantry.x,
            y=self.pantry.y,
            max_speed_linear=100,
            max_speed_angular=100,
            bypass_final_orientation=True,
            stop_before_distance=170,
            before_pose_func=self.before_pose2,
            after_pose_func=self.after_pose2,
        )
        if Camp().color == Camp.Colors.blue:
            pose2.y += 20
        else:
            pose2.y -= 20
        if self.planner.shared_properties.table == TableEnum.Training:
            pose2.x = -880
            pose2.y = -1350
        self.poses.append(pose2)
        self.logger.info(f"{self.name}: pose2: x={pose2.x: 5.2f} y={pose2.y: 5.2f} O={pose2.O: 3.2f}°")

    async def before_pose1(self):
        self.logger.info(f"{self.name}: before_pose1")
        self.set_avoidance(AvoidanceStrategy.Disabled)
        await asyncio.sleep(self.initial_delay)

    async def after_pose1(self):
        self.logger.info(f"{self.name}: after_pose1")
        self.set_avoidance(AvoidanceStrategy.AvoidanceCpp)

    async def before_pose2(self):
        self.logger.info(f"{self.name}: before_pose2")
        if self.wait:
            await self.planner.pami_event.wait()

        self.planner.led.color = Color("lightblue")
        await set_countdown_color(self.planner, "orange")
        await asyncio.sleep(self.start_delay)
        self.planner.led.color = Color("green")
        await set_countdown_color(self.planner, "green")

    async def after_pose2(self):
        self.logger.info(f"{self.name}: after_pose2")
        self.planner.led.color = Color("red")
        await set_countdown_color(self.planner, "red")
        self.strategy.clear()
        self.planner.flag_motor.on()

    def weight(self) -> float:
        return 9_999_999.0

Pami4Action #

Bases: Action

Action for PAMI 4.

Plan
  • BA: disable pantry
  • B1: wait initial_delay seconds (for PAMI 6 to move)
  • B1: disable avoidance
  • P1: move to X=same Y=-1245 angle=bypass
  • P2: move to X=680 Y=-1245 angle=180
  • A2: restore avoidance
  • B3: wait for pami_event (if wait==True)
  • B3: wait start_delay seconds (probably 0)
  • P3: step out: X=450
  • P4: go to PantryID.LocalBottom
  • A4: enable flag motor
Source code in cogip/tools/planner/actions/pami.py
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
class Pami4Action(Action):
    """
    Action for PAMI 4.

    Plan:
        - BA: disable pantry
        - B1: wait initial_delay seconds (for PAMI 6 to move)
        - B1: disable avoidance
        - P1: move to X=same Y=-1245 angle=bypass
        - P2: move to X=680 Y=-1245 angle=180
        - A2: restore avoidance
        - B3: wait for pami_event (if wait==True)
        - B3: wait start_delay seconds (probably 0)
        - P3: step out: X=450
        - P4: go to PantryID.LocalBottom
        - A4: enable flag motor
    """

    def __init__(self, planner: "Planner", strategy: Strategy, start_delay: int, wait: bool = True):
        super().__init__("PAMI 4 action", planner, strategy, interruptable=False)
        self.wait = wait
        self.before_action_func = self.before_action
        self.start_delay = start_delay
        self.initial_delay = 5
        self.pantry_id = PantryID.LocalBottom

    def set_avoidance(self, new_strategy: AvoidanceStrategy):
        self.logger.info(f"{self.name}: set avoidance to {new_strategy.name}")
        self.planner.shared_properties.avoidance_strategy = new_strategy.val

    @property
    def pantry(self) -> Pantry:
        return self.planner.game_context.pantries[self.pantry_id]

    async def before_action(self):
        self.pantry.enabled = False
        if self.planner.shared_properties.table == TableEnum.Training:
            self.planner.game_context.pantries[PantryID.LocalSide].enabled = False

        self.start_pose = self.pose_current.model_copy()

        pose1 = AdaptedPose(
            x=self.start_pose.x,
            y=-1245,
            max_speed_linear=70,
            max_speed_angular=70,
            bypass_final_orientation=True,
            before_pose_func=self.before_pose1,
            after_pose_func=self.after_pose1,
        )
        self.poses.append(pose1)
        self.logger.info(f"{self.name}: pose1: x={pose1.x: 5.2f} y={pose1.y: 5.2f} O={pose1.O: 3.2f}°")

        pose2 = AdaptedPose(
            x=680,
            y=-1245,
            O=180,
            max_speed_linear=70,
            max_speed_angular=70,
            bypass_final_orientation=False,
            before_pose_func=self.before_pose2,
            after_pose_func=self.after_pose2,
        )
        if self.planner.shared_properties.table == TableEnum.Training:
            pose2.x -= 1000
        self.poses.append(pose2)
        self.logger.info(f"{self.name}: pose2: x={pose2.x: 5.2f} y={pose2.y: 5.2f} O={pose2.O: 3.2f}°")

        pose3 = AdaptedPose(
            x=450,
            y=-1245,
            max_speed_linear=100,
            max_speed_angular=100,
            bypass_final_orientation=True,
            before_pose_func=self.before_pose3,
            after_pose_func=self.after_pose3,
        )
        if self.planner.shared_properties.table == TableEnum.Training:
            pose3.x -= 1000
        self.poses.append(pose3)
        self.logger.info(f"{self.name}: pose3: x={pose3.x: 5.2f} y={pose3.y: 5.2f} O={pose3.O: 3.2f}°")

        pose4 = Pose(
            x=self.pantry.x + 20,
            y=self.pantry.y,
            max_speed_linear=100,
            max_speed_angular=100,
            bypass_final_orientation=True,
            stop_before_distance=170,
            before_pose_func=self.before_pose4,
            after_pose_func=self.after_pose4,
        )
        if self.planner.shared_properties.table == TableEnum.Training:
            pose4.x = -880
            pose4.y = -1000
        self.poses.append(pose4)
        self.logger.info(f"{self.name}: pose4: x={pose4.x: 5.2f} y={pose4.y: 5.2f} O={pose4.O: 3.2f}°")

    async def before_pose1(self):
        self.logger.info(f"{self.name}: before_pose1")
        self.set_avoidance(AvoidanceStrategy.Disabled)
        await asyncio.sleep(self.initial_delay)

    async def after_pose1(self):
        self.logger.info(f"{self.name}: after_pose1")

    async def before_pose2(self):
        self.logger.info(f"{self.name}: before_pose2")

    async def after_pose2(self):
        self.logger.info(f"{self.name}: after_pose2")
        self.set_avoidance(AvoidanceStrategy.AvoidanceCpp)

    async def before_pose3(self):
        self.logger.info(f"{self.name}: before_pose3")
        if self.wait:
            await self.planner.pami_event.wait()

        self.planner.led.color = Color("lightblue")
        await set_countdown_color(self.planner, "orange")
        await asyncio.sleep(self.start_delay)
        self.planner.led.color = Color("green")
        await set_countdown_color(self.planner, "green")

    async def after_pose3(self):
        self.logger.info(f"{self.name}: after_pose3")

    async def before_pose4(self):
        self.logger.info(f"{self.name}: before_pose4")

    async def after_pose4(self):
        self.logger.info(f"{self.name}: after_pose4")
        self.planner.led.color = Color("red")
        await set_countdown_color(self.planner, "red")
        self.strategy.clear()
        self.planner.flag_motor.on()

    def weight(self) -> float:
        return 9_999_999.0

Pami5Action #

Bases: Action

Action for PAMI 5.

Plan
  • BA: disable pantry
  • B1: disable avoidance
  • B1: wait initial_delay seconds (for PAMI 4 and 6 to move)
  • P1: move to X=same Y=-1115 angle=bypass
  • P2: move to X=680 Y=-1115 angle=180
  • A2: restore avoidance
  • B3: wait for pami_event (if wait==True)
  • B3: wait start_delay seconds (for PAMI 5 to move)
  • P3: step out: X=450
  • P4: go to PantryID.LocalCenter
  • A4: enable flag motor
Source code in cogip/tools/planner/actions/pami.py
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
class Pami5Action(Action):
    """
    Action for PAMI 5.

    Plan:
        - BA: disable pantry
        - B1: disable avoidance
        - B1: wait initial_delay seconds (for PAMI 4 and 6 to move)
        - P1: move to X=same Y=-1115 angle=bypass
        - P2: move to X=680 Y=-1115 angle=180
        - A2: restore avoidance
        - B3: wait for pami_event (if wait==True)
        - B3: wait start_delay seconds (for PAMI 5 to move)
        - P3: step out: X=450
        - P4: go to PantryID.LocalCenter
        - A4: enable flag motor
    """

    def __init__(self, planner: "Planner", strategy: Strategy, start_delay: int, wait: bool = True):
        super().__init__("PAMI 5 action", planner, strategy, interruptable=False)
        self.wait = wait
        self.before_action_func = self.before_action
        self.start_delay = start_delay
        self.initial_delay = 10
        self.pantry_id = PantryID.LocalCenter

    def set_avoidance(self, new_strategy: AvoidanceStrategy):
        self.logger.info(f"{self.name}: set avoidance to {new_strategy.name}")
        self.planner.shared_properties.avoidance_strategy = new_strategy.val

    @property
    def pantry(self) -> Pantry:
        return self.planner.game_context.pantries[self.pantry_id]

    async def before_action(self):
        self.pantry.enabled = False
        if self.planner.shared_properties.table == TableEnum.Training:
            self.planner.game_context.pantries[PantryID.LocalSide].enabled = False
            self.planner.game_context.pantries[PantryID.LocalBottom].enabled = False

        self.start_pose = self.pose_current.model_copy()

        pose1 = AdaptedPose(
            x=self.start_pose.x,
            y=-1115,
            max_speed_linear=70,
            max_speed_angular=70,
            bypass_final_orientation=True,
            before_pose_func=self.before_pose1,
            after_pose_func=self.after_pose1,
        )
        self.poses.append(pose1)
        self.logger.info(f"{self.name}: pose1: x={pose1.x: 5.2f} y={pose1.y: 5.2f} O={pose1.O: 3.2f}°")

        pose2 = AdaptedPose(
            x=680,
            y=-1115,
            O=180,
            max_speed_linear=70,
            max_speed_angular=70,
            bypass_final_orientation=False,
            before_pose_func=self.before_pose2,
            after_pose_func=self.after_pose2,
        )
        if self.planner.shared_properties.table == TableEnum.Training:
            pose2.x -= 1000
        self.poses.append(pose2)
        self.logger.info(f"{self.name}: pose2: x={pose2.x: 5.2f} y={pose2.y: 5.2f} O={pose2.O: 3.2f}°")

        pose3 = AdaptedPose(
            x=450,
            y=-1115,
            max_speed_linear=100,
            max_speed_angular=100,
            bypass_final_orientation=True,
            before_pose_func=self.before_pose3,
            after_pose_func=self.after_pose3,
        )
        if self.planner.shared_properties.table == TableEnum.Training:
            pose3.x -= 1000
        self.poses.append(pose3)
        self.logger.info(f"{self.name}: pose3: x={pose3.x: 5.2f} y={pose3.y: 5.2f} O={pose3.O: 3.2f}°")

        pose4 = Pose(
            x=self.pantry.x,
            y=self.pantry.y,
            max_speed_linear=100,
            max_speed_angular=100,
            bypass_final_orientation=True,
            stop_before_distance=170,
            before_pose_func=self.before_pose4,
            after_pose_func=self.after_pose4,
        )
        if Camp().color == Camp.Colors.blue:
            pose4.y += 20
        else:
            pose4.y -= 20
        if self.planner.shared_properties.table == TableEnum.Training:
            pose4.x = -880
            pose4.y = -625
        self.poses.append(pose4)
        self.logger.info(f"{self.name}: pose4: x={pose4.x: 5.2f} y={pose4.y: 5.2f} O={pose4.O: 3.2f}°")

    async def before_pose1(self):
        self.logger.info(f"{self.name}: before_pose1")
        self.set_avoidance(AvoidanceStrategy.Disabled)

        await asyncio.sleep(self.initial_delay)

    async def after_pose1(self):
        self.logger.info(f"{self.name}: after_pose1")

    async def before_pose2(self):
        self.logger.info(f"{self.name}: before_pose2")

    async def after_pose2(self):
        self.logger.info(f"{self.name}: after_pose2")
        self.set_avoidance(AvoidanceStrategy.AvoidanceCpp)

    async def before_pose3(self):
        self.logger.info(f"{self.name}: before_pose3")
        if self.wait:
            await self.planner.pami_event.wait()

        self.planner.led.color = Color("lightblue")
        await set_countdown_color(self.planner, "orange")
        await asyncio.sleep(self.start_delay)
        self.planner.led.color = Color("green")
        await set_countdown_color(self.planner, "green")

    async def after_pose3(self):
        self.logger.info(f"{self.name}: after_pose3")

    async def before_pose4(self):
        self.logger.info(f"{self.name}: before_pose4")

    async def after_pose4(self):
        self.logger.info(f"{self.name}: after_pose4")
        self.planner.led.color = Color("red")
        await set_countdown_color(self.planner, "red")
        self.strategy.clear()
        self.planner.flag_motor.on()

    def weight(self) -> float:
        return 9_999_999.0

Pami6Action #

Bases: Action

Action for PAMI 6.

Plan
  • BA: disable pantry
  • B1: disable avoidance
  • B1: wait initial_delay seconds (probably 0)
  • P1: move to X=same Y=-1135 angle=bypass
  • P2: move to X=680 Y=-985 angle=180
  • A2: restore avoidance
  • B3: wait for pami_event (if wait==True)
  • B3: wait start_delay seconds (wait for PAMI 4 and 5 to move)
  • P3: step out: X=450 Y=-985 angle=bypass
  • P4: go to PantryID.MiddleCenter
  • A4: enable flag motor
Source code in cogip/tools/planner/actions/pami.py
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
class Pami6Action(Action):
    """
    Action for PAMI 6.

    Plan:
        - BA: disable pantry
        - B1: disable avoidance
        - B1: wait initial_delay seconds (probably 0)
        - P1: move to X=same Y=-1135 angle=bypass
        - P2: move to X=680 Y=-985 angle=180
        - A2: restore avoidance
        - B3: wait for pami_event (if wait==True)
        - B3: wait start_delay seconds (wait for PAMI 4 and 5 to move)
        - P3: step out: X=450 Y=-985 angle=bypass
        - P4: go to PantryID.MiddleCenter
        - A4: enable flag motor
    """

    def __init__(self, planner: "Planner", strategy: Strategy, start_delay: int, wait: bool = True):
        super().__init__("PAMI 6 action", planner, strategy, interruptable=False)
        self.wait = wait
        self.before_action_func = self.before_action
        self.start_delay = start_delay
        self.initial_delay = 0
        self.pantry_id = PantryID.MiddleCenter

    def set_avoidance(self, new_strategy: AvoidanceStrategy):
        self.logger.info(f"{self.name}: set avoidance to {new_strategy.name}")
        self.planner.shared_properties.avoidance_strategy = new_strategy.val

    @property
    def pantry(self) -> Pantry:
        return self.planner.game_context.pantries[self.pantry_id]

    async def before_action(self):
        self.pantry.enabled = False
        if self.planner.shared_properties.table == TableEnum.Training:
            self.planner.game_context.pantries[PantryID.LocalSide].enabled = False

        self.start_pose = self.pose_current.model_copy()

        pose1 = AdaptedPose(
            x=self.start_pose.x,
            y=-1065,
            max_speed_linear=70,
            max_speed_angular=70,
            bypass_final_orientation=True,
            before_pose_func=self.before_pose1,
            after_pose_func=self.after_pose1,
        )
        self.poses.append(pose1)
        self.logger.info(f"{self.name}: pose1: x={pose1.x: 5.2f} y={pose1.y: 5.2f} O={pose1.O: 3.2f}°")

        pose2 = AdaptedPose(
            x=680,
            y=-985,
            O=180,
            max_speed_linear=70,
            max_speed_angular=70,
            bypass_final_orientation=False,
            before_pose_func=self.before_pose2,
            after_pose_func=self.after_pose2,
        )
        if self.planner.shared_properties.table == TableEnum.Training:
            pose2.x -= 1000
        self.poses.append(pose2)
        self.logger.info(f"{self.name}: pose2: x={pose2.x: 5.2f} y={pose2.y: 5.2f} O={pose2.O: 3.2f}°")

        pose3 = AdaptedPose(
            x=450,
            y=-985,
            max_speed_linear=100,
            max_speed_angular=100,
            bypass_final_orientation=True,
            before_pose_func=self.before_pose3,
            after_pose_func=self.after_pose3,
        )
        if self.planner.shared_properties.table == TableEnum.Training:
            pose3.x -= 1000
        self.poses.append(pose3)
        self.logger.info(f"{self.name}: pose3: x={pose3.x: 5.2f} y={pose3.y: 5.2f} O={pose3.O: 3.2f}°")

        pose4 = AdaptedPose(
            x=self.pantry.x,
            y=self.pantry.y,
            max_speed_linear=100,
            max_speed_angular=100,
            bypass_final_orientation=True,
            stop_before_distance=170,
            before_pose_func=self.before_pose4,
            after_pose_func=self.after_pose4,
        )
        if self.planner.shared_properties.table == TableEnum.Training:
            pose4.x = -880
            pose4.y = -200

        self.poses.append(pose4)
        self.logger.info(f"{self.name}: pose4: x={pose4.x: 5.2f} y={pose4.y: 5.2f} O={pose4.O: 3.2f}°")

    async def before_pose1(self):
        self.logger.info(f"{self.name}: before_pose1")
        self.set_avoidance(AvoidanceStrategy.Disabled)
        await asyncio.sleep(self.initial_delay)

    async def after_pose1(self):
        self.logger.info(f"{self.name}: after_pose1")

    async def before_pose2(self):
        self.logger.info(f"{self.name}: before_pose2")

    async def after_pose2(self):
        self.logger.info(f"{self.name}: after_pose2")

    async def before_pose3(self):
        self.logger.info(f"{self.name}: before_pose3")
        if self.wait:
            await self.planner.pami_event.wait()

        self.planner.led.color = Color("lightblue")
        await set_countdown_color(self.planner, "orange")
        await asyncio.sleep(self.start_delay)
        self.planner.led.color = Color("green")
        await set_countdown_color(self.planner, "green")

    async def after_pose3(self):
        self.logger.info(f"{self.name}: after_pose3")
        self.set_avoidance(AvoidanceStrategy.AvoidanceCpp)

    async def before_pose4(self):
        self.logger.info(f"{self.name}: before_pose4")

    async def after_pose4(self):
        self.logger.info(f"{self.name}: after_pose4")
        self.planner.led.color = Color("red")
        await set_countdown_color(self.planner, "red")
        self.strategy.clear()
        self.planner.flag_motor.on()

    def weight(self) -> float:
        return 9_999_999.0