How can we alternate between DQ_SerialManipulatorDH and DQ_SerialManipulatorMDH? #13
-
Hello everyone, I would like to know how can we alternate between DQ_SerialManipulatorDH and DQ_SerialManipulatorMDH across different functions in the code. For example, consider the code below: #include <iostream>
#include <dqrobotics/DQ.h>
#include <dqrobotics/robot_modeling/DQ_SerialManipulatorDH.h>
#include <dqrobotics/robot_modeling/DQ_SerialManipulatorMDH.h>
#include <dqrobotics/robots/KukaLw4Robot.h>
#include <dqrobotics/robots/FrankaEmikaPandaRobot.h>
#include <memory>
using namespace DQ_robotics;
void function1(std::shared_ptr<DQ_SerialManipulatorDH> robot);
void function2(std::shared_ptr<DQ_SerialManipulatorDH> robot);
void function1(std::shared_ptr<DQ_SerialManipulatorDH> robot)
{
function2(robot);
}
void function2(std::shared_ptr<DQ_SerialManipulatorDH> robot)
{
// do stuff
}
int main(int argc, char **argv)
{
std::shared_ptr<DQ_SerialManipulatorDH> robot(nullptr);
robot = std::make_shared<DQ_SerialManipulatorDH>(KukaLw4Robot::kinematics());
return 0;
} In the code above I am using a DQ_SerialManipulatorDH object. If I would like to test the same code for a DQ_SerialManipulatorMDH, I would need to change all the object types to DQ_SerialManipulatorMDH everywhere in the code. The code above is short and simple, but when the code has several functions and the DQ_SerialManipulator object is passed across all of them, it is no so easy to adapt the code to use DQ_SerialManipulatorDH or DQ_SerialManipulatorMDH in a simple way. Maybe I am missing some simple way of doing that, but at the moment I have not found a solution yet. How would you recommend me to use the same code for both types of objects? Kind regards, |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 6 replies
-
Hi @marcos-pereira, It suffices to use Kind regards, |
Beta Was this translation helpful? Give feedback.
-
Closed discussions don't show up in the list anymore so maybe we can leave this open? |
Beta Was this translation helpful? Give feedback.
Hi @marcos-pereira,
It suffices to use
DQ_SerialManipulator
, the superclass, as the argument for your methods. When passing an object ofDQ_SerialManipulatorDH
orDQ_SerialManipulatorMDH
, the compiler (or interpreter, in the case of MATLAB) is clever enough to recognize that the object belongs to one subclass or another and use the appropriate method implementation.Kind regards,
Bruno