Control Libraries 7.4.0
Loading...
Searching...
No Matches
bind_jacobian.cpp
1#include "state_representation_bindings.hpp"
2
3#include <tuple>
4#include <state_representation/State.hpp>
5#include <state_representation/space/Jacobian.hpp>
6
7void bind_jacobian(py::module_& m) {
8 py::class_<Jacobian, std::shared_ptr<Jacobian>, State> c(m, "Jacobian");
9
10 c.def(py::init(), "Empty constructor for a Jacobian");
11 c.def(py::init<const std::string&, unsigned int, const std::string&, const std::string&>(),
12 "Constructor with name, number of joints, frame name and reference frame provided",
13 "robot_name"_a, "nb_joints"_a, "frame"_a, "reference_frame"_a = "world");
14 c.def(py::init<const std::string&, const std::vector<std::string>&, const std::string&, const std::string&>(),
15 "Constructor with name, joint names, frame name and reference frame provided",
16 "robot_name"_a, "joint_names"_a, "frame"_a, "reference_frame"_a = "world");
17 c.def(py::init<const std::string&, const std::string&, const Eigen::MatrixXd&, const std::string&>(),
18 "Constructor with name, frame, Jacobian matrix and reference frame provided",
19 "robot_name"_a, "frame"_a, "data"_a, "reference_frame"_a = "world");
20 c.def(py::init<const std::string&, const std::vector<std::string>&, const std::string&, const Eigen::MatrixXd&, const std::string&>(),
21 "Constructor with name, joint names, frame name, Jacobian matrix and reference frame provided",
22 "robot_name"_a, "joint_names"_a, "frame"_a, "data"_a, "reference_frame"_a = "world");
23 c.def(py::init<const Jacobian&>(), "Copy constructor of a Jacobian", "jacobian"_a);
24
25 c.def_static("Random", py::overload_cast<const std::string&, unsigned int, const std::string&, const std::string&>(&Jacobian::Random),
26 "Constructor for a random Jacobian",
27 "robot_name"_a, "nb_joints"_a, "frame"_a, "reference_frame"_a = "world");
28 c.def_static("Random", py::overload_cast<const std::string&, const std::vector<std::string>&, const std::string&, const std::string&>(&Jacobian::Random),
29 "Constructor for a random Jacobian",
30 "robot_name"_a, "joint_names"_a, "frame"_a, "reference_frame"_a = "world");
31
32 c.def("rows", &Jacobian::rows, "Getter of the number of rows attribute");
33 c.def("row", &Jacobian::row, "Accessor of the row data at given index");
34 c.def("cols", &Jacobian::cols, "Getter of the number of cols attribute");
35 c.def("col", &Jacobian::col, "Accessor of the column data at given index");
36 c.def("get_joint_names", &Jacobian::get_joint_names, "Getter of the joint_names attribute");
37 c.def("get_frame", &Jacobian::get_frame, "Getter of the frame attribute");
38 c.def("get_reference_frame", &Jacobian::get_reference_frame, "Getter of the reference_frame attribute");
39 c.def("data", &Jacobian::data, "Getter of the data attribute");
40
41 c.def("set_joint_names", py::overload_cast<unsigned int>(&Jacobian::set_joint_names), "Setter of the joint names attribute from the number of joints", "nb_joints"_a);
42 c.def("set_joint_names", py::overload_cast<const std::vector<std::string>&>(&Jacobian::set_joint_names), "Setter of the joint names attribute from a vector of joint names", "joint_names"_a);
43 c.def("set_reference_frame", &Jacobian::set_reference_frame, "Setter of the reference frame", "reference_frame"_a);
44 c.def("set_data", &Jacobian::set_data, "Setter of the data attribute", "data"_a);
45 c.def("set_zero", &Jacobian::set_zero, "Set the Jacobian matrix to a zero value");
46 c.def("copy", &Jacobian::copy, "Return a copy of the Jacobian");
47
48 c.def("inverse", [](const Jacobian& jacobian) {
49 return jacobian.inverse();
50 }, "Return the inverse of the Jacobian matrix");
51 c.def("inverse", [](const Jacobian& jacobian, const Eigen::MatrixXd& matrix) {
52 return jacobian.inverse(matrix);
53 }, "Solve the system X = inv(J) * M to obtain X");
54 c.def("inverse", [](const Jacobian& jacobian, const CartesianTwist& twist) {
55 return jacobian.inverse(twist);
56 }, "Transform the given Cartesian twist to joint space");
57 c.def("is_incompatible", &Jacobian::is_incompatible, "Check if the Jacobian is incompatible for operations with the state given as argument", "state_a");
58 c.def("pseudoinverse", [](const Jacobian& jacobian) {
59 return jacobian.pseudoinverse();
60 }, "Return the pseudoinverse of the Jacobian matrix");
61 c.def("pseudoinverse", [](const Jacobian& jacobian, const Eigen::MatrixXd& matrix) {
62 return jacobian.pseudoinverse(matrix);
63 }, "Multiply the given matrix by the pseudoinverse of the Jacobian matrix");
64 c.def("pseudoinverse", [](const Jacobian& jacobian, const CartesianTwist& twist) {
65 return jacobian.pseudoinverse(twist);
66 }, "Transform a Cartesian twist to joint space by pre-multiplying the Jacobian pseudoinverse");
67 c.def("transpose", [](const Jacobian& jacobian) {
68 return jacobian.transpose();
69 }, "Return the transpose of the Jacobian matrix");
70 c.def("transpose", [](const Jacobian& jacobian, const CartesianWrench& wrench) {
71 return jacobian.transpose(wrench);
72 }, "Transform a Cartesian wrench to joint space by pre-multiplying the Jacobian transpose");
73
74 c.def("__getitem__", [](const Jacobian& jacobian, std::tuple<int, int> coefficients) {
75 return jacobian(std::get<0>(coefficients), std::get<1>(coefficients));
76 }, "Overload the [] operator to access the value at given (row, col)");
77 c.def("__setitem__", [](Jacobian& jacobian, std::tuple<int, int> coefficients, double value) {
78 jacobian(std::get<0>(coefficients), std::get<1>(coefficients)) = value;
79 return jacobian;
80 }, "Overload the [] operator to modify the value at given (row, col)");
81
82 c.def(py::self * Eigen::MatrixXd());
83 c.def(Eigen::Matrix<double, 6, 6>() * py::self);
84 c.def(py::self * JointVelocities());
85 c.def(CartesianPose() * py::self);
86
87 c.def("__copy__", [](const Jacobian &jacobian) {
88 return Jacobian(jacobian);
89 });
90 c.def("__deepcopy__", [](const Jacobian &jacobian, py::dict) {
91 return Jacobian(jacobian);
92 }, "memo"_a);
93 c.def("__repr__", [](const Jacobian& jacobian) {
94 std::stringstream buffer;
95 buffer << jacobian;
96 return buffer.str();
97 });
98}
99
Class to define Cartesian pose in Cartesian space as 3D position and quaternion based orientation.
Class to define twist in Cartesian space as 3D linear and angular velocity vectors.
Class to define wrench in Cartesian space as 3D force and torque vectors.
Class to define a robot Jacobian matrix.
Definition Jacobian.hpp:21
Jacobian copy() const
Return a copy of the Jacobian.
Definition Jacobian.cpp:162
const std::vector< std::string > & get_joint_names() const
Getter of the joint names attribute.
Definition Jacobian.cpp:101
Eigen::VectorXd row(unsigned int index) const
Accessor of the row data at given index.
Definition Jacobian.cpp:89
const Eigen::MatrixXd & data() const
Getter of the data attribute.
Definition Jacobian.cpp:113
void set_zero()
Set the Jacobian matrix to a zero value.
Definition Jacobian.cpp:156
Eigen::MatrixXd pseudoinverse() const
Return the pseudoinverse of the Jacobian matrix.
Definition Jacobian.cpp:245
unsigned int cols() const
Getter of the number of columns attribute.
Definition Jacobian.cpp:93
Eigen::MatrixXd transpose() const
Return the transpose of the Jacobian matrix.
Definition Jacobian.cpp:261
const std::string & get_reference_frame() const
Getter of the reference frame attribute.
Definition Jacobian.cpp:109
unsigned int rows() const
Getter of the number of rows attribute.
Definition Jacobian.cpp:85
Eigen::MatrixXd inverse() const
Return the inverse of the Jacobian matrix.
Definition Jacobian.cpp:172
const std::string & get_frame() const
Getter of the frame attribute.
Definition Jacobian.cpp:105
void set_joint_names(unsigned int nb_joints)
Setter of the joint names attribute from the number of joints.
Definition Jacobian.cpp:118
bool is_incompatible(const State &state) const override
Check if the Jacobian is incompatible for operations with the state given as argument.
Definition Jacobian.cpp:192
void set_data(const Eigen::MatrixXd &data) override
Setter of the data attribute.
Definition Jacobian.cpp:150
void set_reference_frame(const std::string &reference_frame)
Setter of the reference frame.
Definition Jacobian.cpp:145
Eigen::VectorXd col(unsigned int index) const
Accessor of the column data at given index.
Definition Jacobian.cpp:97
static Jacobian Random(const std::string &robot_name, unsigned int nb_joints, const std::string &frame, const std::string &reference_frame="world")
Constructor for a random Jacobian.
Definition Jacobian.cpp:66
Class to define velocities of the joints.
Abstract class to represent a state.
Definition State.hpp:25