1#include "state_representation_bindings.h"
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_property_readonly_static(
"__array_priority__", [](py::object) {
return 10000; });
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);
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");
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");
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);
49 c.def(
"inverse", &
Jacobian::inverse,
"Return the inverse of the Jacobian matrix");
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");
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");
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;
65 },
"Overload the [] operator to modify the value at given (row, col)");
67 c.def(py::self * Eigen::MatrixXd());
68 c.def(py::self * py::self);
73 c.def(Eigen::MatrixXd() * py::self);
75 c.def(
"__copy__", [](
const Jacobian &jacobian) {
78 c.def(
"__deepcopy__", [](
const Jacobian &jacobian, py::dict) {
81 c.def(
"__repr__", [](
const Jacobian& jacobian) {
82 std::stringstream buffer;
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.
Jacobian copy() const
Return a copy of the JointPositions.
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.
Jacobian pseudoinverse() const
Return the pseudoinverse of the Jacobian matrix.
unsigned int cols() const
Getter of the number of columns attribute.
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...
const std::string & get_reference_frame() const
Getter of the reference_frame attribute.
unsigned int rows() const
Getter of the number of rows attribute.
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...
const std::string & get_frame() const
Getter of the frame attribute.
Jacobian inverse() const
Return the inverse of the Jacobian matrix If the matrix is not invertible, an error is thrown advisin...
void set_joint_names(unsigned int nb_joints)
Setter of the joint_names attribute from the number of joints.
void set_data(const Eigen::MatrixXd &data) override
Setter of the data attribute.
Jacobian transpose() const
Return the transpose of the Jacobian matrix.
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.