Skip to content

Commit 30f10d4

Browse files
Retreive tests
1 parent bab80f6 commit 30f10d4

File tree

7 files changed

+95
-116
lines changed

7 files changed

+95
-116
lines changed

libraries/robotutils/include/robotutils/GenericStateDerivative.h

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -12,46 +12,27 @@ struct LowPassDerivativeFilter{
1212
Eigen::Matrix<double,state_size,3> raw_state;
1313
Eigen::Matrix<double,state_size,3> filtered_state;
1414

15-
Eigen::Matrix<double,state_size,3> deriv_raw_state;
16-
Eigen::Matrix<double,state_size,3> deriv_filtered_state;
1715
bool is_first = true;
1816

19-
std::tuple<Eigen::Matrix<double,state_size,1>,Eigen::Matrix<double,state_size,1>> update(Eigen::Matrix<double,state_size,1> in_raw_state, Eigen::Matrix<double,state_size,1> deriv_in_raw_state, double sample_time){
17+
Eigen::Matrix<double,state_size,1> update(Eigen::Matrix<double,state_size,1> in_raw_state, double sample_time){
2018
if(is_first){
2119
is_first = false;
2220
raw_state.col(2) = in_raw_state;
2321
raw_state.col(1) = raw_state.col(2);
2422
raw_state.col(0) = raw_state.col(2);
25-
26-
deriv_raw_state.col(2) = deriv_in_raw_state;
27-
deriv_raw_state.col(1) = deriv_raw_state.col(2);
28-
deriv_raw_state.col(0) = deriv_raw_state.col(2);
29-
3023
} else {
3124
raw_state.col(2) = in_raw_state;
32-
deriv_raw_state.col(2) = deriv_in_raw_state;
3325
}
3426
filtered_state.col(2) = 0.222955 * raw_state.col(2)+
3527
0.445910 * raw_state.col(1)+
3628
0.222955 * raw_state.col(0)+
3729
0.295200 * filtered_state.col(1)+
3830
-0.187020 * filtered_state.col(0);
39-
40-
deriv_filtered_state.col(2) = 0.222955 * deriv_raw_state.col(2)+
41-
0.445910 * deriv_raw_state.col(1)+
42-
0.222955 * deriv_raw_state.col(0)+
43-
0.295200 * deriv_filtered_state.col(1)+
44-
-0.187020 * deriv_filtered_state.col(0);
45-
4631
for (size_t i = 0; i < 2; ++i){
4732
raw_state.col(i) = raw_state.col(i + 1);
4833
filtered_state.col(i) = filtered_state.col(i + 1);
49-
50-
deriv_raw_state.col(i) = deriv_raw_state.col(i + 1);
51-
deriv_filtered_state.col(i) = deriv_filtered_state.col(i + 1);
52-
5334
}
54-
return {filtered_state.col(2),deriv_filtered_state.col(2)};
35+
return filtered_state.col(2);
5536
}
5637
};
5738

libraries/robotutils/include/robotutils/LBRController.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,11 @@ class RobotLBR : public KUKA::FRI::LBRClient
5353
}
5454

5555
inline operator bool() const {
56-
return continue_robot_motion.load(std::memory_order_relaxed);
56+
return continue_robot_motion.load();
5757
}
5858

5959
inline void cancel(){
60-
continue_robot_motion.store(false,std::memory_order_relaxed);
60+
continue_robot_motion.store(false);
6161
}
6262

6363
private:

libraries/robotutils/include/robotutils/RippleFilter.h

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
#include <tuple>
55
#include <array>
6+
#include <numbers>
67
#include <Eigen/Dense>
78

89
namespace curan {
@@ -12,22 +13,16 @@ namespace ripple{
1213
struct Damper{
1314
double damper_derivative = 0.0;
1415
double value = 0.0;
15-
double prev_vel = 0.0;
16+
double prev_value = 0.0;
1617
double delta = 0.0;
1718

1819
template<size_t siz>
1920
void compute(const Eigen::Matrix<double,siz,1>& dq,double sample_time){
20-
const double trigger_point = 0.1;
2121
double max_vel = dq.array().abs().maxCoeff();
22-
double possible_damper_value = std::pow(max_vel/trigger_point,2.0);
23-
if(possible_damper_value < 1.0){
24-
value = possible_damper_value;
25-
damper_derivative = (2.0*max_vel)/(trigger_point*trigger_point)*((max_vel-prev_vel)/sample_time);
26-
} else {
27-
value = 1.0;
28-
damper_derivative = 0.0;
29-
}
30-
prev_vel = max_vel;
22+
//value = 0.5-0.5*cos(std::min(3.14159265358979323,std::abs(max_vel)*20.0));
23+
value = std::min(std::abs(max_vel)*5,1.0);
24+
damper_derivative = (value-prev_value)/sample_time;
25+
prev_value = value;
3126
delta = std::abs(max_vel*sample_time);
3227
};
3328

@@ -43,13 +38,13 @@ namespace ripple{
4338
std::array<double,3> y_f = {0.0,0.0,0.0};
4439
std::array<double,3> y = {0.0,0.0,0.0};
4540

46-
std::array<double,3> dy_f = {0.0,0.0,0.0};
47-
std::array<double,3> dy = {0.0,0.0,0.0};
41+
//std::array<double,3> dy_f = {0.0,0.0,0.0};
42+
//std::array<double,3> dy = {0.0,0.0,0.0};
4843
};
4944

5045
void shift_filter_data(Data& data);
5146

52-
void update_filter_data(Data& data, const double& torque, const double& dtorque);
47+
void update_filter_data(Data& data, const double& torque);
5348

5449
/*
5550
this function returns a tuple with the following rules:

libraries/robotutils/src/RippleFilter.cpp

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,31 +10,21 @@ void shift_filter_data(Data& data){
1010
data.y[0] = data.y[1];
1111
data.y[1] = data.y[2];
1212

13-
data.dy[0] = data.dy[1];
14-
data.dy[1] = data.dy[2];
15-
1613
data.y_f[0] = data.y_f[1];
1714
data.y_f[1] = data.y_f[2];
1815
data.y_f[2] = 0.0;
19-
20-
data.dy_f[0] = data.dy_f[1];
21-
data.dy_f[1] = data.dy_f[2];
22-
data.dy_f[2] = 0.0;
2316
}
2417

25-
void update_filter_data(Data& data, const double& torque, const double& dtorque){
18+
void update_filter_data(Data& data, const double& torque){
2619
data.y[2] = torque;
27-
data.dy[2] = dtorque;
2820
}
2921

3022
std::tuple<double,double> execute(const Properties& props,const Damper& damper, Data& data){
3123
const double A = 2.0 * props.width * props.frequency * damper.delta;
3224
const double B = 4.0 + props.frequency * props.frequency * damper.delta * damper.delta;
33-
double y_f2 = (1.0/(A+B)) * (A*data.y[2] - A*data.y[0] - 2.0*(B-8.0) * data.y_f[1] - (B-A)*data.y_f[0] );
34-
double dy_f2 = (1.0/(A+B)) * (A*data.dy[2] - A*data.dy[0] - 2.0*(B-8.0) * data.dy_f[1] - (B-A)*data.dy_f[0] );
35-
data.y_f[2] = damper.value*y_f2;
36-
data.dy_f[2] = damper.value*dy_f2;
37-
return std::make_tuple(data.y_f[2],data.dy_f[2]);
25+
double y_f2 = (damper.value/(A+B)) * (A*data.y[2] - A*data.y[0] - (2.0*(B-8.0) * data.y_f[1] + (B-A)*data.y_f[0]) );
26+
data.y_f[2] = y_f2;
27+
return std::make_tuple(y_f2,0.0);
3828
}
3929

4030
}

libraries/robotutils/src/ViewFiltering.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,17 +37,17 @@ namespace robotic {
3737
double filtered_torque_value = iiwa.measured_torque()[j];
3838
double deriv_filtered_torque_value = (iiwa.measured_torque()[j]-prev_tau[j])/(iiwa.sample_time());
3939
curan::robotic::ripple::shift_filter_data(joint_data_first_harmonic[j]);
40-
curan::robotic::ripple::update_filter_data(joint_data_first_harmonic[j], filtered_torque_value,deriv_filtered_torque_value);
40+
curan::robotic::ripple::update_filter_data(joint_data_first_harmonic[j], filtered_torque_value);
4141
auto [filtered_harm_1,partial_derivative_1] = curan::robotic::ripple::execute(first_harmonic[j],damper, joint_data_first_harmonic[j]);
4242
filtered_torque_value -= filtered_harm_1;
4343
deriv_filtered_torque_value -= partial_derivative_1;
4444
curan::robotic::ripple::shift_filter_data(joint_data_second_harmonic[j]);
45-
curan::robotic::ripple::update_filter_data(joint_data_second_harmonic[j], filtered_torque_value,deriv_filtered_torque_value);
45+
curan::robotic::ripple::update_filter_data(joint_data_second_harmonic[j], filtered_torque_value);
4646
auto [filtered_harm_2,partial_derivative_2]= curan::robotic::ripple::execute(second_harmonic[j],damper, joint_data_second_harmonic[j]);
4747
filtered_torque_value -= filtered_harm_2;
4848
deriv_filtered_torque_value -= partial_derivative_2;
4949
curan::robotic::ripple::shift_filter_data(joint_data_third_harmonic[j]);
50-
curan::robotic::ripple::update_filter_data(joint_data_third_harmonic[j], filtered_torque_value,deriv_filtered_torque_value);
50+
curan::robotic::ripple::update_filter_data(joint_data_third_harmonic[j], filtered_torque_value);
5151
auto [ filtered_harm_3,partial_derivative_3] = curan::robotic::ripple::execute(third_harmonic[j],damper, joint_data_third_harmonic[j]);
5252
filtered_torque_value -= filtered_harm_3;
5353
deriv_filtered_torque_value -= partial_derivative_3;
@@ -58,12 +58,12 @@ namespace robotic {
5858
prev_tau = iiwa.measured_torque();
5959

6060
//const auto& [filtered_torque, filtered_torque_derivative] = filtering_mechanism.update(raw_filtered_torque,partial_derivative_torque,iiwa.sample_time());
61-
const auto& [filtered_torque, filtered_torque_derivative] = filtering_mechanism.update(raw_filtered_torque,raw_deriv_filtered_torque,iiwa.sample_time());
61+
const auto& filtered_torque = filtering_mechanism.update(raw_filtered_torque,iiwa.sample_time());
6262
//state.cmd_q = iiwa.joints() + Eigen::Matrix<double,curan::robotic::number_of_joints,1>::Constant(0.5 / 180.0 * M_PI * sin(2 * M_PI * 10 * currentTime));
6363
state.cmd_q = init_q;
6464
state.cmd_q[0] = iiwa.joints()[0]+ (0.5 / 180.0 * M_PI * sin(2 * M_PI * 10 * currentTime));
6565
state.user_defined = raw_filtered_torque;
66-
state.user_defined2 = filtered_torque_derivative;
66+
//state.user_defined2 = filtered_torque_derivative;
6767
state.user_defined4 = (iiwa.measured_torque()-prev_tau)/iiwa.sample_time();
6868
currentTime += iiwa.sample_time();
6969
return std::move(state);

resources/controller174000.zip

45.7 MB
Binary file not shown.

0 commit comments

Comments
 (0)