Control Libraries 6.3.4
Loading...
Searching...
No Matches
bind_jacobian.cpp
1#include "state_representation_bindings.h"
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_property_readonly_static("__array_priority__", [](py::object) { return 10000; });
11
12 c.def(py::init(), "Empty constructor for a Jacobian");
13 c.def(py::init<const std::string&, unsigned int, const std::string&, const std::string&>(),
14 "Constructor with name, number of joints, frame name and reference frame provided",
15 "robot_name"_a, "nb_joints"_a, "frame"_a, "reference_frame"_a = "world");
16 c.def(py::init<const std::string&, const std::vector<std::string>&, const std::string&, const std::string&>(),
17 "Constructor with name, joint names, frame name and reference frame provided",
18 "robot_name"_a, "joint_names"_a, "frame"_a, "reference_frame"_a = "world");
19 c.def(py::init<const std::string&, const std::string&, const Eigen::MatrixXd&, const std::string&>(),
20 "Constructor with name, frame, Jacobian matrix and reference frame provided",
21 "robot_name"_a, "frame"_a, "data"_a, "reference_frame"_a = "world");
22 c.def(py::init<const std::string&, const std::vector<std::string>&, const std::string&, const Eigen::MatrixXd&, const std::string&>(),
23 "Constructor with name, joint names, frame name, Jacobian matrix and reference frame provided",
24 "robot_name"_a, "joint_names"_a, "frame"_a, "data"_a, "reference_frame"_a = "world");
25 c.def(py::init<const Jacobian&>(), "Copy constructor of a Jacobian", "jacobian"_a);
26
27 c.def_static("Random", py::overload_cast<const std::string&, unsigned int, const std::string&, const std::string&>(&Jacobian::Random),
28 "Constructor for a random Jacobian",
29 "robot_name"_a, "nb_joints"_a, "frame"_a, "reference_frame"_a = "world");
30 c.def_static("Random", py::overload_cast<const std::string&, const std::vector<std::string>&, const std::string&, const std::string&>(&Jacobian::Random),
31 "Constructor for a random Jacobian",
32 "robot_name"_a, "joint_names"_a, "frame"_a, "reference_frame"_a = "world");
33
34 c.def("rows", &Jacobian::rows, "Getter of the number of rows attribute");
35 c.def("row", &Jacobian::row, "Accessor of the row data at given index");
36 c.def("cols", &Jacobian::cols, "Getter of the number of cols attribute");
37 c.def("col", &Jacobian::col, "Accessor of the column data at given index");
38 c.def("get_joint_names", &Jacobian::get_joint_names, "Getter of the joint_names attribute");
39 c.def("get_frame", &Jacobian::get_frame, "Getter of the frame attribute");
40 c.def("get_reference_frame", &Jacobian::get_reference_frame, "Getter of the reference_frame attribute");
41 c.def("data", &Jacobian::data, "Getter of the data attribute");
42
43 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);
44 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);
45 c.def("set_reference_frame", py::overload_cast<const CartesianPose&>(&Jacobian::set_reference_frame), "Setter of the reference_frame attribute from a CartesianPose", "reference_frame"_a);
46 c.def("set_data", py::overload_cast<const Eigen::MatrixXd&>(&Jacobian::set_data), "Setter of the data attribute", "data"_a);
47
48 c.def("transpose", &Jacobian::transpose, "Return the transpose of the Jacobian matrix");
49 c.def("inverse", &Jacobian::inverse, "Return the inverse of the Jacobian matrix");
50 c.def("pseudoinverse", &Jacobian::pseudoinverse, "Return the pseudoinverse of the Jacobian matrix");
51 c.def("copy", &Jacobian::copy, "Return a copy of the Jacobian");
52 c.def("solve", [](const Jacobian& jacobian, const Eigen::MatrixXd& matrix) {
53 return jacobian.solve(matrix);
54 }, "Solve the system X = inv(J)*M to obtain X which is more efficient than multiplying with the pseudo-inverse");
55 c.def("solve", [](const Jacobian& jacobian, const CartesianTwist& twist) {
56 return jacobian.solve(twist);
57 }, "Solve the system dX = J*dq to obtain dq which is more efficient than multiplying with the pseudo-inverse");
58
59 c.def("__getitem__", [](const Jacobian& jacobian, std::tuple<int, int> coefficients) {
60 return jacobian(std::get<0>(coefficients), std::get<1>(coefficients));
61 }, "Overload the [] operator to access the value at given (row, col)");
62 c.def("__setitem__", [](Jacobian& jacobian, std::tuple<int, int> coefficients, double value) {
63 jacobian(std::get<0>(coefficients), std::get<1>(coefficients)) = value;
64 return jacobian;
65 }, "Overload the [] operator to modify the value at given (row, col)");
66
67 c.def(py::self * Eigen::MatrixXd());
68 c.def(py::self * py::self);
69 c.def(py::self * JointVelocities());
70 c.def(py::self * CartesianTwist());
71 c.def(py::self * CartesianWrench());
72 c.def(CartesianPose() * py::self);
73 c.def(Eigen::MatrixXd() * py::self);
74
75 c.def("__copy__", [](const Jacobian &jacobian) {
76 return Jacobian(jacobian);
77 });
78 c.def("__deepcopy__", [](const Jacobian &jacobian, py::dict) {
79 return Jacobian(jacobian);
80 }, "memo"_a);
81 c.def("__repr__", [](const Jacobian& jacobian) {
82 std::stringstream buffer;
83 buffer << jacobian;
84 return buffer.str();
85 });
86}
87
Class to define CartesianPose 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:20
Jacobian copy() const
Return a copy of the JointPositions.
Definition: Jacobian.cpp:258
const std::vector< std::string > & get_joint_names() const
Getter of the joint_names attribute.
Definition: Jacobian.hpp:360
Eigen::VectorXd row(unsigned int index) const
Accessor of the row data at given index.
Definition: Jacobian.hpp:352
const Eigen::MatrixXd & data() const
Getter of the data attribute.
Definition: Jacobian.hpp:392
Jacobian pseudoinverse() const
Return the pseudoinverse of the Jacobian matrix.
Definition: Jacobian.cpp:157
unsigned int cols() const
Getter of the number of columns attribute.
Definition: Jacobian.hpp:348
Eigen::MatrixXd solve(const Eigen::MatrixXd &matrix) const
Solve the system X = inv(J)*M to obtain X which is more efficient than multiplying with the pseudo-in...
Definition: Jacobian.cpp:230
const std::string & get_reference_frame() const
Getter of the reference_frame attribute.
Definition: Jacobian.hpp:388
unsigned int rows() const
Getter of the number of rows attribute.
Definition: Jacobian.hpp:344
void set_reference_frame(const CartesianPose &reference_frame)
Setter of the reference_frame attribute from a CartesianPose Update the value of the data matrix acco...
Definition: Jacobian.cpp:133
const std::string & get_frame() const
Getter of the frame attribute.
Definition: Jacobian.hpp:384
Jacobian inverse() const
Return the inverse of the Jacobian matrix If the matrix is not invertible, an error is thrown advisin...
Definition: Jacobian.cpp:145
void set_joint_names(unsigned int nb_joints)
Setter of the joint_names attribute from the number of joints.
Definition: Jacobian.hpp:364
void set_data(const Eigen::MatrixXd &data) override
Setter of the data attribute.
Definition: Jacobian.hpp:396
Jacobian transpose() const
Return the transpose of the Jacobian matrix.
Definition: Jacobian.cpp:137
Eigen::VectorXd col(unsigned int index) const
Accessor of the column data at given index.
Definition: Jacobian.hpp:356
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:70
Class to define velocities of the joints.
Abstract class to represent a state.
Definition: State.hpp:25