Skip to content

Commit dde9313

Browse files
Commit changes to robot API
1 parent 5e58e7f commit dde9313

File tree

12 files changed

+252
-60
lines changed

12 files changed

+252
-60
lines changed

CMakeLists.txt

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,18 @@ cmake_minimum_required(VERSION 3.24)
22
cmake_policy(SET CMP0091 NEW)
33
cmake_policy(SET CMP0075 NEW)
44

5+
#Language definitions used throught the entire project
6+
set(CMAKE_CXX_STANDARD 20)
7+
set(CMAKE_CXX_STANDARD_REQUIRED YES)
8+
9+
set(VCPKG_OVERLAY_TRIPLETS "${CMAKE_CURRENT_LIST_DIR}/vcpkg_custom_triplet/")
10+
511
if(UNIX)
6-
string(VCPKG_TARGET_TRIPLET "x64-linux")
7-
string(VCPKG_HOST_TRIPLET "x64-linux")
12+
set(VCPKG_TARGET_TRIPLET "x64-linux-mixed")
13+
set(VCPKG_HOST_TRIPLET "x64-linux-mixed")
814
endif(UNIX)
915

1016
if(WIN32)
11-
set(VCPKG_OVERLAY_TRIPLETS "${CMAKE_CURRENT_LIST_DIR}/vcpkg_custom_triplet/")
1217
set(VCPKG_TARGET_TRIPLET "x64-windows-mixed")
1318
set(VCPKG_HOST_TRIPLET "x64-windows-mixed")
1419
endif(WIN32)
@@ -17,9 +22,7 @@ set(VCPKG_ROOT "${CMAKE_CURRENT_LIST_DIR}/vcpkg")
1722
set(CMAKE_TOOLCHAIN_FILE "${VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake")
1823

1924

20-
#Language definitions used throught the entire project
21-
set(CMAKE_CXX_STANDARD 20)
22-
set(CMAKE_CXX_STANDARD_REQUIRED YES)
25+
2326

2427
project(Curan)
2528

@@ -44,19 +47,12 @@ set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
4447
#Find all required third parties (this should be moved elsewhere)
4548
find_package(asio CONFIG REQUIRED)
4649
find_package(Eigen3 CONFIG REQUIRED)
47-
find_package(Ceres CONFIG REQUIRED)
48-
find_package(unofficial-skia CONFIG REQUIRED)
4950
find_package(nlohmann_json REQUIRED)
50-
find_package(glfw3 3.3 REQUIRED)
51-
find_package(Boost COMPONENTS filesystem)
5251
find_package(Vulkan REQUIRED)
5352
find_package(vsg CONFIG REQUIRED)
5453
find_package(vsgXchange CONFIG REQUIRED)
5554
find_package(vsgImGui CONFIG REQUIRED)
56-
find_package(pugixml CONFIG REQUIRED)
57-
find_package(PCL CONFIG REQUIRED)
58-
find_package(GTest CONFIG REQUIRED)
59-
find_package(rbdl CONFIG REQUIRED)
55+
find_package(RBDL CONFIG REQUIRED)
6056
#find_package(Torch CONFIG REQUIRED)
6157
#find_package(OpenMP REQUIRED)
6258
#find_package(LAPACK REQUIRED)
@@ -102,16 +98,16 @@ add_custom_target(
10298
add_subdirectory(libraries)
10399

104100
# Add medical applications
105-
add_subdirectory(applications)
101+
#add_subdirectory(applications)
106102

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

110106
# Add medical applications
111-
add_subdirectory(unittests)
107+
#add_subdirectory(unittests)
112108

113109
# Add tests for submodules of curan, i.e. utilities, communication, etc...
114110
add_subdirectory(tests)
115111

116112
# Add medical applications
117-
add_subdirectory(tutorials)
113+
#add_subdirectory(tutorials)

README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,17 @@ When using VScode to compile the project, if the previous order of the build ins
206206
the build fails due to incorrect configurations. When you find yourself faced with these problems the simplest solution is to delete the
207207
.vscode folder and the build folder and reconfigure the project, this usually solves all the problems.
208208

209+
# Ninja
210+
According to this [link](https://public.kitware.com/Bug/view.php?id=13910) on linux sometimes cmake fails to execute.
211+
```bash
212+
sudo chmod o+r /your/path/to/ninja
213+
```
214+
215+
to find the path to ninja you can run on your terminal
216+
``` bash
217+
which ninja
218+
```
219+
209220
## Acknowledgments
210221
The volume reconstruction code is essencially a copy of [IGSIO](https://github.com/IGSIO/IGSIO) modified to work with the interal classes and structures of Curan.
211222

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/CMakeLists.txt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,14 @@ src/JointVelocityController.cpp
77
src/RobotState.cpp
88
src/ImpedanceController.cpp
99
src/CartesianVelocityController.cpp
10+
src/RippleFilter.cpp
11+
src/ViewFiltering.cpp
1012
)
1113

12-
message("MARK--------- RBDL string ${RBDL_LIBRARY}")
13-
1414
target_link_libraries(robotutils
1515
PUBLIC
1616
${RBDL_LIBRARY}
17+
utils
1718
Eigen3::Eigen
1819
FRILibrary
1920
gaussianmixture
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
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 state_size>
11+
struct LowPassDerivativeFilter{
12+
Eigen::Matrix<double,state_size,3> raw_state;
13+
Eigen::Matrix<double,state_size,3> filtered_state;
14+
15+
Eigen::Matrix<double,state_size,3> deriv_raw_state;
16+
Eigen::Matrix<double,state_size,3> deriv_filtered_state;
17+
bool is_first = true;
18+
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, double sample_time){
20+
return update(in_raw_state,Eigen::Matrix<double,state_size,1>::Zero(),sample_time);
21+
}
22+
23+
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> partial_removal, double sample_time){
24+
if(is_first){
25+
is_first = false;
26+
raw_state.col(2) = in_raw_state;
27+
raw_state.col(1) = raw_state.col(2);
28+
raw_state.col(0) = raw_state.col(2);
29+
} else {
30+
raw_state.col(2) = in_raw_state;
31+
}
32+
filtered_state.col(2) = 0.222955 * raw_state.col(2)+
33+
0.445910 * raw_state.col(1)+
34+
0.222955 * raw_state.col(0)+
35+
0.295200 * filtered_state.col(1)+
36+
-0.187020 * filtered_state.col(0);
37+
38+
deriv_raw_state.col(2) = (1.0/sample_time)*(raw_state.col(2)-raw_state.col(1))-partial_removal;
39+
deriv_filtered_state.col(2) = 0.222955 * deriv_raw_state.col(2)+
40+
0.445910 * deriv_raw_state.col(1)+
41+
0.222955 * deriv_raw_state.col(0)+
42+
0.295200 * deriv_filtered_state.col(1)+
43+
-0.187020 * deriv_filtered_state.col(0);
44+
45+
for (size_t i = 0; i < 2; ++i){
46+
raw_state.col(i) = raw_state.col(i + 1);
47+
filtered_state.col(i) = filtered_state.col(i + 1);
48+
49+
deriv_raw_state.col(i) = deriv_raw_state.col(i + 1);
50+
deriv_filtered_state.col(i) = deriv_filtered_state.col(i + 1);
51+
52+
}
53+
return {filtered_state.col(2),deriv_filtered_state.col(2)};
54+
}
55+
};
56+
57+
58+
}
59+
}
60+
61+
#endif

libraries/robotutils/include/robotutils/RippleFilter.h

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
1-
#ifndef CURAN_RIPPLE_FILTER
2-
#define CURAN_RIPPLE_FILTER
1+
#ifndef CURAN_RIPPLE_FILTER_
2+
#define CURAN_RIPPLE_FILTER_
33

4+
#include <tuple>
45
#include <array>
56

67
namespace curan {
78
namespace robotic {
89
namespace ripple{
9-
namespace detail{
10-
1110
struct Properties{
11+
double damper_prev;
1212
double damper;
1313
double width;
1414
double frequency;
1515
double delta;
1616

17-
Properties(double in_width = 5.0, double in_frequency = 320.0) : damper{0.0}, width{in_width}, frequency{in_frequency}, delta{0.0} {};
17+
Properties(double in_width = 5.0, double in_frequency = 320.0) : damper_prev{0.0},damper{0.0}, width{in_width}, frequency{in_frequency}, delta{0.0} {};
1818

1919
};
2020

@@ -34,10 +34,14 @@ namespace detail{
3434

3535
void update_filter_data(Data& data, const double& torque);
3636

37-
double execute(const Properties& props, Data& data);
38-
} // namespace detail
39-
37+
/*
38+
this function returns a tuple with the following rules:
39+
[ filtered_torque , ficticious_torque_deriv_by_activation_function ]
4040
41+
basically the derivative of the filtered torque has two components, the derivative due to the changes in the real torque
42+
and the changes due to the scalling function that shuts down the filter
43+
*/
44+
std::tuple<double,double> execute(const Properties& props, Data& data);
4145

4246
}
4347
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#ifndef CURAN_VIEW_FILTERING_
2+
#define CURAN_VIEW_FILTERING_
3+
4+
#include "LBRController.h"
5+
#include "RippleFilter.h"
6+
#include "GenericStateDerivative.h"
7+
#include <array>
8+
9+
namespace curan {
10+
namespace robotic {
11+
12+
struct ViewFiltering : public UserData{
13+
std::array<ripple::Data, number_of_joints> joint_data_first_harmonic;
14+
std::array<ripple::Data, number_of_joints> joint_data_second_harmonic;
15+
std::array<ripple::Data, number_of_joints> joint_data_third_harmonic;
16+
std::array<ripple::Properties, number_of_joints> first_harmonic;
17+
std::array<ripple::Properties, number_of_joints> second_harmonic;
18+
std::array<ripple::Properties, number_of_joints> third_harmonic;
19+
20+
LowPassDerivativeFilter<number_of_joints> filtering_mechanism;
21+
Eigen::Matrix<double,number_of_joints,1> previous_q;
22+
23+
bool is_first_loop = true;
24+
ViewFiltering();
25+
virtual ~ViewFiltering(){};
26+
EigenState&& update(const RobotModel<number_of_joints>& iiwa, EigenState&& state, Eigen::Matrix<double,Eigen::Dynamic,Eigen::Dynamic>& composed_task_jacobians) override;
27+
};
28+
29+
}
30+
}
31+
32+
#endif

libraries/robotutils/src/RippleFilter.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@
55
namespace curan{
66
namespace robotic{
77
namespace ripple{
8-
namespace detail{
98

109
void update_filter_properties(Properties& properties,const Observation& observation){
1110
double damper_trigger = 0.2*properties.frequency;
1211
double filtered_frequency = std::abs(observation.current_vel)*properties.frequency;
12+
properties.damper_prev = properties.damper;
1313
properties.damper = filtered_frequency < damper_trigger ? std::pow(filtered_frequency/damper_trigger,2) : 1.0;
1414
properties.delta = std::abs(observation.current_delta);
1515
}
@@ -27,12 +27,13 @@ void update_filter_data(Data& data, const double& torque){
2727
data.y[2] = torque;
2828
}
2929

30-
double execute(const Properties& props, Data& data){
30+
std::tuple<double,double> execute(const Properties& props, Data& data, double sample_time){
3131
const double A = 2.0 * props.width * props.frequency * props.delta;
3232
const double B = 4.0 + props.frequency * props.frequency * props.delta * props.delta;
33-
data.y_f[2] = (props.damper/(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-
return data.y_f[2];
35-
}
33+
const double damper_derivative = (props.damper-props.damper_prev)/sample_time;
34+
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] );
35+
data.y_f[2] = props.damper*y_f2;
36+
return {data.y_f[2],damper_derivative*y_f2};
3637
}
3738

3839
}
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
#include "robotutils/ViewFiltering.h"
2+
3+
namespace curan {
4+
namespace robotic {
5+
6+
ViewFiltering::ViewFiltering(){
7+
for (size_t filter_index = 0; filter_index < number_of_joints; ++filter_index)
8+
{
9+
first_harmonic[filter_index].frequency = (filter_index == 4) ? 320.0 : 320.0;
10+
second_harmonic[filter_index].frequency = (filter_index == 4) ? 640.0 : 640.0;
11+
third_harmonic[filter_index].frequency = (filter_index == 4) ? 1280.0 : 1280.0;
12+
}
13+
}
14+
15+
EigenState&& ViewFiltering::update(const RobotModel<number_of_joints>& iiwa, EigenState&& state, Eigen::Matrix<double,Eigen::Dynamic,Eigen::Dynamic>& composed_task_jacobians){
16+
using vector_type = curan::robotic::RobotModel<curan::robotic::number_of_joints>::vector_type;
17+
static double currentTime = 0.0;
18+
/*
19+
We remove some energy from the system whilst moving the robot in free space. Thus we guarantee that the system is passive
20+
*/
21+
22+
state.cmd_tau = -iiwa.mass() * iiwa.velocities();
23+
vector_type raw_filtered_torque = vector_type::Zero();
24+
vector_type partial_derivative_torque = vector_type::Zero();
25+
if(filtering_mechanism.is_first)
26+
previous_q = iiwa.joints();
27+
28+
double fastest_velocity_found = std::numeric_limits<double>::min();
29+
size_t offset_fastest_filter = 0;
30+
31+
for (size_t joint_i = 0; joint_i < curan::robotic::number_of_joints; ++joint_i)
32+
{
33+
const curan::robotic::ripple::Observation obser_i_j{iiwa.velocities()[joint_i], iiwa.joints()[joint_i] - previous_q[joint_i]};
34+
ripple::update_filter_properties(first_harmonic[joint_i], obser_i_j);
35+
ripple::update_filter_properties(second_harmonic[joint_i], obser_i_j);
36+
ripple::update_filter_properties(third_harmonic[joint_i], obser_i_j);
37+
double vel_modulus_i = std::abs(iiwa.velocities()[joint_i]);
38+
if (fastest_velocity_found < vel_modulus_i)
39+
{
40+
fastest_velocity_found = vel_modulus_i;
41+
offset_fastest_filter = joint_i;
42+
}
43+
}
44+
previous_q = iiwa.joints();
45+
46+
for (size_t j = 0; j < curan::robotic::number_of_joints; ++j)
47+
{
48+
double filtered_torque_value = iiwa.measured_state()->tau[j];
49+
ripple::shift_filter_data(joint_data_first_harmonic[j], 0.0);
50+
ripple::update_filter_data(joint_data_first_harmonic[j], filtered_torque_value);
51+
auto [filtered_harm_1,partial_derivative_1] = ripple::execute(first_harmonic[offset_fastest_filter], joint_data_first_harmonic[j]);
52+
filtered_torque_value -= filtered_harm_1;
53+
ripple::shift_filter_data(joint_data_second_harmonic[j], 0.0);
54+
ripple::update_filter_data(joint_data_second_harmonic[j], filtered_torque_value);
55+
auto [filtered_harm_2,partial_derivative_2]= ripple::execute(second_harmonic[offset_fastest_filter], joint_data_second_harmonic[j]);
56+
filtered_torque_value -= filtered_harm_2;
57+
ripple::shift_filter_data(joint_data_third_harmonic[j], 0.0);
58+
ripple::update_filter_data(joint_data_third_harmonic[j], filtered_torque_value);
59+
auto [ filtered_harm_3,partial_derivative_3] = ripple::execute(third_harmonic[offset_fastest_filter], joint_data_third_harmonic[j]);
60+
partial_derivative_torque[j] = partial_derivative_1 + partial_derivative_2 +partial_derivative_3;
61+
filtered_torque_value -= filtered_harm_3;
62+
raw_filtered_torque[j] = -filtered_torque_value - iiwa.gravity()[j] - iiwa.coriolis()[j];
63+
}
64+
65+
const auto& [filtered_torque, filtered_torque_derivative] = filtering_mechanism.update(raw_filtered_torque,partial_derivative_torque,iiwa.sample_time());
66+
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));
67+
68+
currentTime += iiwa.sample_time();
69+
return std::move(state);
70+
}
71+
72+
}
73+
}

0 commit comments

Comments
 (0)