× Overview The Robot Learning Hub Curriculum Safety For Schools Contact Sales

Demo: Handshake

Status Available
Level Beginner+
Time 10–15 minutes

The robot uses the RealSense camera to detect that a user is in front of it, moves its arm into a handshake pose, waits briefly, and then returns to idle.

Honest note

This is a vision-assisted classroom demo. It should not be described as perfect hand detection or full human understanding. The first version uses simple user presence in an approximate interaction zone while students learn how perception can start a behavior.

What students learn

Students learn how camera input can trigger robot motion and why robots need conservative movement when interacting near people.

Hardware used

  • RealSense camera
  • Arm servos
  • Optional hand servo
  • Motion node

Concepts covered

  • RealSense camera input
  • User presence detection
  • Perception-triggered behavior
  • Human-robot interaction
  • Motion locking
  • Returning to neutral pose

Run command

Terminal
ros2 run swayform_demos handshake_demo

Starter code

This version uses a timeout so the demo does not wait forever. Read the function names before running to understand the flow: wait, detect, execute, return home.

Note: These examples are written as classroom starter code. Final hardware APIs can be adjusted to match the installed SwayForm software image.
python — handshake_demo.py
"""
Demo: Handshake

Purpose:
Use a simple RealSense-based presence check to trigger a handshake pose.

Important:
This is a vision-assisted classroom demo. It does not claim perfect hand
detection or human-level understanding.
"""

from time import sleep, time
from swayform.motion import MotionClient
from swayform.vision import RealSenseInput


DETECTION_TIMEOUT_SECONDS = 10
HANDSHAKE_HOLD_SECONDS = 2.0

HANDSHAKE_POSE = {
    "shoulder_pitch": 38,
    "shoulder_roll": 10,
    "elbow_pitch": 82,
    "wrist_yaw": 0,
}


def wait_for_user(camera: RealSenseInput, timeout: float) -> bool:
    """
    Wait until the camera reports a user inside the interaction zone.
    Returns True if a user is found, otherwise False.
    """
    start_time = time()

    while time() - start_time < timeout:
        if camera.user_in_interaction_zone():
            return True

        sleep(0.1)

    return False


def run_handshake(motion: MotionClient) -> None:
    """
    Move into a conservative handshake pose, wait briefly,
    then return to idle.
    """
    motion.move_joint_group("right_arm", HANDSHAKE_POSE)
    sleep(HANDSHAKE_HOLD_SECONDS)
    motion.safe_pose("idle")


def main() -> None:
    motion = MotionClient()
    camera = RealSenseInput()

    motion.safe_pose("idle")
    print("Waiting for user...")

    user_detected = wait_for_user(camera, DETECTION_TIMEOUT_SECONDS)

    if not user_detected:
        print("No user detected. Returning to idle.")
        motion.safe_pose("idle")
        return

    try:
        motion.lock_behavior("handshake_demo")
        run_handshake(motion)
    finally:
        motion.unlock_behavior("handshake_demo")
        motion.safe_pose("idle")


if __name__ == "__main__":
    main()

Code walkthrough

Detection timeout
The robot should not wait forever. A timeout keeps the demo predictable and helps students understand that robot behaviors need exit conditions.
wait_for_user
This function checks the camera repeatedly until a user is detected or the timeout ends. Students can adjust the detection distance later.
Handshake pose
The handshake pose is a controlled arm position, not a fast reach. Human-facing demos should move slowly and conservatively.
Failure path
If no user is detected, the robot does nothing dramatic. It prints a message and stays safe.
finally block
The finally block makes sure the robot unlocks the behavior and returns to idle even if something interrupts the script.

Try changing this

  • Change how long the robot holds the handshake pose.
  • Add a small head nod before the arm moves.
  • Add a spoken prompt if speakers are connected.
  • Adjust the detection distance.
Safety

Keep the handshake motion slow and predictable. Do not make the arm snap toward the user.

Next step

After Handshake, try Lab 06: RealSense Detection Basics.