ZombieMutex

30 results · ↑ ↓ navigate · Enter open · Esc close

All snippets

TypeScript / Tested teaching helper

Bound a synthetic actuator command

Clamp a finite command into a configured range; reject malformed limits.

TypeScript

export function boundedActuatorCommand(requested:number,limit=0.6):number|null{
  if(!Number.isFinite(requested)||!Number.isFinite(limit)||limit<=0||limit>1)return null;
  return Math.max(-limit,Math.min(limit,requested));
}

What matters

A tiny tested mathematical helper, not firmware or a safe motor controller. Actual robotic systems require hardware stops, power limits, feedback, emergency-stop circuits and verification under faults.

Test these cases

  • Clamps positive and negative commands
  • Rejects NaN/Infinity
  • Rejects zero or out-of-range limits

Sources and limits

This is a reference snippet, not a substitute for reviewing the full vendor API contract, concurrency rules or production threat model. Do not paste secrets into sample code.

This pure helper has runnable Node.js tests in the downloadable educational bundle. Those tests do not verify a full production security system.