|
| 1 | +/** |
| 2 | +(C) Copyright 2011-2025 DQ Robotics Developers |
| 3 | +
|
| 4 | +This file is part of DQ Robotics. |
| 5 | +
|
| 6 | + DQ Robotics is free software: you can redistribute it and/or modify |
| 7 | + it under the terms of the GNU Lesser General Public License as published by |
| 8 | + the Free Software Foundation, either version 3 of the License, or |
| 9 | + (at your option) any later version. |
| 10 | +
|
| 11 | + DQ Robotics is distributed in the hope that it will be useful, |
| 12 | + but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | + GNU Lesser General Public License for more details. |
| 15 | +
|
| 16 | + You should have received a copy of the GNU Lesser General Public License |
| 17 | + along with DQ Robotics. If not, see <http://www.gnu.org/licenses/>. |
| 18 | +
|
| 19 | +Contributors: |
| 20 | +- Juan Jose Quiroz Omana (juanjose.quirozomana@manchester.ac.uk) |
| 21 | +*/ |
| 22 | + |
| 23 | +#include <iostream> |
| 24 | +#include <dqrobotics/DQ.h> |
| 25 | +#include <dqrobotics/robot_modeling/DQ_SerialManipulatorDH.h> |
| 26 | +#include <dqrobotics/robot_modeling/DQ_SerialManipulatorMDH.h> |
| 27 | +using namespace DQ_robotics; |
| 28 | + |
| 29 | +/** |
| 30 | + * @brief perform_tests This function tests the following methods: get_parameter, get_parameters, |
| 31 | + * set_parameter, and set_parameters in the DQ_SerialManipulatorDH and |
| 32 | + * DQ_SerialManipulatorMDH classes. |
| 33 | + * @param robot A smart pointer of a DQ_SerialManipulatorDH or DQ_SerialManipulatorMDH robot. |
| 34 | + * @param dh_matrix The DH matrix used to create the smart pointer of the robot. |
| 35 | + * @param msg The desired message to be displayed. |
| 36 | + */ |
| 37 | +template<typename T> |
| 38 | +void perform_tests(const std::shared_ptr<T>& robot, const MatrixXd& dh_matrix, const std::string& msg); |
| 39 | + |
| 40 | + |
| 41 | +int main() |
| 42 | +{ |
| 43 | + Matrix<double,5,7> dh_matrix(5,7); |
| 44 | + dh_matrix <<11, 12, 13, 14, 15, 16, 17, // theta |
| 45 | + 21, 22, 23, 24, 25, 26, 27, // d |
| 46 | + 31, 32, 33, 34, 35, 36, 37, // a |
| 47 | + 41, 42, 43, 44, 45, 46, 47, // alpha |
| 48 | + 0, 0, 0, 0, 0, 0, 0; |
| 49 | + |
| 50 | + auto dh_robot = std::make_shared<DQ_SerialManipulatorDH>(dh_matrix); |
| 51 | + auto mdh_robot = std::make_shared<DQ_SerialManipulatorMDH>(dh_matrix); |
| 52 | + |
| 53 | + perform_tests(dh_robot, dh_matrix, "DQ_SerialManipulatorDH"); |
| 54 | + perform_tests(mdh_robot, dh_matrix, "DQ_SerialManipulatorMDH"); |
| 55 | + |
| 56 | + return 0; |
| 57 | +} |
| 58 | + |
| 59 | + |
| 60 | + |
| 61 | +template<typename T> |
| 62 | +void perform_tests(const std::shared_ptr<T>& robot, const MatrixXd& dh_matrix, const std::string& msg) |
| 63 | +{ |
| 64 | + std::vector<DQ_ParameterDH> parameters = |
| 65 | + {DQ_ParameterDH::THETA, DQ_ParameterDH::D, DQ_ParameterDH::A, DQ_ParameterDH::ALPHA}; |
| 66 | + |
| 67 | + std::vector<std::string> string_parameters = |
| 68 | + {"THETA", "D", "A", "ALPHA"}; |
| 69 | + |
| 70 | + std::vector<const char*> char_parameters = |
| 71 | + {"THETA", "D", "A", "ALPHA"}; |
| 72 | + |
| 73 | + // Test get_parameter |
| 74 | + for (int i=0;i<robot->get_dim_configuration_space();i++) |
| 75 | + for(int j=0;j<=3;j++) |
| 76 | + assert(dh_matrix(j,i) == robot->get_parameter(parameters.at(j), i)); |
| 77 | + |
| 78 | + // Test get_parameters |
| 79 | + for (int i=0;i<robot->get_dim_configuration_space();i++) |
| 80 | + for(int j=0;j<=3;j++) |
| 81 | + assert(dh_matrix.row(j).transpose() == robot->get_parameters(parameters.at(j))); |
| 82 | + |
| 83 | + // Set the new parameters |
| 84 | + for(int j=0;j<=3;j++) |
| 85 | + robot->set_parameters(string_parameters.at(j), dh_matrix.row(j)/10); |
| 86 | + |
| 87 | + // Test if the new parameters were set correctly using get_parameter |
| 88 | + for (int i=0;i<robot->get_dim_configuration_space();i++) |
| 89 | + for(int j=0;j<=3;j++) |
| 90 | + assert(dh_matrix(j,i)/10 == robot->get_parameter(string_parameters.at(j), i)); |
| 91 | + |
| 92 | + // Test if the new parameters were set correctly using get_parameters |
| 93 | + for(int j=0;j<=3;j++) |
| 94 | + assert(dh_matrix.row(j).transpose()/10 == robot->get_parameters(char_parameters.at(j))); |
| 95 | + |
| 96 | + std::cout<<msg + ": setters and getters of the DH parameters are working as expected!"<<std::endl; |
| 97 | +} |
0 commit comments