Skip to content

play_tune

Runs at once Any mode Takes control

Play a tune through the arm's playing motor. The drive plays the notes in order with its own timing, so they keep their lengths exactly. The command returns as soon as the robot has taken the tune. A tone or tune asked for while another plays replaces it. Like beep(), it plays on the d axis: no torque during a move. Programs' sounds are switched on or off together with set_sound(programs=...).

Syntax

robot.play_tune(notes)

Arguments

Name Type Default Description
notes list required 1 to 30 (note, seconds) pairs. The note is a name such as "A4" (440 Hz), "C#5" or "Eb3", a pitch from 20 to 3000 Hz, or 0 for a rest. Each lasts 0.02 to 5 s.

Returns

Nothing.

Examples

robot.play_tune([("C5", 0.1), ("E5", 0.1), ("G5", 0.2)])
robot.play_tune([("A3", 0.2), (0, 0.1), ("A3", 0.3)])
Usage restrictions 4 codes

This command runs at once; it is not queued. The robot accepts it in any mode and state, from the client that holds control or when no client does.

It answers with one of these codes when it does not carry the command out:

  • [6101] Control held by another client — another client holds control; the message names it
  • [6003] Invalid arguments — no notes or more than 30, a note that is not a (note, seconds) pair, an unknown note name, a pitch out of range, or a length out of range. The message names the note
  • [6025] RTI not running or not answering — rTI did not answer within 1 s: it is not running or not responding. The command may still have taken effect
  • [6026] Refused by RTI — programs' sounds are switched off (set_sound(programs=0)), or the drives do not hold now: the motors are off, the robot is flashing a drive or starting. The message says why

In Python, a code above raises CommandRejected; its number is the code. The call raises:

  • CommandRejected: The robot refused it: a note is not valid, or another client holds control. Or RTI refused it or did not answer within 1 s (Errors:).
  • RobotTimeout: The robot did not answer within 5 s.
  • RobotConnectionError: The client is not connected.

If the connection drops while the call waits for the robot's answer, it raises CommandRejected with the code CONNECTION_LOST (DISCONNECTED after disconnect()); while it waits for the robot's status, RobotConnectionError.

Like every immediate command, it also answers BAD_ARGS when a raw client sends a value the robot cannot read at all, and INTERNAL when it fails inside the robot.

Protocol

A client that does not use robotclient sends this over the TCP command protocol (port 29000) for the example above:

{"id": "c1", "cmd": "play_tune", "args": [[["C5", 0.1], ["E5", 0.1], ["G5", 0.2]]]}

See also