API Reference¶
This section contains the complete API documentation for all LittleBot packages.
C++ API¶
Hardware Interface¶
-
namespace littlebot_base
To more information about the serial library used, please visit: https://github.com/NestorDP/cppserial.
Enums
-
enum class SerialError
Values:
-
enumerator None
-
enumerator InsufficientPermissions
-
enumerator ConfigBaudrateFailed
-
enumerator ReadFailed
-
enumerator WriteFailed
-
enumerator AlreadyOpen
-
enumerator NotOpen
-
enumerator NotClosed
-
enumerator Unknown
-
enumerator None
-
enum class DriverError
Values:
-
enumerator None
-
enumerator NoData
-
enumerator DecodeFailure
-
enumerator EncodeFailure
-
enumerator SizeMismatch
-
enumerator SerialReadError
-
enumerator SerialWriteError
-
enumerator InvalidControlChar
-
enumerator NoCommand
-
enumerator SerialInsufficientPermissions
-
enumerator SerialConfigBaudrateFailed
-
enumerator SerialReadFailed
-
enumerator SerialWriteFailed
-
enumerator SerialAlreadyOpen
-
enumerator SerialNotOpen
-
enumerator SerialNotClosed
-
enumerator Unknown
-
enumerator None
Variables
-
constexpr size_t kNumWheels = 2
-
class ILittlebotDriver
- #include <i_littlebot_driver.hpp>
Subclassed by littlebot_base::LittlebotDriver
Public Functions
-
ILittlebotDriver(const ILittlebotDriver&) = delete
Prevent copy and assignment.
-
virtual ~ILittlebotDriver() = default
Deconstructor for the ILittlebotDriver class.
-
virtual DriverError init() noexcept = 0
Initialize the driver.
- Returns:
DriverError The result of the initialization
-
virtual void readRTData(WheelRTData &state) const noexcept = 0
Read the current state from the RT buffer.
Note
This method is RT-safe (control loop)
- Parameters:
state – Reference to WheelRTData structure to store the read data
-
virtual void writeRTData(const WheelRTData &command) noexcept = 0
Write the command to the RT buffer.
Note
This method is RT-safe (control loop)
- Parameters:
command – Reference to WheelRTData structure containing the command data
-
virtual bool requestStatus() noexcept = 0
Receive data from the hardware and update the RT buffer.
Note
This method is NOT RT-safe (executor / IO thread)
- Returns:
true if data was received successfully
- Returns:
false if an error occurred
-
virtual bool sendCommand() noexcept = 0
Send command data to the hardware.
Note
This method is NOT RT-safe (executor / IO thread)
- Returns:
true if data was sent successfully
- Returns:
false if an error occurred
-
virtual DriverError getLastError() const noexcept = 0
Get the last error that occurred.
- Returns:
DriverError The last error code
-
virtual const DriverErrorCounters &getErrorCounters() const noexcept = 0
Get the error counters.
- Returns:
const DriverErrorCounters& Reference to the error counters structure
Public Static Attributes
-
static constexpr char kCommandChar = {'C'}
Command control characters.
-
static constexpr char kStatusChar = {'S'}
Status control characters.
-
ILittlebotDriver(const ILittlebotDriver&) = delete
-
class ILittlebotDriverFactory
- #include <i_littlebot_driver_factory.hpp>
Subclassed by littlebot_base::LittlebotDriverFactory
-
template<typename T>
class IRTBuffer - #include <i_rt_buffer.hpp>
-
class ISerialPort
- #include <i_serial_port.hpp>
Subclassed by littlebot_base::SerialPort
Public Functions
-
virtual ~ISerialPort() = default
Deconstructor for the ISerialPort class.
-
virtual SerialError open(std::string port, int baudrate) noexcept = 0
Open the serial port.
- Parameters:
port – Serial port device path (e.g., “/dev/ttyUSB0”)
baudrate – Baud rate for the serial communication
- Returns:
SerialError indicating success or type of failure
-
virtual SerialError close() noexcept = 0
Close the serial port.
- Returns:
SerialError indicating success or type of failure
-
virtual int read(std::vector<uint8_t> &payload) noexcept = 0
Read Packet from the serial port.
- Parameters:
payload – Vector to store the read packet data. Implementations must ensure the frame size never exceeds kMaxFrameSize.
- Returns:
Number of bytes read
-
virtual int write(const std::vector<uint8_t> &payload) noexcept = 0
Write Packet to the serial port.
- Parameters:
payload – Vector containing the packet data to write payload.size() must be <= kMaxFrameSize.
- Returns:
Number of bytes written
-
inline virtual bool isOpen() const noexcept
Check if the serial port is open.
- Returns:
true if the serial port is open
- Returns:
false if the serial port is closed
Public Static Attributes
-
static constexpr size_t kMaxFrameSize = 256
Maximum size of a frame that can be sent/received.
-
virtual ~ISerialPort() = default
-
class LittlebotDriver : public littlebot_base::ILittlebotDriver
- #include <littlebot_driver.hpp>
Public Functions
Construct a new Littlebot Driver object.
- Parameters:
serial_port – Shared pointer to the serial port interface
rt_state_buffer – Shared pointer to the real-time buffer interface for wheel state data
rt_command_buffer – Shared pointer to the real-time buffer interface for wheel command data
joint_names – Vector of joint names
port – Serial port name
baudrate – Serial port baudrate
-
virtual DriverError init() noexcept override
Initialize the driver.
Override the virtual method from ILittlebotDriver
-
virtual void readRTData(WheelRTData &state) const noexcept override
Read the current state from the RT buffer.
Override the virtual method from ILittlebotDriver
-
virtual void writeRTData(const WheelRTData &command) noexcept override
Write the command to the RT buffer.
Override the virtual method from ILittlebotDriver
-
virtual bool requestStatus() noexcept override
Receive data from the hardware and update the RT buffer.
Override the virtual method from ILittlebotDriver
-
virtual bool sendCommand() noexcept override
Send command data to the hardware.
Override the virtual method from ILittlebotDriver
-
inline virtual DriverError getLastError() const noexcept override
Get the last error that occurred.
Override the virtual method from ILittlebotDriver
-
inline virtual const DriverErrorCounters &getErrorCounters() const noexcept override
Get the error counters.
Override the virtual method from ILittlebotDriver
-
class LittlebotDriverFactory : public littlebot_base::ILittlebotDriverFactory
- #include <littlebot_driver_factory.hpp>
-
class LittlebotHardwareComponent : public hardware_interface::SystemInterface
- #include <littlebot_hardware_component.hpp>
Public Functions
-
LittlebotHardwareComponent() = default
Default constructor for the LittlebotHardwareComponent class.
-
~LittlebotHardwareComponent() = default
Deconstructor for the LittlebotHardwareComponent class.
-
hardware_interface::CallbackReturn on_init(const hardware_interface::HardwareComponentInterfaceParams ¶ms) override
Initialize the hardware component with the given parameters.
-
hardware_interface::CallbackReturn on_configure(const rclcpp_lifecycle::State &state) override
Configure the hardware communication.
-
std::vector<hardware_interface::StateInterface> export_state_interfaces() override
Export the state interfaces.
-
std::vector<hardware_interface::CommandInterface> export_command_interfaces() override
Export the command interfaces.
-
hardware_interface::return_type read(const rclcpp::Time &time, const rclcpp::Duration &period) override
Read the state of the hardware component.
-
hardware_interface::return_type write(const rclcpp::Time &time, const rclcpp::Duration &period) override
Write the command to the hardware component.
Set the Littlebot driver factory.
Note
This method is mainly used for testing purposes
- Parameters:
factory – Shared pointer to the Littlebot driver factory
-
LittlebotHardwareComponent() = default
-
class RosRTBuffer : public littlebot_base::IRTBuffer<littlebot_base::WheelRTData>
- #include <ros_rt_buffer.hpp>
-
class SerialPort : public littlebot_base::ISerialPort
- #include <serial_port.hpp>
Public Functions
-
virtual SerialError open(std::string port, int baudrate) noexcept override
Open the serial port.
Override the virtual method from ISerialPort
-
virtual SerialError close() noexcept override
Close the serial port.
Override the virtual method from ISerialPort
-
virtual int read(std::vector<uint8_t> &payload) noexcept override
Read packet data from the serial port.
Override the virtual method from ISerialPort
-
virtual int write(const std::vector<uint8_t> &payload) noexcept override
Write packet data to the serial port.
Override the virtual method from ISerialPort
-
virtual SerialError open(std::string port, int baudrate) noexcept override
-
struct WheelRTData
- #include <types.hpp>
-
struct DriverErrorCounters
- #include <types.hpp>
-
class Wheel
- #include <wheel.hpp>
Public Functions
-
inline void setCommandVelocity(double velocity)
Set the command velocity for the wheel.
- Parameters:
velocity – Desired command velocity
-
inline void setJointName(const std::string &joint_name)
Set the joint name for the wheel.
- Parameters:
joint_name – Name of the joint
-
inline void setStatusVelocity(double velocity)
Set the status velocity for the wheel.
- Parameters:
velocity – Measured status velocity
-
inline void setStatusPosition(double position)
Set the status position for the wheel.
- Parameters:
position – Measured status position
-
inline double getCommandVelocity() const
Get the command velocity for the wheel.
-
inline double getStatusPosition() const
Get the status position for the wheel.
-
inline double getStatusVelocity() const
Get the status velocity for the wheel.
-
inline std::string getJointName() const
Get the joint name for the wheel.
-
inline void setCommandVelocity(double velocity)
-
namespace codec
Functions
-
void encode(std::vector<uint8_t> &payload, const std::vector<Wheel> &wheels)
Encode wheel command data into a protobuf payload.
This function serializes the command velocities of the wheels into a protobuf message suitable for transmission to the hardware.
- Parameters:
payload – Output payload that will contain the serialized protobuf message
wheels – Vector of wheels providing command data
- Throws:
std::runtime_error – if serialization fails
-
void decode(const std::vector<uint8_t> &payload, std::vector<Wheel> &wheels)
Decode wheel state data from a protobuf payload.
This function deserializes a protobuf message received from the hardware and updates the wheel status fields. Existing wheel metadata (e.g., joint names) is preserved.
- Parameters:
payload – Input payload containing the serialized protobuf message
wheels – Vector of wheels to be updated with decoded state data
- Throws:
std::runtime_error – if parsing fails or data size mismatches
-
void encode(std::vector<uint8_t> &payload, const std::vector<Wheel> &wheels)
-
enum class SerialError
Communication¶
Warning
doxygenclass: Cannot find class “littlebot_base::LittlebotCommunication” in doxygen xml output for project “littlebot” from directory: /home/docs/checkouts/readthedocs.org/user_builds/littlebot/checkouts/latest/docs/doxygen/xml
RQT Plugin¶
Warning
doxygennamespace: Cannot find namespace “littlebot_rqt_plugin” in doxygen xml output for project “littlebot” from directory: /home/docs/checkouts/readthedocs.org/user_builds/littlebot/checkouts/latest/docs/doxygen/xml