-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
20 changed files
with
2,427 additions
and
878 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
build --distdir=./bazel_build | ||
build --cxxopt=-std=c++17 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,7 @@ src/examples/scripts/env/* | |
src/examples/scripts/__pycache__/* | ||
*.tum | ||
*cache | ||
data/ | ||
docs/ | ||
|
||
*~ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
# LICENSE | ||
# Bazel Build for KIT Real-Time Time-Optimal Path Parameterization (RTTOPP) | ||
|
||
|
||
package(default_visibility = ["//visibility:public"]) | ||
|
||
|
||
# https://docs.bazel.build/versions/master/be/c-cpp.html#cc_library | ||
cc_library( | ||
name = "rttopp", | ||
srcs = glob([ | ||
"src/demo_trajectories.cpp", | ||
"include/rttopp/*.h" | ||
]), | ||
includes = ["include"], | ||
hdrs = ["include/rttopp/rttopp2.h"], # Public interface of the library | ||
deps = ["@json//:nlohmann_json", | ||
"@com_gitlab_libeigen_eigen//:eigen" | ||
], | ||
copts = [] | ||
) | ||
|
||
cc_library( | ||
name = "param_random_waypoints_example_generic", | ||
srcs = glob([ | ||
"examples/param_random_waypoints_generic.cpp", | ||
"include/rttopp/*.h" | ||
]), | ||
includes = ["include"], | ||
hdrs = ["include/rttopp/rttopp2.h"], # Public interface of the library | ||
deps = ["@json//:nlohmann_json", | ||
"@com_gitlab_libeigen_eigen//:eigen" | ||
], | ||
copts = [] | ||
) | ||
|
||
cc_library( | ||
name = "param_random_waypoints_iiwa", | ||
srcs = glob([ | ||
"examples/param_random_waypoints_iiwa.cpp", | ||
"include/rttopp/*.h" | ||
]), | ||
includes = ["include"], | ||
hdrs = ["include/rttopp/rttopp2.h"], # Public interface of the library | ||
deps = ["@json//:nlohmann_json", | ||
"@com_gitlab_libeigen_eigen//:eigen" | ||
], | ||
copts = [] | ||
) | ||
|
||
cc_library( | ||
name = "param_random_waypoints_generic_sampling_example", | ||
srcs = glob([ | ||
"examples/param_random_waypoints_generic_sampling_example.cpp", | ||
"include/rttopp/*.h" | ||
]), | ||
includes = ["include"], | ||
hdrs = ["include/rttopp/rttopp2.h"], # Public interface of the library | ||
deps = ["@json//:nlohmann_json", | ||
"@com_gitlab_libeigen_eigen//:eigen" | ||
], | ||
copts = [] | ||
) | ||
|
||
cc_library( | ||
name = "param_failed_random_waypoints_example_generic", | ||
srcs = glob([ | ||
"examples/param_failed_random_waypoints_example_generic.cpp", | ||
"include/rttopp/*.h" | ||
]), | ||
includes = ["include"], | ||
hdrs = ["include/rttopp/rttopp2.h"], # Public interface of the library | ||
deps = ["@json//:nlohmann_json", | ||
"@com_gitlab_libeigen_eigen//:eigen" | ||
], | ||
copts = [] | ||
) | ||
|
||
|
||
cc_test( | ||
name = "path_velocity_limit_tests", | ||
srcs = glob([ | ||
"tests/path_velocity_limit.cpp", | ||
"include/rttopp/*.h" | ||
]), | ||
includes = ["include"], | ||
deps = [":rttopp", | ||
"@json//:nlohmann_json", | ||
"@com_gitlab_libeigen_eigen//:eigen", | ||
"@com_google_googletest//:gtest", | ||
"@com_google_googletest//:gtest_main" | ||
], | ||
copts = [] | ||
) | ||
|
||
|
||
cc_test( | ||
name = "test_preprocessing", | ||
srcs = glob([ | ||
"tests/test_preprocessing.cpp", | ||
"include/rttopp/*.h" | ||
]), | ||
includes = ["include"], | ||
deps = [":rttopp", | ||
"@json//:nlohmann_json", | ||
"@com_gitlab_libeigen_eigen//:eigen", | ||
"@com_google_googletest//:gtest", | ||
"@com_google_googletest//:gtest_main" | ||
], | ||
copts = [] | ||
) | ||
|
||
cc_test( | ||
name = "param_tests", | ||
srcs = glob([ | ||
"tests/param.cpp", | ||
"include/rttopp/*.h" | ||
]), | ||
includes = ["include"], | ||
deps = [":rttopp", | ||
"@json//:nlohmann_json", | ||
"@com_gitlab_libeigen_eigen//:eigen", | ||
"@com_google_googletest//:gtest", | ||
"@com_google_googletest//:gtest_main" | ||
], | ||
copts = [] | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
workspace(name = "rttopp") | ||
|
||
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") | ||
load("@bazel_tools//tools/build_defs/repo:git.bzl", "git_repository") | ||
|
||
|
||
# Google test | ||
# Get it from https://github.com/google/benchmark/blob/main/WORKSPACE#L13 | ||
git_repository( | ||
name = "com_google_googletest", | ||
remote = "https://github.com/google/googletest.git", | ||
tag = "release-1.11.0", | ||
) | ||
|
||
git_repository( | ||
name = "com_google_benchmark", | ||
remote = "https://github.com/google/benchmark.git", | ||
tag = "v1.6.1", | ||
) | ||
|
||
http_archive( | ||
name = "com_gitlab_libeigen_eigen", | ||
sha256 = "0215c6593c4ee9f1f7f28238c4e8995584ebf3b556e9dbf933d84feb98d5b9ef", | ||
strip_prefix = "eigen-3.3.8", | ||
urls = [ | ||
"https://gitlab.com/libeigen/eigen/-/archive/3.3.8/eigen-3.3.8.tar.bz2", | ||
], | ||
build_file_content = | ||
""" | ||
# See https://github.com/ceres-solver/ceres-solver/issues/337. | ||
cc_library( | ||
name = 'eigen', | ||
srcs = [], | ||
includes = ['.'], | ||
hdrs = glob(['Eigen/**', | ||
'unsupported/Eigen/**']), | ||
visibility = ['//visibility:public'], | ||
) | ||
""" | ||
) | ||
|
||
# Boost | ||
new_local_repository( | ||
name = "boost", | ||
path = "/usr/include/boost", | ||
build_file = "external/boost.BUILD", | ||
) | ||
|
||
# json | ||
new_local_repository( | ||
name = "json", | ||
path = "external/json", | ||
build_file = "external/json.BUILD", | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
#include <chrono> | ||
#include <experimental/filesystem> | ||
#include <fstream> | ||
#include <iomanip> | ||
|
||
#include <rttopp/demo_trajectories.h> | ||
#include <rttopp/rttopp2.h> | ||
|
||
// This program reads the failed .json file and compute it again for faster | ||
// development | ||
constexpr auto N_JOINTS = 6; | ||
constexpr auto N_TRAJECTORIES = 100; | ||
|
||
template <typename EigenVectorType, typename VectorType> | ||
void fromVectroAsEigenVector(VectorType &v, EigenVectorType &mat) { | ||
mat = Eigen::Map<EigenVectorType, Eigen::Unaligned>(v.data(), v.size()); | ||
} | ||
|
||
rttopp::Waypoints<N_JOINTS> fromJson(const nlohmann::json &j) { | ||
size_t n_waypoints = j["waypoints"].size(); | ||
rttopp::Waypoints<N_JOINTS> waypoints(n_waypoints); | ||
|
||
for (size_t idx = 0; idx < n_waypoints; ++idx) { | ||
auto joint_positions = | ||
j["waypoints"][idx]["joints"]["position"].get<std::vector<double>>(); | ||
|
||
auto &waypoint = waypoints[idx].joints.position; | ||
fromVectroAsEigenVector(joint_positions, waypoint); | ||
} | ||
|
||
return waypoints; | ||
} | ||
|
||
int main(int argc, char **argv) { // NOLINT bugprone-exception-escape | ||
if (argc == 1) { | ||
std::cout << "Please give the directory to the .json files. Abort."; | ||
return EXIT_FAILURE; | ||
} | ||
// Todo(Xi): what if we want to run a specific file in the directory?? | ||
rttopp::RTTOPP2<N_JOINTS> topp; | ||
Eigen::VectorXd durations(N_TRAJECTORIES), inf_means(N_TRAJECTORIES), | ||
inf_std_devs(N_TRAJECTORIES), nums_gridpoints(N_TRAJECTORIES), | ||
max_normalized_velocities(N_TRAJECTORIES), | ||
max_normalized_accelerations(N_TRAJECTORIES); | ||
|
||
// Read Files | ||
size_t i = 0; | ||
size_t i_failed = 0; | ||
std::string path = argv[1]; | ||
for (const auto &entry : | ||
std::experimental::filesystem::directory_iterator(path)) { | ||
std::ifstream ifs(entry.path()); | ||
nlohmann::json j = nlohmann::json::parse(ifs); | ||
|
||
auto waypoints = fromJson(j); | ||
|
||
// Set constraints | ||
rttopp::Constraints<N_JOINTS> constraints; | ||
constraints.joints = | ||
rttopp::demo_trajectories::generateGenericJointConstraints<N_JOINTS>(); | ||
|
||
// set a small velocity at start and end | ||
waypoints.front().joints.velocity = | ||
0.0 * rttopp::WaypointJointDataType<N_JOINTS>::Ones(); | ||
waypoints.back().joints.velocity = | ||
0.0 * rttopp::WaypointJointDataType<N_JOINTS>::Ones(); | ||
|
||
rttopp::Result result = topp.parameterizeFull(constraints, waypoints); | ||
if (result.error()) { | ||
std::cout << "Error: " << result.message() << std::endl; | ||
} | ||
|
||
size_t num_gridpoints; | ||
rttopp::Result verification = topp.verifyTrajectory( | ||
false, &num_gridpoints, &inf_means[i], &inf_std_devs[i], | ||
&max_normalized_velocities[i], &max_normalized_accelerations[i]); | ||
|
||
if (verification.error()) { | ||
std::cout << "error in trajectory " << entry.path() << std::endl; | ||
std::cout << "-----------------------\n" << std::endl; | ||
} | ||
|
||
if (result.error() || verification.error()) { | ||
++i_failed; | ||
nlohmann::json j_out = topp.toJson(waypoints); | ||
|
||
// auto new_path = entry.path(); | ||
// auto file_name = new_path.filename(); | ||
|
||
// std::string path_prefix_str = "new_"; | ||
// std::experimental::filesystem::path new_file_name(path_prefix_str); | ||
// new_file_name += file_name; | ||
// new_path.replace_filename(new_file_name); | ||
|
||
// std::ofstream of(new_path); | ||
std::ofstream of(entry.path()); | ||
|
||
// ToDo(Xi): Should we overwrite it? | ||
if (!of.is_open()) { | ||
std::cout << "Could not write to file: " << entry.path() << std::endl; | ||
return 0; | ||
} | ||
|
||
of << std::setw(4) << j_out << std::endl; | ||
} | ||
++i; | ||
} | ||
|
||
std::cout << "Checked " << i << " cases, " << i_failed << " of them failed." | ||
<< std::endl; | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.