Low-level & advanced

This page covers the primitives for talking to the robot when no dedicated typed command exists yet, and for defining your own commands.

Free-form skills

PetoiBittle.Skill sends any named skill ("k" + name) without needing a dedicated type. This is handy for custom skills you have uploaded to the robot.

PetoiBittle.send_command(connection, PetoiBittle.Skill("balance"))

Raw commands and queries

For anything the firmware understands but this package does not model yet (including sensor, pin, and other hardware-dependent commands whose wire format is device-specific), use the raw primitives. PetoiBittle.RawCommand sends a token and returns nothing; PetoiBittle.RawQuery sends a token and hands you back the raw response line for you to parse with PetoiBittle.parse_number.

# send an arbitrary command
PetoiBittle.send_command(connection, PetoiBittle.RawCommand("p"))

# send a command and read back the raw response line
response = PetoiBittle.send_command(connection, PetoiBittle.RawQuery("b"))
value = PetoiBittle.parse_number(Float64, codeunits(response.line))
Warning

The response format of raw queries is whatever the firmware emits; this package does not interpret it. Check the Petoi serial protocol for the exact reply of the command you are sending.

PetoiBittle.Skill — Type
Skill(skill_name)

A command that executes a predefined skill_name. Please consult the Petoi documentation to get the list of predefined skills (e.g. here). You can also add your own skills and attach names to them.

skill_name should be an iterable of Char, e.g. String or a Vector{Char}.

source
PetoiBittle.RawCommand — Type
RawCommand(token::AbstractString)

A low-level PetoiBittle.Command that sends token verbatim (newline-terminated) without interpreting it. This is the escape hatch for any firmware command that does not yet have a dedicated typed command in this package, including sensor, pin, and other device-specific commands whose exact protocol is hardware-dependent.

# equivalent to sending "p\n" to the robot
PetoiBittle.send_command(connection, PetoiBittle.RawCommand("p"))

For a command that expects a response back, use PetoiBittle.RawQuery.

source
PetoiBittle.RawResponse — Type
RawResponse(line::String)

The result of a PetoiBittle.RawQuery: the raw response line the robot sent back, trimmed of its trailing carriage return / newline. Parse it yourself according to whatever the queried command returns.

source

Defining your own command

A command is any subtype of PetoiBittle.Command that implements PetoiBittle.serialize_to_bytes!. Optionally override PetoiBittle.command_terminator (for binary '~'-terminated or unterminated commands), PetoiBittle.command_return_type together with PetoiBittle.validate_return_type / PetoiBittle.deserialize_from_bytes (for commands that read a response), and the PetoiBittle.before_command / PetoiBittle.after_command hooks. The zero-allocation serialization helpers below are useful building blocks.

PetoiBittle._serialize_token! — Function
_serialize_token!(bytes, token::AbstractString, startidx)

Write the ASCII token byte for byte to bytes starting at startidx, without allocating. Used by fixed-token commands (skills, postures, gaits, ...). Accepts any AbstractString (String, SubString, ...); it specializes per concrete type at the call site, so it stays type-stable and allocation-free. Returns the modified bytes and the next to last modified index.

julia> PetoiBittle._serialize_token!(zeros(UInt8, 5), "ksit", 1)
(UInt8[0x6b, 0x73, 0x69, 0x74, 0x00], 5)
source
PetoiBittle._serialize_raw_i8! — Function
_serialize_raw_i8!(bytes, value::Int, startidx)

Write value as a single raw signed-byte (two's complement) to bytes at startidx. Used by binary commands whose arguments are packed as raw bytes (for example joint angles in a transform-to-frame command). Errors if value is outside the signed 8-bit range -128:127. Returns the modified bytes and the next to last modified index.

julia> PetoiBittle._serialize_raw_i8!(zeros(UInt8, 2), -1, 1)
(UInt8[0xff, 0x00], 2)
source