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

ci: setup CI using script #29

Merged
merged 19 commits into from
Jul 6, 2023
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Sync .clang-format with ament_lint
and run pre-commit all files

Signed-off-by: Alex Moriarty <[email protected]>
  • Loading branch information
moriarty committed Jun 30, 2023
commit c7a2de7957c33760ec846a13782e9ab67ece00da
85 changes: 15 additions & 70 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -1,75 +1,20 @@
---
BasedOnStyle: Google
ColumnLimit: 120
MaxEmptyLinesToKeep: 1
SortIncludes: false
Language: Cpp
BasedOnStyle: Google

Standard: Auto
IndentWidth: 2
TabWidth: 2
UseTab: Never
AccessModifierOffset: -2
ConstructorInitializerIndentWidth: 2
NamespaceIndentation: None
ContinuationIndentWidth: 4
IndentCaseLabels: true
IndentFunctionDeclarationAfterType: false

AlignEscapedNewlinesLeft: false
AlignTrailingComments: true

AllowAllParametersOfDeclarationOnNextLine: false
ExperimentalAutoDetectBinPacking: false
ObjCSpaceBeforeProtocolList: true
Cpp11BracedListStyle: false

AllowShortBlocksOnASingleLine: true
AllowShortIfStatementsOnASingleLine: false
AllowShortLoopsOnASingleLine: false
AllowShortFunctionsOnASingleLine: None
AllowShortCaseLabelsOnASingleLine: false

AlwaysBreakTemplateDeclarations: true
AlwaysBreakBeforeMultilineStrings: false
BreakBeforeBinaryOperators: false
BreakBeforeTernaryOperators: false
BreakConstructorInitializersBeforeComma: true

BinPackParameters: true
ConstructorInitializerAllOnOneLineOrOnePerLine: true
DerivePointerBinding: false
PointerBindsToType: true

PenaltyExcessCharacter: 50
PenaltyBreakBeforeFirstCallParameter: 30
PenaltyBreakComment: 1000
PenaltyBreakFirstLessLess: 10
PenaltyBreakString: 100
PenaltyReturnTypeOnItsOwnLine: 50

SpacesBeforeTrailingComments: 2
SpacesInParentheses: false
SpacesInAngles: false
SpaceInEmptyParentheses: false
SpacesInCStyleCastParentheses: false
SpaceAfterCStyleCast: false
SpaceAfterControlStatementKeyword: true
SpaceBeforeAssignmentOperators: true

# Configure each individual brace in BraceWrapping
BreakBeforeBraces: Custom

# Control of individual brace wrapping cases
AlignAfterOpenBracket: AlwaysBreak
BraceWrapping:
AfterCaseLabel: true
AfterClass: true
AfterControlStatement: true
AfterEnum: true
AfterFunction: true
AfterNamespace: true
AfterStruct: true
AfterUnion: true
BeforeCatch: true
BeforeElse: true
IndentBraces: false
AfterClass: true
AfterFunction: true
AfterNamespace: true
AfterStruct: true
AfterEnum: true
BreakBeforeBraces: Custom
ColumnLimit: 100
ConstructorInitializerIndentWidth: 0
ContinuationIndentWidth: 2
DerivePointerAlignment: false
PointerAlignment: Middle
ReflowComments: false
...
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# ros2_robotiq_gripper

This repository contains the ROS 2 driver, controller and description packages for working with a Robotiq Gripper.

# ros2_robotiq_gripper

## Build status

Original file line number Diff line number Diff line change
@@ -29,7 +29,6 @@
#pragma once

#include "controller_interface/controller_interface.hpp"

#include "std_srvs/srv/trigger.hpp"

namespace robotiq_controllers
@@ -41,17 +40,19 @@ class RobotiqActivationController : public controller_interface::ControllerInter

controller_interface::InterfaceConfiguration state_interface_configuration() const override;

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

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

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

CallbackReturn on_init() override;

private:
bool reactivateGripper(std_srvs::srv::Trigger::Request::SharedPtr req,
std_srvs::srv::Trigger::Response::SharedPtr resp);
bool reactivateGripper(
std_srvs::srv::Trigger::Request::SharedPtr req,
std_srvs::srv::Trigger::Response::SharedPtr resp);

static constexpr double ASYNC_WAITING = 2.0;
enum CommandInterfaces
58 changes: 28 additions & 30 deletions robotiq_controllers/src/robotiq_activation_controller.cpp
Original file line number Diff line number Diff line change
@@ -30,7 +30,8 @@

namespace robotiq_controllers
{
controller_interface::InterfaceConfiguration RobotiqActivationController::command_interface_configuration() const
controller_interface::InterfaceConfiguration
RobotiqActivationController::command_interface_configuration() const
{
controller_interface::InterfaceConfiguration config;
config.type = controller_interface::interface_configuration_type::INDIVIDUAL;
@@ -41,75 +42,71 @@ controller_interface::InterfaceConfiguration RobotiqActivationController::comman
return config;
}

controller_interface::InterfaceConfiguration RobotiqActivationController::state_interface_configuration() const
controller_interface::InterfaceConfiguration
RobotiqActivationController::state_interface_configuration() const
{
controller_interface::InterfaceConfiguration config;
config.type = controller_interface::interface_configuration_type::INDIVIDUAL;

return config;
}

controller_interface::return_type RobotiqActivationController::update(const rclcpp::Time& /*time*/,
const rclcpp::Duration& /*period*/)
controller_interface::return_type RobotiqActivationController::update(
const rclcpp::Time & /*time*/, const rclcpp::Duration & /*period*/)
{
return controller_interface::return_type::OK;
}

rclcpp_lifecycle::node_interfaces::LifecycleNodeInterface::CallbackReturn
RobotiqActivationController::on_activate(const rclcpp_lifecycle::State& /*previous_state*/)
RobotiqActivationController::on_activate(const rclcpp_lifecycle::State & /*previous_state*/)
{
// Check command interfaces.
if (command_interfaces_.size() != 2)
{
RCLCPP_ERROR(get_node()->get_logger(), "Expected %d command interfaces, but got %zu.", 2,
command_interfaces_.size());
if (command_interfaces_.size() != 2) {
RCLCPP_ERROR(
get_node()->get_logger(), "Expected %d command interfaces, but got %zu.", 2,
command_interfaces_.size());
return rclcpp_lifecycle::node_interfaces::LifecycleNodeInterface::CallbackReturn::ERROR;
}

try
{
try {
// Create service for re-activating the gripper.
reactivate_gripper_srv_ = get_node()->create_service<std_srvs::srv::Trigger>(
"~/reactivate_gripper",
[this](std_srvs::srv::Trigger::Request::SharedPtr req, std_srvs::srv::Trigger::Response::SharedPtr resp) {
this->reactivateGripper(req, resp);
});
}
catch (...)
{
"~/reactivate_gripper",
[this](
std_srvs::srv::Trigger::Request::SharedPtr req,
std_srvs::srv::Trigger::Response::SharedPtr resp) { this->reactivateGripper(req, resp); });
} catch (...) {
return LifecycleNodeInterface::CallbackReturn::ERROR;
}
return LifecycleNodeInterface::CallbackReturn::SUCCESS;
}

rclcpp_lifecycle::node_interfaces::LifecycleNodeInterface::CallbackReturn
RobotiqActivationController::on_deactivate(const rclcpp_lifecycle::State& /*previous_state*/)
RobotiqActivationController::on_deactivate(const rclcpp_lifecycle::State & /*previous_state*/)
{
try
{
try {
reactivate_gripper_srv_.reset();
}
catch (...)
{
} catch (...) {
return LifecycleNodeInterface::CallbackReturn::ERROR;
}

return LifecycleNodeInterface::CallbackReturn::SUCCESS;
}

rclcpp_lifecycle::node_interfaces::LifecycleNodeInterface::CallbackReturn RobotiqActivationController::on_init()
rclcpp_lifecycle::node_interfaces::LifecycleNodeInterface::CallbackReturn
RobotiqActivationController::on_init()
{
return LifecycleNodeInterface::CallbackReturn::SUCCESS;
}

bool RobotiqActivationController::reactivateGripper(std_srvs::srv::Trigger::Request::SharedPtr /*req*/,
std_srvs::srv::Trigger::Response::SharedPtr resp)
bool RobotiqActivationController::reactivateGripper(
std_srvs::srv::Trigger::Request::SharedPtr /*req*/,
std_srvs::srv::Trigger::Response::SharedPtr resp)
{
command_interfaces_[REACTIVATE_GRIPPER_RESPONSE].set_value(ASYNC_WAITING);
command_interfaces_[REACTIVATE_GRIPPER_CMD].set_value(1.0);

while (command_interfaces_[REACTIVATE_GRIPPER_RESPONSE].get_value() == ASYNC_WAITING)
{
while (command_interfaces_[REACTIVATE_GRIPPER_RESPONSE].get_value() == ASYNC_WAITING) {
std::this_thread::sleep_for(std::chrono::milliseconds(50));
}
resp->success = command_interfaces_[REACTIVATE_GRIPPER_RESPONSE].get_value();
@@ -120,4 +117,5 @@ bool RobotiqActivationController::reactivateGripper(std_srvs::srv::Trigger::Requ

#include "pluginlib/class_list_macros.hpp"

PLUGINLIB_EXPORT_CLASS(robotiq_controllers::RobotiqActivationController, controller_interface::ControllerInterface)
PLUGINLIB_EXPORT_CLASS(
robotiq_controllers::RobotiqActivationController, controller_interface::ControllerInterface)
4 changes: 2 additions & 2 deletions robotiq_driver/include/robotiq_driver/crc.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#pragma once

#include <vector>
#include <cstdint>
#include <vector>

uint16_t computeCRC(const std::vector<uint8_t>& cmd);
uint16_t computeCRC(const std::vector<uint8_t> & cmd);
15 changes: 8 additions & 7 deletions robotiq_driver/include/robotiq_driver/hardware_interface.hpp
Original file line number Diff line number Diff line change
@@ -39,9 +39,8 @@
#include "hardware_interface/types/hardware_interface_return_values.hpp"
#include "rclcpp/macros.hpp"
#include "rclcpp/rclcpp.hpp"

#include "robotiq_driver/visibility_control.h"
#include "robotiq_driver/robotiq_gripper_interface.hpp"
#include "robotiq_driver/visibility_control.h"

namespace robotiq_driver
{
@@ -54,7 +53,7 @@ class RobotiqGripperHardwareInterface : public hardware_interface::SystemInterfa
RobotiqGripperHardwareInterface();

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

ROBOTIQ_DRIVER_PUBLIC
std::vector<hardware_interface::StateInterface> export_state_interfaces() override;
@@ -63,16 +62,18 @@ class RobotiqGripperHardwareInterface : public hardware_interface::SystemInterfa
std::vector<hardware_interface::CommandInterface> export_command_interfaces() override;

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

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

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

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

private:
static constexpr double NO_NEW_CMD_ = std::numeric_limits<double>::quiet_NaN();
Original file line number Diff line number Diff line change
@@ -28,11 +28,11 @@

#pragma once

#include <serial/serial.h>

#include <string>
#include <vector>

#include <serial/serial.h>

/**
* @brief This class is responsible for communicating with the gripper via a serial port, and maintaining a record of
* the gripper's current state.
@@ -41,7 +41,7 @@
class RobotiqGripperInterface
{
public:
RobotiqGripperInterface(const std::string& com_port = "/dev/ttyUSB0", uint8_t slave_id = 0x09);
RobotiqGripperInterface(const std::string & com_port = "/dev/ttyUSB0", uint8_t slave_id = 0x09);

/**
* @brief Activates the gripper.
@@ -122,7 +122,8 @@ class RobotiqGripperInterface

private:
std::vector<uint8_t> createReadCommand(uint16_t first_register, uint8_t num_registers);
std::vector<uint8_t> createWriteCommand(uint16_t first_register, const std::vector<uint16_t>& data);
std::vector<uint8_t> createWriteCommand(
uint16_t first_register, const std::vector<uint16_t> & data);

/**
* @brief read response from the gripper.
@@ -138,7 +139,7 @@ class RobotiqGripperInterface
* @param cmd The command.
* @throw serial::IOException on failure to successfully communicate with gripper port
*/
void sendCommand(const std::vector<uint8_t>& cmd);
void sendCommand(const std::vector<uint8_t> & cmd);

/**
* @brief Read the current status of the gripper, and update member variables as appropriate.
Loading