From 009273bf66b8a6ac5b6ef5944767249dde3e0628 Mon Sep 17 00:00:00 2001 From: Joschua Gosda <joschua.gosda@control.lth.se> Date: Thu, 19 May 2022 11:42:16 +0200 Subject: [PATCH] tried handing over shared model ptr directly but cannot be given to python cuz of its type --- c++/include/gpm.hpp | 2 +- c++/include/loadKinematicModel.hpp | 7 +++---- c++/src/gpm.cpp | 5 ++--- c++/src/loadKinematicModel.cpp | 14 +++++++------- c++/src/main.cpp | 4 ++-- 5 files changed, 15 insertions(+), 17 deletions(-) diff --git a/c++/include/gpm.hpp b/c++/include/gpm.hpp index ca063b9..4d367ee 100644 --- a/c++/include/gpm.hpp +++ b/c++/include/gpm.hpp @@ -3,4 +3,4 @@ std::pair<Eigen::Matrix<double, 7, 1>, Eigen::Matrix<double, 6, 1>> gpm(Eigen::Matrix<double, 6, 1> &desPose, Eigen::Matrix<double, 6, 1> &desVelocity, -Eigen::Matrix<double, 7, 1> &jointAngles, Eigen::Matrix<double, 7, 1> &jointVelocity, void * kinematic_ptr); +Eigen::Matrix<double, 7, 1> &jointAngles, Eigen::Matrix<double, 7, 1> &jointVelocity, std::shared_ptr<rl::mdl::Model> model); diff --git a/c++/include/loadKinematicModel.hpp b/c++/include/loadKinematicModel.hpp index ca6d3ad..b6be6d0 100644 --- a/c++/include/loadKinematicModel.hpp +++ b/c++/include/loadKinematicModel.hpp @@ -4,10 +4,9 @@ class Arm { public: Arm(std::string path); - void* get_pointer2arm(); + std::shared_ptr<rl::mdl::Model> get_pointer2arm(); private: - rl::mdl::Kinematic* kin_pointer; - rl::mdl::Kinematic kin_model; - void* void_pointer; + //rl::mdl::Kinematic kin_model; + std::shared_ptr<rl::mdl::Model> model; }; diff --git a/c++/src/gpm.cpp b/c++/src/gpm.cpp index 6967410..4aac275 100644 --- a/c++/src/gpm.cpp +++ b/c++/src/gpm.cpp @@ -11,12 +11,11 @@ std::pair<Eigen::Matrix<double, 7, 1>, Eigen::Matrix<double, 6, 1>> gpm(Eigen::Matrix<double, 6, 1> &desPose, Eigen::Matrix<double, 6, 1> &desVelocity, -Eigen::Matrix<double, 7, 1> &jointAngles, Eigen::Matrix<double, 7, 1> &jointVelocity, void * kinematic_ptr) { +Eigen::Matrix<double, 7, 1> &jointAngles, Eigen::Matrix<double, 7, 1> &jointVelocity, std::shared_ptr<rl::mdl::Model> model) { + rl::mdl::Kinematic* kinematic = dynamic_cast<rl::mdl::Kinematic*>(model.get()); // FORWARD KINEMATICS - rl::mdl::Kinematic* kinematic = (rl::mdl::Kinematic*) kinematic_ptr; - std::cout << "adress of pointer gpm " << kinematic_ptr << std::endl; //std::cout << "pointer in gpm" << kinematic_ptr << std::endl; diff --git a/c++/src/loadKinematicModel.cpp b/c++/src/loadKinematicModel.cpp index 553ad68..856f00a 100644 --- a/c++/src/loadKinematicModel.cpp +++ b/c++/src/loadKinematicModel.cpp @@ -7,15 +7,15 @@ Arm::Arm(std::string path){ rl::mdl::UrdfFactory factory; - std::shared_ptr<rl::mdl::Model> model(factory.create(path)); - kin_pointer = dynamic_cast<rl::mdl::Kinematic*>(model.get()); - kin_model = *(kin_pointer); - rl::mdl::Kinematic* tmp_pointer = &kin_model; - void_pointer = (void*) tmp_pointer; - std::cout << "adress of pointer load " << void_pointer << std::endl; + std::shared_ptr<rl::mdl::Model> model_tmp(factory.create(path)); + model = model_tmp; + + + //std::cout << "adress of pointer load " << void_pointer << std::endl; } -void* Arm::get_pointer2arm() {return void_pointer;} +std::shared_ptr<rl::mdl::Model> Arm::get_pointer2arm() {return model;} + /* class Arm { public: diff --git a/c++/src/main.cpp b/c++/src/main.cpp index b6a4228..43be50a 100644 --- a/c++/src/main.cpp +++ b/c++/src/main.cpp @@ -24,7 +24,7 @@ int main(int, char**) { rl::mdl::Kinematic* kinematic = dynamic_cast<rl::mdl::Kinematic*>(model.get()); Arm right_arm("/home/joschua/Coding/forceControl/master-project/c++/models/urdf/yumi_right.urdf"); - void* test_pointer = right_arm.get_pointer2arm(); + std::shared_ptr<rl::mdl::Model> abc = right_arm.get_pointer2arm(); // Is Values Eigen::Matrix<double, 6, 1> actualPosition; @@ -44,7 +44,7 @@ int main(int, char**) { desVelocity << 0.0, 0.0, 0.0, 0.0, 0.0, 0.0; std::pair<Eigen::Matrix<double, 7, 1>, Eigen::Matrix<double, 6, 1>> result; - result = gpm(desPose, desVelocity, jointAngles, jointVelocity, test_pointer); + result = gpm(desPose, desVelocity, jointAngles, jointVelocity, abc); std::cout << "desired joint values: \n" << result.first << std::endl; std::cout << "current pose: \n" << result.second << std::endl; -- GitLab