11import logging
22from contextlib import ExitStack
3- from pathlib import Path
43from time import sleep
54from typing import Annotated , Optional
65
76import pyrealsense2 as rs
87import rcsss
98import rcsss .control .fr3_desk
109import typer
11- from PIL import Image
1210from rcsss .camera .realsense import RealSenseCameraSet
13- from rcsss .config import create_sample_config_yaml , read_config_yaml
1411from rcsss .control .record import PoseList
1512from rcsss .control .utils import load_creds_fr3_desk
1613from rcsss .envs .factories import get_urdf_path
2118main_app = typer .Typer (help = "CLI tool for the Robot Control Stack (RCS)." )
2219
2320
24- @main_app .command ()
25- def sample_config (
26- path : Annotated [
27- str , typer .Option ("-p" , help = "Path to where the default config file should be saved" )
28- ] = "config.yaml" ,
29- ):
30- """Creates a sample yaml config file"""
31- create_sample_config_yaml (path )
32-
33-
3421# REALSENSE CLI
3522realsense_app = typer .Typer ()
3623main_app .add_typer (
@@ -53,52 +40,6 @@ def serials():
5340 logger .info (" %s: %s" , device .product_line , device .serial )
5441
5542
56- @realsense_app .command ()
57- def test (
58- path : Annotated [str , typer .Argument (help = "Path to the config file" )],
59- ):
60- """Tests all configured and connected realsense by saving the current picture."""
61- cfg = read_config_yaml (path )
62- assert cfg .hw .camera_type == "realsense" , "Only realsense cameras are supported for this test."
63- assert cfg .hw .camera_config is not None , "Camera config is not set."
64- assert cfg .hw .camera_config .realsense_config is not None , "Realsense config is not set."
65- cs = RealSenseCameraSet (cfg .hw .camera_config .realsense_config )
66- cs .warm_up ()
67- testdir = Path (cfg .hw .camera_config .realsense_config .record_path )
68- frame_set = cs .poll_frame_set ()
69- for device_str in cfg .hw .camera_config .realsense_config .name_to_identifier :
70- assert device_str in frame_set .frames
71- frame = frame_set .frames [device_str ]
72- if frame .camera .color is not None :
73- im = Image .fromarray (frame .camera .color .data , mode = "RGB" )
74- im .save (testdir / f"test_img_{ device_str } .png" )
75- if frame .camera .depth is not None :
76- im = Image .fromarray (frame .camera .depth .data )
77- im .save (testdir / f"test_depth_{ device_str } .png" )
78- if frame .camera .ir is not None :
79- im = Image .fromarray (frame .camera .ir .data )
80- im .save (testdir / f"test_ir_{ device_str } .png" )
81- if frame .imu is not None :
82- logger .info ("IMU data: %s %s" , frame .imu .accel , frame .imu .gyro )
83-
84-
85- @realsense_app .command ()
86- def test_record (
87- path : Annotated [str , typer .Argument (help = "Path to the config file" )],
88- n_frames : Annotated [int , typer .Argument (help = "Name of the camera that should be tested" )] = 100 ,
89- ):
90- """Tests all configured and connected realsense by saving the current picture."""
91- cfg = read_config_yaml (path )
92- assert cfg .hw .camera_type == "realsense" , "Only realsense cameras are supported for this test."
93- assert cfg .hw .camera_config is not None , "Camera config is not set."
94- assert cfg .hw .camera_config .realsense_config is not None , "Realsense config is not set."
95- cs = RealSenseCameraSet (cfg .hw .camera_config .realsense_config )
96- cs .start (warm_up = True )
97- while cs .buffer_size () < n_frames :
98- sleep (1 / cfg .hw .camera_config .realsense_config .frame_rate )
99- cs .stop ()
100-
101-
10243# FR3 CLI
10344fr3_app = typer .Typer ()
10445main_app .add_typer (
0 commit comments