Skip to content

Commit

Permalink
Removed ros-linter. Reformatted code as per Studio conventions.
Browse files Browse the repository at this point in the history
  • Loading branch information
kineticsystem committed Sep 5, 2023
1 parent 76c5497 commit 8788593
Show file tree
Hide file tree
Showing 16 changed files with 370 additions and 246 deletions.
76 changes: 65 additions & 11 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -1,20 +1,74 @@
---
Language: Cpp
BasedOnStyle: Google
ColumnLimit: 120
MaxEmptyLinesToKeep: 1
SortIncludes: false

Standard: Auto
IndentWidth: 2
TabWidth: 2
UseTab: Never
AccessModifierOffset: -2
AlignAfterOpenBracket: AlwaysBreak
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
BraceWrapping:
AfterCaseLabel: true
AfterClass: true
AfterControlStatement: true
AfterEnum: true
AfterFunction: true
AfterNamespace: true
AfterStruct: true
AfterEnum: true
BreakBeforeBraces: Custom
ColumnLimit: 100
ConstructorInitializerIndentWidth: 0
ContinuationIndentWidth: 2
DerivePointerAlignment: false
PointerAlignment: Middle
ReflowComments: false
...
AfterUnion: true
BeforeCatch: true
BeforeElse: true
IndentBraces: false
2 changes: 1 addition & 1 deletion .github/workflows/ci-ros-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ jobs:
with:
distribution: rolling
linter: cpplint
arguments: "--linelength=100 --filter=-whitespace/newline"
arguments: "--linelength=120 --filter=-whitespace/newline"
package-name: robotiq_driver
robotiq_controllers
robotiq_description
Original file line number Diff line number Diff line change
Expand Up @@ -40,19 +40,17 @@ 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
Expand Down
58 changes: 30 additions & 28 deletions robotiq_controllers/src/robotiq_activation_controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@

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;
Expand All @@ -42,71 +41,75 @@ RobotiqActivationController::command_interface_configuration() const
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();
Expand All @@ -117,5 +120,4 @@ bool RobotiqActivationController::reactivateGripper(

#include "pluginlib/class_list_macros.hpp"

PLUGINLIB_EXPORT_CLASS(
robotiq_controllers::RobotiqActivationController, controller_interface::ControllerInterface)
PLUGINLIB_EXPORT_CLASS(robotiq_controllers::RobotiqActivationController, controller_interface::ControllerInterface)
2 changes: 1 addition & 1 deletion robotiq_driver/include/robotiq_driver/crc.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,4 @@
#include <cstdint>
#include <vector>

uint16_t computeCRC(const std::vector<uint8_t> & cmd);
uint16_t computeCRC(const std::vector<uint8_t>& cmd);
11 changes: 4 additions & 7 deletions robotiq_driver/include/robotiq_driver/default_driver.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,10 @@

#pragma once

#include <serial/serial.h>

#include <robotiq_driver/driver.hpp>
#include <serial/serial.h>
#include <string>
#include <vector>

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

bool connect() override;
void disconnect() override;
Expand Down Expand Up @@ -101,8 +99,7 @@ class DefaultDriver : public Driver

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

/**
* @brief read response from the gripper.
Expand All @@ -118,7 +115,7 @@ class DefaultDriver : public Driver
* @param cmd The command.
* @throw serial::IOException on failure to successfully communicate with gripper port
*/
void send_command(const std::vector<uint8_t> & cmd);
void send_command(const std::vector<uint8_t>& cmd);

/**
* @brief Read the current status of the gripper, and update member variables as appropriate.
Expand Down
11 changes: 6 additions & 5 deletions robotiq_driver/include/robotiq_driver/default_driver_factory.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,13 @@

#pragma once

#include <hardware_interface/hardware_info.hpp>
#include <memory>
#include <robotiq_driver/default_driver_factory.hpp>
#include <robotiq_driver/driver_factory.hpp>

#include <hardware_interface/hardware_info.hpp>

#include <memory>

namespace robotiq_driver
{
/**
Expand All @@ -48,11 +50,10 @@ class DefaultDriverFactory : public DriverFactory
* @param info The hardware information.
* @return A driver to interact with the hardware.
*/
std::unique_ptr<Driver> create(const hardware_interface::HardwareInfo & info) const;
std::unique_ptr<Driver> create(const hardware_interface::HardwareInfo& info) const;

protected:
// Seam for testing.
virtual std::unique_ptr<Driver> create_driver(
const hardware_interface::HardwareInfo & info) const;
virtual std::unique_ptr<Driver> create_driver(const hardware_interface::HardwareInfo& info) const;
};
} // namespace robotiq_driver
2 changes: 1 addition & 1 deletion robotiq_driver/include/robotiq_driver/driver_factory.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,6 @@ namespace robotiq_driver
class DriverFactory
{
public:
virtual std::unique_ptr<Driver> create(const hardware_interface::HardwareInfo & info) const = 0;
virtual std::unique_ptr<Driver> create(const hardware_interface::HardwareInfo& info) const = 0;
};
} // namespace robotiq_driver
Loading

0 comments on commit 8788593

Please sign in to comment.