Skip to content

Commit 1389dec

Browse files
committed
Add clang-format from RAI
Signed-off-by: Kacper Dąbrowski <[email protected]>
1 parent 351dc0b commit 1389dec

File tree

5 files changed

+153
-135
lines changed

5 files changed

+153
-135
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
Language: Cpp
2+
BasedOnStyle: Google
3+
4+
AccessModifierOffset: -2
5+
AlignAfterOpenBracket: AlwaysBreak
6+
BraceWrapping:
7+
AfterClass: true
8+
AfterFunction: true
9+
AfterNamespace: true
10+
AfterStruct: true
11+
AfterEnum: true
12+
BreakBeforeBraces: Custom
13+
ColumnLimit: 100
14+
ConstructorInitializerIndentWidth: 0
15+
ContinuationIndentWidth: 2
16+
DerivePointerAlignment: false
17+
PointerAlignment: Middle
18+
ReflowComments: false

ros2_ws/src/robotic_manipulation/include/robotic_manipulation/arm_controller.h

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,17 @@
1717

1818
#include <moveit/move_group_interface/move_group_interface.h>
1919

20-
class ArmController {
20+
class ArmController
21+
{
2122
public:
2223
ArmController() = default;
2324
~ArmController();
2425

2526
void Initialize();
2627

27-
geometry_msgs::msg::Pose CalculatePose(double x, double y, double z,
28-
double r = 0.0);
28+
geometry_msgs::msg::Pose CalculatePose(double x, double y, double z, double r = 0.0);
2929

30-
bool
31-
MoveThroughWaypoints(std::vector<geometry_msgs::msg::Pose> const &waypoints);
30+
bool MoveThroughWaypoints(std::vector<geometry_msgs::msg::Pose> const & waypoints);
3231

3332
void Open();
3433
void Close();
@@ -37,9 +36,9 @@ class ArmController {
3736
bool GetGripper();
3837

3938
std::vector<double> CaptureJointValues();
40-
bool SetJointValues(std::vector<double> const &jointValues);
39+
bool SetJointValues(std::vector<double> const & jointValues);
4140

42-
void SetReferenceFrame(std::string const &frame);
41+
void SetReferenceFrame(std::string const & frame);
4342

4443
private:
4544
// The joint values for the gripper to be open and closed.

ros2_ws/src/robotic_manipulation/src/arm_controller.cpp

Lines changed: 45 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@
1515

1616
#include "robotic_manipulation/arm_controller.h"
1717

18-
#include <rosgraph_msgs/msg/clock.hpp>
19-
2018
#include <numbers>
19+
#include <rosgraph_msgs/msg/clock.hpp>
2120

22-
void ArmController::Initialize() {
21+
void ArmController::Initialize()
22+
{
2323
m_node = rclcpp::Node::make_shared("arm_controller");
2424
m_node->set_parameter(rclcpp::Parameter("use_sim_time", true));
2525

@@ -28,32 +28,31 @@ void ArmController::Initialize() {
2828
m_executor.add_node(m_node);
2929
m_spinner = std::thread([this]() { m_executor.spin(); });
3030

31-
m_pandaArm = std::make_shared<moveit::planning_interface::MoveGroupInterface>(
32-
m_node, "panda_arm");
33-
m_hand = std::make_shared<moveit::planning_interface::MoveGroupInterface>(
34-
m_node, "hand");
31+
m_pandaArm =
32+
std::make_shared<moveit::planning_interface::MoveGroupInterface>(m_node, "panda_arm");
33+
m_hand = std::make_shared<moveit::planning_interface::MoveGroupInterface>(m_node, "hand");
3534

3635
m_pandaArm->setMaxVelocityScalingFactor(1.0);
3736
m_pandaArm->setMaxAccelerationScalingFactor(1.0);
3837
}
3938

40-
ArmController::~ArmController() {
39+
ArmController::~ArmController()
40+
{
4141
m_executor.cancel();
4242
if (m_spinner.joinable()) {
4343
m_spinner.join();
4444
}
4545
}
4646

47-
geometry_msgs::msg::Pose ArmController::CalculatePose(double x, double y,
48-
double z, double r) {
47+
geometry_msgs::msg::Pose ArmController::CalculatePose(double x, double y, double z, double r)
48+
{
4949
geometry_msgs::msg::Pose pose;
5050
pose.position.x = x;
5151
pose.position.y = y;
5252
pose.position.z = z;
5353

5454
auto quat = tf2::Quaternion();
55-
quat.setEuler(EndEffectorBaseRoll, EndEffectorBasePitch,
56-
EndEffectorBaseYaw + r);
55+
quat.setEuler(EndEffectorBaseRoll, EndEffectorBasePitch, EndEffectorBaseYaw + r);
5756
pose.orientation.x = quat.x();
5857
pose.orientation.y = quat.y();
5958
pose.orientation.z = quat.z();
@@ -62,72 +61,75 @@ geometry_msgs::msg::Pose ArmController::CalculatePose(double x, double y,
6261
return pose;
6362
}
6463

65-
bool ArmController::MoveThroughWaypoints(
66-
std::vector<geometry_msgs::msg::Pose> const &waypoints) {
64+
bool ArmController::MoveThroughWaypoints(std::vector<geometry_msgs::msg::Pose> const & waypoints)
65+
{
6766
auto logger = m_node->get_logger();
6867

6968
int constexpr NumTries = 10;
7069
for (int i = 0; i < NumTries; i++) {
7170
moveit_msgs::msg::RobotTrajectory trajectory;
72-
if (m_pandaArm->computeCartesianPath(waypoints, 0.01, 0.0, trajectory) ==
73-
-1) {
74-
RCLCPP_ERROR(logger,
75-
"MoveThroughWaypoints: Failed to compute Cartesian path");
71+
if (m_pandaArm->computeCartesianPath(waypoints, 0.01, 0.0, trajectory) == -1) {
72+
RCLCPP_ERROR(logger, "MoveThroughWaypoints: Failed to compute Cartesian path");
7673
continue;
7774
}
7875

79-
if (m_pandaArm->execute(trajectory) ==
80-
moveit::core::MoveItErrorCode::SUCCESS) {
76+
if (m_pandaArm->execute(trajectory) == moveit::core::MoveItErrorCode::SUCCESS) {
8177
return true;
8278
}
83-
RCLCPP_ERROR(logger, "MoveThroughWaypoints: Failed to execute "
84-
"trajectory, trying again...");
79+
RCLCPP_ERROR(
80+
logger,
81+
"MoveThroughWaypoints: Failed to execute "
82+
"trajectory, trying again...");
8583
}
8684

8785
RCLCPP_ERROR(
88-
logger,
89-
"MoveThroughWaypoints: Failed to execute trajectory after %d tries",
90-
NumTries);
86+
logger, "MoveThroughWaypoints: Failed to execute trajectory after %d tries", NumTries);
9187
return false;
9288
}
9389

94-
void ArmController::Open() {
90+
void ArmController::Open()
91+
{
9592
gripper.store(true);
9693
m_hand->setJointValueTarget("panda_finger_joint1", OpenGripperJointValue);
9794
while (m_hand->move() != moveit::core::MoveItErrorCode::SUCCESS) {
9895
RCLCPP_ERROR(m_node->get_logger(), "Failed to open hand");
9996
}
10097
}
10198

102-
void ArmController::Close() {
99+
void ArmController::Close()
100+
{
103101
gripper.store(false);
104102
m_hand->setJointValueTarget("panda_finger_joint1", ClosedGripperJointValue);
105103
while (m_hand->move() != moveit::core::MoveItErrorCode::SUCCESS) {
106104
RCLCPP_ERROR(m_node->get_logger(), "Failed to close hand");
107105
}
108106
}
109107

110-
std::vector<double> ArmController::GetEffectorPose() {
108+
std::vector<double> ArmController::GetEffectorPose()
109+
{
111110
auto pose = m_pandaArm->getCurrentPose().pose;
112-
auto rotation = tf2::Quaternion(pose.orientation.x, pose.orientation.y,
113-
pose.orientation.z, pose.orientation.w);
111+
auto rotation =
112+
tf2::Quaternion(pose.orientation.x, pose.orientation.y, pose.orientation.z, pose.orientation.w);
114113
tf2::Matrix3x3 m(rotation);
115114
m.getRPY(pose.orientation.x, pose.orientation.y, pose.orientation.z, 0);
116-
return {pose.position.x,
117-
pose.position.y,
118-
pose.position.z,
119-
pose.orientation.x,
120-
pose.orientation.y - EndEffectorBasePitch,
121-
pose.orientation.z - (tf2Radians(180.0) - EndEffectorBaseYaw)};
115+
return {
116+
pose.position.x,
117+
pose.position.y,
118+
pose.position.z,
119+
pose.orientation.x,
120+
pose.orientation.y - EndEffectorBasePitch,
121+
pose.orientation.z - (tf2Radians(180.0) - EndEffectorBaseYaw)};
122122
};
123123

124124
bool ArmController::GetGripper() { return gripper.load(); }
125125

126-
std::vector<double> ArmController::CaptureJointValues() {
126+
std::vector<double> ArmController::CaptureJointValues()
127+
{
127128
return m_pandaArm->getCurrentJointValues();
128129
}
129130

130-
bool ArmController::SetJointValues(std::vector<double> const &jointValues) {
131+
bool ArmController::SetJointValues(std::vector<double> const & jointValues)
132+
{
131133
m_pandaArm->setJointValueTarget(jointValues);
132134
if (m_pandaArm->move() != moveit::core::MoveItErrorCode::SUCCESS) {
133135
RCLCPP_ERROR(m_node->get_logger(), "Failed to set joint values");
@@ -136,17 +138,18 @@ bool ArmController::SetJointValues(std::vector<double> const &jointValues) {
136138
return true;
137139
}
138140

139-
void ArmController::SetReferenceFrame(std::string const &frame) {
141+
void ArmController::SetReferenceFrame(std::string const & frame)
142+
{
140143
m_pandaArm->setPoseReferenceFrame(frame);
141144
}
142145

143-
void ArmController::WaitForClockMessage() {
146+
void ArmController::WaitForClockMessage()
147+
{
144148
bool clockReceived = false;
145149
auto qos = rclcpp::QoS(rclcpp::KeepLast(1));
146150
qos.best_effort();
147151
auto subscription = m_node->create_subscription<rosgraph_msgs::msg::Clock>(
148-
"/clock", qos,
149-
[&](rosgraph_msgs::msg::Clock::SharedPtr) { clockReceived = true; });
152+
"/clock", qos, [&](rosgraph_msgs::msg::Clock::SharedPtr) { clockReceived = true; });
150153
while (!clockReceived) {
151154
rclcpp::spin_some(m_node);
152155
}

0 commit comments

Comments
 (0)