dqrobotics / cpp

The DQ Robotics library in C++
https://dqrobotics.github.io
GNU Lesser General Public License v3.0
39 stars 13 forks source link

[QUESTION] Is there a way to change the robot of a DQ_SerialManipulator during runtime? #27

Closed marcos-pereira closed 5 years ago

marcos-pereira commented 5 years ago

Hello,

I would like to know if there is a way to change the robot of a DQ_SerialManipulator during runtime.

Something like:

DQ_SerialManipulator robot_serial_manipulator();
...
robot_serial_manipulator = KukaLw4Robot::kinematics();
...
robot_serial_manipulator = AnotherRobot::kinematics();
...
robot_serial_manipulator = MyOtherRobot::kinematics();
...

This yields an error of the following type

error: cannot convert ‘DQ_robotics::DQ_SerialManipulator’ to ‘DQ_robotics::DQ_SerialManipulator()’ in assignment

My goal is to be able to use the robot_serial_manipulator overall in the code without having to declare a DQ_SerialManipulator for each robot. I want to use the same code for different robots chosen during runtime.

Stable PPA DQ Robotics version: 19.10.0-0~201910030916~ubuntu18.04.1

Thank you,

Marcos

mmmarinho commented 5 years ago

Hello, @marcos-pereira,

Yes! The constructor DQ_SerialManipulator() is deleted because an uninitialized DQ_SerialManipulator doesn't make sense and calling any of its methods would have unspecified behavior.

The correct way to do this is with a pointer. From what I understand of your problem, a raw pointer would suffice:

#include <iostream>
#include <vector>

#include <dqrobotics/robot_modeling/DQ_SerialManipulator.h>
#include <dqrobotics/robots/KukaLw4Robot.h>
#include <dqrobotics/robots/Ax18ManipulatorRobot.h>
#include <dqrobotics/robots/ComauSmartSixRobot.h>

using namespace DQ_robotics;

void do_something_with_dq_serial_manipulator(DQ_SerialManipulator* robot)
{
    std::cout << "Joint count: " << robot->get_dim_configuration_space() << std::endl;
}

void test_issue_27()
{
    DQ_SerialManipulator robot_a = KukaLw4Robot::kinematics();
    DQ_SerialManipulator robot_b = Ax18ManipulatorRobot::kinematics();
    DQ_SerialManipulator robot_c = ComauSmartSixRobot::kinematics();

    std::vector<DQ_SerialManipulator*> serial_manipulators;
    serial_manipulators.push_back(&robot_a);
    serial_manipulators.push_back(&robot_b);
    serial_manipulators.push_back(&robot_c);

    for(DQ_SerialManipulator* serial_manipulator: serial_manipulators)
    {
        do_something_with_dq_serial_manipulator(serial_manipulator);
    }
}

int main(void)
{
    test_issue_27();
    return 0;
}