MCPcopy Create free account
hub / github.com/ecto/muni / drain

Method drain

bvr/firmware/crates/control-loop/src/command_processor.rs:53–94  ·  view source on GitHub ↗

Drain all pending commands from the channel. For Twist commands, only the latest is kept (newer commands overwrite older). For other commands, they are accumulated and returned in order.

(&mut self, cmd_rx: &mut mpsc::Receiver<Command>)

Source from the content-addressed store, hash-verified

51 /// For Twist commands, only the latest is kept (newer commands overwrite older).
52 /// For other commands, they are accumulated and returned in order.
53 pub fn drain(&mut self, cmd_rx: &mut mpsc::Receiver<Command>) -> ProcessedCommands {
54 let mut result = ProcessedCommands::default();
55 self.dropped_twists = 0;
56
57 while let Ok(cmd) = cmd_rx.try_recv() {
58 match cmd {
59 Command::Twist(twist) => {
60 if result.latest_twist.is_some() {
61 self.dropped_twists += 1;
62 }
63 result.latest_twist = Some(twist);
64 }
65 Command::EStop => {
66 result.estop_triggered = true;
67 }
68 Command::EStopRelease => {
69 result.estop_release_requested = true;
70 }
71 Command::SetMode(mode) => {
72 result.mode_request = Some(mode);
73 }
74 Command::Heartbeat => {
75 result.heartbeat_received = true;
76 }
77 Command::Tool(tc) => {
78 result.tool_command = Some(tc);
79 }
80 Command::LidarToggle(_) => {
81 // LidarToggle is handled per-connection in WebRTC, not forwarded
82 }
83 Command::SetGoal { .. } => {
84 // SetGoal is handled by dispatch / navigation controller
85 }
86 }
87 }
88
89 if self.dropped_twists > 0 {
90 debug!(dropped = self.dropped_twists, "Dropped stale Twist commands");
91 }
92
93 result
94 }
95
96 /// Get count of dropped twist commands from last drain
97 pub fn dropped_twists(&self) -> u32 {

Callers 8

run_rover_sessionFunction · 0.80
reader_taskMethod · 0.80
reader_taskFunction · 0.80
depth_thread_mainFunction · 0.80
test_drain_emptyFunction · 0.80

Calls 1

try_recvMethod · 0.80

Tested by 4

test_drain_emptyFunction · 0.64