-
Notifications
You must be signed in to change notification settings - Fork 9
/
PedsimAgent.py
300 lines (242 loc) · 11.3 KB
/
PedsimAgent.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
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
260
261
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
import numpy as np
from enum import Enum
from FlatlandModel import FlatlandModel
from HelperFunctions import *
class PedsimStartupMode(Enum):
DEFAULT = 0
WAIT_TIMER = 1
TRIGGER_ZONE = 2
class PedsimWaypointMode(Enum):
LOOP = 0
RANDOM = 1
class PedsimAgentType(Enum):
ADULT = 0
CHILD = 1
ELDER = 2
FORKLIFT = 3
SERVICEROBOT = 4
class InteractiveObstacleType(Enum):
SHELF = 0
class PedsimInteractiveObstacle():
def __init__(self):
self.obstacleType = InteractiveObstacleType.SHELF
# TODO...
class PedsimAgent():
def __init__(self, name = "", flatlandModelPath = "") -> None:
self.name = name
# set default values (derived from pedsim_msgs/Ped.msg)
self.id = 0
self.pos = np.zeros(2)
self.type = "adult"
self.yaml_file = ""
self.flatlandModel = None # FlatlandModel instance
if flatlandModelPath != "":
self.loadFlatlandModel(flatlandModelPath)
self.number_of_peds = 1
self.vmax = 0.3
self.start_up_mode = "default"
self.wait_time = 0.0
self.trigger_zone_radius = 0.0
self.max_talking_distance = 5.0
self.max_servicing_radius = 5.0
self.chatting_probability = 0.0
self.tell_story_probability = 0.0
self.group_talking_probability = 0.0
self.talking_and_walking_probability = 0.0
self.requesting_service_probability = 0.0
self.requesting_guide_probability = 0.0
self.requesting_follower_probability = 0.0
self.talking_base_time = 10.0
self.tell_story_base_time = 0.0
self.group_talking_base_time = 10.0
self.talking_and_walking_base_time = 6.0
self.receiving_service_base_time = 20.0
self.requesting_service_base_time = 30.0
self.force_factor_desired = 1.0
self.force_factor_obstacle = 1.0
self.force_factor_social = 5.0
self.force_factor_robot = 0.0
self.waypoints = [] # list of 2D numpy arrays
self.waypoint_mode = 0
def loadFlatlandModel(self, path: str):
self.yaml_file = path
model = FlatlandModel()
model.load(path)
self.flatlandModel = model
def __eq__(self, other):
if not isinstance(other, PedsimAgent):
return NotImplemented
if self.name != other.name:
return False
if self.flatlandModel != other.flatlandModel:
return False
if self.id != other.id:
return False
if not np.allclose(self.pos, other.pos):
return False
if self.type != other.type:
return False
if self.yaml_file != other.yaml_file:
return False
if self.number_of_peds != other.number_of_peds:
return False
if not np.allclose(self.vmax, other.vmax):
return False
if self.start_up_mode != other.start_up_mode:
return False
if not np.allclose(self.wait_time, other.wait_time):
return False
if not np.allclose(self.trigger_zone_radius, other.trigger_zone_radius):
return False
if not np.allclose(self.chatting_probability, other.chatting_probability):
return False
if not np.allclose(self.tell_story_probability, other.tell_story_probability):
return False
if not np.allclose(self.group_talking_probability, other.group_talking_probability):
return False
if not np.allclose(self.talking_and_walking_probability, other.talking_and_walking_probability):
return False
if not np.allclose(self.requesting_service_probability, other.requesting_service_probability):
return False
if not np.allclose(self.requesting_guide_probability, other.requesting_guide_probability):
return False
if not np.allclose(self.requesting_follower_probability, other.requesting_follower_probability):
return False
if not np.allclose(self.max_talking_distance, other.max_talking_distance):
return False
if not np.allclose(self.max_servicing_radius, other.max_servicing_radius):
return False
if not np.allclose(self.talking_base_time, other.talking_base_time):
return False
if not np.allclose(self.tell_story_base_time, other.tell_story_base_time):
return False
if not np.allclose(self.group_talking_base_time, other.group_talking_base_time):
return False
if not np.allclose(self.talking_and_walking_base_time, other.talking_and_walking_base_time):
return False
if not np.allclose(self.receiving_service_base_time, other.receiving_service_base_time):
return False
if not np.allclose(self.requesting_service_base_time, other.requesting_service_base_time):
return False
if not np.allclose(self.force_factor_desired, other.force_factor_desired):
return False
if not np.allclose(self.force_factor_obstacle, other.force_factor_obstacle):
return False
if not np.allclose(self.force_factor_social, other.force_factor_social):
return False
if not np.allclose(self.force_factor_robot, other.force_factor_robot):
return False
if len(self.waypoints) != len(other.waypoints):
return False
if not np.all([np.allclose(wpa, wpb) for wpa, wpb in zip(self.waypoints, other.waypoints)]):
return False
if self.waypoint_mode != other.waypoint_mode:
return False
return True
def toDict(self):
d = {}
d["name"] = self.name
d["id"] = self.id
d["pos"] = [float(val) for val in self.pos]
d["type"] = self.type
d["yaml_file"] = self.yaml_file
d["number_of_peds"] = self.number_of_peds
d["vmax"] = self.vmax
d["start_up_mode"] = self.start_up_mode
d["wait_time"] = self.wait_time
d["trigger_zone_radius"] = self.trigger_zone_radius
d["chatting_probability"] = self.chatting_probability
d["tell_story_probability"] = self.tell_story_probability
d["group_talking_probability"] = self.group_talking_probability
d["talking_and_walking_probability"] = self.talking_and_walking_probability
d["requesting_service_probability"] = self.requesting_service_probability
d["requesting_guide_probability"] = self.requesting_guide_probability
d["requesting_follower_probability"] = self.requesting_follower_probability
d["max_talking_distance"] = self.max_talking_distance
d["max_servicing_radius"] = self.max_servicing_radius
d["talking_base_time"] = self.talking_base_time
d["tell_story_base_time"] = self.tell_story_base_time
d["group_talking_base_time"] = self.group_talking_base_time
d["talking_and_walking_base_time"] = self.talking_and_walking_base_time
d["receiving_service_base_time"] = self.receiving_service_base_time
d["requesting_service_base_time"] = self.requesting_service_base_time
d["force_factor_desired"] = self.force_factor_desired
d["force_factor_obstacle"] = self.force_factor_obstacle
d["force_factor_social"] = self.force_factor_social
d["force_factor_robot"] = self.force_factor_robot
d["waypoints"] = [[float(val) for val in wp] for wp in self.waypoints]
d["waypoint_mode"] = self.waypoint_mode
return d
@staticmethod
def fromDict(d : dict):
a = PedsimAgent(d["name"], d["yaml_file"])
a.name = d["name"]
a.id = d["id"]
a.pos = np.array([d["pos"][0], d["pos"][1]])
a.type = d["type"]
a.yaml_file = get_current_user_path(d["yaml_file"])
a.number_of_peds = d["number_of_peds"]
a.vmax = d["vmax"]
a.start_up_mode = d["start_up_mode"]
a.wait_time = d["wait_time"]
a.trigger_zone_radius = d["trigger_zone_radius"]
a.chatting_probability = d["chatting_probability"]
a.tell_story_probability = d["tell_story_probability"]
a.group_talking_probability = d["group_talking_probability"]
a.talking_and_walking_probability = d["talking_and_walking_probability"]
a.requesting_service_probability = d["requesting_service_probability"]
a.requesting_guide_probability = d["requesting_guide_probability"]
a.requesting_follower_probability = d["requesting_follower_probability"]
a.max_talking_distance = d["max_talking_distance"]
a.max_servicing_radius = d["max_servicing_radius"]
a.talking_base_time = d["talking_base_time"]
a.tell_story_base_time = d["tell_story_base_time"]
a.group_talking_base_time = d["group_talking_base_time"]
a.talking_and_walking_base_time = d["talking_and_walking_base_time"]
a.receiving_service_base_time = d["receiving_service_base_time"]
a.requesting_service_base_time = d["requesting_service_base_time"]
a.force_factor_desired = d["force_factor_desired"]
a.force_factor_obstacle = d["force_factor_obstacle"]
a.force_factor_social = d["force_factor_social"]
a.force_factor_robot = d["force_factor_robot"]
a.waypoints = [np.array([wp[0], wp[1]]) for wp in d["waypoints"]]
a.waypoint_mode = int(d["waypoint_mode"])
return a
def getPedMsg(self):
try:
from pedsim_msgs.msg import Ped
from geometry_msgs.msg import Point
except:
return None
msg = Ped()
msg.id = self.id
msg.pos = Point(self.pos[0], self.pos[1], 0)
msg.type = self.type
msg.yaml_file = self.yaml_file
msg.number_of_peds = self.number_of_peds
msg.vmax = self.vmax
msg.start_up_mode = self.start_up_mode
msg.wait_time = self.wait_time
msg.trigger_zone_radius = self.trigger_zone_radius
msg.chatting_probability = self.chatting_probability
msg.tell_story_probability = self.tell_story_probability
msg.group_talking_probability = self.group_talking_probability
msg.talking_and_walking_probability = self.talking_and_walking_probability
msg.requesting_service_probability = self.requesting_service_probability
msg.requesting_guide_probability = self.requesting_guide_probability
msg.requesting_follower_probability = self.requesting_follower_probability
msg.max_talking_distance = self.max_talking_distance
msg.max_servicing_radius = self.max_servicing_radius
msg.talking_base_time = self.talking_base_time
msg.tell_story_base_time = self.tell_story_base_time
msg.group_talking_base_time = self.group_talking_base_time
msg.talking_and_walking_base_time = self.talking_and_walking_base_time
msg.receiving_service_base_time = self.receiving_service_base_time
msg.requesting_service_base_time = self.requesting_service_base_time
msg.force_factor_desired = self.force_factor_desired
msg.force_factor_obstacle = self.force_factor_obstacle
msg.force_factor_social = self.force_factor_social
msg.force_factor_robot = self.force_factor_robot
msg.waypoints = [Point(wp[0], wp[1], 0) for wp in self.waypoints]
msg.waypoint_mode = self.waypoint_mode
return msg