Execute control command with safety verification
(&mut self, command: ControlCommand)
| 232 | |
| 233 | /// Execute control command with safety verification |
| 234 | pub fn execute_command(&mut self, command: ControlCommand) -> Result<SafetyProof, String> { |
| 235 | let start = std::time::Instant::now(); |
| 236 | |
| 237 | // Step 1: Check safety envelope |
| 238 | let envelope_satisfied = self.check_envelope(&command); |
| 239 | if !envelope_satisfied { |
| 240 | return Err("Safety envelope violation".to_string()); |
| 241 | } |
| 242 | |
| 243 | // Step 2: Check human exclusion |
| 244 | let humans_excluded = self.check_human_exclusion(&command); |
| 245 | if !humans_excluded { |
| 246 | self.near_miss_count += 1; |
| 247 | return Err("Human exclusion zone violation".to_string()); |
| 248 | } |
| 249 | |
| 250 | // Step 3: Check torque limits |
| 251 | let torque_ok = self.check_torque(&command); |
| 252 | if !torque_ok { |
| 253 | return Err("Torque limit exceeded".to_string()); |
| 254 | } |
| 255 | |
| 256 | // Step 4: Check failsafe |
| 257 | let failsafe_ready = self.check_failsafe(&command.robot_id); |
| 258 | if !failsafe_ready { |
| 259 | return Err("Failsafe not ready".to_string()); |
| 260 | } |
| 261 | |
| 262 | // Step 5: Simulate execution |
| 263 | let simulated_outcome = self.simulate(&command); |
| 264 | |
| 265 | // Step 6: Update robot state |
| 266 | if let Some(robot) = self.robots.get_mut(&command.robot_id) { |
| 267 | robot.position_x = command.target_x; |
| 268 | robot.position_y = command.target_y; |
| 269 | robot.speed_mps = command.target_speed; |
| 270 | robot.torque_nm = command.target_torque; |
| 271 | robot.status = RobotStatus::Moving; |
| 272 | } |
| 273 | |
| 274 | self.command_history.push(command.clone()); |
| 275 | |
| 276 | let latency = start.elapsed(); |
| 277 | |
| 278 | // Verify real-time performance: control loop should be <100ms |
| 279 | if latency.as_millis() > 100 { |
| 280 | eprintln!( |
| 281 | "Warning: Control latency {}ms exceeds 100ms target", |
| 282 | latency.as_millis() |
| 283 | ); |
| 284 | } |
| 285 | |
| 286 | // Step 7: Generate proof |
| 287 | let timestamp = std::time::SystemTime::now() |
| 288 | .duration_since(std::time::UNIX_EPOCH) |
| 289 | .unwrap() |
| 290 | .as_secs(); |
| 291 |