1#include "state_representation_bindings.hpp"
4#include <state_representation/State.hpp>
5#include <state_representation/space/Jacobian.hpp>
7void bind_jacobian(py::module_& m) {
8 py::class_<Jacobian, std::shared_ptr<Jacobian>,
State> c(m,
"Jacobian");
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);
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");
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");
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);
48 c.def(
"inverse", [](
const Jacobian& jacobian) {
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");
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) {
60 },
"Return the pseudoinverse of the Jacobian matrix");
61 c.def(
"pseudoinverse", [](
const Jacobian& jacobian,
const Eigen::MatrixXd& matrix) {
63 },
"Multiply the given matrix by the pseudoinverse of the Jacobian matrix");
66 },
"Transform a Cartesian twist to joint space by pre-multiplying the Jacobian pseudoinverse");
67 c.def(
"transpose", [](
const Jacobian& jacobian) {
69 },
"Return the transpose of the Jacobian matrix");
72 },
"Transform a Cartesian wrench to joint space by pre-multiplying the Jacobian transpose");
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;
80 },
"Overload the [] operator to modify the value at given (row, col)");
82 c.def(py::self * Eigen::MatrixXd());
83 c.def(Eigen::Matrix<double, 6, 6>() * py::self);
87 c.def(
"__copy__", [](
const Jacobian &jacobian) {
90 c.def(
"__deepcopy__", [](
const Jacobian &jacobian, py::dict) {
93 c.def(
"__repr__", [](
const Jacobian& jacobian) {
94 std::stringstream buffer;
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.
Jacobian copy() const
Return a copy of the Jacobian.
const std::vector< std::string > & get_joint_names() const
Getter of the joint names attribute.
Eigen::VectorXd row(unsigned int index) const
Accessor of the row data at given index.
const Eigen::MatrixXd & data() const
Getter of the data attribute.
void set_zero()
Set the Jacobian matrix to a zero value.
Eigen::MatrixXd pseudoinverse() const
Return the pseudoinverse of the Jacobian matrix.
unsigned int cols() const
Getter of the number of columns attribute.
Eigen::MatrixXd transpose() const
Return the transpose of the Jacobian matrix.
const std::string & get_reference_frame() const
Getter of the reference frame attribute.
unsigned int rows() const
Getter of the number of rows attribute.
Eigen::MatrixXd inverse() const
Return the inverse of the Jacobian matrix.
const std::string & get_frame() const
Getter of the frame attribute.
void set_joint_names(unsigned int nb_joints)
Setter of the joint names attribute from the number of joints.
bool is_incompatible(const State &state) const override
Check if the Jacobian is incompatible for operations with the state given as argument.
void set_data(const Eigen::MatrixXd &data) override
Setter of the data attribute.
void set_reference_frame(const std::string &reference_frame)
Setter of the reference frame.
Eigen::VectorXd col(unsigned int index) const
Accessor of the column data at given index.
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.
Class to define velocities of the joints.
Abstract class to represent a state.