Skip to content

Commit 35f07ef

Browse files
Commit final ripple experiment
1 parent 30f10d4 commit 35f07ef

File tree

14 files changed

+241
-66
lines changed

14 files changed

+241
-66
lines changed

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,6 @@ build/
33
.vscode/
44
_site/
55
resources/swing/R4F.glb
6-
plus_config/wire_reconstructions/wire_reconstruction_recording/RecordingTest.igs_20240508_215732.mha
6+
plus_config/wire_reconstructions/wire_reconstruction_recording/RecordingTest.igs_20240508_215732.mha
7+
8+
isofurface_extraction.exe "C:\Dev\experiments_for_thesis\registration\vol\reconstruction_results1.mha" "C:\Dev\experiments_for_thesis\registration\vol\masked_volume.mha"

CMakeLists.txt

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@ set(VCPKG_ROOT "${CMAKE_CURRENT_LIST_DIR}/vcpkg")
2222
set(CMAKE_TOOLCHAIN_FILE "${VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake")
2323

2424

25-
26-
2725
project(Curan)
2826

2927
if(WIN32)
@@ -47,18 +45,18 @@ set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
4745
#Find all required third parties (this should be moved elsewhere)
4846
find_package(asio CONFIG REQUIRED)
4947
find_package(Eigen3 CONFIG REQUIRED)
48+
find_package(Ceres CONFIG REQUIRED)
49+
find_package(unofficial-skia CONFIG REQUIRED)
5050
find_package(nlohmann_json REQUIRED)
5151
find_package(Vulkan REQUIRED)
52+
find_package(glfw3 3.3 REQUIRED)
53+
find_package(Boost COMPONENTS filesystem)
5254
find_package(vsg CONFIG REQUIRED)
5355
find_package(vsgXchange CONFIG REQUIRED)
5456
find_package(vsgImGui CONFIG REQUIRED)
5557
find_package(RBDL CONFIG REQUIRED)
56-
#find_package(Torch CONFIG REQUIRED)
57-
#find_package(OpenMP REQUIRED)
58-
#find_package(LAPACK REQUIRED)
59-
#find_package(BLAS REQUIRED)
60-
#find_package(gflags REQUIRED)
61-
#find_package(glog REQUIRED)
58+
find_package(gflags REQUIRED)
59+
find_package(glog REQUIRED)
6260

6361

6462
#Externally provided targets
@@ -98,7 +96,7 @@ add_custom_target(
9896
add_subdirectory(libraries)
9997

10098
# Add medical applications
101-
#add_subdirectory(applications)
99+
add_subdirectory(applications)
102100

103101
# Most of the time there is no need to compile the tests and the tutorials
104102
# folder so you can comment out these subfolders from the build directory

libraries/CMakeLists.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
add_subdirectory(utils)
22
add_subdirectory(communication)
3-
#add_subdirectory(userinterface)
3+
add_subdirectory(userinterface)
44
add_subdirectory(rendering)
5-
#add_subdirectory(imageprocessing)
6-
#add_subdirectory(optimization)
7-
#add_subdirectory(geometry)
5+
add_subdirectory(imageprocessing)
6+
add_subdirectory(optimization)
7+
add_subdirectory(geometry)
88
add_subdirectory(gaussianmixtures)
99
add_subdirectory(robotutils)

libraries/robotutils/include/robotutils/GenericStateDerivative.h

Lines changed: 0 additions & 43 deletions
This file was deleted.
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
#ifndef CURAN_MASSRIPPLE_FILTER_
2+
#define CURAN_MASSRIPPLE_FILTER_
3+
4+
#include <tuple>
5+
#include <array>
6+
#include <numbers>
7+
#include <Eigen/Dense>
8+
9+
namespace curan {
10+
namespace robotic {
11+
namespace massripple{
12+
13+
template<size_t n_joints>
14+
struct Damper{
15+
double value = 0.0;
16+
double delta = 0.0;
17+
size_t critical_index = 0;
18+
19+
Eigen::Matrix<double,n_joints,n_joints> B;
20+
Eigen::Matrix<double,n_joints,n_joints> K;
21+
Eigen::Matrix<double,n_joints,n_joints> D;
22+
Eigen::Matrix<double,n_joints,n_joints> Kt;
23+
Eigen::Matrix<double,n_joints,n_joints> R;
24+
25+
Damper(const Eigen::Matrix<double,n_joints,n_joints>& in_B,
26+
const Eigen::Matrix<double,n_joints,n_joints>& in_K,
27+
const Eigen::Matrix<double,n_joints,n_joints>& in_D,
28+
const Eigen::Matrix<double,n_joints,n_joints>& in_Kt,
29+
const Eigen::Matrix<double,n_joints,n_joints>& in_R) : B{in_B}, K{in_K}, D{in_D}, Kt{in_Kt}, R{in_R}
30+
{
31+
}
32+
33+
34+
void compute(const Eigen::Matrix<double,n_joints,n_joints>& M,const Eigen::Matrix<double,n_joints,1>& dq,double sample_time){
35+
Eigen::Matrix<double,n_joints,1> w = 2*R(dq.array().abs().matrix());
36+
Eigen::Matrix<double,n_joints,1> G = Eigen::Matrix<double,n_joints,1>::Zero();
37+
for(double& g : G.rowwise()){
38+
39+
}
40+
double amplitude = G.array().abs().maxCoeff(critical_index);
41+
value = std::min((dq[critical_index]*dq[critical_index])/(0.1*0.1),1.0);
42+
delta = std::abs(dq[critical_index]*sample_time);
43+
};
44+
45+
};
46+
47+
struct Properties{
48+
double width;
49+
double frequency;
50+
Properties(double in_width = 5.0, double in_frequency = 320.0) : width{in_width}, frequency{in_frequency}{};
51+
};
52+
53+
struct Data{
54+
std::array<double,3> y_f = {0.0,0.0,0.0};
55+
std::array<double,3> y = {0.0,0.0,0.0};
56+
};
57+
58+
void shift_filter_data(Data& data);
59+
60+
void update_filter_data(Data& data, const double& torque);
61+
62+
/*
63+
this function returns a tuple with the following rules:
64+
[ filtered_torque , ficticious_torque_deriv_by_activation_function ]
65+
66+
basically the derivative of the filtered torque has two components, the derivative due to the changes in the real torque
67+
and the changes due to the scalling function that shuts down the filter
68+
*/
69+
template<size_t n_joints>
70+
double execute(const std::array<Properties,n_joints>& props,const Damper<n_joints>& damper, Data& data){
71+
const double A = 2.0 * props[damper.critical_index].width * props[damper.critical_index].frequency * damper.delta;
72+
const double B = 4.0 + props[damper.critical_index].frequency * props[damper.critical_index].frequency * damper.delta * damper.delta;
73+
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]) );
74+
data.y_f[2] = y_f2;
75+
return y_f2;
76+
}
77+
78+
}
79+
}
80+
}
81+
82+
#endif
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#ifndef CURAN_JOINT_IMPEDANCE_CONTROLLER_
2+
#define CURAN_JOINT_IMPEDANCE_CONTROLLER_
3+
4+
#include "LBRController.h"
5+
6+
namespace curan {
7+
namespace robotic {
8+
9+
struct JointImpedanceController : public UserData{
10+
JointImpedanceController();
11+
EigenState&& update(const RobotModel<number_of_joints>& iiwa, EigenState&& state, Eigen::Matrix<double,Eigen::Dynamic,Eigen::Dynamic>& composed_task_jacobians) override;
12+
};
13+
14+
}
15+
}
16+
17+
#endif
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
#ifndef CURAN_GENERIC_STATE_DERIVATIVE_
2+
#define CURAN_GENERIC_STATE_DERIVATIVE_
3+
4+
#include <Eigen/Dense>
5+
#include <tuple>
6+
7+
namespace curan {
8+
namespace robotic {
9+
10+
template<size_t filter_size>
11+
struct LowPassDerivativeFilter{
12+
Eigen::Matrix<double,filter_size,3> raw_state;
13+
Eigen::Matrix<double,filter_size,3> filtered_state;
14+
Eigen::Matrix<double,1,5> coefficient;
15+
16+
bool is_first = true;
17+
18+
LowPassDerivativeFilter(double nyquist_frequency,double cutoff){
19+
double c = std::cos(0.5*cutoff/nyquist_frequency)/std::sin(0.5*cutoff/nyquist_frequency);
20+
coefficient = Eigen::Matrix<double,1,5>::Zero();
21+
double a0 = c*c*2+1.4142*c+1;
22+
coefficient << 1/a0 , 2/a0 , 1/a0 , (2-2*c*c)/a0 , (c*c-1.4142*c+1)/a0;
23+
}
24+
25+
Eigen::Matrix<double,filter_size,1> update(Eigen::Matrix<double,filter_size,1> in_raw_state, double sample_time){
26+
if(is_first){
27+
is_first = false;
28+
raw_state.col(2) = in_raw_state;
29+
raw_state.col(1) = raw_state.col(2);
30+
raw_state.col(0) = raw_state.col(2);
31+
} else {
32+
raw_state.col(2) = in_raw_state;
33+
}
34+
filtered_state.col(2) = coefficient[0] * raw_state.col(2)+
35+
coefficient[1] * raw_state.col(1)+
36+
coefficient[2] * raw_state.col(0)+
37+
coefficient[3] * filtered_state.col(1)+
38+
coefficient[4] * filtered_state.col(0);
39+
for (size_t i = 0; i < 2; ++i){
40+
raw_state.col(i) = raw_state.col(i + 1);
41+
filtered_state.col(i) = filtered_state.col(i + 1);
42+
}
43+
return filtered_state.col(2);
44+
}
45+
};
46+
47+
48+
}
49+
}
50+
51+
#endif

libraries/robotutils/include/robotutils/ViewFiltering.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
#include "LBRController.h"
55
#include "RippleFilter.h"
6-
#include "GenericStateDerivative.h"
6+
#include "LowPassDerivativeFilter.h"
77
#include <array>
88

99
namespace curan {
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#include "robotutils/InertiaAwareRippleFilter.h"
2+
3+
#include <cmath>
4+
5+
namespace curan{
6+
namespace robotic{
7+
namespace massripple{
8+
9+
void shift_filter_data(Data& data){
10+
data.y[0] = data.y[1];
11+
data.y[1] = data.y[2];
12+
13+
data.y_f[0] = data.y_f[1];
14+
data.y_f[1] = data.y_f[2];
15+
data.y_f[2] = 0.0;
16+
}
17+
18+
void update_filter_data(Data& data, const double& torque){
19+
data.y[2] = torque;
20+
}
21+
22+
}
23+
}
24+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#include "robotutils/JointImpedanceController.h"
2+
3+
namespace curan {
4+
namespace robotic {
5+
6+
JointImpedanceController::JointImpedanceController(){
7+
}
8+
9+
EigenState&& JointImpedanceController::update(const RobotModel<number_of_joints>& iiwa, EigenState&& state, Eigen::Matrix<double,Eigen::Dynamic,Eigen::Dynamic>& composed_task_jacobians){
10+
static double currentTime = 0.0;
11+
/*
12+
We remove some energy from the system whilst moving the robot in free space. Thus we guarantee that the system is passive
13+
*/
14+
Eigen::Matrix<double,7,1> desired_velocity = Eigen::Matrix<double,7,1>::Ones()*actuation;
15+
16+
//state.cmd_tau = 35*(desired_velocity-filtered_velocity);
17+
state.cmd_tau = 35*iiwa.mass()*(desired_velocity-filtered_velocity);
18+
state.user_defined = filtered_velocity;
19+
timer += iiwa.sample_time();
20+
21+
22+
/*
23+
The Java controller has two values which it reads, namely:
24+
1) commanded_joint_position
25+
2) commanded_torque
26+
The torque is computed in the previous line, but the position can remain empty. One problem with this approach is that if the deviation
27+
between the reference position and the commanded position is larger than 5 degrees the robot triggers a safety stop 1. To avoid this
28+
the first solution is to set the commanded position to be equal to the current position. This approach has a drawback where the error between
29+
both commanded and current position is always zero, which results in the friction compensator being "shut off". We avoid this problem
30+
by adding a small perturbation to the reference position with a relative high frequency.
31+
*/
32+
state.cmd_q = iiwa.joints() + Eigen::Matrix<double,number_of_joints,1>::Constant(0.5 / 180.0 * M_PI * sin(2 * M_PI * 10 * currentTime));
33+
34+
currentTime += iiwa.sample_time();
35+
return std::move(state);
36+
}
37+
38+
}
39+
}

0 commit comments

Comments
 (0)