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

This PR adds the class DQ_FreeFlyingRobot() #58

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
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
3 changes: 3 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ ADD_LIBRARY(dqrobotics SHARED
src/robot_modeling/DQ_DifferentialDriveRobot.cpp
src/robot_modeling/DQ_WholeBody.cpp
src/robot_modeling/DQ_SerialWholeBody.cpp
src/robot_modeling/DQ_FreeFlyingRobot.cpp

src/robot_control/DQ_KinematicController.cpp
src/robot_control/DQ_PseudoinverseController.cpp
Expand Down Expand Up @@ -111,6 +112,7 @@ INSTALL(FILES
include/dqrobotics/robot_modeling/DQ_DifferentialDriveRobot.h
include/dqrobotics/robot_modeling/DQ_WholeBody.h
include/dqrobotics/robot_modeling/DQ_SerialWholeBody.h
include/dqrobotics/robot_modeling/DQ_FreeFlyingRobot.h
DESTINATION "include/dqrobotics/robot_modeling")

# robot_control headers
Expand Down Expand Up @@ -181,6 +183,7 @@ INSTALL(FILES
src/robot_modeling/DQ_DifferentialDriveRobot.cpp
src/robot_modeling/DQ_WholeBody.cpp
src/robot_modeling/DQ_SerialWholeBody.cpp
src/robot_modeling/DQ_FreeFlyingRobot.cpp
DESTINATION "src/dqrobotics/robot_modeling")

# robots folder
Expand Down
62 changes: 62 additions & 0 deletions include/dqrobotics/robot_modeling/DQ_FreeFlyingRobot.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/**
(C) Copyright 2023 DQ Robotics Developers

This file is part of DQ Robotics.

DQ Robotics is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

DQ Robotics is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License
along with DQ Robotics. If not, see <http://www.gnu.org/licenses/>.

Contributors:

1. Bruno Vilhena Adorno ([email protected])
Responsible for the original implementation in file DQ_FreeFlyingRobot.m
https://github.com/dqrobotics/matlab/pull/66/commits

2. Juan Jose Quiroz Omana ([email protected])
Created this file.
*/

#pragma once
#include <dqrobotics/robot_modeling/DQ_Kinematics.h>

namespace DQ_robotics
{

class DQ_FreeFlyingRobot: public DQ_Kinematics
{
protected:

void _invalid_signature(const std::string& msg) const;

public:
DQ_FreeFlyingRobot();

//Virtual method overloads (DQ_Kinematics)
virtual DQ fkm (const VectorXd&) const override;
virtual DQ fkm (const VectorXd&, const int&) const override;
virtual MatrixXd pose_jacobian(const VectorXd&, const int&) const override;
virtual MatrixXd pose_jacobian_derivative(const VectorXd& q,
const VectorXd& q_dot,
const int& to_ith_link) const override;




DQ fkm(const DQ& pose) const;
MatrixXd pose_jacobian(const DQ& pose) const;
MatrixXd pose_jacobian_derivative(const DQ& pose_derivative) const;

};

}

143 changes: 143 additions & 0 deletions src/robot_modeling/DQ_FreeFlyingRobot.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
/**
(C) Copyright 2023 DQ Robotics Developers

This file is part of DQ Robotics.

DQ Robotics is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

DQ Robotics is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License
along with DQ Robotics. If not, see <http://www.gnu.org/licenses/>.

Contributors:

1. Bruno Vilhena Adorno ([email protected])
Responsible for the original implementation in file DQ_FreeFlyingRobot.m
https://github.com/dqrobotics/matlab/pull/66/commits

2. Juan Jose Quiroz Omana ([email protected])
Created this file.
*/

#include <dqrobotics/robot_modeling/DQ_FreeFlyingRobot.h>

namespace DQ_robotics
{

/**
* @brief Constructor of the DQ_FreeFlyingRobot() class.
*/
DQ_FreeFlyingRobot::DQ_FreeFlyingRobot()
{
dim_configuration_space_ = 8;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can add that documentation @bvadorno mentioned in MATLAB, as it might be useful here too.
It can be on the description of the method, after the @brief.

        % This robot configuration is given by the unit dual quaternion
        % that represents it's pose. Although strictly speaking this is
        % a 6-dimensional manifold, here we're counting the numbers of
        % coefficients in the unit dual quaternion. Recall that a unit
        % dual quaternion has two constraints, therefore even though it
        % has eight coefficients, these two constraints decreases the
        % number of dimensions of the underlying manifold.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mmmarinho thank you for your feedback. I'm going to implement the required modifications once the @dqrobotics/developers team reaches an agreement or consensus about the DQ_FreeFlyingRobot() class.

}


/**
* @brief Internal method to handle invalid signatures. This method
* throws an exception with the following message:
*
* "This signature is not supported in this class. "
* msg + ", where pose is a unit dual quaternion, which "
* "represents the free-flying robot configuration. "
*
* @param msg Message to provide the valid signature. Ex:
*
* auto msg = std::string("Use fkm(pose)");
* _invalid_signature(msg);
*/
void DQ_FreeFlyingRobot::_invalid_signature(const std::string &msg) const
{
throw std::runtime_error(std::string("This signature is not supported in this class. ") +
msg + std::string(", where pose is a unit dual quaternion, which ")+
std::string("represents the free-flying robot configuration. "));
}


DQ DQ_FreeFlyingRobot::fkm(const VectorXd&) const
{
_invalid_signature(std::string("Use fkm(pose)"));
return DQ(1);
}


DQ DQ_FreeFlyingRobot::fkm(const VectorXd&, const int&) const
{
_invalid_signature(std::string("Use fkm(pose)"));
return DQ(1);
}

MatrixXd DQ_FreeFlyingRobot::pose_jacobian(const VectorXd&, const int&) const
{
_invalid_signature(std::string("Use pose_jacobian(pose)"));
return Eigen::MatrixXd::Zero(2,2);
}

MatrixXd DQ_FreeFlyingRobot::pose_jacobian_derivative(const VectorXd&, const VectorXd&, const int&) const
{
_invalid_signature(std::string("Use pose_jacobian_derivative(pose_derivative). "
"pose_derivative denotes the time derivative of pose"));
return Eigen::MatrixXd::Zero(2,2);
}


/**
* @brief This method returns the free-flying robot pose.
* @param pose The unit dual quaternion that represents
* the free-flying robot configuration.
* @return pose The free-flying robot pose.
*/
DQ DQ_FreeFlyingRobot::fkm(const DQ& pose) const
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See my comment for pose_jacobian

{
return pose;
}

/**
* @brief This method returns the pose Jacobian J that satisfies
*
* x_dot = J*twist,
*
* where x_dot is the time derivative of the unit dual quaternion
* that represents the free-flying robot pose, and twist = vec8(csi),
* where csi satisfies the dual quaternion propagation equation
* xdot = (1/2)*csi*x.
*
* @param pose The unit dual quaternion that represents
* the free-flying robot configuration.
* @return The desired pose Jacobian.
*/
MatrixXd DQ_FreeFlyingRobot::pose_jacobian(const DQ &pose) const
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same for the comment below. However, this method is in CPP currently NOT compatible with the other derived classes. Would it instead be expecting a VectorXd as input that, then, is converted to a DQ? You might want to discuss this with @bvadorno .

% calculates the mobile robot pose Jacobian. If an index is
% passed as an argument, just ignore it because there is
% only one element in the chain. However, we have to tackle
% this case to ensure compatibility with other
% DQ_Kinematics objects.

{
return haminus8(0.5*pose);
}


/**
* @brief This method returns the pose Jacobian derivative of J, where
* J is the pose Jacobian that satisfies
*
* x_dot = J*twist,
*
* where x_dot is the time derivative of the unit dual quaternion
* that represents the free-flying robot pose, and twist = vec8(csi),
* where csi satisfies the dual quaternion propagation equation
* xdot = (1/2)*csi*x.
*
* @param pose The unit dual quaternion that represents
* the free-flying robot configuration.
* @param pose_derivative The time derivative of the robot configuration.
* @return The desired pose Jacobian derivative.
*/
MatrixXd DQ_FreeFlyingRobot::pose_jacobian_derivative(const DQ &pose_derivative) const
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This it not yet available in MATLAB? It needs to show up there first.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mmmarinho No, it's not. Like several implementations related to Jacobian derivatives that are currently implemented only in the C++ version, I added it and proposed a numerical test in ` in this PR. However, I understand your point. I'm going to propose the pose_jacobian_derivative method in Matlab first, as suggested. =)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @juanjqo and @mmmarinho,

This is undesirable. Why are those implementations appearing in the C++ version and not in MATLAB? This only causes confusion and potential for code divergence in the long run.

All the best,
Bruno

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @bvadorno, I agree. Several methods were added to the C++ (master branch) version in the last months for internal developments. Some of them are related to the Jacobian derivatives. This indeed created a divergence between both versions of the DQ Robotics. However, this issue was discussed internally in our meetings, and we defined several tasks to fix it. Such tasks are summarized in the Pending tasks for the 23.04 release discussions. Furthermore, it was highlighted that new methods must first been added/proposed in Matlab.

Best regards,

Juancho

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @juanjqo,

True! Thank you for refreshing my memory. 😃

Kind regards,
Bruno

{
return haminus8(0.5*pose_derivative);
}

}