@@ -8,8 +8,8 @@ use color_eyre::Result;
88use futures_util:: SinkExt ;
99use futures_util:: StreamExt ;
1010use hardware:: {
11- ButtonEventMsgInterface , CameraInterface , IdInterface , MicrophoneInterface , NetworkInterface ,
12- PathsInterface , RecordingInterface , SpeakerInterface , TimeInterface ,
11+ ButtonEventMsgInterface , IdInterface , MicrophoneInterface , NetworkInterface , PathsInterface ,
12+ RGBDSensorsInterface , RecordingInterface , SpeakerInterface , TimeInterface ,
1313} ;
1414use hardware:: {
1515 FallDownStateInterface , LowCommandInterface , LowStateInterface , RemoteControllerStateInterface ,
@@ -29,10 +29,9 @@ use tokio::{
2929use tokio_tungstenite:: tungstenite:: Message ;
3030use tokio_util:: sync:: CancellationToken ;
3131use types:: audio:: SpeakerRequest ;
32- use types:: camera_position:: CameraPosition ;
3332use types:: messages:: { IncomingMessage , OutgoingMessage } ;
3433use types:: samples:: Samples ;
35- use types :: ycbcr422_image :: YCbCr422Image ;
34+ use zed :: RGBDSensors ;
3635
3736use crate :: HardwareInterface ;
3837
@@ -45,6 +44,7 @@ struct WorkerChannels {
4544 button_event_msg_sender : Sender < SimulationMessage < ButtonEventMsg > > ,
4645 remote_controller_state_sender : Sender < SimulationMessage < RemoteControllerState > > ,
4746 transform_stamped_sender : Sender < SimulationMessage < TransformStamped > > ,
47+ rgbd_sensors_sender : Sender < SimulationMessage < RGBDSensors > > ,
4848}
4949
5050#[ derive( Clone , Debug , Deserialize ) ]
@@ -68,6 +68,7 @@ pub struct MujocoHardwareInterface {
6868 button_event_msg_receiver : Mutex < Receiver < SimulationMessage < ButtonEventMsg > > > ,
6969 remote_controller_state_receiver : Mutex < Receiver < SimulationMessage < RemoteControllerState > > > ,
7070 transform_stamped_receiver : Mutex < Receiver < SimulationMessage < TransformStamped > > > ,
71+ rgbd_sensors_receiver : Mutex < Receiver < SimulationMessage < RGBDSensors > > > ,
7172}
7273
7374impl MujocoHardwareInterface {
@@ -84,6 +85,7 @@ impl MujocoHardwareInterface {
8485 let ( remote_controller_state_sender, remote_controller_state_receiver) =
8586 channel ( CHANNEL_CAPACITY ) ;
8687 let ( transform_stamped_sender, transform_stamped_receiver) = channel ( CHANNEL_CAPACITY ) ;
88+ let ( rgbd_sensors_sender, rgbd_sensors_receiver) = channel ( CHANNEL_CAPACITY ) ;
8789
8890 let worker_channels = WorkerChannels {
8991 low_state_sender,
@@ -92,6 +94,7 @@ impl MujocoHardwareInterface {
9294 button_event_msg_sender,
9395 remote_controller_state_sender,
9496 transform_stamped_sender,
97+ rgbd_sensors_sender,
9598 } ;
9699
97100 let time = Arc :: new ( Mutex :: new ( SystemTime :: UNIX_EPOCH ) ) ;
@@ -118,6 +121,7 @@ impl MujocoHardwareInterface {
118121 button_event_msg_receiver : Mutex :: new ( button_event_msg_receiver) ,
119122 remote_controller_state_receiver : Mutex :: new ( remote_controller_state_receiver) ,
120123 transform_stamped_receiver : Mutex :: new ( transform_stamped_receiver) ,
124+ rgbd_sensors_receiver : Mutex :: new ( rgbd_sensors_receiver) ,
121125 } )
122126 }
123127}
@@ -221,9 +225,15 @@ async fn handle_message(
221225 . await ?
222226 }
223227 SimulationMessage {
224- payload : ServerMessageKind :: RGBDSensors ( _) ,
225- ..
226- } => todo ! ( ) ,
228+ payload : ServerMessageKind :: RGBDSensors ( rgbd_sensors) ,
229+ time,
230+ } => {
231+ * hardware_interface_time. lock ( ) = time;
232+ worker_channels
233+ . rgbd_sensors_sender
234+ . send ( SimulationMessage :: new ( time, rgbd_sensors) )
235+ . await ?
236+ }
227237 } ;
228238
229239 Ok ( ( ) )
@@ -234,15 +244,15 @@ impl LowStateInterface for MujocoHardwareInterface {
234244 self . low_state_receiver
235245 . lock ( )
236246 . blocking_recv ( )
237- . ok_or_eyre ( "channel closed" )
247+ . ok_or_eyre ( "low state channel closed" )
238248 }
239249}
240250
241251impl LowCommandInterface for MujocoHardwareInterface {
242252 fn write_low_command ( & self , low_command : LowCommand ) -> Result < ( ) > {
243253 self . low_command_sender
244254 . blocking_send ( low_command)
245- . wrap_err ( "send error" )
255+ . wrap_err ( "low command send error" )
246256 }
247257}
248258
@@ -251,7 +261,7 @@ impl FallDownStateInterface for MujocoHardwareInterface {
251261 self . fall_down_receiver
252262 . lock ( )
253263 . blocking_recv ( )
254- . ok_or_eyre ( "channel closed" )
264+ . ok_or_eyre ( "fall down state channel closed" )
255265 }
256266}
257267
@@ -260,7 +270,7 @@ impl ButtonEventMsgInterface for MujocoHardwareInterface {
260270 self . button_event_msg_receiver
261271 . lock ( )
262272 . blocking_recv ( )
263- . ok_or_eyre ( "channel closed" )
273+ . ok_or_eyre ( "button event msg channel closed" )
264274 }
265275}
266276
@@ -282,6 +292,15 @@ impl TransformStampedInterface for MujocoHardwareInterface {
282292 }
283293}
284294
295+ impl RGBDSensorsInterface for MujocoHardwareInterface {
296+ fn read_rgbd_sensors ( & self ) -> Result < SimulationMessage < RGBDSensors > > {
297+ self . rgbd_sensors_receiver
298+ . lock ( )
299+ . blocking_recv ( )
300+ . ok_or_eyre ( "channel closed" )
301+ }
302+ }
303+
285304impl TimeInterface for MujocoHardwareInterface {
286305 fn get_now ( & self ) -> SystemTime {
287306 * self . time . lock ( )
@@ -348,10 +367,4 @@ impl RecordingInterface for MujocoHardwareInterface {
348367 }
349368}
350369
351- impl CameraInterface for MujocoHardwareInterface {
352- fn read_from_camera ( & self , camera_position : CameraPosition ) -> Result < YCbCr422Image > {
353- Ok ( YCbCr422Image :: default ( ) )
354- }
355- }
356-
357370impl HardwareInterface for MujocoHardwareInterface { }
0 commit comments