Skip to content
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
101 changes: 101 additions & 0 deletions include/dqrobotics/robot_modeling/DQ_ParameterDH.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
/**
(C) Copyright 2011-2025 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. Juan Jose Quiroz Omana (juanjose.quirozomana@manchester.ac.uk)
- Responsible for the original implementation.
*/

#include <unordered_map>
#include <iostream>
#pragma once

namespace DQ_robotics
{
class DQ_ParameterDH
{
public:
enum PARAMETER{
THETA,
D,
A,
ALPHA
};
private:
PARAMETER parameter_;
const std::unordered_map<std::string, PARAMETER>
map_ = {{"THETA", THETA},
{"D" , D},
{"A" , A},
{"ALPHA", ALPHA},
};

/**
* @brief _get_parameter sets the parameter member using a string as argument.
* @param parameter The desired parameter to be set. Example: "THETA", "D", "A", or "ALPHA".
*/
void _set_parameter(const std::string& parameter)
{
try {
parameter_ = map_.at(parameter);
} catch (...) {
throw std::runtime_error("The parameter \""+ parameter+ "\" is not supported. Use THETA, D, A, or ALPHA");
}
}
public:
/**
* @brief DQ_ParameterDH Default constructor method.
*/
DQ_ParameterDH() = default;

/**
* @brief DQ_ParameterDH Constructor method
* @param parameter The desired DH parameter. Example: THETA, D, A, or ALPHA.
*/
DQ_ParameterDH(const PARAMETER& parameter): parameter_{parameter}{};

// This definition enables switch cases and comparisons.
constexpr operator PARAMETER() const { return parameter_; }

/**
* @brief DQ_ParameterDH Constructor method that allows string parameters.
* This is done to keep the language compatibility between
* Matlab and Python/C++, as discussed in
* https://github.com/dqrobotics/cpp/pull/69
* @param parameter The desired DH parameter. Example: "THETA", "D", "A", or "ALPHA".
*/
DQ_ParameterDH(const std::string& parameter){
_set_parameter(parameter);
}


/**
* @brief DQ_ParameterDH Constructor method that allows char parameters.
* This is done to keep the language compatibility between
* Matlab and Python/C++, as discussed in
* https://github.com/dqrobotics/cpp/pull/69
* @param parameter_c The desired DH parameter. Example: "THETA", "D", "A", or "ALPHA".
*/
DQ_ParameterDH(const char* parameter_c){
_set_parameter(parameter_c);
}

};
}


5 changes: 2 additions & 3 deletions include/dqrobotics/robot_modeling/DQ_SerialManipulator.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,8 @@ This file is part of DQ Robotics.
along with DQ Robotics. If not, see <http://www.gnu.org/licenses/>.

Contributors:
- Murilo M. Marinho (murilomarinho@ieee.org)
- Mateus Rodrigues Martins (martinsrmateus@gmail.com)
- Juan Jose Quiroz Omana (juanjqo@g.ecc.u-tokyo.ac.jp)
1. Murilo M. Marinho (murilomarinho@ieee.org)
2. Mateus Rodrigues Martins (martinsrmateus@gmail.com)
*/

#include <dqrobotics/robot_modeling/DQ_Kinematics.h>
Expand Down
18 changes: 15 additions & 3 deletions include/dqrobotics/robot_modeling/DQ_SerialManipulatorDH.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#pragma once
/**
(C) Copyright 2020-2022 DQ Robotics Developers
(C) Copyright 2011-2025 DQ Robotics Developers

This file is part of DQ Robotics.

Expand All @@ -18,12 +18,16 @@ This file is part of DQ Robotics.
along with DQ Robotics. If not, see <http://www.gnu.org/licenses/>.

Contributors:
- Murilo M. Marinho (murilomarinho@ieee.org)
- Juan Jose Quiroz Omana (juanjqo@g.ecc.u-tokyo.ac.jp)
1. Murilo M. Marinho (murilomarinho@ieee.org)
- Responsible for the original implementation.

2. Juan Jose Quiroz Omana (juanjqogm@gmail.com)
- Added methods to get and set the DH parameters.
*/


#include <dqrobotics/robot_modeling/DQ_SerialManipulator.h>
#include <dqrobotics/robot_modeling/DQ_ParameterDH.h>

namespace DQ_robotics
{
Expand All @@ -36,6 +40,14 @@ class DQ_SerialManipulatorDH: public DQ_SerialManipulator
DQ _get_w(const int& ith) const;
DQ _dh2dq(const double& q, const int& ith) const;
public:
VectorXd get_parameters(const DQ_ParameterDH& parameter_type) const;
double get_parameter(const DQ_ParameterDH& parameter_type,
const int& to_ith_link) const;
void set_parameters(const DQ_ParameterDH& parameter_type,
const VectorXd& vector_parameters);
void set_parameter(const DQ_ParameterDH& parameter_type,
const int& to_ith_link,
const double& parameter);

// Deprecated on 22.04, will be removed on the next release.
enum [[deprecated("Use ? instead.")]] JOINT_TYPES{ JOINT_ROTATIONAL=0, JOINT_PRISMATIC };
Expand Down
18 changes: 15 additions & 3 deletions include/dqrobotics/robot_modeling/DQ_SerialManipulatorMDH.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#pragma once
/**
(C) Copyright 2022 DQ Robotics Developers
(C) Copyright 2011-2025 DQ Robotics Developers

This file is part of DQ Robotics.

Expand All @@ -18,11 +18,15 @@ This file is part of DQ Robotics.
along with DQ Robotics. If not, see <http://www.gnu.org/licenses/>.

Contributors:
- Murilo M. Marinho (murilomarinho@ieee.org)
- Juan Jose Quiroz Omana - juanjqo@g.ecc.u-tokyo.ac.jp
1. Murilo M. Marinho (murilomarinho@ieee.org)
- Responsible for the original implementation.

2. Juan Jose Quiroz Omana (juanjqogm@gmail.com)
- Added methods to get and set the DH parameters.
*/

#include <dqrobotics/robot_modeling/DQ_SerialManipulator.h>
#include <dqrobotics/robot_modeling/DQ_ParameterDH.h>

namespace DQ_robotics
{
Expand All @@ -35,6 +39,14 @@ class DQ_SerialManipulatorMDH: public DQ_SerialManipulator
DQ _get_w(const int& ith) const;
DQ _mdh2dq(const double& q, const int& ith) const;
public:
VectorXd get_parameters(const DQ_ParameterDH& parameter_type) const;
double get_parameter(const DQ_ParameterDH& parameter_type,
const int& to_ith_link) const;
void set_parameters(const DQ_ParameterDH& parameter_type,
const VectorXd& vector_parameters);
void set_parameter(const DQ_ParameterDH& parameter_type,
const int& to_ith_link,
const double& parameter);

// Deprecated on 22.04, will be removed on the next release.
enum [[deprecated("Use ? instead.")]] JOINT_TYPES{ JOINT_ROTATIONAL=0, JOINT_PRISMATIC };
Expand Down
7 changes: 3 additions & 4 deletions src/robot_modeling/DQ_SerialManipulator.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
(C) Copyright 2011-2020 DQ Robotics Developers
(C) Copyright 2011-2025 DQ Robotics Developers

This file is part of DQ Robotics.

Expand All @@ -17,9 +17,8 @@ This file is part of DQ Robotics.
along with DQ Robotics. If not, see <http://www.gnu.org/licenses/>.

Contributors:
- Murilo M. Marinho (murilomarinho@ieee.org)
- Mateus Rodrigues Martins (martinsrmateus@gmail.com)
- Juan Jose Quiroz Omana (juanjqo@g.ecc.u-tokyo.ac.jp)
1. Murilo M. Marinho (murilomarinho@ieee.org)
2. Mateus Rodrigues Martins (martinsrmateus@gmail.com)
*/

#include <dqrobotics/robot_modeling/DQ_SerialManipulator.h>
Expand Down
105 changes: 102 additions & 3 deletions src/robot_modeling/DQ_SerialManipulatorDH.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
(C) Copyright 2020-2022 DQ Robotics Developers
(C) Copyright 2011-2025 DQ Robotics Developers

This file is part of DQ Robotics.

Expand All @@ -17,8 +17,11 @@ This file is part of DQ Robotics.
along with DQ Robotics. If not, see <http://www.gnu.org/licenses/>.

Contributors:
- Murilo M. Marinho (murilomarinho@ieee.org)
- Juan Jose Quiroz Omana (juanjqo@g.ecc.u-tokyo.ac.jp)
1. Murilo M. Marinho (murilomarinho@ieee.org)
- Responsible for the original implementation.

2. Juan Jose Quiroz Omana (juanjqogm@gmail.com)
- Added methods to get and set the DH parameters.
*/

#include <dqrobotics/robot_modeling/DQ_SerialManipulatorDH.h>
Expand Down Expand Up @@ -99,6 +102,102 @@ DQ DQ_SerialManipulatorDH::_dh2dq(const double &q, const int &ith) const
);
}

/**
* @brief DQ_SerialManipulatorDH::get_parameters returns a vector containing the DH parameters.
* @param parameter_type Parameter type, which which corresponds to THETA, D, A, or ALPHA.
* @return A vector containing the desired DH parameters.
*/
VectorXd DQ_SerialManipulatorDH::get_parameters(const DQ_ParameterDH &parameter_type) const
{
switch (parameter_type) {
case DQ_ParameterDH::THETA:
return dh_matrix_.row(0);
case DQ_ParameterDH::D:
return dh_matrix_.row(1);
case DQ_ParameterDH::A:
return dh_matrix_.row(2);
case DQ_ParameterDH::ALPHA:
return dh_matrix_.row(3);
default:
throw std::runtime_error("Wrong type of parameter");
}
}

/**
* @brief DQ_SerialManipulatorDH::get_parameter returns the DH parameter of the ith joint.
* @param parameter_type Parameter type, which which corresponds to THETA, D, A, or ALPHA.
* @param to_ith_link The joint number.
* @return The desired DH parameter.
*/
double DQ_SerialManipulatorDH::get_parameter(const DQ_ParameterDH &parameter_type,
const int &to_ith_link) const
{
_check_to_ith_link(to_ith_link);
switch (parameter_type) {
case DQ_ParameterDH::THETA:
return dh_matrix_(0, to_ith_link);
case DQ_ParameterDH::D:
return dh_matrix_(1, to_ith_link);
case DQ_ParameterDH::A:
return dh_matrix_(2, to_ith_link);
case DQ_ParameterDH::ALPHA:
return dh_matrix_(3, to_ith_link);
default:
throw std::runtime_error("Wrong type of parameter");
}
}

/**
* @brief DQ_SerialManipulatorDH::set_parameters sets the DH parameters.
* @param parameter_type Parameter type, which which corresponds to THETA, D, A, or ALPHA.
* @param vector_parameters A vector containing the new parameters.
*/
void DQ_SerialManipulatorDH::set_parameters(const DQ_ParameterDH &parameter_type,
const VectorXd &vector_parameters)
{
_check_q_vec(vector_parameters);
switch (parameter_type) {
case DQ_ParameterDH::THETA:
dh_matrix_.row(0) = vector_parameters;
break;
case DQ_ParameterDH::D:
dh_matrix_.row(1) = vector_parameters;
break;
case DQ_ParameterDH::A:
dh_matrix_.row(2) = vector_parameters;
break;
case DQ_ParameterDH::ALPHA:
dh_matrix_.row(3) = vector_parameters;
break;
}
}

/**
* @brief DQ_SerialManipulatorDH::set_parameter sets the DH parameter of the ith joint.
* @param parameter_type Parameter type, which which corresponds to THETA, D, A, or ALPHA.
* @param to_ith_link The joint number.
* @param parameter The new parameter.
*/
void DQ_SerialManipulatorDH::set_parameter(const DQ_ParameterDH &parameter_type,
const int &to_ith_link, const double &parameter)
{
_check_to_ith_link(to_ith_link);
switch (parameter_type) {
case DQ_ParameterDH::THETA:
dh_matrix_(0, to_ith_link) = parameter;
break;
case DQ_ParameterDH::D:
dh_matrix_(1, to_ith_link) = parameter;
break;
case DQ_ParameterDH::A:
dh_matrix_(2, to_ith_link) = parameter;
break;
case DQ_ParameterDH::ALPHA:
dh_matrix_(3, to_ith_link) = parameter;
break;
}
}


/**
* @brief This protected method computes the dual quaternion related with the time derivative of the
Expand Down
Loading
Loading