forked from AabidPatel/Vision-Based-Maze-Solving-Robot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinterface.py
126 lines (107 loc) · 3.76 KB
/
interface.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
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
119
120
121
122
123
124
125
126
from enum import Flag, Enum
import numpy as np
"""
DO NOT MODIFY THIS FILE!
This file defines the interface between the server code and the player's code
"""
class Action(Flag):
IDLE = 0
# movement actions
FORWARD = 1
BACKWARD = 2
LEFT = 4
RIGHT = 8
# check-in when player believes a target is reached
CHECKIN = 16
# end the current phase
QUIT = 32
class Phase(Enum):
EXPLORATION = 1
NAVIGATION = 2
class Player:
"""
This is a base class. Inherit it like the KeyboardPlayerPyGame example in player.py
"""
def __init__(self):
self._targets = None # this is to be set by the game server when it is being constructed
self._state = None # this is to be set by the game server
self._K = None # this is to be set by the game server
self.reset()
def reset(self) -> None:
"""
This function is to be invoked by the game play function before starting the game
:return: None
"""
raise NotImplementedError('Your player class should at least implement '
'this function to enable reset of the players.')
def pre_exploration(self) -> None:
"""
The player can implement any preparation code to be executed before exploration
:return: None
"""
print('pre exploration')
def pre_navigation(self) -> None:
"""
The player can implement any preparation code to be executed before navigation
:return: None
"""
print('pre navigation')
def act(self) -> Action:
"""
This function is to be invoked by the game server in each step, right after invoking see(fpv)
return an action
"""
raise NotImplementedError('Your player class should at least implement '
'this function to tell the robot what to do next after seeing the image.')
def see(self, fpv: np.ndarray) -> None:
"""
This function is to be invoked by the game server in each step
:param fpv: an opencv image (BGR format)
"""
raise NotImplementedError('Your player class should at least implement '
'this function to receive a new observation.')
def get_target_images(self) -> list[np.ndarray]:
"""
This function is to be invoked by players
:return: a reference to the internal list of target fpv images, i.e., self._targets
"""
return self._targets
def set_target_images(self, images: list[np.ndarray]) -> None:
"""
This function is to be invoked by the game server after exploration is finished
:param images: a list of images that represents the target
:return: None
"""
self._targets = images
def get_state(self):
"""
This function is to be invoked by players
:return: a tuple of the following items:
bot_fpv: np.ndarray
phase: Phase
step: int
time: float
fps: float
time_left: float
"""
return self._state
def set_state(self, state):
"""
This function is to be invoked by the game server
:param state: a 6-tuple
:return: None
"""
self._state = state
def get_camera_intrinsic_matrix(self) -> np.ndarray:
"""
This function is to be invoked by players
:return: a 3x3 camera intrinsic matrix for the robot's FPV camera
"""
return self._K
def set_camera_intrinsic_matrix(self, K: np.ndarray):
"""
This function is to be invoked by the game server
:param K: camera intrinsic matrix
:return: None
"""
self._K = np.array(K)