Skip to content

Commit 5b6b976

Browse files
authored
fix inertia indexing (#37)
1 parent d99dd93 commit 5b6b976

2 files changed

Lines changed: 17 additions & 6 deletions

File tree

fd_controllers/fd_inertia_broadcaster/src/fd_inertia_broadcaster.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,19 +43,21 @@ class State;
4343
namespace fd_inertia_broadcaster
4444
{
4545
const auto kUninitializedValue = std::numeric_limits<double>::quiet_NaN();
46-
const size_t sizeFlattenedInertia = 15;
46+
const size_t sizeFlattenedInertia = 21;
4747

48-
unsigned int flattened_index_from_triangular_index(unsigned int idx_row, unsigned int idx_col)
48+
unsigned int flattened_index_from_triangular_index(
49+
unsigned int idx_row,
50+
unsigned int idx_col,
51+
unsigned int dim = 6)
4952
{
5053
unsigned int i = idx_row;
5154
unsigned int j = idx_col;
5255
if (idx_col < idx_row) {
5356
i = idx_col;
5457
j = idx_row;
5558
}
56-
return i * (i - 1) / 2 + j;
59+
return i * (2 * dim - i - 1) / 2 + j;
5760
}
58-
5961
template<class Derived>
6062
void matrixEigenToMsg(const Eigen::MatrixBase<Derived> & e, std_msgs::msg::Float64MultiArray & m)
6163
{

fd_hardware/src/fd_effort_hi.cpp

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,18 @@ namespace fd_hardware
4040

4141
rclcpp::Logger LOGGER = rclcpp::get_logger("FDEffortHardwareInterface");
4242

43-
unsigned int flattened_index_from_triangular_index(unsigned int i, unsigned int j)
43+
unsigned int flattened_index_from_triangular_index(
44+
unsigned int idx_row,
45+
unsigned int idx_col,
46+
unsigned int dim = 6)
4447
{
45-
return i * (i - 1) / 2 + j;
48+
unsigned int i = idx_row;
49+
unsigned int j = idx_col;
50+
if (idx_col < idx_row) {
51+
i = idx_col;
52+
j = idx_row;
53+
}
54+
return i * (2 * dim - i - 1) / 2 + j;
4655
}
4756

4857

0 commit comments

Comments
 (0)