Skip to content

Commit 424ca2a

Browse files
authored
Merge pull request #316 from lbr-stack/backport-315-to-jazzy
Backport 315 to jazzy
2 parents 195d57d + ba4ac4b commit 424ca2a

12 files changed

Lines changed: 81 additions & 80 deletions

File tree

lbr_demos/lbr_demos_advanced_cpp/CMakeLists.txt

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,4 @@ install(
7676
RUNTIME DESTINATION lib/${PROJECT_NAME}
7777
)
7878

79-
install(
80-
DIRECTORY config
81-
DESTINATION share/${PROJECT_NAME}
82-
)
83-
8479
ament_package()

lbr_demos/lbr_demos_advanced_cpp/config/lbr_system_config.yaml

Lines changed: 0 additions & 37 deletions
This file was deleted.

lbr_demos/lbr_demos_advanced_cpp/doc/lbr_demos_advanced_cpp.rst

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,14 +62,12 @@ This demo uses the admittance controller.
6262
- ``FRI control mode``: ``POSITION_CONTROL``
6363
- ``FRI client command mode``: ``POSITION``
6464

65-
#. Launch the robot driver (please note that a different system configuration file is used with heavier smoothing!):
65+
#. Launch the robot driver:
6666

6767
.. code-block:: bash
6868
6969
ros2 launch lbr_bringup hardware.launch.py \
7070
ctrl:=admittance_controller \
71-
sys_cfg_pkg:=lbr_demos_advanced_cpp \
72-
sys_cfg:=config/lbr_system_config.yaml \
7371
model:=iiwa7 # [iiwa7, iiwa14, med7, med14]
7472
7573
#. Now gently move the robot at the end-effector.

lbr_description/ros2_control/lbr_controllers.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@
108108
chain_tip: lbr_link_ee
109109
damping: 0.2 # damping factor for the pseudo-inverse of the Jacobian
110110
max_linear_velocity: 2.0 # maximum linear velocity
111-
max_angular_velocity: 2.0 # maximum linear acceleration
111+
max_angular_velocity: 2.0 # maximum angular velocity
112112
joint_gains: [1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0] # joint gains
113113
cartesian_gains: [1.0, 1.0, 1.0, 1.0, 1.0, 1.0] # cartesian gains
114114
filter:
@@ -121,9 +121,9 @@
121121
chain_root: lbr_link_0
122122
chain_tip: lbr_link_ee
123123
twist_in_tip_frame: true # if true, the twist command is expressed in the tip frame, otherwise in the root frame
124-
damping: 0.2 # damping factor for the pseudo-inverse of the Jacobian
125-
max_linear_velocity: 0.1 # maximum linear velocity
126-
max_angular_velocity: 0.1 # maximum linear acceleration
124+
damping: 0.02 # damping factor for the pseudo-inverse of the Jacobian
125+
max_linear_velocity: 0.2 # maximum linear velocity
126+
max_angular_velocity: 0.2 # maximum angular velocity
127127
joint_gains: [1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0] # joint gains
128128
cartesian_gains: [1.0, 1.0, 1.0, 1.0, 1.0, 1.0] # cartesian gains
129129
timeout: 0.2 # zeros the twist command when no command is received within timeout [s]

lbr_fri_ros2/include/lbr_fri_ros2/math.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,12 @@
33

44
#include <array>
55

6+
#include "lbr_fri_ros2/types.hpp"
7+
68
namespace lbr_fri_ros2 {
79
bool norm_in_bounds(const double &x0, const double &x1, const double &x2, const double &max);
810
bool norm_in_bounds(const std::array<double, 3> &vec, const double &max);
11+
bool all_jnts_in_bounds(const_jnt_array_t_ref vals, const_jnt_array_t_ref lower,
12+
const_jnt_array_t_ref upper);
913
} // namespace lbr_fri_ros2
1014
#endif // LBR_FRI_ROS2__MATH_HPP_

lbr_fri_ros2/src/control.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,10 +101,10 @@ void AdmittanceImpl::log_info() const {
101101

102102
void InvJacCtrlImpl::compute_impl_(const_jnt_array_t_ref q, jnt_array_t_ref dq) {
103103
// clip velocity
104-
twist_target_.head(3).unaryExpr([&](double v) {
104+
twist_target_.head(3) = twist_target_.head(3).unaryExpr([&](double v) {
105105
return std::clamp(v, -parameters_.max_linear_velocity, parameters_.max_linear_velocity);
106106
});
107-
twist_target_.tail(3).unaryExpr([&](double v) {
107+
twist_target_.tail(3) = twist_target_.tail(3).unaryExpr([&](double v) {
108108
return std::clamp(v, -parameters_.max_angular_velocity, parameters_.max_angular_velocity);
109109
});
110110

lbr_fri_ros2/src/math.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,13 @@ bool norm_in_bounds(const double &x0, const double &x1, const double &x2, const
88
bool norm_in_bounds(const std::array<double, 3> &vec, const double &max) {
99
return norm_in_bounds(vec[0], vec[1], vec[2], max);
1010
}
11+
bool all_jnts_in_bounds(const_jnt_array_t_ref vals, const_jnt_array_t_ref lower,
12+
const_jnt_array_t_ref upper) {
13+
for (std::size_t i = 0; i < vals.size(); ++i) {
14+
if (vals[i] < lower[i] || upper[i] < vals[i]) {
15+
return false;
16+
}
17+
}
18+
return true;
19+
}
1120
} // namespace lbr_fri_ros2

lbr_ros2_control/include/lbr_ros2_control/controllers/twist_controller.hpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include "lbr_fri_ros2/control.hpp"
2222
#include "lbr_fri_ros2/formatting.hpp"
2323
#include "lbr_fri_ros2/kinematics.hpp"
24+
#include "lbr_fri_ros2/math.hpp"
2425
#include "lbr_fri_ros2/types.hpp"
2526
#include "lbr_ros2_control/system_interface_type_values.hpp"
2627

@@ -53,6 +54,7 @@ class TwistController : public controller_interface::ControllerInterface {
5354
void reset_command_buffer_();
5455
void zero_joint_velocity_command_();
5556
void configure_joint_names_();
57+
void configure_joint_limits_();
5658
void configure_inv_jac_ctrl_impl_();
5759
void log_info_() const;
5860

@@ -62,10 +64,11 @@ class TwistController : public controller_interface::ControllerInterface {
6264

6365
// joint veloctiy computation
6466
std::unique_ptr<lbr_fri_ros2::InvJacCtrlImpl> inv_jac_ctrl_impl_ptr_;
65-
lbr_fri_ros2::jnt_array_t q_, dq_;
67+
lbr_fri_ros2::jnt_array_t q_, q_target_, dq_;
6668

6769
// interfaces
6870
lbr_fri_ros2::jnt_name_array_t joint_names_;
71+
lbr_fri_ros2::jnt_array_t lower_joint_limits_, upper_joint_limits_;
6972
std::vector<std::reference_wrapper<hardware_interface::LoanedStateInterface>>
7073
joint_position_state_interfaces_;
7174
std::unique_ptr<std::reference_wrapper<hardware_interface::LoanedStateInterface>>

lbr_ros2_control/src/controllers/admittance_controller.cpp

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,7 @@ AdmittanceController::on_configure(const rclcpp_lifecycle::State & /*previous_st
183183

184184
controller_interface::CallbackReturn
185185
AdmittanceController::on_activate(const rclcpp_lifecycle::State & /*previous_state*/) {
186+
initialized_ = false;
186187
if (!assign_state_interfaces_()) {
187188
release_state_interfaces_();
188189
return controller_interface::CallbackReturn::ERROR;
@@ -256,12 +257,12 @@ void AdmittanceController::configure_joint_names_() {
256257
if (joint_names_.size() != lbr_fri_ros2::N_JNTS) {
257258
RCLCPP_ERROR(
258259
this->get_node()->get_logger(),
259-
"Number of joint names (%ld) does not match the number of joints in the robot (%d).",
260+
"Number of joint names '%ld' does not match the number of joints in the robot '%d'.",
260261
joint_names_.size(), lbr_fri_ros2::N_JNTS);
261262
throw std::runtime_error("Failed to configure joint names.");
262263
}
263264
std::string robot_name = this->get_node()->get_parameter("robot_name").as_string();
264-
for (int i = 0; i < lbr_fri_ros2::N_JNTS; ++i) {
265+
for (std::size_t i = 0; i < lbr_fri_ros2::N_JNTS; ++i) {
265266
joint_names_[i] = robot_name + "_A" + std::to_string(i + 1);
266267
}
267268
}
@@ -270,8 +271,8 @@ void AdmittanceController::configure_admittance_impl_() {
270271
if (this->get_node()->get_parameter("admittance.mass").as_double_array().size() !=
271272
lbr_fri_ros2::CARTESIAN_DOF) {
272273
RCLCPP_ERROR(this->get_node()->get_logger(),
273-
"Number of mass values (%ld) does not match the number of cartesian degrees of "
274-
"freedom (%d).",
274+
"Number of mass values '%ld' does not match the number of cartesian degrees of "
275+
"freedom '%d'.",
275276
this->get_node()->get_parameter("admittance.mass").as_double_array().size(),
276277
lbr_fri_ros2::CARTESIAN_DOF);
277278
throw std::runtime_error("Failed to configure admittance parameters.");
@@ -280,32 +281,32 @@ void AdmittanceController::configure_admittance_impl_() {
280281
lbr_fri_ros2::CARTESIAN_DOF) {
281282
RCLCPP_ERROR(
282283
this->get_node()->get_logger(),
283-
"Number of damping values (%ld) does not match the number of cartesian degrees of freedom "
284-
"(%d).",
284+
"Number of damping values '%ld' does not match the number of cartesian degrees of freedom "
285+
"'%d'.",
285286
this->get_node()->get_parameter("admittance.damping").as_double_array().size(),
286287
lbr_fri_ros2::CARTESIAN_DOF);
287288
throw std::runtime_error("Failed to configure admittance parameters.");
288289
}
289290
if (this->get_node()->get_parameter("admittance.stiffness").as_double_array().size() !=
290291
lbr_fri_ros2::CARTESIAN_DOF) {
291292
RCLCPP_ERROR(this->get_node()->get_logger(),
292-
"Number of stiffness values (%ld) does not match the number of cartesian degrees "
293+
"Number of stiffness values '%ld' does not match the number of cartesian degrees "
293294
"of freedom "
294-
"(%d).",
295+
"'%d'.",
295296
this->get_node()->get_parameter("admittance.stiffness").as_double_array().size(),
296297
lbr_fri_ros2::CARTESIAN_DOF);
297298
throw std::runtime_error("Failed to configure admittance parameters.");
298299
}
299300
lbr_fri_ros2::cart_array_t mass_array;
300-
for (unsigned int i = 0; i < lbr_fri_ros2::CARTESIAN_DOF; ++i) {
301+
for (std::size_t i = 0; i < lbr_fri_ros2::CARTESIAN_DOF; ++i) {
301302
mass_array[i] = this->get_node()->get_parameter("admittance.mass").as_double_array()[i];
302303
}
303304
lbr_fri_ros2::cart_array_t damping_array;
304-
for (unsigned int i = 0; i < lbr_fri_ros2::CARTESIAN_DOF; ++i) {
305+
for (std::size_t i = 0; i < lbr_fri_ros2::CARTESIAN_DOF; ++i) {
305306
damping_array[i] = this->get_node()->get_parameter("admittance.damping").as_double_array()[i];
306307
}
307308
lbr_fri_ros2::cart_array_t stiffness_array;
308-
for (unsigned int i = 0; i < lbr_fri_ros2::CARTESIAN_DOF; ++i) {
309+
for (std::size_t i = 0; i < lbr_fri_ros2::CARTESIAN_DOF; ++i) {
309310
stiffness_array[i] =
310311
this->get_node()->get_parameter("admittance.stiffness").as_double_array()[i];
311312
}
@@ -318,7 +319,7 @@ void AdmittanceController::configure_inv_jac_ctrl_impl_() {
318319
lbr_fri_ros2::N_JNTS) {
319320
RCLCPP_ERROR(
320321
this->get_node()->get_logger(),
321-
"Number of joint gains (%ld) does not match the number of joints in the robot (%d).",
322+
"Number of joint gains '%ld' does not match the number of joints in the robot '%d'.",
322323
this->get_node()->get_parameter("inv_jac_ctrl.joint_gains").as_double_array().size(),
323324
lbr_fri_ros2::N_JNTS);
324325
throw std::runtime_error("Failed to configure joint gains.");
@@ -327,19 +328,19 @@ void AdmittanceController::configure_inv_jac_ctrl_impl_() {
327328
lbr_fri_ros2::CARTESIAN_DOF) {
328329
RCLCPP_ERROR(
329330
this->get_node()->get_logger(),
330-
"Number of cartesian gains (%ld) does not match the number of cartesian degrees of freedom "
331-
"(%d).",
331+
"Number of cartesian gains '%ld' does not match the number of cartesian degrees of freedom "
332+
"'%d'.",
332333
this->get_node()->get_parameter("inv_jac_ctrl.cartesian_gains").as_double_array().size(),
333334
lbr_fri_ros2::CARTESIAN_DOF);
334335
throw std::runtime_error("Failed to configure cartesian gains.");
335336
}
336337
lbr_fri_ros2::jnt_array_t joint_gains_array;
337-
for (unsigned int i = 0; i < lbr_fri_ros2::N_JNTS; ++i) {
338+
for (std::size_t i = 0; i < lbr_fri_ros2::N_JNTS; ++i) {
338339
joint_gains_array[i] =
339340
this->get_node()->get_parameter("inv_jac_ctrl.joint_gains").as_double_array()[i];
340341
}
341342
lbr_fri_ros2::cart_array_t cartesian_gains_array;
342-
for (unsigned int i = 0; i < lbr_fri_ros2::CARTESIAN_DOF; ++i) {
343+
for (std::size_t i = 0; i < lbr_fri_ros2::CARTESIAN_DOF; ++i) {
343344
cartesian_gains_array[i] =
344345
this->get_node()->get_parameter("inv_jac_ctrl.cartesian_gains").as_double_array()[i];
345346
}

lbr_ros2_control/src/controllers/lbr_joint_position_command_controller.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ void LBRJointPositionCommandController::configure_joint_names_() {
8686
throw std::runtime_error("Failed to configure joint names.");
8787
}
8888
std::string robot_name = this->get_node()->get_parameter("robot_name").as_string();
89-
for (int i = 0; i < lbr_fri_ros2::N_JNTS; ++i) {
89+
for (std::size_t i = 0; i < lbr_fri_ros2::N_JNTS; ++i) {
9090
joint_names_[i] = robot_name + "_A" + std::to_string(i + 1);
9191
}
9292
}

0 commit comments

Comments
 (0)