viam-sdk 0.45.2__py3-none-win_amd64.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 viam-sdk might be problematic. Click here for more details.

Files changed (476) hide show
  1. viam/__init__.py +71 -0
  2. viam/app/__init__.py +0 -0
  3. viam/app/_logs.py +34 -0
  4. viam/app/app_client.py +2525 -0
  5. viam/app/billing_client.py +143 -0
  6. viam/app/data_client.py +1715 -0
  7. viam/app/ml_training_client.py +251 -0
  8. viam/app/provisioning_client.py +95 -0
  9. viam/app/viam_client.py +260 -0
  10. viam/components/__init__.py +0 -0
  11. viam/components/arm/__init__.py +16 -0
  12. viam/components/arm/arm.py +223 -0
  13. viam/components/arm/client.py +124 -0
  14. viam/components/arm/service.py +123 -0
  15. viam/components/audio_input/__init__.py +18 -0
  16. viam/components/audio_input/audio_input.py +81 -0
  17. viam/components/audio_input/client.py +70 -0
  18. viam/components/audio_input/service.py +114 -0
  19. viam/components/base/__init__.py +13 -0
  20. viam/components/base/base.py +260 -0
  21. viam/components/base/client.py +153 -0
  22. viam/components/base/service.py +138 -0
  23. viam/components/board/__init__.py +9 -0
  24. viam/components/board/board.py +414 -0
  25. viam/components/board/client.py +241 -0
  26. viam/components/board/service.py +223 -0
  27. viam/components/button/__init__.py +10 -0
  28. viam/components/button/button.py +41 -0
  29. viam/components/button/client.py +52 -0
  30. viam/components/button/service.py +46 -0
  31. viam/components/camera/__init__.py +22 -0
  32. viam/components/camera/camera.py +138 -0
  33. viam/components/camera/client.py +98 -0
  34. viam/components/camera/service.py +105 -0
  35. viam/components/component_base.py +65 -0
  36. viam/components/encoder/__init__.py +18 -0
  37. viam/components/encoder/client.py +83 -0
  38. viam/components/encoder/encoder.py +118 -0
  39. viam/components/encoder/service.py +72 -0
  40. viam/components/gantry/__init__.py +11 -0
  41. viam/components/gantry/client.py +115 -0
  42. viam/components/gantry/gantry.py +156 -0
  43. viam/components/gantry/service.py +113 -0
  44. viam/components/generic/__init__.py +18 -0
  45. viam/components/generic/client.py +62 -0
  46. viam/components/generic/generic.py +76 -0
  47. viam/components/generic/service.py +40 -0
  48. viam/components/gripper/__init__.py +11 -0
  49. viam/components/gripper/client.py +85 -0
  50. viam/components/gripper/gripper.py +114 -0
  51. viam/components/gripper/service.py +81 -0
  52. viam/components/input/__init__.py +15 -0
  53. viam/components/input/client.py +194 -0
  54. viam/components/input/input.py +297 -0
  55. viam/components/input/service.py +175 -0
  56. viam/components/motor/__init__.py +11 -0
  57. viam/components/motor/client.py +168 -0
  58. viam/components/motor/motor.py +301 -0
  59. viam/components/motor/service.py +150 -0
  60. viam/components/movement_sensor/__init__.py +21 -0
  61. viam/components/movement_sensor/client.py +161 -0
  62. viam/components/movement_sensor/movement_sensor.py +253 -0
  63. viam/components/movement_sensor/service.py +146 -0
  64. viam/components/pose_tracker/__init__.py +17 -0
  65. viam/components/pose_tracker/client.py +50 -0
  66. viam/components/pose_tracker/pose_tracker.py +40 -0
  67. viam/components/pose_tracker/service.py +45 -0
  68. viam/components/power_sensor/__init__.py +17 -0
  69. viam/components/power_sensor/client.py +86 -0
  70. viam/components/power_sensor/power_sensor.py +104 -0
  71. viam/components/power_sensor/service.py +72 -0
  72. viam/components/sensor/__init__.py +18 -0
  73. viam/components/sensor/client.py +49 -0
  74. viam/components/sensor/sensor.py +48 -0
  75. viam/components/sensor/service.py +51 -0
  76. viam/components/servo/__init__.py +11 -0
  77. viam/components/servo/client.py +86 -0
  78. viam/components/servo/service.py +80 -0
  79. viam/components/servo/servo.py +114 -0
  80. viam/components/switch/__init__.py +10 -0
  81. viam/components/switch/client.py +83 -0
  82. viam/components/switch/service.py +72 -0
  83. viam/components/switch/switch.py +95 -0
  84. viam/errors.py +105 -0
  85. viam/gen/__init__.py +0 -0
  86. viam/gen/app/__init__.py +0 -0
  87. viam/gen/app/agent/__init__.py +0 -0
  88. viam/gen/app/agent/v1/__init__.py +0 -0
  89. viam/gen/app/agent/v1/agent_grpc.py +29 -0
  90. viam/gen/app/agent/v1/agent_pb2.py +47 -0
  91. viam/gen/app/agent/v1/agent_pb2.pyi +280 -0
  92. viam/gen/app/cloudslam/__init__.py +0 -0
  93. viam/gen/app/cloudslam/v1/__init__.py +0 -0
  94. viam/gen/app/cloudslam/v1/cloud_slam_grpc.py +70 -0
  95. viam/gen/app/cloudslam/v1/cloud_slam_pb2.py +54 -0
  96. viam/gen/app/cloudslam/v1/cloud_slam_pb2.pyi +384 -0
  97. viam/gen/app/data/__init__.py +0 -0
  98. viam/gen/app/data/v1/__init__.py +0 -0
  99. viam/gen/app/data/v1/data_grpc.py +206 -0
  100. viam/gen/app/data/v1/data_pb2.py +178 -0
  101. viam/gen/app/data/v1/data_pb2.pyi +1485 -0
  102. viam/gen/app/datapipelines/__init__.py +0 -0
  103. viam/gen/app/datapipelines/v1/__init__.py +0 -0
  104. viam/gen/app/datapipelines/v1/data_pipelines_grpc.py +84 -0
  105. viam/gen/app/datapipelines/v1/data_pipelines_pb2.py +56 -0
  106. viam/gen/app/datapipelines/v1/data_pipelines_pb2.pyi +370 -0
  107. viam/gen/app/dataset/__init__.py +0 -0
  108. viam/gen/app/dataset/v1/__init__.py +0 -0
  109. viam/gen/app/dataset/v1/dataset_grpc.py +60 -0
  110. viam/gen/app/dataset/v1/dataset_pb2.py +40 -0
  111. viam/gen/app/dataset/v1/dataset_pb2.pyi +179 -0
  112. viam/gen/app/datasync/__init__.py +0 -0
  113. viam/gen/app/datasync/v1/__init__.py +0 -0
  114. viam/gen/app/datasync/v1/data_sync_grpc.py +47 -0
  115. viam/gen/app/datasync/v1/data_sync_pb2.py +70 -0
  116. viam/gen/app/datasync/v1/data_sync_pb2.pyi +425 -0
  117. viam/gen/app/mlinference/__init__.py +0 -0
  118. viam/gen/app/mlinference/v1/__init__.py +0 -0
  119. viam/gen/app/mlinference/v1/ml_inference_grpc.py +28 -0
  120. viam/gen/app/mlinference/v1/ml_inference_pb2.py +23 -0
  121. viam/gen/app/mlinference/v1/ml_inference_pb2.pyi +63 -0
  122. viam/gen/app/mltraining/__init__.py +0 -0
  123. viam/gen/app/mltraining/v1/__init__.py +0 -0
  124. viam/gen/app/mltraining/v1/ml_training_grpc.py +78 -0
  125. viam/gen/app/mltraining/v1/ml_training_pb2.py +124 -0
  126. viam/gen/app/mltraining/v1/ml_training_pb2.pyi +415 -0
  127. viam/gen/app/packages/__init__.py +0 -0
  128. viam/gen/app/packages/v1/__init__.py +0 -0
  129. viam/gen/app/packages/v1/packages_grpc.py +54 -0
  130. viam/gen/app/packages/v1/packages_pb2.py +52 -0
  131. viam/gen/app/packages/v1/packages_pb2.pyi +311 -0
  132. viam/gen/app/v1/__init__.py +0 -0
  133. viam/gen/app/v1/app_grpc.py +863 -0
  134. viam/gen/app/v1/app_pb2.py +649 -0
  135. viam/gen/app/v1/app_pb2.pyi +5279 -0
  136. viam/gen/app/v1/billing_grpc.py +76 -0
  137. viam/gen/app/v1/billing_pb2.py +92 -0
  138. viam/gen/app/v1/billing_pb2.pyi +463 -0
  139. viam/gen/app/v1/end_user_grpc.py +59 -0
  140. viam/gen/app/v1/end_user_pb2.py +55 -0
  141. viam/gen/app/v1/end_user_pb2.pyi +181 -0
  142. viam/gen/app/v1/robot_grpc.py +55 -0
  143. viam/gen/app/v1/robot_pb2.py +127 -0
  144. viam/gen/app/v1/robot_pb2.pyi +1202 -0
  145. viam/gen/common/__init__.py +0 -0
  146. viam/gen/common/v1/__init__.py +0 -0
  147. viam/gen/common/v1/common_grpc.py +0 -0
  148. viam/gen/common/v1/common_pb2.py +78 -0
  149. viam/gen/common/v1/common_pb2.pyi +687 -0
  150. viam/gen/component/__init__.py +0 -0
  151. viam/gen/component/arm/__init__.py +0 -0
  152. viam/gen/component/arm/v1/__init__.py +0 -0
  153. viam/gen/component/arm/v1/arm_grpc.py +102 -0
  154. viam/gen/component/arm/v1/arm_pb2.py +74 -0
  155. viam/gen/component/arm/v1/arm_pb2.pyi +344 -0
  156. viam/gen/component/audioinput/__init__.py +0 -0
  157. viam/gen/component/audioinput/v1/__init__.py +0 -0
  158. viam/gen/component/audioinput/v1/audioinput_grpc.py +63 -0
  159. viam/gen/component/audioinput/v1/audioinput_pb2.py +45 -0
  160. viam/gen/component/audioinput/v1/audioinput_pb2.pyi +179 -0
  161. viam/gen/component/base/__init__.py +0 -0
  162. viam/gen/component/base/v1/__init__.py +0 -0
  163. viam/gen/component/base/v1/base_grpc.py +94 -0
  164. viam/gen/component/base/v1/base_pb2.py +66 -0
  165. viam/gen/component/base/v1/base_pb2.pyi +258 -0
  166. viam/gen/component/board/__init__.py +0 -0
  167. viam/gen/component/board/v1/__init__.py +0 -0
  168. viam/gen/component/board/v1/board_grpc.py +127 -0
  169. viam/gen/component/board/v1/board_pb2.py +103 -0
  170. viam/gen/component/board/v1/board_pb2.pyi +496 -0
  171. viam/gen/component/button/__init__.py +0 -0
  172. viam/gen/component/button/v1/__init__.py +0 -0
  173. viam/gen/component/button/v1/button_grpc.py +38 -0
  174. viam/gen/component/button/v1/button_pb2.py +28 -0
  175. viam/gen/component/button/v1/button_pb2.pyi +39 -0
  176. viam/gen/component/camera/__init__.py +0 -0
  177. viam/gen/component/camera/v1/__init__.py +0 -0
  178. viam/gen/component/camera/v1/camera_grpc.py +79 -0
  179. viam/gen/component/camera/v1/camera_pb2.py +67 -0
  180. viam/gen/component/camera/v1/camera_pb2.pyi +373 -0
  181. viam/gen/component/encoder/__init__.py +0 -0
  182. viam/gen/component/encoder/v1/__init__.py +0 -0
  183. viam/gen/component/encoder/v1/encoder_grpc.py +62 -0
  184. viam/gen/component/encoder/v1/encoder_pb2.py +44 -0
  185. viam/gen/component/encoder/v1/encoder_pb2.pyi +147 -0
  186. viam/gen/component/gantry/__init__.py +0 -0
  187. viam/gen/component/gantry/v1/__init__.py +0 -0
  188. viam/gen/component/gantry/v1/gantry_grpc.py +86 -0
  189. viam/gen/component/gantry/v1/gantry_pb2.py +62 -0
  190. viam/gen/component/gantry/v1/gantry_pb2.pyi +239 -0
  191. viam/gen/component/generic/__init__.py +0 -0
  192. viam/gen/component/generic/v1/__init__.py +0 -0
  193. viam/gen/component/generic/v1/generic_grpc.py +37 -0
  194. viam/gen/component/generic/v1/generic_pb2.py +23 -0
  195. viam/gen/component/generic/v1/generic_pb2.pyi +6 -0
  196. viam/gen/component/gripper/__init__.py +0 -0
  197. viam/gen/component/gripper/v1/__init__.py +0 -0
  198. viam/gen/component/gripper/v1/gripper_grpc.py +70 -0
  199. viam/gen/component/gripper/v1/gripper_pb2.py +48 -0
  200. viam/gen/component/gripper/v1/gripper_pb2.pyi +137 -0
  201. viam/gen/component/inputcontroller/__init__.py +0 -0
  202. viam/gen/component/inputcontroller/v1/__init__.py +0 -0
  203. viam/gen/component/inputcontroller/v1/input_controller_grpc.py +71 -0
  204. viam/gen/component/inputcontroller/v1/input_controller_pb2.py +55 -0
  205. viam/gen/component/inputcontroller/v1/input_controller_pb2.pyi +243 -0
  206. viam/gen/component/motor/__init__.py +0 -0
  207. viam/gen/component/motor/v1/__init__.py +0 -0
  208. viam/gen/component/motor/v1/motor_grpc.py +118 -0
  209. viam/gen/component/motor/v1/motor_pb2.py +86 -0
  210. viam/gen/component/motor/v1/motor_pb2.pyi +368 -0
  211. viam/gen/component/movementsensor/__init__.py +0 -0
  212. viam/gen/component/movementsensor/v1/__init__.py +0 -0
  213. viam/gen/component/movementsensor/v1/movementsensor_grpc.py +110 -0
  214. viam/gen/component/movementsensor/v1/movementsensor_pb2.py +78 -0
  215. viam/gen/component/movementsensor/v1/movementsensor_pb2.pyi +384 -0
  216. viam/gen/component/posetracker/__init__.py +0 -0
  217. viam/gen/component/posetracker/v1/__init__.py +0 -0
  218. viam/gen/component/posetracker/v1/pose_tracker_grpc.py +46 -0
  219. viam/gen/component/posetracker/v1/pose_tracker_pb2.py +34 -0
  220. viam/gen/component/posetracker/v1/pose_tracker_pb2.pyi +79 -0
  221. viam/gen/component/powersensor/__init__.py +0 -0
  222. viam/gen/component/powersensor/v1/__init__.py +0 -0
  223. viam/gen/component/powersensor/v1/powersensor_grpc.py +62 -0
  224. viam/gen/component/powersensor/v1/powersensor_pb2.py +42 -0
  225. viam/gen/component/powersensor/v1/powersensor_pb2.pyi +124 -0
  226. viam/gen/component/sensor/__init__.py +0 -0
  227. viam/gen/component/sensor/v1/__init__.py +0 -0
  228. viam/gen/component/sensor/v1/sensor_grpc.py +45 -0
  229. viam/gen/component/sensor/v1/sensor_pb2.py +25 -0
  230. viam/gen/component/sensor/v1/sensor_pb2.pyi +6 -0
  231. viam/gen/component/servo/__init__.py +0 -0
  232. viam/gen/component/servo/v1/__init__.py +0 -0
  233. viam/gen/component/servo/v1/servo_grpc.py +70 -0
  234. viam/gen/component/servo/v1/servo_pb2.py +50 -0
  235. viam/gen/component/servo/v1/servo_pb2.pyi +150 -0
  236. viam/gen/component/switch/__init__.py +0 -0
  237. viam/gen/component/switch/v1/__init__.py +0 -0
  238. viam/gen/component/switch/v1/switch_grpc.py +54 -0
  239. viam/gen/component/switch/v1/switch_pb2.py +40 -0
  240. viam/gen/component/switch/v1/switch_pb2.pyi +109 -0
  241. viam/gen/component/testecho/__init__.py +0 -0
  242. viam/gen/component/testecho/v1/__init__.py +0 -0
  243. viam/gen/component/testecho/v1/testecho_grpc.py +52 -0
  244. viam/gen/component/testecho/v1/testecho_pb2.py +36 -0
  245. viam/gen/component/testecho/v1/testecho_pb2.pyi +114 -0
  246. viam/gen/module/__init__.py +0 -0
  247. viam/gen/module/v1/__init__.py +0 -0
  248. viam/gen/module/v1/module_grpc.py +61 -0
  249. viam/gen/module/v1/module_pb2.py +43 -0
  250. viam/gen/module/v1/module_pb2.pyi +211 -0
  251. viam/gen/proto/__init__.py +0 -0
  252. viam/gen/proto/rpc/__init__.py +0 -0
  253. viam/gen/proto/rpc/examples/__init__.py +0 -0
  254. viam/gen/proto/rpc/examples/echo/__init__.py +0 -0
  255. viam/gen/proto/rpc/examples/echo/v1/__init__.py +0 -0
  256. viam/gen/proto/rpc/examples/echo/v1/echo_grpc.py +44 -0
  257. viam/gen/proto/rpc/examples/echo/v1/echo_pb2.py +32 -0
  258. viam/gen/proto/rpc/examples/echo/v1/echo_pb2.pyi +87 -0
  259. viam/gen/proto/rpc/examples/echoresource/__init__.py +0 -0
  260. viam/gen/proto/rpc/examples/echoresource/v1/__init__.py +0 -0
  261. viam/gen/proto/rpc/examples/echoresource/v1/echoresource_grpc.py +43 -0
  262. viam/gen/proto/rpc/examples/echoresource/v1/echoresource_pb2.py +29 -0
  263. viam/gen/proto/rpc/examples/echoresource/v1/echoresource_pb2.pyi +93 -0
  264. viam/gen/proto/rpc/v1/__init__.py +0 -0
  265. viam/gen/proto/rpc/v1/auth_grpc.py +47 -0
  266. viam/gen/proto/rpc/v1/auth_pb2.py +34 -0
  267. viam/gen/proto/rpc/v1/auth_pb2.pyi +92 -0
  268. viam/gen/proto/rpc/webrtc/__init__.py +0 -0
  269. viam/gen/proto/rpc/webrtc/v1/__init__.py +0 -0
  270. viam/gen/proto/rpc/webrtc/v1/grpc_grpc.py +0 -0
  271. viam/gen/proto/rpc/webrtc/v1/grpc_pb2.py +43 -0
  272. viam/gen/proto/rpc/webrtc/v1/grpc_pb2.pyi +304 -0
  273. viam/gen/proto/rpc/webrtc/v1/signaling_grpc.py +54 -0
  274. viam/gen/proto/rpc/webrtc/v1/signaling_pb2.py +70 -0
  275. viam/gen/proto/rpc/webrtc/v1/signaling_pb2.pyi +496 -0
  276. viam/gen/provisioning/__init__.py +0 -0
  277. viam/gen/provisioning/v1/__init__.py +0 -0
  278. viam/gen/provisioning/v1/provisioning_grpc.py +51 -0
  279. viam/gen/provisioning/v1/provisioning_pb2.py +39 -0
  280. viam/gen/provisioning/v1/provisioning_pb2.pyi +188 -0
  281. viam/gen/robot/__init__.py +0 -0
  282. viam/gen/robot/v1/__init__.py +0 -0
  283. viam/gen/robot/v1/robot_grpc.py +208 -0
  284. viam/gen/robot/v1/robot_pb2.py +188 -0
  285. viam/gen/robot/v1/robot_pb2.pyi +1020 -0
  286. viam/gen/service/__init__.py +0 -0
  287. viam/gen/service/datamanager/__init__.py +0 -0
  288. viam/gen/service/datamanager/v1/__init__.py +0 -0
  289. viam/gen/service/datamanager/v1/data_manager_grpc.py +38 -0
  290. viam/gen/service/datamanager/v1/data_manager_pb2.py +28 -0
  291. viam/gen/service/datamanager/v1/data_manager_pb2.pyi +39 -0
  292. viam/gen/service/discovery/__init__.py +0 -0
  293. viam/gen/service/discovery/v1/__init__.py +0 -0
  294. viam/gen/service/discovery/v1/discovery_grpc.py +39 -0
  295. viam/gen/service/discovery/v1/discovery_pb2.py +29 -0
  296. viam/gen/service/discovery/v1/discovery_pb2.pyi +51 -0
  297. viam/gen/service/generic/__init__.py +0 -0
  298. viam/gen/service/generic/v1/__init__.py +0 -0
  299. viam/gen/service/generic/v1/generic_grpc.py +29 -0
  300. viam/gen/service/generic/v1/generic_pb2.py +21 -0
  301. viam/gen/service/generic/v1/generic_pb2.pyi +6 -0
  302. viam/gen/service/mlmodel/__init__.py +0 -0
  303. viam/gen/service/mlmodel/v1/__init__.py +0 -0
  304. viam/gen/service/mlmodel/v1/mlmodel_grpc.py +37 -0
  305. viam/gen/service/mlmodel/v1/mlmodel_pb2.py +83 -0
  306. viam/gen/service/mlmodel/v1/mlmodel_pb2.pyi +480 -0
  307. viam/gen/service/motion/__init__.py +0 -0
  308. viam/gen/service/motion/v1/__init__.py +0 -0
  309. viam/gen/service/motion/v1/motion_grpc.py +87 -0
  310. viam/gen/service/motion/v1/motion_pb2.py +97 -0
  311. viam/gen/service/motion/v1/motion_pb2.pyi +838 -0
  312. viam/gen/service/navigation/__init__.py +0 -0
  313. viam/gen/service/navigation/v1/__init__.py +0 -0
  314. viam/gen/service/navigation/v1/navigation_grpc.py +102 -0
  315. viam/gen/service/navigation/v1/navigation_pb2.py +84 -0
  316. viam/gen/service/navigation/v1/navigation_pb2.pyi +419 -0
  317. viam/gen/service/sensors/__init__.py +0 -0
  318. viam/gen/service/sensors/v1/__init__.py +0 -0
  319. viam/gen/service/sensors/v1/sensors_grpc.py +46 -0
  320. viam/gen/service/sensors/v1/sensors_pb2.py +68 -0
  321. viam/gen/service/sensors/v1/sensors_pb2.pyi +137 -0
  322. viam/gen/service/shell/__init__.py +0 -0
  323. viam/gen/service/shell/v1/__init__.py +0 -0
  324. viam/gen/service/shell/v1/shell_grpc.py +55 -0
  325. viam/gen/service/shell/v1/shell_pb2.py +45 -0
  326. viam/gen/service/shell/v1/shell_pb2.pyi +307 -0
  327. viam/gen/service/slam/__init__.py +0 -0
  328. viam/gen/service/slam/v1/__init__.py +0 -0
  329. viam/gen/service/slam/v1/slam_grpc.py +61 -0
  330. viam/gen/service/slam/v1/slam_pb2.py +51 -0
  331. viam/gen/service/slam/v1/slam_pb2.pyi +213 -0
  332. viam/gen/service/vision/__init__.py +0 -0
  333. viam/gen/service/vision/v1/__init__.py +0 -0
  334. viam/gen/service/vision/v1/vision_grpc.py +87 -0
  335. viam/gen/service/vision/v1/vision_pb2.py +69 -0
  336. viam/gen/service/vision/v1/vision_pb2.pyi +454 -0
  337. viam/gen/stream/__init__.py +0 -0
  338. viam/gen/stream/v1/__init__.py +0 -0
  339. viam/gen/stream/v1/stream_grpc.py +59 -0
  340. viam/gen/stream/v1/stream_pb2.py +39 -0
  341. viam/gen/stream/v1/stream_pb2.pyi +161 -0
  342. viam/gen/tagger/__init__.py +0 -0
  343. viam/gen/tagger/v1/__init__.py +0 -0
  344. viam/gen/tagger/v1/tagger_grpc.py +0 -0
  345. viam/gen/tagger/v1/tagger_pb2.py +16 -0
  346. viam/gen/tagger/v1/tagger_pb2.pyi +15 -0
  347. viam/logging.py +216 -0
  348. viam/media/__init__.py +0 -0
  349. viam/media/audio.py +16 -0
  350. viam/media/utils/__init__.py +0 -0
  351. viam/media/utils/pil/__init__.py +51 -0
  352. viam/media/utils/pil/viam_rgba_plugin.py +73 -0
  353. viam/media/viam_rgba.py +10 -0
  354. viam/media/video.py +217 -0
  355. viam/module/__init__.py +5 -0
  356. viam/module/module.py +281 -0
  357. viam/module/service.py +66 -0
  358. viam/module/types.py +23 -0
  359. viam/operations.py +124 -0
  360. viam/proto/__init__.py +0 -0
  361. viam/proto/app/__init__.py +554 -0
  362. viam/proto/app/agent/__init__.py +28 -0
  363. viam/proto/app/billing.py +58 -0
  364. viam/proto/app/cloudslam/__init__.py +48 -0
  365. viam/proto/app/data/__init__.py +138 -0
  366. viam/proto/app/datapipelines/__init__.py +56 -0
  367. viam/proto/app/dataset/__init__.py +36 -0
  368. viam/proto/app/datasync/__init__.py +44 -0
  369. viam/proto/app/end_user.py +34 -0
  370. viam/proto/app/mlinference/__init__.py +15 -0
  371. viam/proto/app/mltraining/__init__.py +52 -0
  372. viam/proto/app/packages/__init__.py +38 -0
  373. viam/proto/app/robot.py +84 -0
  374. viam/proto/common/__init__.py +66 -0
  375. viam/proto/component/__init__.py +0 -0
  376. viam/proto/component/arm/__init__.py +48 -0
  377. viam/proto/component/audioinput/__init__.py +30 -0
  378. viam/proto/component/base/__init__.py +42 -0
  379. viam/proto/component/board/__init__.py +62 -0
  380. viam/proto/component/button/__init__.py +15 -0
  381. viam/proto/component/camera/__init__.py +46 -0
  382. viam/proto/component/encoder/__init__.py +28 -0
  383. viam/proto/component/gantry/__init__.py +40 -0
  384. viam/proto/component/generic/__init__.py +12 -0
  385. viam/proto/component/gripper/__init__.py +30 -0
  386. viam/proto/component/inputcontroller/__init__.py +38 -0
  387. viam/proto/component/motor/__init__.py +56 -0
  388. viam/proto/component/movementsensor/__init__.py +50 -0
  389. viam/proto/component/posetracker/__init__.py +19 -0
  390. viam/proto/component/powersensor/__init__.py +30 -0
  391. viam/proto/component/sensor/__init__.py +12 -0
  392. viam/proto/component/servo/__init__.py +32 -0
  393. viam/proto/component/switch/__init__.py +26 -0
  394. viam/proto/component/testecho/__init__.py +30 -0
  395. viam/proto/module/__init__.py +38 -0
  396. viam/proto/provisioning/__init__.py +36 -0
  397. viam/proto/robot/__init__.py +130 -0
  398. viam/proto/rpc/__init__.py +0 -0
  399. viam/proto/rpc/auth.py +34 -0
  400. viam/proto/rpc/examples/__init__.py +0 -0
  401. viam/proto/rpc/examples/echo/__init__.py +26 -0
  402. viam/proto/rpc/examples/echoresource/__init__.py +30 -0
  403. viam/proto/rpc/webrtc/__init__.py +0 -0
  404. viam/proto/rpc/webrtc/grpc.py +36 -0
  405. viam/proto/rpc/webrtc/signaling.py +58 -0
  406. viam/proto/service/__init__.py +0 -0
  407. viam/proto/service/datamanager/__init__.py +19 -0
  408. viam/proto/service/discovery/__init__.py +15 -0
  409. viam/proto/service/generic/__init__.py +12 -0
  410. viam/proto/service/mlmodel/__init__.py +54 -0
  411. viam/proto/service/motion/__init__.py +68 -0
  412. viam/proto/service/navigation/__init__.py +58 -0
  413. viam/proto/service/sensors/__init__.py +18 -0
  414. viam/proto/service/shell/__init__.py +36 -0
  415. viam/proto/service/slam/__init__.py +36 -0
  416. viam/proto/service/vision/__init__.py +46 -0
  417. viam/proto/stream/__init__.py +36 -0
  418. viam/proto/tagger/__init__.py +6 -0
  419. viam/py.typed +0 -0
  420. viam/resource/__init__.py +0 -0
  421. viam/resource/base.py +123 -0
  422. viam/resource/easy_resource.py +153 -0
  423. viam/resource/manager.py +126 -0
  424. viam/resource/registry.py +199 -0
  425. viam/resource/rpc_client_base.py +65 -0
  426. viam/resource/rpc_service_base.py +48 -0
  427. viam/resource/types.py +213 -0
  428. viam/robot/__init__.py +0 -0
  429. viam/robot/client.py +909 -0
  430. viam/robot/service.py +69 -0
  431. viam/rpc/__init__.py +0 -0
  432. viam/rpc/dial.py +420 -0
  433. viam/rpc/libviam_rust_utils.dll +0 -0
  434. viam/rpc/server.py +201 -0
  435. viam/rpc/signaling.py +29 -0
  436. viam/rpc/types.py +22 -0
  437. viam/services/__init__.py +0 -0
  438. viam/services/discovery/__init__.py +12 -0
  439. viam/services/discovery/client.py +55 -0
  440. viam/services/discovery/discovery.py +52 -0
  441. viam/services/discovery/service.py +43 -0
  442. viam/services/generic/__init__.py +18 -0
  443. viam/services/generic/client.py +58 -0
  444. viam/services/generic/generic.py +58 -0
  445. viam/services/generic/service.py +29 -0
  446. viam/services/mlmodel/__init__.py +24 -0
  447. viam/services/mlmodel/client.py +37 -0
  448. viam/services/mlmodel/mlmodel.py +78 -0
  449. viam/services/mlmodel/service.py +38 -0
  450. viam/services/mlmodel/utils.py +101 -0
  451. viam/services/motion/__init__.py +17 -0
  452. viam/services/motion/client.py +215 -0
  453. viam/services/motion/motion.py +378 -0
  454. viam/services/motion/service.py +132 -0
  455. viam/services/navigation/__init__.py +11 -0
  456. viam/services/navigation/client.py +99 -0
  457. viam/services/navigation/navigation.py +250 -0
  458. viam/services/navigation/service.py +137 -0
  459. viam/services/service_base.py +78 -0
  460. viam/services/service_client_base.py +46 -0
  461. viam/services/slam/__init__.py +17 -0
  462. viam/services/slam/client.py +62 -0
  463. viam/services/slam/service.py +75 -0
  464. viam/services/slam/slam.py +111 -0
  465. viam/services/vision/__init__.py +15 -0
  466. viam/services/vision/client.py +206 -0
  467. viam/services/vision/service.py +146 -0
  468. viam/services/vision/vision.py +315 -0
  469. viam/sessions_client.py +245 -0
  470. viam/streams.py +44 -0
  471. viam/utils.py +365 -0
  472. viam/version_metadata.py +4 -0
  473. viam_sdk-0.45.2.dist-info/METADATA +157 -0
  474. viam_sdk-0.45.2.dist-info/RECORD +476 -0
  475. viam_sdk-0.45.2.dist-info/WHEEL +4 -0
  476. viam_sdk-0.45.2.dist-info/licenses/LICENSE +202 -0
viam/robot/client.py ADDED
@@ -0,0 +1,909 @@
1
+ import asyncio
2
+ import sys
3
+ from dataclasses import dataclass
4
+ from datetime import datetime
5
+ from threading import RLock
6
+ from typing import Any, Dict, List, Optional, Union
7
+
8
+ from grpclib import GRPCError, Status
9
+ from grpclib.client import Channel
10
+ from typing_extensions import Self
11
+
12
+ import viam
13
+ from viam import logging
14
+ from viam.components.component_base import ComponentBase
15
+ from viam.errors import ResourceNotFoundError
16
+ from viam.proto.common import LogEntry, PoseInFrame, ResourceName, Transform
17
+ from viam.proto.robot import (
18
+ BlockForOperationRequest,
19
+ CancelOperationRequest,
20
+ FrameSystemConfig,
21
+ FrameSystemConfigRequest,
22
+ FrameSystemConfigResponse,
23
+ GetCloudMetadataRequest,
24
+ GetCloudMetadataResponse,
25
+ GetMachineStatusRequest,
26
+ GetMachineStatusResponse,
27
+ GetModelsFromModulesRequest,
28
+ GetModelsFromModulesResponse,
29
+ GetOperationsRequest,
30
+ GetOperationsResponse,
31
+ GetVersionRequest,
32
+ GetVersionResponse,
33
+ LogRequest,
34
+ ModuleModel,
35
+ Operation,
36
+ ResourceNamesRequest,
37
+ ResourceNamesResponse,
38
+ RobotServiceStub,
39
+ ShutdownRequest,
40
+ StopAllRequest,
41
+ StopExtraParameters,
42
+ TransformPoseRequest,
43
+ TransformPoseResponse,
44
+ )
45
+ from viam.resource.base import ResourceBase
46
+ from viam.resource.manager import ResourceManager
47
+ from viam.resource.registry import Registry
48
+ from viam.resource.rpc_client_base import ReconfigurableResourceRPCClientBase, ResourceRPCClientBase
49
+ from viam.resource.types import API, RESOURCE_TYPE_COMPONENT, RESOURCE_TYPE_SERVICE
50
+ from viam.rpc.dial import DialOptions, ViamChannel, _dial_inner, dial
51
+ from viam.services.service_base import ServiceBase
52
+ from viam.sessions_client import SessionsClient
53
+ from viam.utils import datetime_to_timestamp, dict_to_struct
54
+
55
+ LOGGER = logging.getLogger(__name__)
56
+
57
+
58
+ class RobotClient:
59
+ """gRPC client for a machine. This class should be used for all interactions with a machine.
60
+
61
+ There are 2 ways to instantiate a robot client::
62
+
63
+ RobotClient.at_address(...)
64
+ RobotClient.with_channel(...)
65
+
66
+ You can use the client standalone or within a context::
67
+
68
+ machine = await RobotClient.at_address(...)
69
+ async with await RobotClient.with_channel(...) as machine: ...
70
+
71
+ You must ``close()`` the machine to release resources.
72
+
73
+ Note: Machines used within a context are automatically closed UNLESS created with a channel. Machines created using ``with_channel`` are
74
+ not automatically closed.
75
+
76
+ Establish a Connection::
77
+
78
+ import asyncio
79
+
80
+ from viam.rpc.dial import DialOptions, Credentials
81
+ from viam.robot.client import RobotClient
82
+
83
+
84
+ async def connect():
85
+ opts = RobotClient.Options.with_api_key(
86
+ # Replace "<API-KEY>" (including brackets) with your machine's API key
87
+ api_key='<API-KEY>',
88
+ # Replace "<API-KEY-ID>" (including brackets) with your machine's API key ID
89
+ api_key_id='<API-KEY-ID>'
90
+ )
91
+ return await RobotClient.at_address('<ADDRESS-FROM-THE-VIAM-APP>', opts)
92
+
93
+
94
+ async def main():
95
+ # Make a RobotClient
96
+ machine = await connect()
97
+ print('Resources:')
98
+ print(machine.resource_names)
99
+ await machine.close()
100
+
101
+ if __name__ == '__main__':
102
+ asyncio.run(main())
103
+
104
+ For more information, see `Machine Management API <https://docs.viam.com/appendix/apis/robot/>`_.
105
+ """
106
+
107
+ @dataclass
108
+ class Options:
109
+ refresh_interval: int = 0
110
+ """
111
+ How often to refresh the status of the parts of the machine in seconds.
112
+ If not set, the machine will not be refreshed automatically
113
+ """
114
+
115
+ dial_options: Optional[DialOptions] = None
116
+ """
117
+ Options used to connect clients to gRPC servers
118
+ """
119
+
120
+ log_level: int = logging.INFO
121
+ """
122
+ The log level to output
123
+ """
124
+
125
+ check_connection_interval: int = 10
126
+ """
127
+ The frequency (in seconds) at which to check if the machine is still connected. 0 (zero) signifies no connection checks
128
+ """
129
+
130
+ attempt_reconnect_interval: int = 1
131
+ """
132
+ The frequency (in seconds) at which to attempt to reconnect a disconnected machine. 0 (zero) signifies no reconnection attempts
133
+ """
134
+
135
+ disable_sessions: bool = False
136
+ """
137
+ Whether sessions are disabled
138
+ """
139
+
140
+ @classmethod
141
+ def with_api_key(cls, api_key: str, api_key_id: str, **kwargs) -> Self:
142
+ """
143
+ Create RobotClient.Options with an API key for credentials and default values for other arguments.
144
+
145
+ ::
146
+
147
+ # Replace "<API-KEY>" (including brackets) with your machine's API key
148
+ api_key = '<API-KEY>'
149
+ # Replace "<API-KEY-ID>" (including brackets) with your machine's API key ID
150
+ api_key_id = '<API-KEY-ID>'
151
+
152
+ opts = RobotClient.Options.with_api_key(api_key, api_key_id)
153
+
154
+ machine = await RobotClient.at_address('<ADDRESS-FROM-THE-VIAM-APP>', opts)
155
+
156
+ Args:
157
+ api_key (str): your API key
158
+ api_key_id (str): your API key ID. Must be a valid UUID
159
+
160
+ Raises:
161
+ ValueError: Raised if the api_key_id is not a valid UUID
162
+
163
+ Returns:
164
+ Self: the RobotClient.Options
165
+
166
+ For more information, see `Establish a connection <https://docs.viam.com/appendix/apis/robot/#establish-a-connection>`_.
167
+ """
168
+ self = cls(**kwargs)
169
+ dial_opts = DialOptions.with_api_key(api_key, api_key_id)
170
+ self.dial_options = dial_opts
171
+ return self
172
+
173
+ @classmethod
174
+ async def at_address(cls, address: str, options: Options) -> Self:
175
+ """Create a robot client that is connected to the machine at the provided address.
176
+
177
+ ::
178
+
179
+ async def connect():
180
+
181
+ opts = RobotClient.Options.with_api_key(
182
+ # Replace "<API-KEY>" (including brackets) with your machine's API key
183
+ api_key='<API-KEY>',
184
+ # Replace "<API-KEY-ID>" (including brackets) with your machine's API key ID
185
+ api_key_id='<API-KEY-ID>'
186
+ )
187
+ return await RobotClient.at_address('ADDRESS FROM THE VIAM APP', opts)
188
+
189
+
190
+ async def main():
191
+ # Make a RobotClient
192
+ machine = await connect()
193
+
194
+ Args:
195
+ address (str): Address of the machine (IP address, URL, etc.)
196
+ options (Options): Options for connecting and refreshing
197
+
198
+ Returns:
199
+ Self: the RobotClient
200
+
201
+ For more information, see `Establish a connection <https://docs.viam.com/appendix/apis/robot/#establish-a-connection>`_.
202
+ """
203
+ logging.setLevel(options.log_level)
204
+ channel = await dial(address, options.dial_options)
205
+ machine = await cls._with_channel(channel, options, True, robot_addr=address)
206
+ machine._address = address
207
+ return machine
208
+
209
+ @classmethod
210
+ async def with_channel(cls, channel: Union[Channel, ViamChannel], options: Options) -> Self:
211
+ """Create a machine that is connected to a machine over the given channel.
212
+
213
+ Any machines created using this method will *NOT* automatically close the channel upon exit.
214
+
215
+ ::
216
+
217
+ from viam.robot.client import RobotClient
218
+ from viam.rpc.dial import DialOptions, dial
219
+
220
+
221
+ async def connect_with_channel() -> RobotClient:
222
+ async with await dial('ADDRESS', DialOptions()) as channel:
223
+ return await RobotClient.with_channel(channel, RobotClient.Options())
224
+
225
+ machine = await connect_with_channel()
226
+
227
+ Args:
228
+ channel (ViamChannel): The channel that is connected to a machine, obtained by ``viam.rpc.dial``
229
+ options (Options): Options for refreshing. Any connection options will be ignored.
230
+
231
+ Returns:
232
+ Self: the RobotClient
233
+
234
+ For more information, see `Establish a connection <https://docs.viam.com/appendix/apis/robot/#establish-a-connection>`_.
235
+ """
236
+ logging.setLevel(options.log_level)
237
+ return await cls._with_channel(channel, options, False)
238
+
239
+ @classmethod
240
+ async def _with_channel(
241
+ cls, channel: Union[Channel, ViamChannel], options: Options, close_channel: bool, robot_addr: Optional[str] = None
242
+ ):
243
+ """INTERNAL USE ONLY"""
244
+
245
+ self = cls()
246
+
247
+ if isinstance(channel, Channel):
248
+ self._channel = channel
249
+ self._viam_channel = None
250
+ else:
251
+ self._channel = channel.channel
252
+ self._viam_channel = channel
253
+
254
+ self._connected = True
255
+ self._client = RobotServiceStub(self._channel)
256
+ self._manager = ResourceManager()
257
+ self._lock = RLock()
258
+ self._resource_names = []
259
+ self._should_close_channel = close_channel
260
+ self._options = options
261
+ self._address = self._channel._path if self._channel._path else f"{self._channel._host}:{self._channel._port}"
262
+ self._sessions_client = SessionsClient(
263
+ self._channel, self._address, self._options.dial_options, disabled=self._options.disable_sessions, robot_addr=robot_addr
264
+ )
265
+
266
+ try:
267
+ await self.refresh()
268
+ except Exception:
269
+ LOGGER.error("Unable to establish a connection to the machine. Ensure the machine is online and reachable and try again.")
270
+ await self.close()
271
+ raise ConnectionError("Unable to establish a connection to the machine.")
272
+
273
+ if options.refresh_interval > 0:
274
+ self._refresh_task = asyncio.create_task(
275
+ self._refresh_every(options.refresh_interval), name=f"{viam._TASK_PREFIX}-robot_refresh_metadata"
276
+ )
277
+
278
+ if options.check_connection_interval > 0 or options.attempt_reconnect_interval > 0:
279
+ self._check_connection_task = asyncio.create_task(
280
+ self._check_connection(options.check_connection_interval, options.attempt_reconnect_interval),
281
+ name=f"{viam._TASK_PREFIX}-robot_check_connection",
282
+ )
283
+
284
+ return self
285
+
286
+ _channel: Channel
287
+ _viam_channel: Optional[ViamChannel]
288
+ _lock: RLock
289
+ _manager: ResourceManager
290
+ _client: RobotServiceStub
291
+ _connected: bool
292
+ _address: str
293
+ _options: Options
294
+ _refresh_task: Optional[asyncio.Task] = None
295
+ _check_connection_task: Optional[asyncio.Task] = None
296
+ _resource_names: List[ResourceName]
297
+ _should_close_channel: bool
298
+ _closed: bool = False
299
+ _sessions_client: SessionsClient
300
+
301
+ async def refresh(self):
302
+ """
303
+ Manually refresh the underlying parts of this machine.
304
+
305
+ ::
306
+
307
+ await machine.refresh()
308
+
309
+ For more information, see `Machine Management API <https://docs.viam.com/appendix/apis/robot/>`_.
310
+ """
311
+ response: ResourceNamesResponse = await self._client.ResourceNames(ResourceNamesRequest())
312
+ resource_names: List[ResourceName] = list(response.resources)
313
+ with self._lock:
314
+ if resource_names == self._resource_names:
315
+ return
316
+ for rname in resource_names:
317
+ if rname.type not in [RESOURCE_TYPE_COMPONENT, RESOURCE_TYPE_SERVICE]:
318
+ continue
319
+ if rname.subtype == "remote":
320
+ continue
321
+
322
+ await self._create_or_reset_client(rname)
323
+
324
+ for rname in self.resource_names:
325
+ if rname not in resource_names:
326
+ await self._manager.remove_resource(rname)
327
+
328
+ self._resource_names = resource_names
329
+
330
+ async def _create_or_reset_client(self, resourceName: ResourceName):
331
+ if resourceName in self._manager.resources:
332
+ res = self._manager.get_resource(ResourceBase, resourceName)
333
+
334
+ # If the channel hasn't changed, we don't need to do anything for existing clients
335
+ if isinstance(res, ResourceRPCClientBase) or (hasattr(res, "channel") and isinstance(getattr(res, "channel"), Channel)):
336
+ if self._channel is res.channel: # type: ignore
337
+ return
338
+
339
+ if isinstance(res, ReconfigurableResourceRPCClientBase):
340
+ res.reset_channel(self._channel)
341
+ else:
342
+ await self._manager.remove_resource(resourceName)
343
+ self._manager.register(
344
+ Registry.lookup_api(API.from_resource_name(resourceName)).create_rpc_client(resourceName.name, self._channel)
345
+ )
346
+ else:
347
+ try:
348
+ self._manager.register(
349
+ Registry.lookup_api(API.from_resource_name(resourceName)).create_rpc_client(resourceName.name, self._channel)
350
+ )
351
+ except ResourceNotFoundError:
352
+ pass
353
+
354
+ async def _refresh_every(self, interval: int):
355
+ while True:
356
+ await asyncio.sleep(interval)
357
+ try:
358
+ await self.refresh()
359
+ except Exception as e:
360
+ LOGGER.error("Failed to refresh status", exc_info=e)
361
+
362
+ async def _check_connection(self, check_every: int, reconnect_every: int):
363
+ if check_every <= 0:
364
+ check_every = reconnect_every
365
+ if check_every <= 0 and reconnect_every <= 0:
366
+ return
367
+
368
+ while True:
369
+ await asyncio.sleep(check_every)
370
+
371
+ # Failure to grab resources could be for spurious, non-networking reasons. Try three times just to be safe.
372
+ connection_error = None
373
+ for _ in range(3):
374
+ try:
375
+ await self._client.ResourceNames(ResourceNamesRequest(), timeout=1)
376
+ connection_error = None
377
+ break
378
+ except Exception as e:
379
+ connection_error = e
380
+ await asyncio.sleep(0.1)
381
+ if connection_error:
382
+ msg = "Lost connection to machine."
383
+ if reconnect_every > 0:
384
+ msg += (
385
+ f" Attempting to reconnect to {self._address} every {reconnect_every} second{'s' if reconnect_every != 1 else ''}"
386
+ )
387
+ LOGGER.error(msg, exc_info=connection_error)
388
+ self._close_channel()
389
+ self._connected = False
390
+
391
+ if reconnect_every <= 0:
392
+ continue
393
+
394
+ if self._connected:
395
+ continue
396
+
397
+ reconnect_attempts = self._options.dial_options.max_reconnect_attempts if self._options.dial_options else 3
398
+
399
+ for _ in range(reconnect_attempts):
400
+ try:
401
+ self._sessions_client.reset()
402
+
403
+ channel = await _dial_inner(self._address, self._options.dial_options)
404
+
405
+ client: RobotServiceStub
406
+ if isinstance(channel, Channel):
407
+ client = RobotServiceStub(channel)
408
+ else:
409
+ client = RobotServiceStub(channel.channel)
410
+ await client.ResourceNames(ResourceNamesRequest())
411
+
412
+ if isinstance(channel, Channel):
413
+ self._channel = channel
414
+ self._viam_channel = None
415
+ else:
416
+ self._channel = channel.channel
417
+ self._viam_channel = channel
418
+ self._client = RobotServiceStub(self._channel)
419
+ direct_dial_address = self._channel._path if self._channel._path else f"{self._channel._host}:{self._channel._port}"
420
+ self._sessions_client = SessionsClient(
421
+ channel=self._channel,
422
+ direct_dial_address=direct_dial_address,
423
+ dial_options=self._options.dial_options,
424
+ disabled=self._options.disable_sessions,
425
+ robot_addr=self._address,
426
+ )
427
+
428
+ await self.refresh()
429
+ self._connected = True
430
+ LOGGER.debug("Successfully reconnected machine")
431
+ break
432
+ except Exception as e:
433
+ LOGGER.error(f"Failed to reconnect, trying again in {reconnect_every}sec", exc_info=e)
434
+ self._sessions_client.reset()
435
+ self._close_channel()
436
+ await asyncio.sleep(reconnect_every)
437
+ if not self._connected:
438
+ # We failed to reconnect, sys.exit() so that this thread doesn't stick around forever.
439
+ sys.exit()
440
+
441
+ def get_component(self, name: ResourceName) -> ComponentBase:
442
+ """Get a component using its ResourceName.
443
+
444
+ This function should not be called directly except in specific cases. The method ``Component.from_robot(...)`` is the preferred
445
+ method for obtaining components.
446
+ ::
447
+
448
+ arm = Arm.from_robot(robot=machine, name="my_arm")
449
+
450
+ Because this function returns a generic ``ComponentBase`` rather than the specific
451
+ component type, it will be necessary to cast the returned component to the desired component. This can be done using a few
452
+ different methods:
453
+
454
+ - Assertion::
455
+
456
+ arm = machine.get_component(Arm.get_resource_name("my_arm"))
457
+ assert isinstance(arm, Arm)
458
+ end_pos = await arm.get_end_position()
459
+
460
+ - Explicit cast::
461
+
462
+ from typing import cast
463
+ arm = machine.get_component(Arm.get_resource_name("my_arm"))
464
+ arm = cast(Arm, arm)
465
+ end_pos = await arm.get_end_position()
466
+
467
+ - Declare type on variable assignment.
468
+
469
+ - Note: If using an IDE, a type error may be shown which can be ignored.
470
+ ::
471
+
472
+ arm: Arm = machine.get_component(Arm.get_resource_name("my_arm")) # type: ignore
473
+ end_pos = await arm.get_end_position()
474
+
475
+ Args:
476
+ name (viam.proto.common.ResourceName): The component's ResourceName
477
+
478
+ Raises:
479
+ ValueError: Raised if the requested resource is not a component
480
+ ComponentNotFoundError: Error if component with the given type and name does not exist in the registry
481
+
482
+ Returns:
483
+ ComponentBase: The component
484
+
485
+ For more information, see `Machine Management API <https://docs.viam.com/appendix/apis/robot/>`_.
486
+ """
487
+ if name.type != RESOURCE_TYPE_COMPONENT:
488
+ raise ValueError(f"ResourceName does not describe a component: {name}")
489
+ with self._lock:
490
+ return self._manager.get_resource(ComponentBase, name)
491
+
492
+ def get_service(self, name: ResourceName) -> ServiceBase:
493
+ """Get a service using its ResourceName
494
+
495
+ This function should not be called directly except in specific cases. The method ``Service.from_robot(...)`` is the preferred
496
+ method for obtaining services.
497
+ ::
498
+
499
+ service = MyService.from_robot(robot=machine, name="my_service")
500
+
501
+ Because this function returns a generic ``ServiceBase`` rather than a specific service type, it will be necessary to cast the
502
+ returned service to the desired service. This can be done using a few methods:
503
+
504
+ - Assertion::
505
+
506
+ service = machine.get_service(MyService.get_resource_name("my_service"))
507
+ assert isinstance(service, MyService)
508
+
509
+ - Explicit cast::
510
+
511
+ from typing import cast
512
+ service = machine.get_service(MyService.get_resource_name("my_service"))
513
+ service = cast(MyService, my_service)
514
+
515
+ - Declare type on variable assignment
516
+
517
+ - Note: If using an IDE, a type error may be shown which can be ignored.
518
+ ::
519
+
520
+ service: MyService = machine.get_service(MyService.get_resource_name("my_service")) # type: ignore
521
+
522
+ Args:
523
+ name (viam.proto.common.ResourceName): The service's ResourceName
524
+
525
+ Raises:
526
+ ValueError: Raised if the requested resource is not a component
527
+ ComponentNotFoundError: Error if component with the given type and name does not exist in the registry
528
+
529
+ Returns:
530
+ ServiceBase: The service
531
+
532
+ For more information, see `Machine Management API <https://docs.viam.com/appendix/apis/robot/>`_.
533
+ """
534
+ if name.type != RESOURCE_TYPE_SERVICE:
535
+ raise ValueError(f"ResourceName does not describe a service: {name}")
536
+ with self._lock:
537
+ return self._manager.get_resource(ServiceBase, name)
538
+
539
+ @property
540
+ def resource_names(self) -> List[ResourceName]:
541
+ """
542
+ Get a list of all resource names
543
+
544
+ ::
545
+
546
+ resource_names = machine.resource_names
547
+
548
+ Returns:
549
+ List[viam.proto.common.ResourceName]: The list of resource names
550
+
551
+ For more information, see `Machine Management API <https://docs.viam.com/appendix/apis/robot/>`_.
552
+ """
553
+ with self._lock:
554
+ return [r for r in self._resource_names]
555
+
556
+ def _close_channel(self, *, tab_count=0):
557
+ tabs = "".join(["\t" for _ in range(tab_count)])
558
+ if self._viam_channel is not None:
559
+ LOGGER.debug(f"{tabs} Closing ViamChannel instance")
560
+ self._viam_channel.close()
561
+ else:
562
+ LOGGER.debug(f"{tabs} Closing grpc-lib Channel instance")
563
+ self._channel.close()
564
+
565
+ async def close(self):
566
+ """
567
+ Cleanly close the underlying connections and stop any periodic tasks.
568
+
569
+ ::
570
+
571
+ await machine.close()
572
+
573
+ For more information, see `Machine Management API <https://docs.viam.com/appendix/apis/robot/>`_.
574
+ """
575
+ LOGGER.debug("Closing RobotClient")
576
+ if self._closed:
577
+ LOGGER.debug("RobotClient is already closed")
578
+ return
579
+
580
+ try:
581
+ self._lock.release()
582
+ except RuntimeError:
583
+ pass
584
+
585
+ self._sessions_client.reset()
586
+
587
+ # Cancel all tasks created by VIAM
588
+ LOGGER.debug("Closing tasks spawned by Viam")
589
+ tasks = [task for task in asyncio.all_tasks() if task.get_name().startswith(viam._TASK_PREFIX)]
590
+ for task in tasks:
591
+ LOGGER.debug(f"\tClosing task {task.get_name()}")
592
+ task.cancel()
593
+ await asyncio.gather(*tasks, return_exceptions=True)
594
+
595
+ if self._should_close_channel:
596
+ LOGGER.debug("Closing gRPC channel to remote robot")
597
+ self._close_channel(tab_count=1)
598
+
599
+ self._closed = True
600
+
601
+ async def __aenter__(self):
602
+ return self
603
+
604
+ async def __aexit__(self, exc_type, exc_value, traceback):
605
+ await self.close()
606
+
607
+ ##############
608
+ # OPERATIONS #
609
+ ##############
610
+
611
+ async def get_operations(self) -> List[Operation]:
612
+ """
613
+ Get the list of operations currently running on the machine.
614
+
615
+ ::
616
+
617
+ operations = await machine.get_operations()
618
+
619
+ Returns:
620
+ List[viam.proto.robot.Operation]: The list of operations currently running on a given machine.
621
+
622
+ For more information, see `Machine Management API <https://docs.viam.com/appendix/apis/robot/>`_.
623
+ """
624
+ request = GetOperationsRequest()
625
+ response: GetOperationsResponse = await self._client.GetOperations(request)
626
+ return list(response.operations)
627
+
628
+ async def cancel_operation(self, id: str):
629
+ """
630
+ Cancels the specified operation on the machine.
631
+
632
+ ::
633
+
634
+ await machine.cancel_operation("INSERT OPERATION ID")
635
+
636
+ Args:
637
+ id (str): ID of operation to cancel.
638
+
639
+ For more information, see `Machine Management API <https://docs.viam.com/appendix/apis/robot/>`_.
640
+ """
641
+ request = CancelOperationRequest(id=id)
642
+ await self._client.CancelOperation(request)
643
+
644
+ async def block_for_operation(self, id: str):
645
+ """
646
+ Blocks on the specified operation on the machine. This function will only return when the specific operation
647
+ has finished or has been cancelled.
648
+
649
+ ::
650
+
651
+ await machine.block_for_operation("INSERT OPERATION ID")
652
+
653
+ Args:
654
+ id (str): ID of operation to block on.
655
+
656
+ For more information, see `Machine Management API <https://docs.viam.com/appendix/apis/robot/>`_.
657
+ """
658
+ request = BlockForOperationRequest(id=id)
659
+ await self._client.BlockForOperation(request)
660
+
661
+ ################
662
+ # FRAME SYSTEM #
663
+ ################
664
+
665
+ async def get_frame_system_config(self, additional_transforms: Optional[List[Transform]] = None) -> List[FrameSystemConfig]:
666
+ """
667
+ Get the configuration of the frame system of a given machine.
668
+
669
+ ::
670
+
671
+ # Get a list of each of the reference frames configured on the machine.
672
+ frame_system = await machine.get_frame_system_config()
673
+ print(f"frame system configuration: {frame_system}")
674
+
675
+ Returns:
676
+ List[viam.proto.robot.FrameSystemConfig]: The configuration of a given machine's frame system.
677
+
678
+ For more information, see `Machine Management API <https://docs.viam.com/appendix/apis/robot/>`_.
679
+ """
680
+ request = FrameSystemConfigRequest(supplemental_transforms=additional_transforms)
681
+ response: FrameSystemConfigResponse = await self._client.FrameSystemConfig(request)
682
+ return list(response.frame_system_configs)
683
+
684
+ async def transform_pose(
685
+ self, query: PoseInFrame, destination: str, additional_transforms: Optional[List[Transform]] = None
686
+ ) -> PoseInFrame:
687
+ """
688
+ Transform a given source Pose from the reference frame to a new specified destination which is a reference frame.
689
+
690
+ ::
691
+
692
+ from viam.proto.common import Pose, PoseInFrame
693
+
694
+ pose = Pose(
695
+ x=1.0, # X coordinate in mm
696
+ y=2.0, # Y coordinate in mm
697
+ z=3.0, # Z coordinate in mm
698
+ o_x=0.0, # X component of orientation vector
699
+ o_y=0.0, # Y component of orientation vector
700
+ o_z=0.0, # Z component of orientation vector
701
+ theta=0.0 # Orientation angle in degrees
702
+ )
703
+
704
+ pose_in_frame = PoseInFrame(
705
+ reference_frame="world",
706
+ pose=pose
707
+ )
708
+
709
+ transformed_pose = await machine.transform_pose(pose_in_frame, "world")
710
+
711
+ Args:
712
+
713
+ query (viam.proto.common.PoseInFrame): The pose that should be transformed.
714
+ destination (str) : The name of the reference frame to transform the given pose to.
715
+
716
+ Returns:
717
+ PoseInFrame: The pose and the reference frame for the new destination.
718
+
719
+ For more information, see `Machine Management API <https://docs.viam.com/appendix/apis/robot/>`_.
720
+ """
721
+ request = TransformPoseRequest(source=query, destination=destination, supplemental_transforms=additional_transforms)
722
+ response: TransformPoseResponse = await self._client.TransformPose(request)
723
+ return response.pose
724
+
725
+ async def transform_point_cloud(self):
726
+ raise NotImplementedError()
727
+
728
+ #################
729
+ # MODULE MODELS #
730
+ #################
731
+
732
+ async def get_models_from_modules(
733
+ self,
734
+ ) -> List[ModuleModel]:
735
+ """
736
+ Get a list of all models provided by local and registry modules on the machine.
737
+ This includes models that are not currently configured on the machine.
738
+
739
+ ::
740
+
741
+ # Get module models
742
+ module_models = await machine.get_models_from_modules(qs)
743
+
744
+ Args:
745
+
746
+ Returns:
747
+ List[ModuleModel]: A list of discovered models.
748
+ """
749
+ request = GetModelsFromModulesRequest()
750
+ response: GetModelsFromModulesResponse = await self._client.GetModelsFromModules(request)
751
+ return list(response.models)
752
+
753
+ ############
754
+ # STOP ALL #
755
+ ############
756
+
757
+ async def stop_all(self, extra: Dict[ResourceName, Dict[str, Any]] = {}):
758
+ """
759
+ Cancel all current and outstanding operations for the machine and stop all actuators and movement.
760
+
761
+ ::
762
+
763
+ # Cancel all current and outstanding operations for the machine and stop all actuators and movement.
764
+ await machine.stop_all()
765
+
766
+ Args:
767
+ extra (Dict[viam.proto.common.ResourceName, Dict[str, Any]]): Any extra parameters to pass to the resources' ``stop`` methods,
768
+ keyed on the resource's ``ResourceName``.
769
+
770
+ For more information, see `Machine Management API <https://docs.viam.com/appendix/apis/robot/>`_.
771
+ """
772
+
773
+ ep: List[StopExtraParameters] = []
774
+ for name, params in extra.items():
775
+ ep.append(StopExtraParameters(name=name, params=dict_to_struct(params)))
776
+ request = StopAllRequest(extra=ep)
777
+ await self._client.StopAll(request)
778
+
779
+ #######
780
+ # LOG #
781
+ #######
782
+
783
+ async def log(self, name: str, level: str, time: datetime, message: str, stack: str):
784
+ """Send log from Python module over gRPC.
785
+
786
+ Create a LogEntry object from the log to send to RDK.
787
+
788
+ Args:
789
+ name (str): The logger's name.
790
+ level (str): The level of the log.
791
+ time (datetime): The log creation time.
792
+ message (str): The log message.
793
+ stack (str): The stack information of the log.
794
+
795
+ For more information, see `Machine Management API <https://docs.viam.com/appendix/apis/robot/>`_.
796
+ """
797
+ entry = LogEntry(level=level, time=datetime_to_timestamp(time), logger_name=name, message=message, stack=stack)
798
+ request = LogRequest(logs=[entry])
799
+ await self._client.Log(request)
800
+
801
+ ######################
802
+ # Get Cloud Metadata #
803
+ ######################
804
+
805
+ async def get_cloud_metadata(self) -> GetCloudMetadataResponse:
806
+ """
807
+ Get app-related information about the machine.
808
+
809
+ ::
810
+
811
+ metadata = await machine.get_cloud_metadata()
812
+ print(metadata.machine_id)
813
+ print(metadata.machine_part_id)
814
+ print(metadata.primary_org_id)
815
+ print(metadata.location_id)
816
+
817
+ Returns:
818
+ viam.proto.robot.GetCloudMetadataResponse: App-related metadata.
819
+
820
+ For more information, see `Machine Management API <https://docs.viam.com/appendix/apis/robot/>`_.
821
+ """
822
+
823
+ request = GetCloudMetadataRequest()
824
+ return await self._client.GetCloudMetadata(request)
825
+
826
+ ############
827
+ # Shutdown #
828
+ ############
829
+
830
+ async def shutdown(self):
831
+ """
832
+ Shutdown shuts down the machine.
833
+
834
+ ::
835
+
836
+ await machine.shutdown()
837
+
838
+ Raises:
839
+ GRPCError: Raised with DeadlineExceeded status if shutdown request times out, or if
840
+ the machine server shuts down before having a chance to send a response. Raised with
841
+ status Unavailable if server is unavailable, or if machine server is in the process of
842
+ shutting down when response is ready.
843
+
844
+ For more information, see `Machine Management API <https://docs.viam.com/appendix/apis/robot/>`_.
845
+ """
846
+ request = ShutdownRequest()
847
+ try:
848
+ await self._client.Shutdown(request)
849
+ LOGGER.info("robot shutdown successful")
850
+ except GRPCError as e:
851
+ if e.status == Status.INTERNAL or e.status == Status.UNKNOWN:
852
+ LOGGER.info("robot shutdown successful")
853
+ elif e.status == Status.UNAVAILABLE:
854
+ LOGGER.warn("server unavailable, likely due to successful robot shutdown")
855
+ raise e
856
+ elif e.status == Status.DEADLINE_EXCEEDED:
857
+ LOGGER.warn("request timeout, robot shutdown may still be successful")
858
+ raise e
859
+ else:
860
+ raise e
861
+
862
+ ######################
863
+ # Get Version #
864
+ ######################
865
+
866
+ async def get_version(self) -> GetVersionResponse:
867
+ """
868
+ Get version information about the machine.
869
+
870
+ ::
871
+
872
+ result = await machine.get_version()
873
+ print(result.platform)
874
+ print(result.version)
875
+ print(result.api_version)
876
+
877
+ Returns:
878
+ viam.proto.robot.GetVersionResponse: Machine version related information.
879
+
880
+ For more information, see `Machine Management API <https://docs.viam.com/appendix/apis/robot/>`_.
881
+ """
882
+
883
+ request = GetVersionRequest()
884
+ return await self._client.GetVersion(request)
885
+
886
+ ######################
887
+ # Get Machine Status #
888
+ ######################
889
+
890
+ async def get_machine_status(self) -> GetMachineStatusResponse:
891
+ """
892
+ Get status information about the machine's resources and configuration.
893
+
894
+ ::
895
+
896
+ machine_status = await machine.get_machine_status()
897
+ machine_state = machine_status.state
898
+ resource_statuses = machine_status.resources
899
+ cloud_metadata = machine_status.resources[0].cloud_metadata
900
+ config_status = machine_status.config
901
+
902
+ Returns:
903
+ viam.proto.robot.GetMachineStatusResponse: current status of the machine (initializing or running), resources (List[ResourceStatus]) and config of the machine.
904
+
905
+ For more information, see `Machine Management API <https://docs.viam.com/appendix/apis/robot/>`_.
906
+ """
907
+
908
+ request = GetMachineStatusRequest()
909
+ return await self._client.GetMachineStatus(request)