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_port — Function
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
PetoiBittle.find_bittle_port — Function
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
PetoiBittle.Connection — Type
ConnectionA connection to Petoi Bittle robot. Use PetoiBittle.connect to open a connection.
PetoiBittle.connect — Function
connect(port::String; [timeout = 5])Open a PetoiBittle.Connection at a specified port. Try for no longer than timeout. The port must be manually PetoiBittle.disconnect-ed when unneeded. The timeout is also being used to set read and write timeouts.
See PetoiBittle.is_bittle_port and PetoiBittle.find_bittle_port.
PetoiBittle.disconnect — Function
disconnect(connection::Connection)Disconnects the connection.
See also: PetoiBittle.Connection, PetoiBittle.connect
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_number — Function
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.5parse_number(bytes)Short-hand for parse_number(Float64, bytes).
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)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.
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)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)PetoiBittle.DigitsIterator — Type
DigitsIteratorA 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))
6PetoiBittle.iterate_digits — Function
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))
6PetoiBittle Constants
PetoiBittle.Constants — Module
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 inUInt8tab:UInt8code of the tab character '\t'newline:UInt8code of the newline character '\n'caret:UInt8code of the caret character '\r'zero:UInt8code of the zero character '0' (a digit)one:UInt8code of the one character '1' (a digit)two:UInt8code of the two character '2' (a digit)three:UInt8code of the three character '3' (a digit)four:UInt8code of the four character '4' (a digit)five:UInt8code of the five character '5' (a digit)six:UInt8code of the six character '6' (a digit)seven:UInt8code of the seven character '7' (a digit)eight:UInt8code of the eight character '8' (a digit)nine:UInt8code of the nine character '9' (a digit)null:UInt8code of the null character '\0' (a terminator)dot:UInt8code of the dot character '.'minus:UInt8code of the minus character '-'space:UInt8code of the space character ' '
julia> PetoiBittle.Constants.char.tab
0x09PetoiBittle.ConstantsPetoiBittle.CommandPetoiBittle.ConnectionPetoiBittle.DigitsIteratorPetoiBittle.GyroCalibratePetoiBittle.GyroStatsPetoiBittle.GyroStatsOutputPetoiBittle.MoveJointSpecPetoiBittle.MoveJointsPetoiBittle.NoResponsePetoiBittle.RestPetoiBittle.SkillPetoiBittle.after_commandPetoiBittle.before_commandPetoiBittle.command_return_typePetoiBittle.connectPetoiBittle.deserialize_from_bytesPetoiBittle.disconnectPetoiBittle.find_bittle_portPetoiBittle.is_bittle_portPetoiBittle.iterate_digitsPetoiBittle.parse_numberPetoiBittle.send_commandPetoiBittle.serialize_to_bytes!PetoiBittle.validate_return_type