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 fixes issue 59 of the Python version of the DQ Robotics #67

Merged
merged 5 commits into from
Sep 26, 2024

Conversation

juanjqo
Copy link
Member

@juanjqo juanjqo commented Jul 31, 2024

Static Badge

@dqrobotics/developers

Hi @mmmarinho,

This PR initializes some variables to match the Matlab implementation. Specifically, I initialized the attributes damping, gain, system_reached_stable_region_, stability_threshold, stability_counter, and stability_counter_max of the class DQ_KinematicController.

This PR fixes the issue 59 in Python by setting the damping to 1e-3 in the class DQ_ClassicQPController(as in the Matlab version).

Furthermore, I added a default damping in the constructor of the class DQ_ClassicQPController to match the implementation of the class DQ_ClassicQPController.m.

Minimal Example

#include <iostream>
#include <dqrobotics/robots/KukaLw4Robot.h>
#include <dqrobotics/robot_control/DQ_ClassicQPController.h>
#include <dqrobotics/solvers/DQ_PROXQPSolver.h>

using namespace DQ_robotics;

int main()
{
    auto robot = std::make_shared<DQ_SerialManipulatorDH>(KukaLw4Robot::kinematics());
    auto solver = std::make_shared<DQ_PROXQPSolver>();
    auto controller = DQ_ClassicQPController(robot, solver);
    auto damping = controller.get_damping();
    std::cout<<damping<<std::endl;
}

Output

0.001

Output of the current version of DQ Robotics (MacOS)

0

Please let me know if additional modifications are required.

Best regards,

Juancho

Copy link
Member

@mmmarinho mmmarinho left a comment

Choose a reason for hiding this comment

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

Thanks, @juanjqo. My major concern is the re-initialization of things already being initialized in the constructor.

@mmmarinho mmmarinho assigned mmmarinho and juanjqo and unassigned mmmarinho Aug 1, 2024
juanjqo added 2 commits August 2, 2024 10:55
… of variables that are initialized in the constructor
…attribute in the constructor. In addition, I fixed the initialization order of the attributes last control and last error signal.
@juanjqo juanjqo marked this pull request as draft August 5, 2024 10:25
@mmmarinho
Copy link
Member

mmmarinho commented Sep 16, 2024

Hi @juanjqo and @bvadorno ,

I'm quoting the reply by @juanjqo here because if we resolve that conversation all the discussion will be lost (AFAIK).

@bvadorno no, they do not match. Unlike the C++ implementation, the Matlab version of DQ_KinematicController.m does not initialize the attributes in the constructor. Instead, they are defined directly in the class. Furthermore, the constructor is public in DQ_KinematicController.m and protected in DQ_KinematicController.h

PS. @bvadorno, In one of our internal DQ robotics meetings, we decided to modify the Matlab version to match the C++ one. This is, initializing the attributes in the constructor. May I follow that plan?

If I may add to this discussion, given that I wasn't part of those meetings.

A bazillion years ago (more accurately 12 years or so), the C++ library had a C++98-ish style, hence in-class initialization was not possible. Please put into context that it inherited from even earlier code and C++11 compilers were still not widespread. For instance,

matrix <double> dq_kin;

In-class initialization has been added to compilers for C++11 and beyond. In-class initialization is preferred in C++11 as well, no doubt. It leads to less repetition and could be less error-prone (if users are observant of the style). However, because constructor initialization isn't wrong, the original style was followed to keep the files consistent across the library (if we do in-class initialization somewhere, I'm sure it's rare).

My initial point when flagging the in-class initialization of the damping factor was simply that the initialization must happen all in the same place. It's fine to move it out of the constructor and have all initialization done in class. It is also reasonable to move the new one to the constructor. What is confusing is to have part of it in class and part of it in the constructor.

…h the Matlab implementation"

This reverts commit 378c3f4.
@juanjqo juanjqo marked this pull request as ready for review September 18, 2024 09:32
@bvadorno
Copy link
Member

Thanks for the additional context, @mmmarinho. Since I'm stuck with C++98, having the context of the functionalities that came after is always a mix of delight (learning cool things) and despair (feeling like a dinosaur).

@juanjqo, since both are correct, let's stick with what we decided in person. I don't remember the reason for our decision anymore, but I'm quite sure we had a good reason (we probably concluded that changing MATLAB would be easier).

Kind regards,
Bruno

Copy link
Member

@mmmarinho mmmarinho left a comment

Choose a reason for hiding this comment

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

Hi @juanjqo,

From what I can see, the current implementation is following the MATLAB format while keeping to the C++ requirements. This seems good to go.

system_reached_stable_region_(false),
last_error_signal_(VectorXd::Zero(1)),//Todo: change this inialization to use empty vector
last_control_signal_(VectorXd::Zero(1)),//Todo: change this inialization to use empty vector
damping_(0),//Todo: change this inialization to use empty vector
Copy link
Member

Choose a reason for hiding this comment

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

@@ -28,14 +35,14 @@ namespace DQ_robotics
DQ_ClassicQPController::DQ_ClassicQPController(DQ_Kinematics* robot, DQ_QuadraticProgrammingSolver* solver):
DQ_QuadraticProgrammingController (robot,solver)
{

set_damping(1e-3); // Default damping.
Copy link
Member

Choose a reason for hiding this comment

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

@mmmarinho mmmarinho merged commit 262ea69 into dqrobotics:master Sep 26, 2024
3 of 6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants