kachaka_api/
lib.rs

1use futures::stream::Stream;
2use image::DynamicImage;
3use kachaka_api::kachaka_api_client::KachakaApiClient as TonicKachakaApiClient;
4use std::collections::HashMap;
5use tonic::transport::Channel;
6pub mod kachaka_api {
7    tonic::include_proto!("kachaka_api");
8}
9
10pub mod api_impl;
11pub mod conversion;
12pub mod options;
13pub mod shelf_location_resolver;
14pub mod types;
15
16pub use options::StartCommandOptions;
17pub use types::{BatteryInfo, CommandResult, CommandState, KachakaApiError, KachakaError, Pose};
18
19#[derive(Clone)]
20pub struct KachakaApiClient {
21    client: TonicKachakaApiClient<Channel>,
22}
23
24impl KachakaApiClient {
25    pub async fn connect<D>(target: D) -> Result<Self, tonic::transport::Error>
26    where
27        D: std::convert::TryInto<tonic::transport::Endpoint>,
28        D::Error: Into<Box<dyn std::error::Error + Send + Sync>>,
29    {
30        let client = TonicKachakaApiClient::connect(target).await?;
31        Ok(Self { client })
32    }
33
34    // getter api
35    // GetRobotSerialNumber
36    pub async fn get_robot_serial_number(
37        &mut self,
38        cursor: i64,
39    ) -> Result<String, KachakaApiError> {
40        api_impl::get_robot_serial_number(&mut self.client, cursor).await
41    }
42
43    pub async fn get_latest_robot_serial_number(&mut self) -> Result<String, KachakaApiError> {
44        api_impl::get_latest_robot_serial_number(&mut self.client).await
45    }
46
47    pub async fn watch_robot_serial_number(
48        &mut self,
49    ) -> impl Stream<Item = Result<String, KachakaApiError>> {
50        api_impl::watch_robot_serial_number(&mut self.client).await
51    }
52
53    // GetRobotVersion
54    pub async fn get_robot_version(&mut self, cursor: i64) -> Result<String, KachakaApiError> {
55        api_impl::get_robot_version(&mut self.client, cursor).await
56    }
57
58    pub async fn get_latest_robot_version(&mut self) -> Result<String, KachakaApiError> {
59        api_impl::get_latest_robot_version(&mut self.client).await
60    }
61
62    pub async fn watch_robot_version(
63        &mut self,
64    ) -> impl Stream<Item = Result<String, KachakaApiError>> {
65        api_impl::watch_robot_version(&mut self.client).await
66    }
67
68    // GetRobotPose
69    pub async fn get_robot_pose(&mut self, cursor: i64) -> Result<Pose, KachakaApiError> {
70        api_impl::get_robot_pose(&mut self.client, cursor).await
71    }
72
73    pub async fn get_latest_robot_pose(&mut self) -> Result<Pose, KachakaApiError> {
74        api_impl::get_latest_robot_pose(&mut self.client).await
75    }
76
77    pub async fn watch_robot_pose(&mut self) -> impl Stream<Item = Result<Pose, KachakaApiError>> {
78        api_impl::watch_robot_pose(&mut self.client).await
79    }
80
81    // GetBatteryInfo
82    pub async fn get_battery_info(&mut self, cursor: i64) -> Result<BatteryInfo, KachakaApiError> {
83        api_impl::get_battery_info(&mut self.client, cursor).await
84    }
85
86    pub async fn get_latest_battery_info(&mut self) -> Result<BatteryInfo, KachakaApiError> {
87        api_impl::get_latest_battery_info(&mut self.client).await
88    }
89
90    pub async fn watch_battery_info(
91        &mut self,
92    ) -> impl Stream<Item = Result<BatteryInfo, KachakaApiError>> {
93        api_impl::watch_battery_info(&mut self.client).await
94    }
95
96    // GetFrontCameraRosImage
97    pub async fn get_front_camera_ros_image(
98        &mut self,
99        cursor: i64,
100    ) -> Result<DynamicImage, KachakaApiError> {
101        api_impl::get_front_camera_ros_image(&mut self.client, cursor).await
102    }
103
104    pub async fn get_latest_front_camera_ros_image(
105        &mut self,
106    ) -> Result<DynamicImage, KachakaApiError> {
107        api_impl::get_latest_front_camera_ros_image(&mut self.client).await
108    }
109
110    pub async fn watch_front_camera_ros_image(
111        &mut self,
112    ) -> impl Stream<Item = Result<DynamicImage, KachakaApiError>> {
113        api_impl::watch_front_camera_ros_image(&mut self.client).await
114    }
115
116    // GetFrontCameraRosCompressedImage
117    pub async fn get_front_camera_ros_compressed_image(
118        &mut self,
119        cursor: i64,
120    ) -> Result<DynamicImage, KachakaApiError> {
121        api_impl::get_front_camera_ros_compressed_image(&mut self.client, cursor).await
122    }
123
124    pub async fn get_latest_front_camera_ros_compressed_image(
125        &mut self,
126    ) -> Result<DynamicImage, KachakaApiError> {
127        api_impl::get_latest_front_camera_ros_compressed_image(&mut self.client).await
128    }
129
130    pub async fn watch_front_camera_ros_compressed_image(
131        &mut self,
132    ) -> impl Stream<Item = Result<DynamicImage, KachakaApiError>> {
133        api_impl::watch_front_camera_ros_compressed_image(&mut self.client).await
134    }
135
136    // GetBackCameraRosImage
137    pub async fn get_back_camera_ros_image(
138        &mut self,
139        cursor: i64,
140    ) -> Result<DynamicImage, KachakaApiError> {
141        api_impl::get_back_camera_ros_image(&mut self.client, cursor).await
142    }
143
144    pub async fn get_latest_back_camera_ros_image(
145        &mut self,
146    ) -> Result<DynamicImage, KachakaApiError> {
147        api_impl::get_latest_back_camera_ros_image(&mut self.client).await
148    }
149
150    pub async fn watch_back_camera_ros_image(
151        &mut self,
152    ) -> impl Stream<Item = Result<DynamicImage, KachakaApiError>> {
153        api_impl::watch_back_camera_ros_image(&mut self.client).await
154    }
155
156    // GetBackCameraRosCompressedImage
157    pub async fn get_back_camera_ros_compressed_image(
158        &mut self,
159        cursor: i64,
160    ) -> Result<DynamicImage, KachakaApiError> {
161        api_impl::get_back_camera_ros_compressed_image(&mut self.client, cursor).await
162    }
163
164    pub async fn get_latest_back_camera_ros_compressed_image(
165        &mut self,
166    ) -> Result<DynamicImage, KachakaApiError> {
167        api_impl::get_latest_back_camera_ros_compressed_image(&mut self.client).await
168    }
169
170    pub async fn watch_back_camera_ros_compressed_image(
171        &mut self,
172    ) -> impl Stream<Item = Result<DynamicImage, KachakaApiError>> {
173        api_impl::watch_back_camera_ros_compressed_image(&mut self.client).await
174    }
175
176    // GetRobotErrorCodeJson
177    pub async fn get_robot_error_code_json(
178        &mut self,
179    ) -> Result<HashMap<i32, HashMap<String, String>>, KachakaApiError> {
180        api_impl::get_robot_error_code_json(&mut self.client).await
181    }
182
183    // GetError
184    pub async fn get_error(&mut self, cursor: i64) -> Result<Vec<KachakaError>, KachakaApiError> {
185        api_impl::get_error(&mut self.client, cursor).await
186    }
187
188    pub async fn get_latest_error(&mut self) -> Result<Vec<KachakaError>, KachakaApiError> {
189        api_impl::get_latest_error(&mut self.client).await
190    }
191
192    pub async fn watch_error(
193        &mut self,
194    ) -> impl Stream<Item = Result<Vec<KachakaError>, KachakaApiError>> {
195        api_impl::watch_error(&mut self.client).await
196    }
197
198    // GetCommandState
199    pub async fn get_command_state(
200        &mut self,
201        cursor: i64,
202    ) -> Result<CommandState, KachakaApiError> {
203        api_impl::get_command_state(&mut self.client, cursor).await
204    }
205
206    pub async fn get_latest_command_state(&mut self) -> Result<CommandState, KachakaApiError> {
207        api_impl::get_latest_command_state(&mut self.client).await
208    }
209
210    pub async fn watch_command_state(
211        &mut self,
212    ) -> impl Stream<Item = Result<CommandState, KachakaApiError>> {
213        api_impl::watch_command_state(&mut self.client).await
214    }
215
216    // GetLastCommandResult
217    pub async fn get_last_command_result(
218        &mut self,
219        cursor: i64,
220    ) -> Result<Option<CommandResult>, KachakaApiError> {
221        api_impl::get_last_command_result(&mut self.client, cursor).await
222    }
223
224    pub async fn watch_last_command_result(
225        &mut self,
226    ) -> impl Stream<Item = Result<Option<CommandResult>, KachakaApiError>> {
227        api_impl::watch_last_command_result(&mut self.client).await
228    }
229
230    // command api
231    pub async fn move_shelf(
232        &mut self,
233        shelf_id: &str,
234        location_id: &str,
235        options: StartCommandOptions,
236    ) -> Result<String, KachakaApiError> {
237        api_impl::move_shelf(&mut self.client, shelf_id, location_id, options).await
238    }
239
240    pub async fn return_shelf(
241        &mut self,
242        shelf_id: &str,
243        options: StartCommandOptions,
244    ) -> Result<String, KachakaApiError> {
245        api_impl::return_shelf(&mut self.client, shelf_id, options).await
246    }
247
248    pub async fn undock_shelf(
249        &mut self,
250        options: StartCommandOptions,
251    ) -> Result<String, KachakaApiError> {
252        api_impl::undock_shelf(&mut self.client, options).await
253    }
254
255    pub async fn move_to_location(
256        &mut self,
257        location_id: &str,
258        options: StartCommandOptions,
259    ) -> Result<String, KachakaApiError> {
260        api_impl::move_to_location(&mut self.client, location_id, options).await
261    }
262
263    pub async fn return_home(
264        &mut self,
265        options: StartCommandOptions,
266    ) -> Result<String, KachakaApiError> {
267        api_impl::return_home(&mut self.client, options).await
268    }
269
270    pub async fn dock_shelf(
271        &mut self,
272        options: StartCommandOptions,
273    ) -> Result<String, KachakaApiError> {
274        api_impl::dock_shelf(&mut self.client, options).await
275    }
276
277    pub async fn speak(
278        &mut self,
279        text: &str,
280        options: StartCommandOptions,
281    ) -> Result<String, KachakaApiError> {
282        api_impl::speak(&mut self.client, text, options).await
283    }
284
285    pub async fn move_to_pose(
286        &mut self,
287        x: f64,
288        y: f64,
289        yaw: f64,
290        options: StartCommandOptions,
291    ) -> Result<String, KachakaApiError> {
292        api_impl::move_to_pose(&mut self.client, x, y, yaw, options).await
293    }
294
295    pub async fn lock(
296        &mut self,
297        duration_sec: f64,
298        options: StartCommandOptions,
299    ) -> Result<String, KachakaApiError> {
300        api_impl::lock(&mut self.client, duration_sec, options).await
301    }
302
303    pub async fn move_forward(
304        &mut self,
305        distance_meter: f64,
306        speed: f64,
307        options: StartCommandOptions,
308    ) -> Result<String, KachakaApiError> {
309        api_impl::move_forward(&mut self.client, distance_meter, speed, options).await
310    }
311
312    pub async fn rotate_in_place(
313        &mut self,
314        angle_radian: f64,
315        options: StartCommandOptions,
316    ) -> Result<String, KachakaApiError> {
317        api_impl::rotate_in_place(&mut self.client, angle_radian, options).await
318    }
319
320    pub async fn dock_any_shelf_with_registration(
321        &mut self,
322        location_id: &str,
323        options: StartCommandOptions,
324    ) -> Result<String, KachakaApiError> {
325        api_impl::dock_any_shelf_with_registration(&mut self.client, location_id, options).await
326    }
327
328    pub async fn cancel_command(&mut self) -> Result<(), KachakaApiError> {
329        api_impl::cancel_command(&mut self.client).await
330    }
331
332    pub async fn proceed(&mut self) -> Result<(), KachakaApiError> {
333        api_impl::proceed(&mut self.client).await
334    }
335
336    // locations
337    // GetLocations
338    pub async fn get_locations(
339        &mut self,
340        cursor: i64,
341    ) -> Result<Vec<kachaka_api::Location>, KachakaApiError> {
342        api_impl::get_locations(&mut self.client, cursor).await
343    }
344
345    pub async fn get_latest_locations(
346        &mut self,
347    ) -> Result<Vec<kachaka_api::Location>, KachakaApiError> {
348        api_impl::get_latest_locations(&mut self.client).await
349    }
350
351    pub async fn watch_locations(
352        &mut self,
353    ) -> impl Stream<Item = Result<Vec<kachaka_api::Location>, KachakaApiError>> {
354        api_impl::watch_locations(&mut self.client).await
355    }
356
357    // shelves
358    // GetShelves
359    pub async fn get_shelves(
360        &mut self,
361        cursor: i64,
362    ) -> Result<Vec<kachaka_api::Shelf>, KachakaApiError> {
363        api_impl::get_shelves(&mut self.client, cursor).await
364    }
365
366    pub async fn get_latest_shelves(&mut self) -> Result<Vec<kachaka_api::Shelf>, KachakaApiError> {
367        api_impl::get_latest_shelves(&mut self.client).await
368    }
369
370    pub async fn watch_shelves(
371        &mut self,
372    ) -> impl Stream<Item = Result<Vec<kachaka_api::Shelf>, KachakaApiError>> {
373        api_impl::watch_shelves(&mut self.client).await
374    }
375
376    // GetMovingShelfId
377    pub async fn get_moving_shelf_id(&mut self, cursor: i64) -> Result<String, KachakaApiError> {
378        api_impl::get_moving_shelf_id(&mut self.client, cursor).await
379    }
380
381    pub async fn get_latest_moving_shelf_id(&mut self) -> Result<String, KachakaApiError> {
382        api_impl::get_latest_moving_shelf_id(&mut self.client).await
383    }
384
385    pub async fn watch_moving_shelf_id(
386        &mut self,
387    ) -> impl Stream<Item = Result<String, KachakaApiError>> {
388        api_impl::watch_moving_shelf_id(&mut self.client).await
389    }
390
391    // ResetShelfPose
392    pub async fn reset_shelf_pose(&mut self, shelf_id: &str) -> Result<(), KachakaApiError> {
393        api_impl::reset_shelf_pose(&mut self.client, shelf_id).await
394    }
395}