isar 1.30.5__py3-none-any.whl → 1.31.1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of isar might be problematic. Click here for more details.

Files changed (62) hide show
  1. isar/apis/api.py +7 -51
  2. isar/apis/models/models.py +1 -0
  3. isar/apis/models/start_mission_definition.py +4 -0
  4. isar/apis/robot_control/robot_controller.py +0 -2
  5. isar/apis/schedule/scheduling_controller.py +12 -4
  6. isar/config/log.py +8 -29
  7. isar/config/open_telemetry.py +62 -0
  8. isar/config/settings.py +12 -0
  9. isar/eventhandlers/eventhandler.py +93 -0
  10. isar/mission_planner/local_planner.py +0 -3
  11. isar/models/events.py +118 -0
  12. isar/modules.py +1 -1
  13. isar/robot/robot.py +16 -21
  14. isar/robot/robot_start_mission.py +8 -14
  15. isar/robot/robot_status.py +2 -3
  16. isar/robot/robot_stop_mission.py +3 -9
  17. isar/robot/robot_task_status.py +3 -7
  18. isar/script.py +4 -1
  19. isar/services/utilities/robot_utilities.py +0 -3
  20. isar/services/utilities/scheduling_utilities.py +45 -35
  21. isar/state_machine/state_machine.py +79 -11
  22. isar/state_machine/states/await_next_mission.py +46 -11
  23. isar/state_machine/states/blocked_protective_stop.py +24 -15
  24. isar/state_machine/states/home.py +40 -9
  25. isar/state_machine/states/monitor.py +83 -14
  26. isar/state_machine/states/offline.py +25 -13
  27. isar/state_machine/states/paused.py +24 -38
  28. isar/state_machine/states/returning_home.py +75 -14
  29. isar/state_machine/states/robot_standing_still.py +41 -11
  30. isar/state_machine/states/stopping.py +52 -67
  31. isar/state_machine/states/unknown_status.py +37 -64
  32. isar/state_machine/transitions/functions/pause.py +39 -10
  33. isar/state_machine/transitions/functions/resume.py +44 -15
  34. isar/state_machine/transitions/functions/robot_status.py +4 -5
  35. isar/state_machine/transitions/functions/stop.py +3 -12
  36. isar/state_machine/transitions/mission.py +12 -2
  37. isar/state_machine/transitions/return_home.py +1 -1
  38. isar/state_machine/utils/common_event_handlers.py +166 -0
  39. isar/storage/blob_storage.py +0 -2
  40. isar/storage/uploader.py +1 -4
  41. {isar-1.30.5.dist-info → isar-1.31.1.dist-info}/METADATA +7 -4
  42. {isar-1.30.5.dist-info → isar-1.31.1.dist-info}/RECORD +48 -58
  43. robot_interface/models/mission/task.py +0 -3
  44. robot_interface/robot_interface.py +1 -4
  45. isar/models/communication/__init__.py +0 -0
  46. isar/models/communication/message.py +0 -8
  47. isar/models/communication/queues/__init__.py +0 -0
  48. isar/models/communication/queues/events.py +0 -58
  49. isar/models/communication/queues/queue_io.py +0 -12
  50. isar/models/communication/queues/queue_timeout_error.py +0 -2
  51. isar/models/communication/queues/queue_utils.py +0 -38
  52. isar/models/communication/queues/status_queue.py +0 -22
  53. isar/models/mission_metadata/__init__.py +0 -0
  54. isar/services/service_connections/stid/__init__.py +0 -0
  55. isar/services/utilities/queue_utilities.py +0 -39
  56. isar/state_machine/generic_states/idle.py +0 -133
  57. isar/state_machine/generic_states/ongoing_mission.py +0 -294
  58. isar/state_machine/generic_states/robot_unavailable.py +0 -61
  59. {isar-1.30.5.dist-info → isar-1.31.1.dist-info}/WHEEL +0 -0
  60. {isar-1.30.5.dist-info → isar-1.31.1.dist-info}/entry_points.txt +0 -0
  61. {isar-1.30.5.dist-info → isar-1.31.1.dist-info}/licenses/LICENSE +0 -0
  62. {isar-1.30.5.dist-info → isar-1.31.1.dist-info}/top_level.txt +0 -0
@@ -1,294 +0,0 @@
1
- import logging
2
- import time
3
- from copy import deepcopy
4
- from enum import Enum
5
- from queue import Queue
6
- from threading import Event
7
- from typing import TYPE_CHECKING, Optional, Tuple
8
-
9
- from isar.config.settings import settings
10
- from isar.models.communication.message import StartMissionMessage
11
- from isar.models.communication.queues.queue_utils import (
12
- check_for_event,
13
- check_for_event_without_consumption,
14
- trigger_event,
15
- )
16
- from isar.services.utilities.threaded_request import ThreadedRequest
17
- from robot_interface.models.exceptions.robot_exceptions import (
18
- ErrorMessage,
19
- RobotException,
20
- RobotRetrieveInspectionException,
21
- )
22
- from robot_interface.models.inspection.inspection import Inspection
23
- from robot_interface.models.mission.mission import Mission
24
- from robot_interface.models.mission.status import TaskStatus
25
- from robot_interface.models.mission.task import InspectionTask, Task
26
-
27
-
28
- class OngoingMissionStates(str, Enum):
29
- Monitor = "monitor"
30
- ReturningHome = "returningHome"
31
-
32
-
33
- if TYPE_CHECKING:
34
- from isar.state_machine.state_machine import StateMachine
35
-
36
-
37
- class OngoingMission:
38
- def __init__(
39
- self,
40
- state_machine: "StateMachine",
41
- state: OngoingMissionStates,
42
- ) -> None:
43
- self.state_machine: "StateMachine" = state_machine
44
- self.logger = logging.getLogger("state_machine")
45
- self.events = state_machine.events
46
- self.awaiting_task_status: bool = False
47
- self.signal_state_machine_to_stop: Event = (
48
- state_machine.signal_state_machine_to_stop
49
- )
50
- self.state: OngoingMissionStates = state
51
-
52
- def start(self) -> None:
53
- self.state_machine.update_state()
54
- self._run()
55
-
56
- def stop(self) -> None:
57
- return
58
-
59
- def _check_and_handle_stop_mission_event(self, event: Queue) -> bool:
60
- if check_for_event(event):
61
- self.state_machine.stop() # type: ignore
62
- return True
63
- return False
64
-
65
- def _check_and_handle_pause_mission_event(self, event: Queue) -> bool:
66
- if check_for_event(event):
67
- self.state_machine.pause() # type: ignore
68
- return True
69
- return False
70
-
71
- def _check_and_handle_mission_started_event(self, event: Queue) -> bool:
72
- if check_for_event(event):
73
- self.state_machine.mission_ongoing = True
74
- return True
75
- return False
76
-
77
- def _check_and_handle_mission_failed_event(self, event: Queue) -> bool:
78
- mission_failed: Optional[ErrorMessage] = check_for_event(event)
79
- if mission_failed is not None:
80
- self.state_machine.logger.warning(
81
- f"Failed to initiate mission "
82
- f"{str(self.state_machine.current_mission.id)[:8]} because: "
83
- f"{mission_failed.error_description}"
84
- )
85
- self.state_machine.current_mission.error_message = ErrorMessage(
86
- error_reason=mission_failed.error_reason,
87
- error_description=mission_failed.error_description,
88
- )
89
- self.state_machine.mission_failed_to_start() # type: ignore
90
- return True
91
- return False
92
-
93
- def _check_and_handle_task_status_failed_event(self, event: Queue) -> bool:
94
- if not self.state_machine.mission_ongoing:
95
- return False
96
-
97
- task_failure: Optional[ErrorMessage] = check_for_event(event)
98
- if task_failure is not None:
99
- self.awaiting_task_status = False
100
- self.state_machine.current_task.error_message = task_failure
101
- self.logger.error(
102
- f"Monitoring task {self.state_machine.current_task.id[:8]} failed "
103
- f"because: {task_failure.error_description}"
104
- )
105
- return self._handle_new_task_status(TaskStatus.Failed)
106
- elif not self.awaiting_task_status:
107
- trigger_event(
108
- self.events.state_machine_events.task_status_request,
109
- self.state_machine.current_task.id,
110
- )
111
- self.awaiting_task_status = True
112
- return False
113
-
114
- def _check_and_handle_task_status_event(self, event: Queue) -> bool:
115
- if not self.state_machine.mission_ongoing:
116
- return False
117
-
118
- status: Optional[TaskStatus] = check_for_event(event)
119
- if status is not None:
120
- self.awaiting_task_status = False
121
- return self._handle_new_task_status(status)
122
- elif not self.awaiting_task_status:
123
- trigger_event(
124
- self.events.state_machine_events.task_status_request,
125
- self.state_machine.current_task.id,
126
- )
127
- self.awaiting_task_status = True
128
- return False
129
-
130
- def _handle_new_task_status(self, status: TaskStatus) -> bool:
131
- if self.state_machine.current_task is None:
132
- self.state_machine.iterate_current_task()
133
-
134
- self.state_machine.current_task.status = status
135
-
136
- if self.state_machine.current_task.is_finished():
137
- self._report_task_status(self.state_machine.current_task)
138
- self.state_machine.publish_task_status(task=self.state_machine.current_task)
139
-
140
- if self.state == OngoingMissionStates.ReturningHome:
141
- if status != TaskStatus.Successful:
142
- self.state_machine.return_home_failed() # type: ignore
143
- return True
144
- self.state_machine.returned_home() # type: ignore
145
- return True
146
-
147
- if self._should_upload_inspections():
148
- get_inspection_thread = ThreadedRequest(
149
- self._queue_inspections_for_upload
150
- )
151
- get_inspection_thread.start_thread(
152
- deepcopy(self.state_machine.current_mission),
153
- deepcopy(self.state_machine.current_task),
154
- name="State Machine Get Inspections",
155
- )
156
-
157
- self.state_machine.iterate_current_task()
158
- if self.state_machine.current_task is None:
159
- self.state_machine.mission_finished() # type: ignore
160
- return True
161
-
162
- # Report and update next task
163
- self.state_machine.current_task.update_task_status()
164
- self.state_machine.publish_task_status(task=self.state_machine.current_task)
165
- return False
166
-
167
- def _check_and_handle_start_mission_event(
168
- self, event: Queue[StartMissionMessage]
169
- ) -> bool:
170
- if check_for_event_without_consumption(event):
171
- self.state_machine.stop() # type: ignore
172
- return True
173
-
174
- return False
175
-
176
- def _run(self) -> None:
177
- self.awaiting_task_status = False
178
- while True:
179
- if self.signal_state_machine_to_stop.is_set():
180
- self.logger.info(
181
- "Stopping state machine from %s state", self.state.name
182
- )
183
- break
184
-
185
- if self._check_and_handle_stop_mission_event(
186
- self.events.api_requests.stop_mission.input
187
- ):
188
- break
189
-
190
- if (
191
- self.state == OngoingMissionStates.Monitor
192
- and self._check_and_handle_pause_mission_event(
193
- self.events.api_requests.pause_mission.input
194
- )
195
- ):
196
- break
197
-
198
- self._check_and_handle_mission_started_event(
199
- self.events.robot_service_events.mission_started
200
- )
201
-
202
- if self._check_and_handle_mission_failed_event(
203
- self.events.robot_service_events.mission_failed
204
- ):
205
- break
206
-
207
- if (
208
- self.state == OngoingMissionStates.ReturningHome
209
- and self._check_and_handle_start_mission_event(
210
- self.events.api_requests.start_mission.input
211
- )
212
- ):
213
- break
214
-
215
- if self._check_and_handle_task_status_failed_event(
216
- self.events.robot_service_events.task_status_failed
217
- ):
218
- break
219
-
220
- if self._check_and_handle_task_status_event(
221
- self.events.robot_service_events.task_status_updated
222
- ):
223
- break
224
-
225
- time.sleep(settings.FSM_SLEEP_TIME)
226
-
227
- def _queue_inspections_for_upload(
228
- self, mission: Mission, current_task: InspectionTask
229
- ) -> None:
230
- try:
231
- inspection: Inspection = self.state_machine.robot.get_inspection(
232
- task=current_task
233
- )
234
- if current_task.inspection_id != inspection.id:
235
- self.logger.warning(
236
- f"The inspection_id of task ({current_task.inspection_id}) "
237
- f"and result ({inspection.id}) is not matching. "
238
- f"This may lead to confusions when accessing the inspection later"
239
- )
240
-
241
- except (RobotRetrieveInspectionException, RobotException) as e:
242
- self._set_error_message(e)
243
- self.logger.error(
244
- f"Failed to retrieve inspections because: {e.error_description}"
245
- )
246
- return
247
-
248
- except Exception as e:
249
- self.logger.error(
250
- f"Failed to retrieve inspections because of unexpected error: {e}"
251
- )
252
- return
253
-
254
- if not inspection:
255
- self.logger.warning(
256
- f"No inspection result data retrieved for task {str(current_task.id)[:8]}"
257
- )
258
-
259
- inspection.metadata.tag_id = current_task.tag_id
260
-
261
- message: Tuple[Inspection, Mission] = (
262
- inspection,
263
- mission,
264
- )
265
- self.state_machine.events.upload_queue.put(message)
266
- self.logger.info(
267
- f"Inspection result: {str(inspection.id)[:8]} queued for upload"
268
- )
269
-
270
- def _report_task_status(self, task: Task) -> None:
271
- if task.status == TaskStatus.Failed:
272
- self.logger.warning(
273
- f"Task: {str(task.id)[:8]} was reported as failed by the robot"
274
- )
275
- elif task.status == TaskStatus.Successful:
276
- self.logger.info(
277
- f"{type(task).__name__} task: {str(task.id)[:8]} completed"
278
- )
279
-
280
- def _should_upload_inspections(self) -> bool:
281
- if settings.UPLOAD_INSPECTIONS_ASYNC:
282
- return False
283
-
284
- return (
285
- self.state_machine.current_task.is_finished()
286
- and self.state_machine.current_task.status == TaskStatus.Successful
287
- and isinstance(self.state_machine.current_task, InspectionTask)
288
- )
289
-
290
- def _set_error_message(self, e: RobotException) -> None:
291
- error_message: ErrorMessage = ErrorMessage(
292
- error_reason=e.error_reason, error_description=e.error_description
293
- )
294
- self.state_machine.current_task.error_message = error_message
@@ -1,61 +0,0 @@
1
- import logging
2
- import time
3
- from enum import Enum
4
- from typing import TYPE_CHECKING
5
-
6
- from isar.models.communication.queues.queue_utils import check_shared_state
7
- from robot_interface.models.mission.status import RobotStatus
8
-
9
-
10
- class RobotUnavailableStates(str, Enum):
11
- BlockedProtectiveStop = "blockedProtectiveStop"
12
- Offline = "offline"
13
-
14
-
15
- if TYPE_CHECKING:
16
- from isar.state_machine.state_machine import StateMachine
17
-
18
-
19
- class RobotUnavailable:
20
- def __init__(
21
- self,
22
- state_machine: "StateMachine",
23
- state: RobotUnavailableStates,
24
- ) -> None:
25
- self.state_machine: "StateMachine" = state_machine
26
- self.logger = logging.getLogger("state_machine")
27
- self.shared_state = self.state_machine.shared_state
28
- self.signal_state_machine_to_stop = state_machine.signal_state_machine_to_stop
29
- self.state: RobotUnavailableStates = state
30
-
31
- def start(self) -> None:
32
- self.state_machine.update_state()
33
- self._run()
34
-
35
- def stop(self) -> None:
36
- return
37
-
38
- def _run(self) -> None:
39
- while True:
40
- if self.signal_state_machine_to_stop.is_set():
41
- self.logger.info(
42
- "Stopping state machine from %s state", self.state.name
43
- )
44
- break
45
-
46
- robot_status: RobotStatus = check_shared_state(
47
- self.shared_state.robot_status
48
- )
49
-
50
- expected_status = (
51
- RobotStatus.BlockedProtectiveStop
52
- if self.state == RobotUnavailableStates.BlockedProtectiveStop
53
- else RobotStatus.Offline
54
- )
55
- if robot_status != expected_status:
56
- transition = self.state_machine.robot_status_changed # type: ignore
57
- break
58
-
59
- time.sleep(self.state_machine.sleep_time)
60
-
61
- transition()
File without changes