@@ -149,7 +149,10 @@ def listener(message: Any, agents: dict[AgentID, Agent]) -> None:
149
149
150
150
# Calculate the acceleration if there has been more than one velocity
151
151
# reading
152
- if prev_velocity .global_frame .timestamp != 0.0 :
152
+ if (
153
+ prev_velocity .global_frame .timestamp != 0.0
154
+ and (timestamp - prev_velocity .global_frame .timestamp ) > 0.0
155
+ ):
153
156
agents [agent_id ].acceleration .global_frame .x = (
154
157
agents [agent_id ].velocity .global_frame .x
155
158
- prev_velocity .global_frame .x
@@ -202,8 +205,11 @@ def listener(message: Any, agents: dict[AgentID, Agent]) -> None:
202
205
timestamp = message .time_boot_ms - agents [agent_id ].clock_offset .value
203
206
204
207
# Calculate the acceleration if there has been more than one velocity
205
- # reading
206
- if prev_velocity .global_relative_frame .timestamp != 0.0 :
208
+ # reading and the time difference is greater than zero
209
+ if (
210
+ prev_velocity .global_relative_frame .timestamp != 0.0
211
+ and (timestamp - prev_velocity .global_relative_frame .timestamp ) > 0.0
212
+ ):
207
213
agents [agent_id ].acceleration .global_relative_frame .x = (
208
214
agents [agent_id ].velocity .global_relative_frame .x
209
215
- prev_velocity .global_relative_frame .x
@@ -259,7 +265,10 @@ def listener(message: Any, agents: dict[AgentID, Agent]) -> None:
259
265
260
266
# Calculate the acceleration if there has been more than one velocity
261
267
# reading
262
- if prev_velocity .local_frame .timestamp != 0.0 :
268
+ if (
269
+ prev_velocity .local_frame .timestamp != 0.0
270
+ and (timestamp - prev_velocity .local_frame .timestamp ) > 0.0
271
+ ):
263
272
agents [agent_id ].acceleration .local_frame .x = (
264
273
agents [agent_id ].velocity .local_frame .x
265
274
- prev_velocity .local_frame .x
0 commit comments