PetoiBittle

Documentation for PetoiBittle.

PetoiBittle connection

PetoiBittle.jl implements convenience functions to find and/or check if a port is connected to Petoi Bittle Dog robot as well as establish a connection with a given port.

PetoiBittle.is_bittle_portFunction
is_bittle_port(port; timeout = 5)

Checks if the port responds with Start and Bittle upon connection. Only waits for timeout seconds for the responses. Returns true/false.

See also: find_bittle_port

source
PetoiBittle.find_bittle_portFunction
find_bittle_port(; individual_port_timeout = 5, verbose = true)

Scan all ports and find the one that returns true when calling is_bittle_port. Passes individual_port_timeout as timeout to is_bittle_port. If verbose=true (default) prints info messages to track scanning progress. If no port Bittle is found, throws an error.

See also: is_bittle_port

source

Users can also use PetoiBittle.LibSerialPort.get_port_list to get a list of all ports compatible with LibSerialPort.

PetoiBittle parsers

PetoiBittle.jl implements simple parsers to parse responses from serial ports of PetoiBittle directly from bytes

PetoiBittle.parse_numberFunction
parse_number(::Type{T}, bytes)

Parse decimal representation of a number of type T from bytes. Stops at non-digits characters, with the exception of - and ..

julia> PetoiBittle.parse_number(Int, [ 0x34, 0x32 ])
42

julia> PetoiBittle.parse_number(Float64, [ 0x2d, 0x30, 0x2e, 0x35 ])
-0.5
source
parse_number(bytes)

Short-hand for parse_number(Float64, bytes).

source
parse_number(::Type{T}, bytes, firstindex, lastindex)

Parse decimal representation of a number of type T from bytes between firstindex and lastindex. The firstindex and lastindex should be valid indices of bytes. Stops at non-digits characters, with the exception of - and ..

Returns (result, nextindex), where result is the actual parsed number and nextindex is either:

  • an index next to a non-digit character or;
  • lastindex + 1
julia> PetoiBittle.parse_number(Float64, [ 0x34, 0x32 ], 1, 1)
(4.0, 2)

julia> PetoiBittle.parse_number(Float64, [ 0x34, 0x32 ], 1, 2)
(42.0, 3)
source

PetoiBittle serializers

PetoiBittle.jl implements simple serializers to write responses to serial ports of PetoiBittle directly as bytes

PetoiBittle.serialize_to_bytes!Function
serialize_to_bytes!(bytes, number::Int, startidx)

Write the number digit by digit to bytes starting at startidx. Negative number start with the - character (0x2d, see PetoiBittle.Constants) Returns the modified bytes and the next to last modified index.

source
serialize_to_bytes!(bytes, spec::MoveJointSpec, startidx)

Write the spec to bytes starting at startidx. Returns the modified bytes and the next to last modified index.

julia> PetoiBittle.serialize_to_bytes!(zeros(UInt8, 4), PetoiBittle.MoveJointSpec(7, 0), 1)
(UInt8[0x37, 0x20, 0x30, 0x00], 4)
source
serialize_to_bytes!(bytes, task::MoveJoints, startidx)

Write the task to bytes starting at startidx. The MoveJoints task always starts with the I character. Returns the modified bytes and the next to last modified index.

julia> PetoiBittle.serialize_to_bytes!(zeros(UInt8, 16), PetoiBittle.MoveJoints((id = 1, angle = 10), (id = 3, angle = -10)), 1)
(UInt8[0x69, 0x31, 0x20, 0x31, 0x30, 0x20, 0x33, 0x20, 0x2d, 0x31, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00], 12)
source
PetoiBittle.DigitsIteratorType
DigitsIterator

A special iterator that iterates over digits of a number Int without allocating an intermediate array. Use the PetoiBittle.iterate_digits function to create the iterator.

julia> PetoiBittle.iterate_digits(123) |> collect
3-element Vector{Int64}:
 1
 2
 3

julia> reduce(+, PetoiBittle.iterate_digits(123))
6
source
PetoiBittle.iterate_digitsFunction
iterate_digits(number::Int)

Creates PetoiBittle.DigitsIterator from number. Use this to iterate through digits of the number without allocating intermediate array.

julia> PetoiBittle.iterate_digits(123) |> collect
3-element Vector{Int64}:
 1
 2
 3

julia> reduce(+, PetoiBittle.iterate_digits(123))
6
source

PetoiBittle Constants

PetoiBittle.ConstantsModule

A sub-module of PetoiBittle containing some useful constants Constants are united in their respective namespaces.

The available namespaces are:

  • char: a list of character codes in UInt8
    • tab: UInt8 code of the tab character '\t'
    • newline: UInt8 code of the newline character '\n'
    • caret: UInt8 code of the caret character '\r'
    • zero: UInt8 code of the zero character '0' (a digit)
    • one: UInt8 code of the one character '1' (a digit)
    • two: UInt8 code of the two character '2' (a digit)
    • three: UInt8 code of the three character '3' (a digit)
    • four: UInt8 code of the four character '4' (a digit)
    • five: UInt8 code of the five character '5' (a digit)
    • six: UInt8 code of the six character '6' (a digit)
    • seven: UInt8 code of the seven character '7' (a digit)
    • eight: UInt8 code of the eight character '8' (a digit)
    • nine: UInt8 code of the nine character '9' (a digit)
    • null: UInt8 code of the null character '\0' (a terminator)
    • dot: UInt8 code of the dot character '.'
    • minus: UInt8 code of the minus character '-'
    • space: UInt8 code of the space character ' '
julia> PetoiBittle.Constants.char.tab
0x09
source