Skip to content
This repository was archived by the owner on Dec 1, 2020. It is now read-only.

Commit cee2479

Browse files
committed
Add vibration boundaries to the yaml so that we may easily change this value when tuning.
1 parent 7517118 commit cee2479

File tree

4 files changed

+27
-13
lines changed

4 files changed

+27
-13
lines changed

march_joint_inertia_controller/config/joint_inertia_controller.yaml

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,18 +37,20 @@ march:
3737
std_samples: 100 # number of samples used to calculate the standard deviation
3838
lambda: 0.96 # Usually chosen between 0.9 and 1.0, but not bigger than one or less than zero
3939
alpha_filter_size: 12 # Determines the filter size in the alpha calculation, recommended between 8 and 32
40+
vibration_boundaries: {1.4, 1.9}
4041
control_points: # All arrays must be of same size. Each inertia corresponds to a gain
41-
inertia: [0.0, 1.0]
42-
p: [150, 300]
43-
d: [0, 5]
42+
inertia: {0.0, 1.0}
43+
p: {150, 300}
44+
d: {0, 5}
4445
linear:
4546
std_samples: 100 # number of samples used to calculate the standard deviation
4647
lambda: 0.96
4748
alpha_filter_size: 12
49+
vibration_boundaries: {1.4, 1.9}
4850
control_points:
49-
inertia: [0.0, 1.0]
50-
p: [150, 300]
51-
d: [0, 5]
51+
inertia: {0.0, 1.0}
52+
p: {150, 300}
53+
d: {0, 5}
5254
constraints:
5355
left_ankle:
5456
trajectory: 0.305

march_joint_inertia_controller/include/march_joint_inertia_controller/inertia_estimator.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ class InertiaEstimator
4747

4848
void setLambda(double lambda);
4949
void setAccSize(size_t acc_size);
50+
void setVibrationBoundaries(std::vector<double> boundaries);
5051

5152
/**
5253
* \brief Applies the Butterworth filter over the last two samples and returns the resulting filtered value
@@ -92,8 +93,8 @@ class InertiaEstimator
9293
std::list<double> standard_deviation;
9394

9495
private:
95-
double min_alpha_ = 1.4; // You might want to be able to adjust this value from a yaml/launch file
96-
double max_alpha_ = 1.9; // You might want to be able to adjust this value from a yaml/launch file
96+
double min_alpha_; // You might want to be able to adjust this value from a yaml/launch file
97+
double max_alpha_; // You might want to be able to adjust this value from a yaml/launch file
9798

9899
// This is a sixth order butterworth filter with a cutoff frequency at 15Hz in Second Order Sections form
99100
std::vector<std::vector<double>> sos_{

march_joint_inertia_controller/include/march_joint_inertia_controller/joint_trajectory_inertia_controller.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,21 +65,26 @@ class HardwareInterfaceAdapter<hardware_interface::EffortJointInterface, joint_t
6565
// Obtain inertia estimator parameters from server
6666
double lambda[2];
6767
int alpha_filter_size[2];
68+
std::vector<std::vector<double>> vibration_boundaries{ { 0.0, 0.0 }, { 0.0, 0.0 } };
69+
std::vector<double> default_vibration = { 0.0, 1.0 };
6870
ros::NodeHandle rotary_estimator_nh(nh, std::string("inertia_estimator/rotary"));
6971
rotary_estimator_nh.param("std_samples", samples_, 100);
7072
rotary_estimator_nh.param("lambda", lambda[0], 1.0);
7173
rotary_estimator_nh.param("alpha_filter_size", alpha_filter_size[0], 12);
74+
rotary_estimator_nh.param("vibration_boundaries", vibration_boundaries[0], default_vibration);
7275

7376
ros::NodeHandle linear_estimator_nh(nh, std::string("inertia_estimator/linear"));
7477
linear_estimator_nh.param("lambda", lambda[1], 1.0);
7578
linear_estimator_nh.param("alpha_filter_size", alpha_filter_size[1], 12);
79+
linear_estimator_nh.param("vibration_boundaries", vibration_boundaries[1], default_vibration);
7680

7781
// Initialize the estimator parameters
7882
inertia_estimators_.resize(num_joints_);
7983
for (unsigned int j = 0; j < num_joints_; ++j)
8084
{
8185
inertia_estimators_[j].setLambda(lambda[(int)floor(j / 2) % 2]); // Produce sequence 00110011
8286
inertia_estimators_[j].setAccSize(alpha_filter_size[(int)floor(j / 2) % 2]);
87+
inertia_estimators_[j].setVibrationBoundaries(vibration_boundaries[(int)floor(j / 2) % 2]);
8388
// pub_[j] = nh.advertise<std_msgs::Float64>("/inertia_publisher/" + joint_handles[j].getName(), 100);
8489
this->pub_[j] = std::make_unique<realtime_tools::RealtimePublisher<std_msgs::Float64>>(
8590
nh, "/inertia_publisher/" + joint_handles[j].getName(), 4);

march_joint_inertia_controller/src/inertia_estimator.cpp

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,12 @@ void InertiaEstimator::setAccSize(size_t acc_size)
7373
filtered_acceleration_array_.resize(acc_size_, 0.0);
7474
}
7575

76+
void InertiaEstimator::setVibrationBoundaries(std::vector<double> boundaries)
77+
{
78+
min_alpha_ = boundaries[0];
79+
max_alpha_ = boundaries[1];
80+
}
81+
7682
double InertiaEstimator::getJointInertia()
7783
{
7884
return joint_inertia_;
@@ -135,8 +141,8 @@ void InertiaEstimator::inertiaEstimate()
135141
K_a_ = alphaCalculation();
136142
auto ita = filtered_acceleration_array_.begin();
137143
auto itt = filtered_joint_torque_.begin();
138-
const double torque_e = *itt - *(itt++);
139-
const double acc_e = *ita - *(ita++);
144+
const double torque_e = *itt - *(++itt);
145+
const double acc_e = *ita - *(++ita);
140146
joint_inertia_ = (torque_e - (acc_e * joint_inertia_)) * K_i_ * K_a_ + joint_inertia_;
141147
}
142148

@@ -152,15 +158,15 @@ double InertiaEstimator::alphaCalculation()
152158
double InertiaEstimator::gainCalculation()
153159
{
154160
auto it = filtered_acceleration_array_.begin();
155-
auto error = *it - *(it++);
161+
auto error = *it - *(++it);
156162
return (corr_coeff_ * error) / (lambda_ + corr_coeff_ * pow(error, 2));
157163
}
158164

159165
// Calculate the correlation coefficient of the acceleration buffer
160166
void InertiaEstimator::correlationCalculation()
161167
{
162168
auto it = filtered_acceleration_array_.begin();
163-
corr_coeff_ = corr_coeff_ / (lambda_ + corr_coeff_ * pow(*it - *(it++), 2));
169+
corr_coeff_ = corr_coeff_ / (lambda_ + corr_coeff_ * pow(*it - *(++it), 2));
164170
const double large_number = 10e8;
165171
if (corr_coeff_ > large_number)
166172
{
@@ -185,7 +191,7 @@ double InertiaEstimator::vibrationCalculation()
185191
double InertiaEstimator::discreteSpeedDerivative(const ros::Duration& period)
186192
{
187193
auto it = velocity_array_.begin();
188-
return (*it - *(it++)) / period.toSec();
194+
return (*it - *(++it)) / period.toSec();
189195
}
190196

191197
void InertiaEstimator::initP(unsigned int samples)

0 commit comments

Comments
 (0)