Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate to ROS2 Humble #4

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ find_package(serial REQUIRED)
find_package(hardware_interface REQUIRED)
find_package(controller_manager REQUIRED)
find_package(rclcpp REQUIRED)
find_package(rclcpp_lifecycle REQUIRED)
find_package(pluginlib REQUIRED)


Expand All @@ -36,6 +37,7 @@ ament_target_dependencies(
controller_manager
serial
rclcpp
rclcpp_lifecycle
pluginlib
)

Expand All @@ -56,6 +58,7 @@ ament_target_dependencies(
hardware_interface
controller_manager
rclcpp
rclcpp_lifecycle
pluginlib
)

Expand Down Expand Up @@ -87,6 +90,7 @@ ament_export_dependencies(
controller_manager
serial
rclcpp
rclcpp_lifecycle
pluginlib
)

Expand Down
17 changes: 9 additions & 8 deletions include/diffdrive_arduino/diffdrive_arduino.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,41 +3,42 @@

#include <cstring>
#include "rclcpp/rclcpp.hpp"
#include "rclcpp_lifecycle/state.hpp"
#include "rclcpp_lifecycle/node_interfaces/lifecycle_node_interface.hpp"
Copy link
Author

@fridfinnurm fridfinnurm Mar 29, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This import may actually be unnecessary (line 7)


#include "hardware_interface/base_interface.hpp"
#include "hardware_interface/system_interface.hpp"
#include "hardware_interface/handle.hpp"
#include "hardware_interface/hardware_info.hpp"
#include "hardware_interface/types/hardware_interface_return_values.hpp"
#include "hardware_interface/types/hardware_interface_status_values.hpp"

#include "config.h"
#include "wheel.h"
#include "arduino_comms.h"


using hardware_interface::return_type;
using hardware_interface::CallbackReturn;

class DiffDriveArduino : public hardware_interface::BaseInterface<hardware_interface::SystemInterface>
class DiffDriveArduino : public hardware_interface::SystemInterface
{


public:
DiffDriveArduino();

return_type configure(const hardware_interface::HardwareInfo & info) override;
CallbackReturn on_init(const hardware_interface::HardwareInfo & info) override;

std::vector<hardware_interface::StateInterface> export_state_interfaces() override;

std::vector<hardware_interface::CommandInterface> export_command_interfaces() override;

return_type start() override;
CallbackReturn on_activate(const rclcpp_lifecycle::State & previous_state) override;

return_type stop() override;
CallbackReturn on_deactivate(const rclcpp_lifecycle::State & previous_state) override;

return_type read() override;
return_type read(const rclcpp::Time & time, const rclcpp::Duration & period) override;

return_type write() override;
return_type write(const rclcpp::Time & time, const rclcpp::Duration & period) override;



Expand Down
18 changes: 10 additions & 8 deletions include/diffdrive_arduino/fake_robot.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,39 +3,41 @@


#include "rclcpp/rclcpp.hpp"
#include "rclcpp_lifecycle/state.hpp"
#include "rclcpp_lifecycle/node_interfaces/lifecycle_node_interface.hpp"

#include "hardware_interface/base_interface.hpp"
#include "hardware_interface/system_interface.hpp"
#include "hardware_interface/handle.hpp"
#include "hardware_interface/hardware_info.hpp"
#include "hardware_interface/types/hardware_interface_return_values.hpp"
#include "hardware_interface/types/hardware_interface_status_values.hpp"

#include "config.h"
#include "wheel.h"

using hardware_interface::return_type;
using hardware_interface::CallbackReturn;

class FakeRobot : public hardware_interface::BaseInterface<hardware_interface::SystemInterface>
class FakeRobot : public hardware_interface::SystemInterface
{


public:
using rclcpp_lifecycle::node_interfaces::LifecycleNodeInterface::CallbackReturn;
FakeRobot();

return_type configure(const hardware_interface::HardwareInfo & info) override;
CallbackReturn on_init(const hardware_interface::HardwareInfo & info) override;

std::vector<hardware_interface::StateInterface> export_state_interfaces() override;

std::vector<hardware_interface::CommandInterface> export_command_interfaces() override;

return_type start() override;
CallbackReturn on_activate(const rclcpp_lifecycle::State & previous_state) override;

return_type stop() override;
CallbackReturn on_deactivate(const rclcpp_lifecycle::State & previous_state) override;

return_type read() override;
return_type read(const rclcpp::Time & time, const rclcpp::Duration & period) override;

return_type write() override;
return_type write(const rclcpp::Time & time, const rclcpp::Duration & period) override;



Expand Down
3 changes: 2 additions & 1 deletion package.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0"?>
<package format="2">
<name>diffdrive_arduino</name>
<version>0.0.1</version>
<version>1.0.0</version>
<description>Provides an interface between diff_drive_controller and an Arduino.</description>

<maintainer email="[email protected]">Josh Newans</maintainer>
Expand All @@ -21,6 +21,7 @@
<depend>controller_manager</depend>
<depend>pluginlib</depend>
<depend>rclcpp</depend>
<depend>rclcpp_lifecycle</depend>
<depend>serial</depend>


Expand Down
24 changes: 10 additions & 14 deletions src/diffdrive_arduino.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ DiffDriveArduino::DiffDriveArduino()



return_type DiffDriveArduino::configure(const hardware_interface::HardwareInfo & info)
CallbackReturn DiffDriveArduino::on_init(const hardware_interface::HardwareInfo & info)
{
if (configure_default(info) != return_type::OK) {
return return_type::ERROR;
if (hardware_interface::SystemInterface::on_init(info) != CallbackReturn::SUCCESS) {
return CallbackReturn::ERROR;
}

RCLCPP_INFO(logger_, "Configuring...");
Expand All @@ -41,8 +41,7 @@ return_type DiffDriveArduino::configure(const hardware_interface::HardwareInfo &

RCLCPP_INFO(logger_, "Finished Configuration");

status_ = hardware_interface::status::CONFIGURED;
return return_type::OK;
return CallbackReturn::SUCCESS;
}

std::vector<hardware_interface::StateInterface> DiffDriveArduino::export_state_interfaces()
Expand Down Expand Up @@ -72,7 +71,7 @@ std::vector<hardware_interface::CommandInterface> DiffDriveArduino::export_comma
}


return_type DiffDriveArduino::start()
CallbackReturn DiffDriveArduino::on_activate(const rclcpp_lifecycle::State & previous_state)
{
RCLCPP_INFO(logger_, "Starting Controller...");

Expand All @@ -81,20 +80,17 @@ return_type DiffDriveArduino::start()
// arduino.setPidValues(14,7,0,100);
arduino_.setPidValues(30, 20, 0, 100);

status_ = hardware_interface::status::STARTED;

return return_type::OK;
return CallbackReturn::SUCCESS;
}

return_type DiffDriveArduino::stop()
CallbackReturn DiffDriveArduino::on_deactivate(const rclcpp_lifecycle::State & previous_state)
{
RCLCPP_INFO(logger_, "Stopping Controller...");
status_ = hardware_interface::status::STOPPED;

return return_type::OK;
return CallbackReturn::SUCCESS;
}

hardware_interface::return_type DiffDriveArduino::read()
hardware_interface::return_type DiffDriveArduino::read(const rclcpp::Time & time, const rclcpp::Duration & period)
{

// TODO fix chrono duration
Expand Down Expand Up @@ -128,7 +124,7 @@ hardware_interface::return_type DiffDriveArduino::read()

}

hardware_interface::return_type DiffDriveArduino::write()
hardware_interface::return_type DiffDriveArduino::write(const rclcpp::Time & time, const rclcpp::Duration & period)
{

if (!arduino_.connected())
Expand Down
23 changes: 10 additions & 13 deletions src/fake_robot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ FakeRobot::FakeRobot()



return_type FakeRobot::configure(const hardware_interface::HardwareInfo & info)
CallbackReturn FakeRobot::on_init(const hardware_interface::HardwareInfo & info)
{
if (configure_default(info) != return_type::OK) {
return return_type::ERROR;
if (hardware_interface::SystemInterface::on_init(info) != CallbackReturn::SUCCESS){
return CallbackReturn::ERROR;
}

RCLCPP_INFO(logger_, "Configuring...");
Expand All @@ -33,8 +33,7 @@ return_type FakeRobot::configure(const hardware_interface::HardwareInfo & info)

RCLCPP_INFO(logger_, "Finished Configuration");

status_ = hardware_interface::status::CONFIGURED;
return return_type::OK;
return CallbackReturn::SUCCESS;
}

std::vector<hardware_interface::StateInterface> FakeRobot::export_state_interfaces()
Expand Down Expand Up @@ -64,23 +63,21 @@ std::vector<hardware_interface::CommandInterface> FakeRobot::export_command_inte
}


return_type FakeRobot::start()
CallbackReturn FakeRobot::on_activate(const rclcpp_lifecycle::State & previous_state)
{
RCLCPP_INFO(logger_, "Starting Controller...");
status_ = hardware_interface::status::STARTED;

return return_type::OK;
return CallbackReturn::SUCCESS;
}

return_type FakeRobot::stop()
CallbackReturn FakeRobot::on_deactivate(const rclcpp_lifecycle::State & previous_state)
{
RCLCPP_INFO(logger_, "Stopping Controller...");
status_ = hardware_interface::status::STOPPED;

return return_type::OK;
return CallbackReturn::SUCCESS;
}

hardware_interface::return_type FakeRobot::read()
hardware_interface::return_type FakeRobot::read(const rclcpp::Time & time, const rclcpp::Duration & period)
{

// TODO fix chrono duration
Expand All @@ -101,7 +98,7 @@ hardware_interface::return_type FakeRobot::read()

}

hardware_interface::return_type FakeRobot::write()
hardware_interface::return_type FakeRobot::write(const rclcpp::Time & time, const rclcpp::Duration & period)
{

// Set the wheel velocities to directly match what is commanded
Expand Down