Joint control

Beyond the built-in skills you can drive individual joints directly. There are three flavours:

Joints are addressed by index; consult the Petoi serial protocol for the joint map of your model. Angles are in degrees.

Use case: nod the head, then strike a pose

using PetoiBittle

connection = PetoiBittle.connect(PetoiBittle.find_bittle_port())

# move joint 0 to +30 and joint 1 to -30 at the same time
PetoiBittle.send_command(connection, PetoiBittle.MoveJoints((id = 0, angle = 30), (id = 1, angle = -30)))

# step the same joint through a little nod, in sequence
PetoiBittle.send_command(connection, PetoiBittle.MoveJointSequence((id = 0, angle = 20), (id = 0, angle = -20), (id = 0, angle = 0)))

# set an entire 16-joint frame at once (here: all neutral)
PetoiBittle.send_command(connection, PetoiBittle.SetAllJoints(ntuple(_ -> 0, 16)))

PetoiBittle.disconnect(connection)
Note

SetAllJoints sends raw signed bytes, so every angle must fit in -128:127. Out-of-range values raise an error when the command is serialized.

Reference

PetoiBittle.MoveJoints — Type
MoveJoints(joint_movements_as_named_tuple...)
MoveJoints(single_tuple_of_move_joint_specs)

A PetoiBittle.Command that specifies which joint to move at which angle. Can be constructed from a vararg argument list of named tuples with id and angle keys present or a single tuple containing multiple PetoiBittle.MoveJointSpec.

julia> PetoiBittle.MoveJoints(
           (id = 8, angle = 10),
           (id = 9, angle = 20)
       )
PetoiBittle.MoveJoints{2}((PetoiBittle.MoveJointSpec(8, 10), PetoiBittle.MoveJointSpec(9, 20)))

julia> PetoiBittle.MoveJoints(
           (id = 9, angle = 10),
           (id = 9, angle = 20)
       )
ERROR: Cannot create MoveJoints. Duplicate `id` found `9`. Set `check_unique = false` to skip the check.
[...]

See also: PetoiBittle.MoveJointSpec

source
PetoiBittle.MoveJointSpec — Type
MoveJointSpec(id::Int, angle::Int)

A command specification for a joint with id id to change its angle to angle. Note, that this structure is not a command by itself. To move a single joint you should still use the PetoiBittle.MoveJoints command.

julia> convert(PetoiBittle.MoveJointSpec, (id = 1, angle = 10))
PetoiBittle.MoveJointSpec(1, 10)

julia> convert(PetoiBittle.MoveJointSpec, (id = 1, ))
ERROR: Cannot convert NamedTuple (id = 1,) to `MoveJointSpec(id = ..., angle = ...)`. Missing key `angle`.
[...]

See also: PetoiBittle.MoveJoints

source
PetoiBittle.MoveJointSequence — Type
MoveJointSequence(joint_movements_as_named_tuple...)
MoveJointSequence(single_tuple_of_move_joint_specs)

A PetoiBittle.Command that moves the listed joints to their target angles one after another, in order (as opposed to PetoiBittle.MoveJoints, which moves them all at once). Serializes to the token "m" followed by space-separated id angle pairs.

Reuses PetoiBittle.MoveJointSpec for each movement. Unlike MoveJoints, repeated joint ids are allowed (the same joint can be stepped through several angles in sequence).

julia> PetoiBittle.MoveJointSequence((id = 0, angle = 30), (id = 0, angle = -30))
PetoiBittle.MoveJointSequence{2}((PetoiBittle.MoveJointSpec(0, 30), PetoiBittle.MoveJointSpec(0, -30)))

See also: PetoiBittle.MoveJoints, PetoiBittle.MoveJointSpec

source
PetoiBittle.SetAllJoints — Type
SetAllJoints(angles::NTuple{16, Int})
SetAllJoints(angle1, angle2, ..., angle16)

A PetoiBittle.Command that sets all 16 joints at once to the given target angles (a "transform to frame"). This is the binary form of the protocol: it serializes to the token "L" followed by 16 raw signed bytes (one per joint) and is terminated by '~' rather than a newline (see PetoiBittle.command_terminator).

Each angle must fit in a signed byte (-128:127); out-of-range values error when the command is serialized. Exactly 16 angles are required.

julia> PetoiBittle.SetAllJoints(ntuple(_ -> 0, 16))
PetoiBittle.SetAllJoints{16}((0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0))

See also: PetoiBittle.MoveJoints (move a subset simultaneously, ASCII form).

source