Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(state_representation): remove error in orientation scaling #147

Merged
merged 9 commits into from
Nov 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ Release Versions:
## Upcoming changes (in development)

- feat(controllers): improve parameter validation of impedance controller (#148)
- fix(state_representation): remove error in orientation scaling (#147)

## 7.2.0

Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
7.2.2
7.2.3
2 changes: 1 addition & 1 deletion demos/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
add_compile_options(-Wall -Wextra -Wpedantic)
endif()

find_package(control_libraries 7.2.2 CONFIG REQUIRED)
find_package(control_libraries 7.2.3 CONFIG REQUIRED)

set(DEMOS_SCRIPTS
task_space_control_loop
Expand Down
2 changes: 1 addition & 1 deletion doxygen/doxygen.conf
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ PROJECT_NAME = "Control Libraries"
# could be handy for archiving the generated documentation or if some version
# control system is used.

PROJECT_NUMBER = 7.2.2
PROJECT_NUMBER = 7.2.3

# Using the PROJECT_BRIEF tag one can provide an optional one line description
# for a project that appears at the top of each page and should give viewer a
Expand Down
2 changes: 1 addition & 1 deletion protocol/clproto_cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
cmake_minimum_required(VERSION 3.15)

project(clproto VERSION 7.2.2)
project(clproto VERSION 7.2.3)

# Default to C99
if(NOT CMAKE_C_STANDARD)
Expand Down
2 changes: 1 addition & 1 deletion python/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
# names of the environment variables that define osqp and openrobots include directories
osqp_path_var = 'OSQP_INCLUDE_DIR'

__version__ = "7.2.2"
__version__ = "7.2.3"
__libraries__ = ['state_representation', 'clproto', 'controllers', 'dynamical_systems', 'robot_model']
__include_dirs__ = ['include']

Expand Down
2 changes: 1 addition & 1 deletion source/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
cmake_minimum_required(VERSION 3.15)

project(control_libraries VERSION 7.2.2)
project(control_libraries VERSION 7.2.3)

# Build options
option(BUILD_TESTING "Build all tests." OFF)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -701,9 +701,11 @@ CartesianState& CartesianState::operator*=(double lambda) {
// operation
this->set_position(lambda * this->get_position());
// calculate the scaled rotation as a displacement from identity
Eigen::Quaterniond w = math_tools::log(this->get_orientation());
// calculate the orientation corresponding to the scaled velocity
this->set_orientation(math_tools::exp(w, lambda / 2.));
auto q = math_tools::exp(math_tools::log(this->get_orientation()), lambda);
if (this->get_orientation().w() * q.w() < 0) {
q = Eigen::Quaterniond(-q.coeffs());
}
this->set_orientation(q);
// calculate the other vectors normally
this->set_twist(lambda * this->get_twist());
this->set_acceleration(lambda * this->get_acceleration());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -731,7 +731,7 @@ TEST(CartesianStateTest, ScalarMultiplication) {
CartesianState cs = CartesianState::Random("test");
CartesianState cscaled = scalar * cs;
EXPECT_TRUE(cscaled.get_position().isApprox(scalar * cs.get_position()));
Eigen::Quaterniond qscaled = math_tools::exp(math_tools::log(cs.get_orientation()), scalar / 2.);
auto qscaled = math_tools::exp(math_tools::log(cs.get_orientation()), scalar);
EXPECT_TRUE(cscaled.get_orientation().coeffs().isApprox(qscaled.coeffs()));
EXPECT_TRUE(cscaled.get_twist().isApprox(scalar * cs.get_twist()));
EXPECT_TRUE(cscaled.get_acceleration().isApprox(scalar * cs.get_acceleration()));
Expand All @@ -749,7 +749,7 @@ TEST(CartesianStateTest, ScalarDivision) {
CartesianState cs = CartesianState::Random("test");
CartesianState cscaled = cs / scalar;
EXPECT_TRUE(cscaled.get_position().isApprox(cs.get_position() / scalar));
Eigen::Quaterniond qscaled = math_tools::exp(math_tools::log(cs.get_orientation()), 1.0 / (2. * scalar));
auto qscaled = math_tools::exp(math_tools::log(cs.get_orientation()), 1.0 / scalar);
EXPECT_TRUE(cscaled.get_orientation().coeffs().isApprox(qscaled.coeffs()));
EXPECT_TRUE(cscaled.get_twist().isApprox(cs.get_twist() / scalar));
EXPECT_TRUE(cscaled.get_acceleration().isApprox(cs.get_acceleration() / scalar));
Expand All @@ -763,6 +763,30 @@ TEST(CartesianStateTest, ScalarDivision) {
EXPECT_THROW(empty / scalar, exceptions::EmptyStateException);
}

TEST(CartesianStateTest, OrientationScaling) {
auto cs = CartesianState::Random("A");

for (int i = 0; i < 5; ++i) {
double scale = static_cast<double>(rand()) / RAND_MAX + i;

auto qscaled = Eigen::Quaterniond::Identity();
auto cscaled = scale * cs;
for (int j = 0; j < i; ++j) {
qscaled = qscaled * cs.get_orientation();
}
qscaled = qscaled * Eigen::Quaterniond::Identity().slerp(scale - i, cs.get_orientation());
EXPECT_LT(cscaled.get_orientation().angularDistance(qscaled), 1e-3);

qscaled = Eigen::Quaterniond::Identity();
cscaled = - scale * cs;
for (int j = 0; j < i; ++j) {
qscaled = qscaled * cs.get_orientation();
}
qscaled = qscaled * Eigen::Quaterniond::Identity().slerp(scale - i, cs.get_orientation());
EXPECT_LT(cscaled.get_orientation().angularDistance(qscaled.conjugate()), 1e-3);
}
}

TEST(CartesianStateTest, Multiplication) {
CartesianState world_cs_first = CartesianState::Random("first");
CartesianState first_cs_second = CartesianState::Random("second", "first");
Expand Down