Tin

Examples · learn/34-robot-safety · 320 of 339

gate

examples/learn/34-robot-safety/gate.tintin run examples/learn/34-robot-safety/gate.tin
robot Arm = so101

fn main() {
  var arm = Arm()
  arm.safe("elbow_flex", -30deg, 30deg)
  arm.validate((p, o) => if p.get("gripper").or(0rad) > 1rad { Some("the gripper opens at most 1rad") } else { None })

  // a validator's refusal ends a run with a fault, and the arm holds where it is
  let r = arm.run(policy(o => Some(Pose { gripper: o.t / 1s * 2rad })), 2s, 10Hz)
  print("{r.steps} steps, stopped by {r.stoppedBy}")

  // the program's own targets are clipped to the bounds
  arm.reach(Pose { elbow_flex: 80deg }, 500ms)
  print(arm.target().get("elbow_flex").or(0rad).deg().fixed(1))

  arm.estop()
  print(arm.run(policy(o => Some(Pose { gripper: 0rad })), 1s, 10Hz).stoppedBy)
}