Wait Time
A wait time is an instruction that lets the robot pause for a given duration on the robot side. Unlike
std::thread::sleep, which only holds up your program, wait_time() is queued like a motion: it takes its place in
the instruction queue, and the instruction that follows starts when the wait has elapsed. This keeps a timed dwell,
for example while a gripper closes, inside the same block as the motions around it.
Waiting Between Motions
wait_time() from the WaitTime trait is a block step like any motion. It takes the duration as a Duration:
robot
.move_ptp(poses::home())
.wait_time(Duration::from_secs(2))
.move_ptp(poses::vertical())
.start()?
.join()?;
info!("Vertical reached after a 2 s robot-side wait.");
The wait is executed by the robot, not by this program. Because the whole block is sent at once, the second motion is already known to the control when the wait ends.
A standalone wait is an instruction like any other, with the same start() and join():
robot.wait_time(Duration::from_secs(1)).start()?.join()?;
Waits and Blending
A wait can follow any unblended step, and a motion can follow a wait with or without blending. A wait cannot be
blended into: after .blending() only a motion may follow, so move_ptp(..).blending(..).wait_time(..) does not
compile.
robot
.move_ptp(poses::home())
.wait_time(Duration::from_secs(1))
.move_ptp(poses::vertical())
.blending(Percent(30.0))
.move_ptp(JointPose::default())
.start()?
.join()?;
info!("Zero reached after sequence.");
Wait Time vs. Thread Sleep
|
|
|
|---|---|---|
Where it executes |
Robot control |
Your program |
Part of the instruction queue |
Yes |
No |
Blocks the calling thread |
No; |
Yes |
Usable inside a block |
Yes |
No |
Full Example
Wait time example
//! Wait time instruction example.
//!
//! Demonstrates how to insert a robot-side wait between motion commands.
//! Unlike `std::thread::sleep`, `wait_time` sends a command to the robot
//! controller that pauses motion execution on the robot side. The wait
//! participates in the instruction queue and blending pipeline.
mod common;
use std::time::Duration;
use common::poses;
use tracing::info;
use voraus_robot_arm::prelude::*;
/// Use `wait_time` between two PTP movements.
///
/// The wait is executed by the robot, not by this program. As a block
/// step it sits between the two motions; the second move only starts
/// after the wait completes.
fn wait_between_moves(robot: &(impl MovePtp + WaitTime)) -> Result<()> {
info!("--- Wait between moves ---");
robot
.move_ptp(poses::home())
.wait_time(Duration::from_secs(2))
.move_ptp(poses::vertical())
.start()?
.join()?;
info!("Vertical reached after a 2 s robot-side wait.");
Ok(())
}
/// A standalone wait is an instruction like any other, with the same
/// terminals.
fn standalone_wait(robot: &impl WaitTime) -> Result<()> {
info!("--- Standalone wait ---");
robot.wait_time(Duration::from_secs(1)).start()?.join()?;
info!("Wait instruction completed (1s).");
Ok(())
}
/// Waits cannot be blended into: after `.blending()` only a motion may
/// follow, so `move_ptp(..).blending(..).wait_time(..)` does not compile.
fn wait_in_sequence(robot: &(impl MovePtp + WaitTime)) -> Result<()> {
info!("--- Wait in instruction sequence ---");
robot
.move_ptp(poses::home())
.wait_time(Duration::from_secs(1))
.move_ptp(poses::vertical())
.blending(Percent(30.0))
.move_ptp(JointPose::default())
.start()?
.join()?;
info!("Zero reached after sequence.");
Ok(())
}
fn main() -> voraus_robot_arm::error::Result<()> {
common::init_logging();
let robot = common::create_connected_robot()?;
wait_between_moves(&robot)?;
standalone_wait(&robot)?;
wait_in_sequence(&robot)?;
info!("Done.");
Ok(())
}
Trait Definition
WaitTime
pub trait WaitTime: BlockQueuing {
/// Queue a wait instruction.
///
/// # Returns
///
/// An [`InstructionHandle`] that resolves when the wait has elapsed.
///
/// # Errors
///
/// Returns [`RobotArmError`](crate::error::RobotArmError) if the
/// instruction cannot be queued.
#[doc(hidden)]
fn execute_wait_time(&self, request: WaitRequest) -> Result<InstructionHandle>;
/// Start a block with a robot-side wait.
///
/// The robot control halts for `duration` before it executes the next
/// instruction; the calling program does not sleep. Chain motions after
/// the wait, or send it alone with [`start`](MotionBlock::start).
///
/// # Example
///
/// ```rust
/// # use std::time::Duration;
/// # use voraus_robot_arm::prelude::*;
/// # fn demo(robot: &(impl WaitTime + MovePtp), next: JointPose) -> Result<()> {
/// // Halt for one second, then move on.
/// robot.wait_time(Duration::from_secs(1)).move_ptp(next).start()?.join()?;
/// # Ok(())
/// # }
/// ```
///
/// # Arguments
///
/// * `duration` - How long the robot halts.
///
/// # Returns
///
/// A block of one wait step, in the wait state.
fn wait_time(&self, duration: Duration) -> MotionBlock<'_, Self, state::Wait>
where
Self: Sized,
{
MotionBlock::single(self, wait_step(duration))
}
}