Skip to content

Commit

Permalink
Created base structure for littlebot_hardware_communication class
Browse files Browse the repository at this point in the history
  • Loading branch information
NestorDP committed Dec 11, 2024
1 parent e08fa1a commit 7d5fcda
Show file tree
Hide file tree
Showing 6 changed files with 452 additions and 0 deletions.
69 changes: 69 additions & 0 deletions littlebot_base/include/littlebot_base/hardware_communication.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
// // @ Copyright 2024 Nestor Neto

#pragma once

#include <string>
#include <vector>

namespace littlebot_base
{

class HardwareCommunication{
public:
/**
* @brief Deconstructor for the HardwareCommunication class
*
*/
virtual ~HardwareCommunication() = default;

/**
* @brief Set the command velocities
*/
virtual void setCommandVelocities(std::vector<float> velocities) = 0;

/**
* @brief Get the status velocities
*/
virtual std::vector<float> getStatusVelocities() const = 0;

/**
* @brief Get the status positions
*/
virtual std::vector<float> getStatusPositionsStatus() const = 0;

protected:
/**
* @brief Constructor for the LittlebotHardwareCommunication class
*/
HardwareCommunication() = default;

private:
/**
* @brief Receive data from the hardware
*/
virtual bool receive() = 0;

/**
* @brief Send data to the hardware
*/
virtual bool send() = 0;

/**
* @brief
*/
std::vector<float> command_velocities_;

/**
* @brief
*/
std::vector<float> status_positions_;

/**
* @brief
*/
std::vector<float> status_velocities_;


};

} // namespace littlebot_base
103 changes: 103 additions & 0 deletions littlebot_base/include/littlebot_base/littlebot_hardware_component.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
// // @ Copyright 2023 Nestor Neto

#pragma once

#include <memory>
#include <string>
#include <unordered_map>
#include <utility>
#include <vector>

#include <hardware_interface/handle.hpp>
#include <hardware_interface/hardware_info.hpp>
#include <hardware_interface/system_interface.hpp>
#include <hardware_interface/types/hardware_interface_return_values.hpp>
#include <rclcpp/rclcpp.hpp>
#include <rclcpp_lifecycle/state.hpp>

namespace littlebot_base
{

class LittlebotHardwareComponent : public hardware_interface::SystemInterface
{
public:
/**
* @brief Deconstructor for the LittlebotHardwareComponent class
*
*/
~LittlebotHardwareComponent() = default;

/**
* @brief
*/
hardware_interface::CallbackReturn on_init(
const hardware_interface::HardwareInfo & info) override;

/**
* @brief
*/
hardware_interface::CallbackReturn on_activate(
const rclcpp_lifecycle::State & state) override;

/**
* @brief
*/
hardware_interface::CallbackReturn on_deactivate(
const rclcpp_lifecycle::State & state) override;

/**
* @brief
*/
std::vector<hardware_interface::StateInterface> export_state_interfaces() override;

/**
* @brief
*/
std::vector<hardware_interface::CommandInterface> export_command_interfaces() override;

/**
* @brief
*/
hardware_interface::return_type read(
const rclcpp::Time & time, const rclcpp::Duration & period) override;

/**
* @brief
*/
hardware_interface::return_type write(
const rclcpp::Time & time, const rclcpp::Duration & period) override;


private:
/**
* @brief The name of the hardware component.
*/
const std::string hardware_component_name_{"LittlebotHardwareComponent"};

/**
* @brief command interface.
*/
std::vector<double> hw_commands_;

/**
* @brief position state interface.
*/
std::vector<double> hw_positions_;

/**
* @brief velocity state interface.
*/
std::vector<double> hw_velocities_;

/**
* @brief
*/
static constexpr int kNumCommandInterface_{1};

/**
* @brief
*/
static constexpr int kNumStateInterface_{2};
};

} // namespace littlebot_base
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
// // @ Copyright 2024 Nestor Neto

#pragma once

#include <string>
#include <vector>

#include <libserial/serial.hpp>

#include "littlebot_base/hardware_communication.hpp"

namespace littlebot_base
{

class LittlebotHardwareCommunication : public HardwareCommunication
{
public:
/**
* @brief Constructor for the LittlebotLittlebotHardwareCommunication class
*/
LittlebotHardwareCommunication(const std::string serial_port);

/**
* @brief Deconstructor for the LittlebotHardwareCommunication class
*/
~LittlebotHardwareCommunication();

/**
* @brief Set the command velocities
*/
void setCommandVelocities(std::vector<float> velocities) override;

/**
* @brief Get the status velocities
*/
std::vector<float> getStatusVelocities() const override;

/**
* @brief Get the status positions
*/
std::vector<float> getStatusPositionsStatus() const override;

private:
/**
* @brief Receive data from the hardware
*/
bool receive() override;

/**
* @brief Send data to the hardware
*/
bool send() override;

/**
* @brief
*/
std::vector<float> command_velocities_;

/**
* @brief
*/
std::vector<float> status_positions_;

/**
* @brief
*/
std::vector<float> status_velocities_;


};

} // namespace littlebot_base
9 changes: 9 additions & 0 deletions littlebot_base/littlebot_hardware_component.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<library path="littlebot_hardware_component">
<class name="littlebot_base/LittlebotHardwareComponent"
type="littlebot_base::LittlebotHardwareComponent"
base_class_type="hardware_interface::SystemInterface">
<description>
The ros2_control LittlebotHardwareComponent using a system hardware interface-type.
</description>
</class>
</library>
49 changes: 49 additions & 0 deletions littlebot_base/src/littlebot_hardware_communication.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// @ Copyright 2024 Nestor Neto

#include <string>
#include <vector>

#include "littlebot_base/littlebot_hardware_comunication.hpp"

namespace littlebot_base
{
LittlebotHardwareCommunication::LittlebotHardwareCommunication(const std::string serial_port)
{
std::cout << "LittlebotHardwareCommunication constructor" << serial_port << std::endl;
}

LittlebotHardwareCommunication::~LittlebotHardwareCommunication()
{
std::cout << "LittlebotHardwareCommunication deconstructor" << std::endl;
}

void LittlebotHardwareCommunication::setCommandVelocities(std::vector<float> velocities)
{
std::cout << "LittlebotHardwareCommunication setCommandVelocities" << std::endl;
}

std::vector<float> LittlebotHardwareCommunication::getStatusVelocities() const
{
std::cout << "LittlebotHardwareCommunication getStatusVelocities" << std::endl;
return std::vector<float>{1.2, 3.4};
}

std::vector<float> LittlebotHardwareCommunication::getStatusPositionsStatus() const
{
std::cout << "LittlebotHardwareCommunication getStatusPositionsStatus" << std::endl;
return std::vector<float>{1.2, 3.4};
}

bool LittlebotHardwareCommunication::receive()
{
std::cout << "LittlebotHardwareCommunication receive" << std::endl;
return true;
}

bool LittlebotHardwareCommunication::send()
{
std::cout << "LittlebotHardwareCommunication send" << std::endl;
return true;
}

} // namespace littlebot_base
Loading

0 comments on commit 7d5fcda

Please sign in to comment.