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.
- viam/__init__.py +71 -0
- viam/app/__init__.py +0 -0
- viam/app/_logs.py +34 -0
- viam/app/app_client.py +2525 -0
- viam/app/billing_client.py +143 -0
- viam/app/data_client.py +1715 -0
- viam/app/ml_training_client.py +251 -0
- viam/app/provisioning_client.py +95 -0
- viam/app/viam_client.py +260 -0
- viam/components/__init__.py +0 -0
- viam/components/arm/__init__.py +16 -0
- viam/components/arm/arm.py +223 -0
- viam/components/arm/client.py +124 -0
- viam/components/arm/service.py +123 -0
- viam/components/audio_input/__init__.py +18 -0
- viam/components/audio_input/audio_input.py +81 -0
- viam/components/audio_input/client.py +70 -0
- viam/components/audio_input/service.py +114 -0
- viam/components/base/__init__.py +13 -0
- viam/components/base/base.py +260 -0
- viam/components/base/client.py +153 -0
- viam/components/base/service.py +138 -0
- viam/components/board/__init__.py +9 -0
- viam/components/board/board.py +414 -0
- viam/components/board/client.py +241 -0
- viam/components/board/service.py +223 -0
- viam/components/button/__init__.py +10 -0
- viam/components/button/button.py +41 -0
- viam/components/button/client.py +52 -0
- viam/components/button/service.py +46 -0
- viam/components/camera/__init__.py +22 -0
- viam/components/camera/camera.py +138 -0
- viam/components/camera/client.py +98 -0
- viam/components/camera/service.py +105 -0
- viam/components/component_base.py +65 -0
- viam/components/encoder/__init__.py +18 -0
- viam/components/encoder/client.py +83 -0
- viam/components/encoder/encoder.py +118 -0
- viam/components/encoder/service.py +72 -0
- viam/components/gantry/__init__.py +11 -0
- viam/components/gantry/client.py +115 -0
- viam/components/gantry/gantry.py +156 -0
- viam/components/gantry/service.py +113 -0
- viam/components/generic/__init__.py +18 -0
- viam/components/generic/client.py +62 -0
- viam/components/generic/generic.py +76 -0
- viam/components/generic/service.py +40 -0
- viam/components/gripper/__init__.py +11 -0
- viam/components/gripper/client.py +85 -0
- viam/components/gripper/gripper.py +114 -0
- viam/components/gripper/service.py +81 -0
- viam/components/input/__init__.py +15 -0
- viam/components/input/client.py +194 -0
- viam/components/input/input.py +297 -0
- viam/components/input/service.py +175 -0
- viam/components/motor/__init__.py +11 -0
- viam/components/motor/client.py +168 -0
- viam/components/motor/motor.py +301 -0
- viam/components/motor/service.py +150 -0
- viam/components/movement_sensor/__init__.py +21 -0
- viam/components/movement_sensor/client.py +161 -0
- viam/components/movement_sensor/movement_sensor.py +253 -0
- viam/components/movement_sensor/service.py +146 -0
- viam/components/pose_tracker/__init__.py +17 -0
- viam/components/pose_tracker/client.py +50 -0
- viam/components/pose_tracker/pose_tracker.py +40 -0
- viam/components/pose_tracker/service.py +45 -0
- viam/components/power_sensor/__init__.py +17 -0
- viam/components/power_sensor/client.py +86 -0
- viam/components/power_sensor/power_sensor.py +104 -0
- viam/components/power_sensor/service.py +72 -0
- viam/components/sensor/__init__.py +18 -0
- viam/components/sensor/client.py +49 -0
- viam/components/sensor/sensor.py +48 -0
- viam/components/sensor/service.py +51 -0
- viam/components/servo/__init__.py +11 -0
- viam/components/servo/client.py +86 -0
- viam/components/servo/service.py +80 -0
- viam/components/servo/servo.py +114 -0
- viam/components/switch/__init__.py +10 -0
- viam/components/switch/client.py +83 -0
- viam/components/switch/service.py +72 -0
- viam/components/switch/switch.py +95 -0
- viam/errors.py +105 -0
- viam/gen/__init__.py +0 -0
- viam/gen/app/__init__.py +0 -0
- viam/gen/app/agent/__init__.py +0 -0
- viam/gen/app/agent/v1/__init__.py +0 -0
- viam/gen/app/agent/v1/agent_grpc.py +29 -0
- viam/gen/app/agent/v1/agent_pb2.py +47 -0
- viam/gen/app/agent/v1/agent_pb2.pyi +280 -0
- viam/gen/app/cloudslam/__init__.py +0 -0
- viam/gen/app/cloudslam/v1/__init__.py +0 -0
- viam/gen/app/cloudslam/v1/cloud_slam_grpc.py +70 -0
- viam/gen/app/cloudslam/v1/cloud_slam_pb2.py +54 -0
- viam/gen/app/cloudslam/v1/cloud_slam_pb2.pyi +384 -0
- viam/gen/app/data/__init__.py +0 -0
- viam/gen/app/data/v1/__init__.py +0 -0
- viam/gen/app/data/v1/data_grpc.py +206 -0
- viam/gen/app/data/v1/data_pb2.py +178 -0
- viam/gen/app/data/v1/data_pb2.pyi +1485 -0
- viam/gen/app/datapipelines/__init__.py +0 -0
- viam/gen/app/datapipelines/v1/__init__.py +0 -0
- viam/gen/app/datapipelines/v1/data_pipelines_grpc.py +84 -0
- viam/gen/app/datapipelines/v1/data_pipelines_pb2.py +56 -0
- viam/gen/app/datapipelines/v1/data_pipelines_pb2.pyi +370 -0
- viam/gen/app/dataset/__init__.py +0 -0
- viam/gen/app/dataset/v1/__init__.py +0 -0
- viam/gen/app/dataset/v1/dataset_grpc.py +60 -0
- viam/gen/app/dataset/v1/dataset_pb2.py +40 -0
- viam/gen/app/dataset/v1/dataset_pb2.pyi +179 -0
- viam/gen/app/datasync/__init__.py +0 -0
- viam/gen/app/datasync/v1/__init__.py +0 -0
- viam/gen/app/datasync/v1/data_sync_grpc.py +47 -0
- viam/gen/app/datasync/v1/data_sync_pb2.py +70 -0
- viam/gen/app/datasync/v1/data_sync_pb2.pyi +425 -0
- viam/gen/app/mlinference/__init__.py +0 -0
- viam/gen/app/mlinference/v1/__init__.py +0 -0
- viam/gen/app/mlinference/v1/ml_inference_grpc.py +28 -0
- viam/gen/app/mlinference/v1/ml_inference_pb2.py +23 -0
- viam/gen/app/mlinference/v1/ml_inference_pb2.pyi +63 -0
- viam/gen/app/mltraining/__init__.py +0 -0
- viam/gen/app/mltraining/v1/__init__.py +0 -0
- viam/gen/app/mltraining/v1/ml_training_grpc.py +78 -0
- viam/gen/app/mltraining/v1/ml_training_pb2.py +124 -0
- viam/gen/app/mltraining/v1/ml_training_pb2.pyi +415 -0
- viam/gen/app/packages/__init__.py +0 -0
- viam/gen/app/packages/v1/__init__.py +0 -0
- viam/gen/app/packages/v1/packages_grpc.py +54 -0
- viam/gen/app/packages/v1/packages_pb2.py +52 -0
- viam/gen/app/packages/v1/packages_pb2.pyi +311 -0
- viam/gen/app/v1/__init__.py +0 -0
- viam/gen/app/v1/app_grpc.py +863 -0
- viam/gen/app/v1/app_pb2.py +649 -0
- viam/gen/app/v1/app_pb2.pyi +5279 -0
- viam/gen/app/v1/billing_grpc.py +76 -0
- viam/gen/app/v1/billing_pb2.py +92 -0
- viam/gen/app/v1/billing_pb2.pyi +463 -0
- viam/gen/app/v1/end_user_grpc.py +59 -0
- viam/gen/app/v1/end_user_pb2.py +55 -0
- viam/gen/app/v1/end_user_pb2.pyi +181 -0
- viam/gen/app/v1/robot_grpc.py +55 -0
- viam/gen/app/v1/robot_pb2.py +127 -0
- viam/gen/app/v1/robot_pb2.pyi +1202 -0
- viam/gen/common/__init__.py +0 -0
- viam/gen/common/v1/__init__.py +0 -0
- viam/gen/common/v1/common_grpc.py +0 -0
- viam/gen/common/v1/common_pb2.py +78 -0
- viam/gen/common/v1/common_pb2.pyi +687 -0
- viam/gen/component/__init__.py +0 -0
- viam/gen/component/arm/__init__.py +0 -0
- viam/gen/component/arm/v1/__init__.py +0 -0
- viam/gen/component/arm/v1/arm_grpc.py +102 -0
- viam/gen/component/arm/v1/arm_pb2.py +74 -0
- viam/gen/component/arm/v1/arm_pb2.pyi +344 -0
- viam/gen/component/audioinput/__init__.py +0 -0
- viam/gen/component/audioinput/v1/__init__.py +0 -0
- viam/gen/component/audioinput/v1/audioinput_grpc.py +63 -0
- viam/gen/component/audioinput/v1/audioinput_pb2.py +45 -0
- viam/gen/component/audioinput/v1/audioinput_pb2.pyi +179 -0
- viam/gen/component/base/__init__.py +0 -0
- viam/gen/component/base/v1/__init__.py +0 -0
- viam/gen/component/base/v1/base_grpc.py +94 -0
- viam/gen/component/base/v1/base_pb2.py +66 -0
- viam/gen/component/base/v1/base_pb2.pyi +258 -0
- viam/gen/component/board/__init__.py +0 -0
- viam/gen/component/board/v1/__init__.py +0 -0
- viam/gen/component/board/v1/board_grpc.py +127 -0
- viam/gen/component/board/v1/board_pb2.py +103 -0
- viam/gen/component/board/v1/board_pb2.pyi +496 -0
- viam/gen/component/button/__init__.py +0 -0
- viam/gen/component/button/v1/__init__.py +0 -0
- viam/gen/component/button/v1/button_grpc.py +38 -0
- viam/gen/component/button/v1/button_pb2.py +28 -0
- viam/gen/component/button/v1/button_pb2.pyi +39 -0
- viam/gen/component/camera/__init__.py +0 -0
- viam/gen/component/camera/v1/__init__.py +0 -0
- viam/gen/component/camera/v1/camera_grpc.py +79 -0
- viam/gen/component/camera/v1/camera_pb2.py +67 -0
- viam/gen/component/camera/v1/camera_pb2.pyi +373 -0
- viam/gen/component/encoder/__init__.py +0 -0
- viam/gen/component/encoder/v1/__init__.py +0 -0
- viam/gen/component/encoder/v1/encoder_grpc.py +62 -0
- viam/gen/component/encoder/v1/encoder_pb2.py +44 -0
- viam/gen/component/encoder/v1/encoder_pb2.pyi +147 -0
- viam/gen/component/gantry/__init__.py +0 -0
- viam/gen/component/gantry/v1/__init__.py +0 -0
- viam/gen/component/gantry/v1/gantry_grpc.py +86 -0
- viam/gen/component/gantry/v1/gantry_pb2.py +62 -0
- viam/gen/component/gantry/v1/gantry_pb2.pyi +239 -0
- viam/gen/component/generic/__init__.py +0 -0
- viam/gen/component/generic/v1/__init__.py +0 -0
- viam/gen/component/generic/v1/generic_grpc.py +37 -0
- viam/gen/component/generic/v1/generic_pb2.py +23 -0
- viam/gen/component/generic/v1/generic_pb2.pyi +6 -0
- viam/gen/component/gripper/__init__.py +0 -0
- viam/gen/component/gripper/v1/__init__.py +0 -0
- viam/gen/component/gripper/v1/gripper_grpc.py +70 -0
- viam/gen/component/gripper/v1/gripper_pb2.py +48 -0
- viam/gen/component/gripper/v1/gripper_pb2.pyi +137 -0
- viam/gen/component/inputcontroller/__init__.py +0 -0
- viam/gen/component/inputcontroller/v1/__init__.py +0 -0
- viam/gen/component/inputcontroller/v1/input_controller_grpc.py +71 -0
- viam/gen/component/inputcontroller/v1/input_controller_pb2.py +55 -0
- viam/gen/component/inputcontroller/v1/input_controller_pb2.pyi +243 -0
- viam/gen/component/motor/__init__.py +0 -0
- viam/gen/component/motor/v1/__init__.py +0 -0
- viam/gen/component/motor/v1/motor_grpc.py +118 -0
- viam/gen/component/motor/v1/motor_pb2.py +86 -0
- viam/gen/component/motor/v1/motor_pb2.pyi +368 -0
- viam/gen/component/movementsensor/__init__.py +0 -0
- viam/gen/component/movementsensor/v1/__init__.py +0 -0
- viam/gen/component/movementsensor/v1/movementsensor_grpc.py +110 -0
- viam/gen/component/movementsensor/v1/movementsensor_pb2.py +78 -0
- viam/gen/component/movementsensor/v1/movementsensor_pb2.pyi +384 -0
- viam/gen/component/posetracker/__init__.py +0 -0
- viam/gen/component/posetracker/v1/__init__.py +0 -0
- viam/gen/component/posetracker/v1/pose_tracker_grpc.py +46 -0
- viam/gen/component/posetracker/v1/pose_tracker_pb2.py +34 -0
- viam/gen/component/posetracker/v1/pose_tracker_pb2.pyi +79 -0
- viam/gen/component/powersensor/__init__.py +0 -0
- viam/gen/component/powersensor/v1/__init__.py +0 -0
- viam/gen/component/powersensor/v1/powersensor_grpc.py +62 -0
- viam/gen/component/powersensor/v1/powersensor_pb2.py +42 -0
- viam/gen/component/powersensor/v1/powersensor_pb2.pyi +124 -0
- viam/gen/component/sensor/__init__.py +0 -0
- viam/gen/component/sensor/v1/__init__.py +0 -0
- viam/gen/component/sensor/v1/sensor_grpc.py +45 -0
- viam/gen/component/sensor/v1/sensor_pb2.py +25 -0
- viam/gen/component/sensor/v1/sensor_pb2.pyi +6 -0
- viam/gen/component/servo/__init__.py +0 -0
- viam/gen/component/servo/v1/__init__.py +0 -0
- viam/gen/component/servo/v1/servo_grpc.py +70 -0
- viam/gen/component/servo/v1/servo_pb2.py +50 -0
- viam/gen/component/servo/v1/servo_pb2.pyi +150 -0
- viam/gen/component/switch/__init__.py +0 -0
- viam/gen/component/switch/v1/__init__.py +0 -0
- viam/gen/component/switch/v1/switch_grpc.py +54 -0
- viam/gen/component/switch/v1/switch_pb2.py +40 -0
- viam/gen/component/switch/v1/switch_pb2.pyi +109 -0
- viam/gen/component/testecho/__init__.py +0 -0
- viam/gen/component/testecho/v1/__init__.py +0 -0
- viam/gen/component/testecho/v1/testecho_grpc.py +52 -0
- viam/gen/component/testecho/v1/testecho_pb2.py +36 -0
- viam/gen/component/testecho/v1/testecho_pb2.pyi +114 -0
- viam/gen/module/__init__.py +0 -0
- viam/gen/module/v1/__init__.py +0 -0
- viam/gen/module/v1/module_grpc.py +61 -0
- viam/gen/module/v1/module_pb2.py +43 -0
- viam/gen/module/v1/module_pb2.pyi +211 -0
- viam/gen/proto/__init__.py +0 -0
- viam/gen/proto/rpc/__init__.py +0 -0
- viam/gen/proto/rpc/examples/__init__.py +0 -0
- viam/gen/proto/rpc/examples/echo/__init__.py +0 -0
- viam/gen/proto/rpc/examples/echo/v1/__init__.py +0 -0
- viam/gen/proto/rpc/examples/echo/v1/echo_grpc.py +44 -0
- viam/gen/proto/rpc/examples/echo/v1/echo_pb2.py +32 -0
- viam/gen/proto/rpc/examples/echo/v1/echo_pb2.pyi +87 -0
- viam/gen/proto/rpc/examples/echoresource/__init__.py +0 -0
- viam/gen/proto/rpc/examples/echoresource/v1/__init__.py +0 -0
- viam/gen/proto/rpc/examples/echoresource/v1/echoresource_grpc.py +43 -0
- viam/gen/proto/rpc/examples/echoresource/v1/echoresource_pb2.py +29 -0
- viam/gen/proto/rpc/examples/echoresource/v1/echoresource_pb2.pyi +93 -0
- viam/gen/proto/rpc/v1/__init__.py +0 -0
- viam/gen/proto/rpc/v1/auth_grpc.py +47 -0
- viam/gen/proto/rpc/v1/auth_pb2.py +34 -0
- viam/gen/proto/rpc/v1/auth_pb2.pyi +92 -0
- viam/gen/proto/rpc/webrtc/__init__.py +0 -0
- viam/gen/proto/rpc/webrtc/v1/__init__.py +0 -0
- viam/gen/proto/rpc/webrtc/v1/grpc_grpc.py +0 -0
- viam/gen/proto/rpc/webrtc/v1/grpc_pb2.py +43 -0
- viam/gen/proto/rpc/webrtc/v1/grpc_pb2.pyi +304 -0
- viam/gen/proto/rpc/webrtc/v1/signaling_grpc.py +54 -0
- viam/gen/proto/rpc/webrtc/v1/signaling_pb2.py +70 -0
- viam/gen/proto/rpc/webrtc/v1/signaling_pb2.pyi +496 -0
- viam/gen/provisioning/__init__.py +0 -0
- viam/gen/provisioning/v1/__init__.py +0 -0
- viam/gen/provisioning/v1/provisioning_grpc.py +51 -0
- viam/gen/provisioning/v1/provisioning_pb2.py +39 -0
- viam/gen/provisioning/v1/provisioning_pb2.pyi +188 -0
- viam/gen/robot/__init__.py +0 -0
- viam/gen/robot/v1/__init__.py +0 -0
- viam/gen/robot/v1/robot_grpc.py +208 -0
- viam/gen/robot/v1/robot_pb2.py +188 -0
- viam/gen/robot/v1/robot_pb2.pyi +1020 -0
- viam/gen/service/__init__.py +0 -0
- viam/gen/service/datamanager/__init__.py +0 -0
- viam/gen/service/datamanager/v1/__init__.py +0 -0
- viam/gen/service/datamanager/v1/data_manager_grpc.py +38 -0
- viam/gen/service/datamanager/v1/data_manager_pb2.py +28 -0
- viam/gen/service/datamanager/v1/data_manager_pb2.pyi +39 -0
- viam/gen/service/discovery/__init__.py +0 -0
- viam/gen/service/discovery/v1/__init__.py +0 -0
- viam/gen/service/discovery/v1/discovery_grpc.py +39 -0
- viam/gen/service/discovery/v1/discovery_pb2.py +29 -0
- viam/gen/service/discovery/v1/discovery_pb2.pyi +51 -0
- viam/gen/service/generic/__init__.py +0 -0
- viam/gen/service/generic/v1/__init__.py +0 -0
- viam/gen/service/generic/v1/generic_grpc.py +29 -0
- viam/gen/service/generic/v1/generic_pb2.py +21 -0
- viam/gen/service/generic/v1/generic_pb2.pyi +6 -0
- viam/gen/service/mlmodel/__init__.py +0 -0
- viam/gen/service/mlmodel/v1/__init__.py +0 -0
- viam/gen/service/mlmodel/v1/mlmodel_grpc.py +37 -0
- viam/gen/service/mlmodel/v1/mlmodel_pb2.py +83 -0
- viam/gen/service/mlmodel/v1/mlmodel_pb2.pyi +480 -0
- viam/gen/service/motion/__init__.py +0 -0
- viam/gen/service/motion/v1/__init__.py +0 -0
- viam/gen/service/motion/v1/motion_grpc.py +87 -0
- viam/gen/service/motion/v1/motion_pb2.py +97 -0
- viam/gen/service/motion/v1/motion_pb2.pyi +838 -0
- viam/gen/service/navigation/__init__.py +0 -0
- viam/gen/service/navigation/v1/__init__.py +0 -0
- viam/gen/service/navigation/v1/navigation_grpc.py +102 -0
- viam/gen/service/navigation/v1/navigation_pb2.py +84 -0
- viam/gen/service/navigation/v1/navigation_pb2.pyi +419 -0
- viam/gen/service/sensors/__init__.py +0 -0
- viam/gen/service/sensors/v1/__init__.py +0 -0
- viam/gen/service/sensors/v1/sensors_grpc.py +46 -0
- viam/gen/service/sensors/v1/sensors_pb2.py +68 -0
- viam/gen/service/sensors/v1/sensors_pb2.pyi +137 -0
- viam/gen/service/shell/__init__.py +0 -0
- viam/gen/service/shell/v1/__init__.py +0 -0
- viam/gen/service/shell/v1/shell_grpc.py +55 -0
- viam/gen/service/shell/v1/shell_pb2.py +45 -0
- viam/gen/service/shell/v1/shell_pb2.pyi +307 -0
- viam/gen/service/slam/__init__.py +0 -0
- viam/gen/service/slam/v1/__init__.py +0 -0
- viam/gen/service/slam/v1/slam_grpc.py +61 -0
- viam/gen/service/slam/v1/slam_pb2.py +51 -0
- viam/gen/service/slam/v1/slam_pb2.pyi +213 -0
- viam/gen/service/vision/__init__.py +0 -0
- viam/gen/service/vision/v1/__init__.py +0 -0
- viam/gen/service/vision/v1/vision_grpc.py +87 -0
- viam/gen/service/vision/v1/vision_pb2.py +69 -0
- viam/gen/service/vision/v1/vision_pb2.pyi +454 -0
- viam/gen/stream/__init__.py +0 -0
- viam/gen/stream/v1/__init__.py +0 -0
- viam/gen/stream/v1/stream_grpc.py +59 -0
- viam/gen/stream/v1/stream_pb2.py +39 -0
- viam/gen/stream/v1/stream_pb2.pyi +161 -0
- viam/gen/tagger/__init__.py +0 -0
- viam/gen/tagger/v1/__init__.py +0 -0
- viam/gen/tagger/v1/tagger_grpc.py +0 -0
- viam/gen/tagger/v1/tagger_pb2.py +16 -0
- viam/gen/tagger/v1/tagger_pb2.pyi +15 -0
- viam/logging.py +216 -0
- viam/media/__init__.py +0 -0
- viam/media/audio.py +16 -0
- viam/media/utils/__init__.py +0 -0
- viam/media/utils/pil/__init__.py +51 -0
- viam/media/utils/pil/viam_rgba_plugin.py +73 -0
- viam/media/viam_rgba.py +10 -0
- viam/media/video.py +217 -0
- viam/module/__init__.py +5 -0
- viam/module/module.py +281 -0
- viam/module/service.py +66 -0
- viam/module/types.py +23 -0
- viam/operations.py +124 -0
- viam/proto/__init__.py +0 -0
- viam/proto/app/__init__.py +554 -0
- viam/proto/app/agent/__init__.py +28 -0
- viam/proto/app/billing.py +58 -0
- viam/proto/app/cloudslam/__init__.py +48 -0
- viam/proto/app/data/__init__.py +138 -0
- viam/proto/app/datapipelines/__init__.py +56 -0
- viam/proto/app/dataset/__init__.py +36 -0
- viam/proto/app/datasync/__init__.py +44 -0
- viam/proto/app/end_user.py +34 -0
- viam/proto/app/mlinference/__init__.py +15 -0
- viam/proto/app/mltraining/__init__.py +52 -0
- viam/proto/app/packages/__init__.py +38 -0
- viam/proto/app/robot.py +84 -0
- viam/proto/common/__init__.py +66 -0
- viam/proto/component/__init__.py +0 -0
- viam/proto/component/arm/__init__.py +48 -0
- viam/proto/component/audioinput/__init__.py +30 -0
- viam/proto/component/base/__init__.py +42 -0
- viam/proto/component/board/__init__.py +62 -0
- viam/proto/component/button/__init__.py +15 -0
- viam/proto/component/camera/__init__.py +46 -0
- viam/proto/component/encoder/__init__.py +28 -0
- viam/proto/component/gantry/__init__.py +40 -0
- viam/proto/component/generic/__init__.py +12 -0
- viam/proto/component/gripper/__init__.py +30 -0
- viam/proto/component/inputcontroller/__init__.py +38 -0
- viam/proto/component/motor/__init__.py +56 -0
- viam/proto/component/movementsensor/__init__.py +50 -0
- viam/proto/component/posetracker/__init__.py +19 -0
- viam/proto/component/powersensor/__init__.py +30 -0
- viam/proto/component/sensor/__init__.py +12 -0
- viam/proto/component/servo/__init__.py +32 -0
- viam/proto/component/switch/__init__.py +26 -0
- viam/proto/component/testecho/__init__.py +30 -0
- viam/proto/module/__init__.py +38 -0
- viam/proto/provisioning/__init__.py +36 -0
- viam/proto/robot/__init__.py +130 -0
- viam/proto/rpc/__init__.py +0 -0
- viam/proto/rpc/auth.py +34 -0
- viam/proto/rpc/examples/__init__.py +0 -0
- viam/proto/rpc/examples/echo/__init__.py +26 -0
- viam/proto/rpc/examples/echoresource/__init__.py +30 -0
- viam/proto/rpc/webrtc/__init__.py +0 -0
- viam/proto/rpc/webrtc/grpc.py +36 -0
- viam/proto/rpc/webrtc/signaling.py +58 -0
- viam/proto/service/__init__.py +0 -0
- viam/proto/service/datamanager/__init__.py +19 -0
- viam/proto/service/discovery/__init__.py +15 -0
- viam/proto/service/generic/__init__.py +12 -0
- viam/proto/service/mlmodel/__init__.py +54 -0
- viam/proto/service/motion/__init__.py +68 -0
- viam/proto/service/navigation/__init__.py +58 -0
- viam/proto/service/sensors/__init__.py +18 -0
- viam/proto/service/shell/__init__.py +36 -0
- viam/proto/service/slam/__init__.py +36 -0
- viam/proto/service/vision/__init__.py +46 -0
- viam/proto/stream/__init__.py +36 -0
- viam/proto/tagger/__init__.py +6 -0
- viam/py.typed +0 -0
- viam/resource/__init__.py +0 -0
- viam/resource/base.py +123 -0
- viam/resource/easy_resource.py +153 -0
- viam/resource/manager.py +126 -0
- viam/resource/registry.py +199 -0
- viam/resource/rpc_client_base.py +65 -0
- viam/resource/rpc_service_base.py +48 -0
- viam/resource/types.py +213 -0
- viam/robot/__init__.py +0 -0
- viam/robot/client.py +909 -0
- viam/robot/service.py +69 -0
- viam/rpc/__init__.py +0 -0
- viam/rpc/dial.py +420 -0
- viam/rpc/libviam_rust_utils.dll +0 -0
- viam/rpc/server.py +201 -0
- viam/rpc/signaling.py +29 -0
- viam/rpc/types.py +22 -0
- viam/services/__init__.py +0 -0
- viam/services/discovery/__init__.py +12 -0
- viam/services/discovery/client.py +55 -0
- viam/services/discovery/discovery.py +52 -0
- viam/services/discovery/service.py +43 -0
- viam/services/generic/__init__.py +18 -0
- viam/services/generic/client.py +58 -0
- viam/services/generic/generic.py +58 -0
- viam/services/generic/service.py +29 -0
- viam/services/mlmodel/__init__.py +24 -0
- viam/services/mlmodel/client.py +37 -0
- viam/services/mlmodel/mlmodel.py +78 -0
- viam/services/mlmodel/service.py +38 -0
- viam/services/mlmodel/utils.py +101 -0
- viam/services/motion/__init__.py +17 -0
- viam/services/motion/client.py +215 -0
- viam/services/motion/motion.py +378 -0
- viam/services/motion/service.py +132 -0
- viam/services/navigation/__init__.py +11 -0
- viam/services/navigation/client.py +99 -0
- viam/services/navigation/navigation.py +250 -0
- viam/services/navigation/service.py +137 -0
- viam/services/service_base.py +78 -0
- viam/services/service_client_base.py +46 -0
- viam/services/slam/__init__.py +17 -0
- viam/services/slam/client.py +62 -0
- viam/services/slam/service.py +75 -0
- viam/services/slam/slam.py +111 -0
- viam/services/vision/__init__.py +15 -0
- viam/services/vision/client.py +206 -0
- viam/services/vision/service.py +146 -0
- viam/services/vision/vision.py +315 -0
- viam/sessions_client.py +245 -0
- viam/streams.py +44 -0
- viam/utils.py +365 -0
- viam/version_metadata.py +4 -0
- viam_sdk-0.45.2.dist-info/METADATA +157 -0
- viam_sdk-0.45.2.dist-info/RECORD +476 -0
- viam_sdk-0.45.2.dist-info/WHEEL +4 -0
- viam_sdk-0.45.2.dist-info/licenses/LICENSE +202 -0
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
from grpclib.server import Stream
|
|
2
|
+
|
|
3
|
+
from viam.proto.common import DoCommandRequest, DoCommandResponse, GetGeometriesRequest, GetGeometriesResponse
|
|
4
|
+
from viam.proto.component.gripper import (
|
|
5
|
+
GrabRequest,
|
|
6
|
+
GrabResponse,
|
|
7
|
+
GripperServiceBase,
|
|
8
|
+
IsMovingRequest,
|
|
9
|
+
IsMovingResponse,
|
|
10
|
+
OpenRequest,
|
|
11
|
+
OpenResponse,
|
|
12
|
+
StopRequest,
|
|
13
|
+
StopResponse,
|
|
14
|
+
)
|
|
15
|
+
from viam.resource.rpc_service_base import ResourceRPCServiceBase
|
|
16
|
+
from viam.utils import dict_to_struct, struct_to_dict
|
|
17
|
+
|
|
18
|
+
from .gripper import Gripper
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
class GripperRPCService(GripperServiceBase, ResourceRPCServiceBase[Gripper]):
|
|
22
|
+
"""
|
|
23
|
+
gRPC Service for a Gripper
|
|
24
|
+
"""
|
|
25
|
+
|
|
26
|
+
RESOURCE_TYPE = Gripper
|
|
27
|
+
|
|
28
|
+
async def Open(self, stream: Stream[OpenRequest, OpenResponse]) -> None:
|
|
29
|
+
request = await stream.recv_message()
|
|
30
|
+
assert request is not None
|
|
31
|
+
name = request.name
|
|
32
|
+
gripper = self.get_resource(name)
|
|
33
|
+
timeout = stream.deadline.time_remaining() if stream.deadline else None
|
|
34
|
+
await gripper.open(extra=struct_to_dict(request.extra), timeout=timeout, metadata=stream.metadata)
|
|
35
|
+
response = OpenResponse()
|
|
36
|
+
await stream.send_message(response)
|
|
37
|
+
|
|
38
|
+
async def Grab(self, stream: Stream[GrabRequest, GrabResponse]) -> None:
|
|
39
|
+
request = await stream.recv_message()
|
|
40
|
+
assert request is not None
|
|
41
|
+
name = request.name
|
|
42
|
+
gripper = self.get_resource(name)
|
|
43
|
+
timeout = stream.deadline.time_remaining() if stream.deadline else None
|
|
44
|
+
grabbed = await gripper.grab(extra=struct_to_dict(request.extra), timeout=timeout, metadata=stream.metadata)
|
|
45
|
+
response = GrabResponse(success=grabbed)
|
|
46
|
+
await stream.send_message(response)
|
|
47
|
+
|
|
48
|
+
async def Stop(self, stream: Stream[StopRequest, StopResponse]) -> None:
|
|
49
|
+
request = await stream.recv_message()
|
|
50
|
+
assert request is not None
|
|
51
|
+
gripper = self.get_resource(request.name)
|
|
52
|
+
timeout = stream.deadline.time_remaining() if stream.deadline else None
|
|
53
|
+
await gripper.stop(extra=struct_to_dict(request.extra), timeout=timeout, metadata=stream.metadata)
|
|
54
|
+
await stream.send_message(StopResponse())
|
|
55
|
+
|
|
56
|
+
async def IsMoving(self, stream: Stream[IsMovingRequest, IsMovingResponse]) -> None:
|
|
57
|
+
request = await stream.recv_message()
|
|
58
|
+
assert request is not None
|
|
59
|
+
name = request.name
|
|
60
|
+
gripper = self.get_resource(name)
|
|
61
|
+
is_moving = await gripper.is_moving()
|
|
62
|
+
response = IsMovingResponse(is_moving=is_moving)
|
|
63
|
+
await stream.send_message(response)
|
|
64
|
+
|
|
65
|
+
async def DoCommand(self, stream: Stream[DoCommandRequest, DoCommandResponse]) -> None:
|
|
66
|
+
request = await stream.recv_message()
|
|
67
|
+
assert request is not None
|
|
68
|
+
gripper = self.get_resource(request.name)
|
|
69
|
+
timeout = stream.deadline.time_remaining() if stream.deadline else None
|
|
70
|
+
result = await gripper.do_command(command=struct_to_dict(request.command), timeout=timeout, metadata=stream.metadata)
|
|
71
|
+
response = DoCommandResponse(result=dict_to_struct(result))
|
|
72
|
+
await stream.send_message(response)
|
|
73
|
+
|
|
74
|
+
async def GetGeometries(self, stream: Stream[GetGeometriesRequest, GetGeometriesResponse]) -> None:
|
|
75
|
+
request = await stream.recv_message()
|
|
76
|
+
assert request is not None
|
|
77
|
+
arm = self.get_resource(request.name)
|
|
78
|
+
timeout = stream.deadline.time_remaining() if stream.deadline else None
|
|
79
|
+
geometries = await arm.get_geometries(extra=struct_to_dict(request.extra), timeout=timeout)
|
|
80
|
+
response = GetGeometriesResponse(geometries=geometries)
|
|
81
|
+
await stream.send_message(response)
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
from viam.resource.registry import Registry, ResourceRegistration
|
|
2
|
+
|
|
3
|
+
from .client import ControllerClient
|
|
4
|
+
from .input import Control, ControlFunction, Controller, Event, EventType
|
|
5
|
+
from .service import InputControllerRPCService
|
|
6
|
+
|
|
7
|
+
__all__ = [
|
|
8
|
+
"Controller",
|
|
9
|
+
"Control",
|
|
10
|
+
"ControlFunction",
|
|
11
|
+
"Event",
|
|
12
|
+
"EventType",
|
|
13
|
+
]
|
|
14
|
+
|
|
15
|
+
Registry.register_api(ResourceRegistration(Controller, InputControllerRPCService, lambda name, channel: ControllerClient(name, channel)))
|
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
import asyncio
|
|
2
|
+
from threading import Lock, RLock
|
|
3
|
+
from time import time
|
|
4
|
+
from typing import Any, Dict, List, Mapping, Optional
|
|
5
|
+
|
|
6
|
+
from google.protobuf.struct_pb2 import Struct
|
|
7
|
+
from grpclib import GRPCError, Status
|
|
8
|
+
from grpclib.client import Channel
|
|
9
|
+
|
|
10
|
+
import viam
|
|
11
|
+
from viam.errors import NotSupportedError
|
|
12
|
+
from viam.logging import getLogger
|
|
13
|
+
from viam.proto.common import DoCommandRequest, DoCommandResponse, Geometry
|
|
14
|
+
from viam.proto.component.inputcontroller import (
|
|
15
|
+
GetControlsRequest,
|
|
16
|
+
GetControlsResponse,
|
|
17
|
+
GetEventsRequest,
|
|
18
|
+
GetEventsResponse,
|
|
19
|
+
InputControllerServiceStub,
|
|
20
|
+
StreamEventsRequest,
|
|
21
|
+
StreamEventsResponse,
|
|
22
|
+
TriggerEventRequest,
|
|
23
|
+
)
|
|
24
|
+
from viam.resource.rpc_client_base import ReconfigurableResourceRPCClientBase, ResourceRPCClientBase
|
|
25
|
+
from viam.utils import ValueTypes, dict_to_struct, get_geometries, struct_to_dict
|
|
26
|
+
|
|
27
|
+
from .input import Control, ControlFunction, Controller, Event, EventType
|
|
28
|
+
|
|
29
|
+
LOGGER = getLogger(__name__)
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
class ControllerClient(Controller, ReconfigurableResourceRPCClientBase):
|
|
33
|
+
"""gRPC client for an Input Controller"""
|
|
34
|
+
|
|
35
|
+
def __init__(self, name: str, channel: Channel):
|
|
36
|
+
self.channel = channel
|
|
37
|
+
self.client = InputControllerServiceStub(channel)
|
|
38
|
+
self.callbacks: Dict[Control, Dict[EventType, Optional[ControlFunction]]] = {}
|
|
39
|
+
self._lock = RLock()
|
|
40
|
+
self._stream_lock = Lock()
|
|
41
|
+
self._is_streaming = False
|
|
42
|
+
self._is_stream_ready = False
|
|
43
|
+
self._callback_extra: Struct = dict_to_struct({})
|
|
44
|
+
super().__init__(name)
|
|
45
|
+
|
|
46
|
+
async def get_controls(
|
|
47
|
+
self,
|
|
48
|
+
*,
|
|
49
|
+
extra: Optional[Dict[str, Any]] = None,
|
|
50
|
+
timeout: Optional[float] = None,
|
|
51
|
+
**kwargs,
|
|
52
|
+
) -> List[Control]:
|
|
53
|
+
md = kwargs.get("metadata", self.Metadata()).proto
|
|
54
|
+
request = GetControlsRequest(controller=self.name, extra=dict_to_struct(extra))
|
|
55
|
+
response: GetControlsResponse = await self.client.GetControls(request, timeout=timeout, metadata=md)
|
|
56
|
+
return [Control(control) for control in response.controls]
|
|
57
|
+
|
|
58
|
+
async def get_events(
|
|
59
|
+
self,
|
|
60
|
+
*,
|
|
61
|
+
extra: Optional[Dict[str, Any]] = None,
|
|
62
|
+
timeout: Optional[float] = None,
|
|
63
|
+
**kwargs,
|
|
64
|
+
) -> Dict[Control, Event]:
|
|
65
|
+
md = kwargs.get("metadata", self.Metadata()).proto
|
|
66
|
+
request = GetEventsRequest(controller=self.name, extra=dict_to_struct(extra))
|
|
67
|
+
response: GetEventsResponse = await self.client.GetEvents(request, timeout=timeout, metadata=md)
|
|
68
|
+
return {Control(event.control): Event.from_proto(event) for (event) in response.events}
|
|
69
|
+
|
|
70
|
+
def register_control_callback(
|
|
71
|
+
self,
|
|
72
|
+
control: Control,
|
|
73
|
+
triggers: List[EventType],
|
|
74
|
+
function: Optional[ControlFunction],
|
|
75
|
+
extra: Optional[Dict[str, Any]] = None,
|
|
76
|
+
**kwargs,
|
|
77
|
+
):
|
|
78
|
+
md = kwargs.get("metadata", self.Metadata())
|
|
79
|
+
self._callback_extra = dict_to_struct(extra)
|
|
80
|
+
with self._lock:
|
|
81
|
+
callbacks = self.callbacks.get(control, {})
|
|
82
|
+
for trigger in triggers:
|
|
83
|
+
if trigger == EventType.BUTTON_CHANGE:
|
|
84
|
+
callbacks[EventType.BUTTON_PRESS] = function
|
|
85
|
+
callbacks[EventType.BUTTON_RELEASE] = function
|
|
86
|
+
else:
|
|
87
|
+
callbacks[trigger] = function
|
|
88
|
+
self.callbacks[control] = callbacks
|
|
89
|
+
|
|
90
|
+
def handle_task_result(task: asyncio.Task):
|
|
91
|
+
try:
|
|
92
|
+
result = task.result()
|
|
93
|
+
LOGGER.debug(f"Task {task.get_name()} returned with result {result}")
|
|
94
|
+
except asyncio.CancelledError:
|
|
95
|
+
pass
|
|
96
|
+
except Exception:
|
|
97
|
+
LOGGER.exception("Exception raised by task = %r", task)
|
|
98
|
+
|
|
99
|
+
task = asyncio.create_task(self._stream_events(md), name=f"{viam._TASK_PREFIX}-input_stream_events")
|
|
100
|
+
task.add_done_callback(handle_task_result)
|
|
101
|
+
|
|
102
|
+
def reset_channel(self, channel: Channel):
|
|
103
|
+
super().reset_channel(channel)
|
|
104
|
+
with self._lock:
|
|
105
|
+
for control, callback in self.callbacks.items():
|
|
106
|
+
for event_type, func in callback.items():
|
|
107
|
+
self.register_control_callback(control, [event_type], func)
|
|
108
|
+
|
|
109
|
+
async def trigger_event(
|
|
110
|
+
self,
|
|
111
|
+
event: Event,
|
|
112
|
+
*,
|
|
113
|
+
extra: Optional[Dict[str, Any]] = None,
|
|
114
|
+
timeout: Optional[float] = None,
|
|
115
|
+
**kwargs,
|
|
116
|
+
):
|
|
117
|
+
md = kwargs.get("metadata", self.Metadata()).proto
|
|
118
|
+
request = TriggerEventRequest(controller=self.name, event=event.proto, extra=dict_to_struct(extra))
|
|
119
|
+
try:
|
|
120
|
+
await self.client.TriggerEvent(request, timeout=timeout, metadata=md)
|
|
121
|
+
except GRPCError as e:
|
|
122
|
+
if e.status == Status.UNIMPLEMENTED and ("does not support triggering events" in e.message if e.message else False):
|
|
123
|
+
raise NotSupportedError(f"Input controller named {self.name} does not support triggering events")
|
|
124
|
+
raise e
|
|
125
|
+
|
|
126
|
+
async def _stream_events(self, metadata: ResourceRPCClientBase.Metadata):
|
|
127
|
+
with self._stream_lock:
|
|
128
|
+
if self._is_streaming:
|
|
129
|
+
return
|
|
130
|
+
self._is_streaming = True
|
|
131
|
+
|
|
132
|
+
if not self.callbacks:
|
|
133
|
+
return
|
|
134
|
+
|
|
135
|
+
md = metadata.proto
|
|
136
|
+
request = StreamEventsRequest(controller=self.name, events=[], extra=self._callback_extra)
|
|
137
|
+
with self._lock:
|
|
138
|
+
for control, callbacks in self.callbacks.items():
|
|
139
|
+
event = StreamEventsRequest.Events(
|
|
140
|
+
control=control,
|
|
141
|
+
events=[et for (et, func) in callbacks.items() if func is not None],
|
|
142
|
+
cancelled_events=[et for (et, func) in callbacks.items() if func is None],
|
|
143
|
+
)
|
|
144
|
+
request.events.append(event)
|
|
145
|
+
|
|
146
|
+
try:
|
|
147
|
+
async with self.client.StreamEvents.open(metadata=md) as stream:
|
|
148
|
+
await stream.send_message(request, end=True)
|
|
149
|
+
self._send_connection_status(True)
|
|
150
|
+
reply: StreamEventsResponse
|
|
151
|
+
async for reply in stream:
|
|
152
|
+
event = reply.event
|
|
153
|
+
self._execute_callback(Event.from_proto(event))
|
|
154
|
+
except Exception as e:
|
|
155
|
+
LOGGER.error(e)
|
|
156
|
+
finally:
|
|
157
|
+
self._send_connection_status(False)
|
|
158
|
+
with self._stream_lock:
|
|
159
|
+
self._is_streaming = False
|
|
160
|
+
self._is_stream_ready = False
|
|
161
|
+
|
|
162
|
+
def _send_connection_status(self, connected: bool):
|
|
163
|
+
for control in self.callbacks.keys():
|
|
164
|
+
event = Event(time=time(), event=EventType.CONNECT if connected else EventType.DISCONNECT, control=control, value=0)
|
|
165
|
+
self._execute_callback(event)
|
|
166
|
+
|
|
167
|
+
def _execute_callback(self, event: Event):
|
|
168
|
+
try:
|
|
169
|
+
callbacks = self.callbacks[event.control]
|
|
170
|
+
callback = callbacks.get(event.event, None)
|
|
171
|
+
all_callback = callbacks.get(EventType.ALL_EVENTS, None)
|
|
172
|
+
except KeyError:
|
|
173
|
+
return
|
|
174
|
+
|
|
175
|
+
if callback is not None:
|
|
176
|
+
callback(event)
|
|
177
|
+
if all_callback is not None:
|
|
178
|
+
all_callback(event)
|
|
179
|
+
|
|
180
|
+
async def do_command(
|
|
181
|
+
self,
|
|
182
|
+
command: Mapping[str, ValueTypes],
|
|
183
|
+
*,
|
|
184
|
+
timeout: Optional[float] = None,
|
|
185
|
+
**kwargs,
|
|
186
|
+
) -> Mapping[str, ValueTypes]:
|
|
187
|
+
md = kwargs.get("metadata", self.Metadata()).proto
|
|
188
|
+
request = DoCommandRequest(name=self.name, command=dict_to_struct(command))
|
|
189
|
+
response: DoCommandResponse = await self.client.DoCommand(request, timeout=timeout, metadata=md)
|
|
190
|
+
return struct_to_dict(response.result)
|
|
191
|
+
|
|
192
|
+
async def get_geometries(self, *, extra: Optional[Dict[str, Any]] = None, timeout: Optional[float] = None, **kwargs) -> List[Geometry]:
|
|
193
|
+
md = kwargs.get("metadata", self.Metadata())
|
|
194
|
+
return await get_geometries(self.client, self.name, extra, timeout, md)
|
|
@@ -0,0 +1,297 @@
|
|
|
1
|
+
import abc
|
|
2
|
+
from dataclasses import dataclass
|
|
3
|
+
from datetime import datetime
|
|
4
|
+
from enum import Enum
|
|
5
|
+
from typing import Any, Callable, Dict, Final, List, Optional
|
|
6
|
+
|
|
7
|
+
from google.protobuf.timestamp_pb2 import Timestamp
|
|
8
|
+
from typing_extensions import Self
|
|
9
|
+
|
|
10
|
+
from viam.components.component_base import ComponentBase
|
|
11
|
+
from viam.errors import NotSupportedError
|
|
12
|
+
from viam.proto.component.inputcontroller import Event as PBEvent
|
|
13
|
+
from viam.resource.types import API, RESOURCE_NAMESPACE_RDK, RESOURCE_TYPE_COMPONENT
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
class EventType(str, Enum):
|
|
17
|
+
"""
|
|
18
|
+
Represents the type of input event.
|
|
19
|
+
"""
|
|
20
|
+
|
|
21
|
+
ALL_EVENTS = "AllEvents"
|
|
22
|
+
"""
|
|
23
|
+
Callbacks registered for this event will be called in ADDITION to other registered event callbacks.
|
|
24
|
+
"""
|
|
25
|
+
|
|
26
|
+
CONNECT = "Connect"
|
|
27
|
+
"""
|
|
28
|
+
Sent at controller initialization, and on reconnects.
|
|
29
|
+
"""
|
|
30
|
+
|
|
31
|
+
DISCONNECT = "Disconnect"
|
|
32
|
+
"""
|
|
33
|
+
If unplugged, or wireless/network times out.
|
|
34
|
+
"""
|
|
35
|
+
|
|
36
|
+
BUTTON_PRESS = "ButtonPress"
|
|
37
|
+
"""
|
|
38
|
+
Typical key press.
|
|
39
|
+
"""
|
|
40
|
+
|
|
41
|
+
BUTTON_RELEASE = "ButtonRelease"
|
|
42
|
+
"""
|
|
43
|
+
Key release.
|
|
44
|
+
"""
|
|
45
|
+
|
|
46
|
+
BUTTON_HOLD = "ButtonHold"
|
|
47
|
+
"""
|
|
48
|
+
Key is held down. This wil likely be a repeated event.
|
|
49
|
+
"""
|
|
50
|
+
|
|
51
|
+
BUTTON_CHANGE = "ButtonChange"
|
|
52
|
+
"""
|
|
53
|
+
Both up and down for convenience during registration, not typically emitted.
|
|
54
|
+
"""
|
|
55
|
+
|
|
56
|
+
POSITION_CHANGE_ABSOLUTE = "PositionChangeAbs"
|
|
57
|
+
"""
|
|
58
|
+
Absolute position is reported via Value, a la joysticks.
|
|
59
|
+
"""
|
|
60
|
+
|
|
61
|
+
POSITION_CHANGE_RELATIVE = "PositionChangeRel"
|
|
62
|
+
"""
|
|
63
|
+
Relative position is reported via Value, a la mice, or simulating axes with up/down buttons.
|
|
64
|
+
"""
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
class Control(str, Enum):
|
|
68
|
+
"""
|
|
69
|
+
Control identifies the input (specific Axis or Button) of a controller.
|
|
70
|
+
"""
|
|
71
|
+
|
|
72
|
+
# Axes
|
|
73
|
+
ABSOLUTE_X = "AbsoluteX"
|
|
74
|
+
ABSOLUTE_Y = "AbsoluteY"
|
|
75
|
+
ABSOLUTE_Z = "AbsoluteZ"
|
|
76
|
+
ABSOLUTE_RX = "AbsoluteRX"
|
|
77
|
+
ABSOLUTE_RY = "AbsoluteRY"
|
|
78
|
+
ABSOLUTE_RZ = "AbsoluteRZ"
|
|
79
|
+
ABSOLUTE_HAT0_X = "AbsoluteHat0X"
|
|
80
|
+
ABSOLUTE_HAT0_Y = "AbsoluteHat0Y"
|
|
81
|
+
|
|
82
|
+
# Buttons
|
|
83
|
+
BUTTON_SOUTH = "ButtonSouth"
|
|
84
|
+
BUTTON_EAST = "ButtonEast"
|
|
85
|
+
BUTTON_WEST = "ButtonWest"
|
|
86
|
+
BUTTON_NORTH = "ButtonNorth"
|
|
87
|
+
BUTTON_LT = "ButtonLT"
|
|
88
|
+
BUTTON_RT = "ButtonRT"
|
|
89
|
+
BUTTON_LT2 = "ButtonLT2"
|
|
90
|
+
BUTTON_RT2 = "ButtonRT2"
|
|
91
|
+
BUTTON_L_THUMB = "ButtonLThumb"
|
|
92
|
+
BUTTON_R_THUMB = "ButtonRThumb"
|
|
93
|
+
BUTTON_SELECT = "ButtonSelect"
|
|
94
|
+
BUTTON_START = "ButtonStart"
|
|
95
|
+
BUTTON_MENU = "ButtonMenu"
|
|
96
|
+
BUTTON_RECORD = "ButtonRecord"
|
|
97
|
+
BUTTON_E_STOP = "ButtonEStop"
|
|
98
|
+
|
|
99
|
+
# Pedals
|
|
100
|
+
ABSOLUTE_PEDAL_ACCELERATOR = "AbsolutePedalAccelerator"
|
|
101
|
+
ABSOLUTE_PEDAL_BRAKE = "AbsolutePedalBrake"
|
|
102
|
+
ABSOLUTE_PEDAL_CLUTCH = "AbsolutePedalClutch"
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
@dataclass
|
|
106
|
+
class Event:
|
|
107
|
+
time: float
|
|
108
|
+
"""seconds since epoch"""
|
|
109
|
+
|
|
110
|
+
event: EventType
|
|
111
|
+
|
|
112
|
+
control: Control
|
|
113
|
+
|
|
114
|
+
value: float
|
|
115
|
+
"""0 or 1 for buttons, -1.0 to +1.0 for axes"""
|
|
116
|
+
|
|
117
|
+
@property
|
|
118
|
+
def proto(self):
|
|
119
|
+
dt = datetime.fromtimestamp(self.time)
|
|
120
|
+
timestamp = Timestamp()
|
|
121
|
+
timestamp.FromDatetime(dt)
|
|
122
|
+
return PBEvent(time=timestamp, event=self.event.value, control=self.control.value, value=self.value)
|
|
123
|
+
|
|
124
|
+
@classmethod
|
|
125
|
+
def from_proto(cls, proto: PBEvent) -> Self:
|
|
126
|
+
dt = proto.time.ToDatetime()
|
|
127
|
+
return cls(dt.timestamp(), EventType(proto.event), Control(proto.control), proto.value)
|
|
128
|
+
|
|
129
|
+
|
|
130
|
+
ControlFunction = Callable[[Event], None]
|
|
131
|
+
|
|
132
|
+
|
|
133
|
+
class Controller(ComponentBase):
|
|
134
|
+
"""
|
|
135
|
+
Controller is a logical "container" more than an actual device
|
|
136
|
+
Could be a single gamepad, or a collection of digitalInterrupts
|
|
137
|
+
and analogReaders, a keyboard, etc.
|
|
138
|
+
|
|
139
|
+
::
|
|
140
|
+
|
|
141
|
+
from viam.components.input import Control, Controller, EventType
|
|
142
|
+
|
|
143
|
+
For more information, see `Input Controller component <https://docs.viam.com/dev/reference/apis/components/input-controller/>`_.
|
|
144
|
+
"""
|
|
145
|
+
|
|
146
|
+
API: Final = API( # pyright: ignore [reportIncompatibleVariableOverride]
|
|
147
|
+
RESOURCE_NAMESPACE_RDK, RESOURCE_TYPE_COMPONENT, "input_controller"
|
|
148
|
+
)
|
|
149
|
+
|
|
150
|
+
@abc.abstractmethod
|
|
151
|
+
async def get_controls(self, *, extra: Optional[Dict[str, Any]] = None, timeout: Optional[float] = None, **kwargs) -> List[Control]:
|
|
152
|
+
"""
|
|
153
|
+
Returns a list of Controls provided by the Controller
|
|
154
|
+
|
|
155
|
+
::
|
|
156
|
+
|
|
157
|
+
# Get the controller from the machine.
|
|
158
|
+
my_controller = Controller.from_robot(
|
|
159
|
+
robot=machine, "my_controller")
|
|
160
|
+
|
|
161
|
+
# Get the list of Controls provided by the controller.
|
|
162
|
+
controls = await my_controller.get_controls()
|
|
163
|
+
|
|
164
|
+
# Print the list of Controls provided by the controller.
|
|
165
|
+
print(f"Controls: {controls}")
|
|
166
|
+
|
|
167
|
+
Returns:
|
|
168
|
+
List[Control]: List of controls provided by the Controller
|
|
169
|
+
|
|
170
|
+
For more information, see `Input Controller component <https://docs.viam.com/dev/reference/apis/components/input-controller/#getcontrols>`_.
|
|
171
|
+
"""
|
|
172
|
+
...
|
|
173
|
+
|
|
174
|
+
@abc.abstractmethod
|
|
175
|
+
async def get_events(
|
|
176
|
+
self, *, extra: Optional[Dict[str, Any]] = None, timeout: Optional[float] = None, **kwargs
|
|
177
|
+
) -> Dict[Control, Event]:
|
|
178
|
+
"""
|
|
179
|
+
Returns the most recent Event for each input
|
|
180
|
+
(which should be the current state)
|
|
181
|
+
|
|
182
|
+
::
|
|
183
|
+
|
|
184
|
+
# Get the controller from the machine.
|
|
185
|
+
my_controller = Controller.from_robot(
|
|
186
|
+
robot=machine, "my_controller")
|
|
187
|
+
|
|
188
|
+
# Get the most recent Event for each Control.
|
|
189
|
+
recent_events = await my_controller.get_events()
|
|
190
|
+
|
|
191
|
+
# Print out the most recent Event for each Control.
|
|
192
|
+
print(f"Recent Events: {recent_events}")
|
|
193
|
+
|
|
194
|
+
Returns:
|
|
195
|
+
Dict[Control, Event]: The most recent event for each input
|
|
196
|
+
|
|
197
|
+
For more information, see `Input Controller component <https://docs.viam.com/dev/reference/apis/components/input-controller/#getevents>`_.
|
|
198
|
+
"""
|
|
199
|
+
...
|
|
200
|
+
|
|
201
|
+
@abc.abstractmethod
|
|
202
|
+
def register_control_callback(
|
|
203
|
+
self,
|
|
204
|
+
control: Control,
|
|
205
|
+
triggers: List[EventType],
|
|
206
|
+
function: Optional[ControlFunction],
|
|
207
|
+
*,
|
|
208
|
+
extra: Optional[Dict[str, Any]] = None,
|
|
209
|
+
**kwargs,
|
|
210
|
+
):
|
|
211
|
+
"""
|
|
212
|
+
Register a function that will fire on given EventTypes for a given
|
|
213
|
+
Control
|
|
214
|
+
|
|
215
|
+
::
|
|
216
|
+
|
|
217
|
+
from viam.components.input import Control, EventType
|
|
218
|
+
|
|
219
|
+
# Define a function to handle pressing the Start Menu Button "BUTTON_START" on
|
|
220
|
+
# your controller, printing out the start time.
|
|
221
|
+
def print_start_time(event):
|
|
222
|
+
print(f"Start Menu Button was pressed at this time: {event.time}")
|
|
223
|
+
|
|
224
|
+
|
|
225
|
+
# Define a function that handles the controller.
|
|
226
|
+
async def handle_controller(controller):
|
|
227
|
+
# Get the list of Controls on the controller.
|
|
228
|
+
controls = await controller.get_controls()
|
|
229
|
+
|
|
230
|
+
# If the "BUTTON_START" Control is found, register the function
|
|
231
|
+
# print_start_time to fire when "BUTTON_START" has the event "ButtonPress"
|
|
232
|
+
# occur.
|
|
233
|
+
if Control.BUTTON_START in controls:
|
|
234
|
+
controller.register_control_callback(
|
|
235
|
+
Control.BUTTON_START, [EventType.BUTTON_PRESS], print_start_time)
|
|
236
|
+
else:
|
|
237
|
+
print("Oops! Couldn't find the start button control! Is your "
|
|
238
|
+
"controller connected?")
|
|
239
|
+
exit()
|
|
240
|
+
|
|
241
|
+
while True:
|
|
242
|
+
await asyncio.sleep(1.0)
|
|
243
|
+
|
|
244
|
+
|
|
245
|
+
async def main():
|
|
246
|
+
# ... < INSERT CONNECTION CODE FROM MACHINE'S CODE SAMPLE TAB >
|
|
247
|
+
|
|
248
|
+
# Get your controller from the machine.
|
|
249
|
+
my_controller = Controller.from_robot(
|
|
250
|
+
robot=machine, "my_controller")
|
|
251
|
+
|
|
252
|
+
# Run the handleController function.
|
|
253
|
+
await handle_controller(my_controller)
|
|
254
|
+
|
|
255
|
+
# ... < INSERT ANY OTHER CODE FOR MAIN FUNCTION >
|
|
256
|
+
|
|
257
|
+
Args:
|
|
258
|
+
control (Control): The control to register the function for
|
|
259
|
+
triggers (List[EventType]): The events that will
|
|
260
|
+
trigger the function
|
|
261
|
+
function (ControlFunction): The function to run on
|
|
262
|
+
specific triggers
|
|
263
|
+
|
|
264
|
+
For more information, see `Input Controller component <https://docs.viam.com/dev/reference/apis/components/input-controller/#registercontrolcallback>`_.
|
|
265
|
+
"""
|
|
266
|
+
...
|
|
267
|
+
|
|
268
|
+
async def trigger_event(
|
|
269
|
+
self,
|
|
270
|
+
event: Event,
|
|
271
|
+
*,
|
|
272
|
+
extra: Optional[Dict[str, Any]] = None,
|
|
273
|
+
timeout: Optional[float] = None,
|
|
274
|
+
**kwargs,
|
|
275
|
+
) -> None: # Explicitly return None for typechecking, as this is technically a NoReturn default implementation
|
|
276
|
+
"""Directly send an Event (such as a button press) from external code
|
|
277
|
+
|
|
278
|
+
::
|
|
279
|
+
|
|
280
|
+
# Get your controller from the machine.
|
|
281
|
+
my_controller = Controller.from_robot(
|
|
282
|
+
robot=machine, "my_controller")
|
|
283
|
+
|
|
284
|
+
# Define a "Button is Pressed" event for the control BUTTON_START.
|
|
285
|
+
button_is_pressed_event = Event(
|
|
286
|
+
time(), EventType.BUTTON_PRESS, Control.BUTTON_START, 1.0)
|
|
287
|
+
|
|
288
|
+
# Trigger the event on your controller. Set this trigger to timeout if it has
|
|
289
|
+
# not completed in 7 seconds.
|
|
290
|
+
await my_controller.trigger_event(event=button_is_pressed_event, timeout=7.0)
|
|
291
|
+
|
|
292
|
+
Args:
|
|
293
|
+
event (Event): The event to trigger
|
|
294
|
+
|
|
295
|
+
For more information, see `Input Controller component <https://docs.viam.com/dev/reference/apis/components/input-controller/#triggerevent>`_.
|
|
296
|
+
"""
|
|
297
|
+
raise NotSupportedError(f"Input controller named {self.name} does not support triggering events")
|