 |
Endorob
1.4
A C++ Robotics library by P. Berthet-Rayne
|
Go to the documentation of this file.
95 #include <Eigen/StdVector>
99 #include <Eigen/Geometry>
101 #include <Eigen/Dense>
128 #define VERBOSE_MODE 1
131 #define M_PI 3.1415926535897932384626433832795
160 typedef Eigen::MatrixXd
Mat;
165 typedef Eigen::VectorXd
Vec;
166 typedef Eigen::Quaterniond
Quat;
169 #define INF_LIM std::numeric_limits<double>::infinity()
172 typedef std::chrono::high_resolution_clock::time_point
Time_point;
174 typedef std::chrono::milliseconds
Ms;
175 typedef std::chrono::duration<double>
Delta_t;
245 bool is_almost_equal(
const double &a,
const double &b,
const double &tolerance = 1E-4);
246 bool is_geq(
const double &a,
const double &b,
const double &tolerance = 1E-4);
247 bool is_leq(
const double &a,
const double &b,
const double &tolerance = 1E-4);
389 void set_weight(
const double &weight,
const int &index = -1);
400 std::vector<Vec3d, Eigen::aligned_allocator<Vec3d>>
m_path;
404 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
457 void save_DH(std::string filename);
465 void load_DH(std::string filename);
479 void add_DH_entry(
const double &a,
const double &alpha,
const double &d,
const double &theta,
const Joint_type &type,
const double &a_bis = 0,
const double &theta_bis = 0,
const uint &flex = 0);
752 Vec follow_the_leader(
const std::vector<
Vec3d, Eigen::aligned_allocator<Vec3d>> path,
const Vec &desired_shape,
const double &translation);
891 std::vector<std::string>
split(
const std::string & s,
char delimiter,
bool remove_empty);
1044 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
1073 void set(
const uint &index1,
const uint &index2,
const uint &block1,
const uint &block2,
const Vec &val);
1092 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
1124 void load_file(
const std::string &file);
1154 std::vector<Mat, Eigen::aligned_allocator<Mat>>
m_q_data;
1155 std::vector<Mat, Eigen::aligned_allocator<Mat>>
m_T_data;
1178 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
void set_curve(const Vec &curve)
Vec3d get_Euler(const Mat &mat)
Get Euler angles.
unsigned long m_iterations
void set_solver_body_target(const Vec &vec)
Set solver's full body target (for full body control)
void threaded_solver_2(int a, int b)
bool m_apply_joint_coupling
Mat get_full_kinematics()
Get the full and complete forward kinematics as a nx4 matrix of homogeneous matrix for each link.
void set_DH_convention(const DH_type &convention)
Set DH convention: modified or standard.
void set_virt_snake_pointer(Virtual_Snake *virt_snake)
void set_flex_gradient(const Vec &vec)
Setup flex gradient for continuum robots; used if the material is not uniformely bending.
Simple pseudo-inverse approach.
Pseudo iverse with null space.
Mat4d rotate_transform_locally(const Mat4d &mat, const Mat3d &rot)
Rotate transform locally.
double rad_to_degree(const double &val)
Snake_Path m_robot_path_for_plot
void set_p0(const Vec3d &p0)
void add_DH_entry(const double &a, const double &alpha, const double &d, const double &theta, const Joint_type &type, const double &a_bis=0, const double &theta_bis=0, const uint &flex=0)
Setup robot DH table one entry at a time (Attention, modified DH convention by default)
bool m_do_not_start_solver
Vec3d get_position_error(const Mat4d &Td, const Mat4d &Te)
Mat4d get_forward_kinematics()
Get the tip pose / homogeneous matrix (forward kinematics)
void damped_least_square_method()
std::string m_file_name_write
Mat3d rot_x(const double &angle)
Get the desired rotation matrix around the X axis rotated by a desired angle:
void set_solver_weight_vec(const uint &index, const double &val)
unsigned joints()
Get robot number of joints (different to the number of DOF if coupling is used)
void set_weight(const double &weight, const int &index=-1)
For continuum or flexible joints (under development)
Rolling-joint (two circular surfaces rolling against each other, changing the contact point)
Vec follow_the_leader_3(Snake_Path path, const Vec &desired_shape, const double &translation)
void convert_fwd_k_into_vec()
unsigned get_iteration()
Get number of iterations.
volatile bool m_thread_running
void reset_q_vec()
Reset robot to startup state.
std::vector< Mat, Eigen::aligned_allocator< Mat > > m_q_data
bool is_reading_finished()
double degree_to_rad(const double &val)
bool is_geq(const double &a, const double &b, const double &tolerance=1E-4)
void set_pe(const Vec3d &pe)
Vec get_IK_solution()
Request for solver's converged solution, whether target is reached or not.
Mat4d m_global_frame_to_robot_increment
std::chrono::milliseconds Ms
void set_file_name_read(const std::string &file)
Vec zero_thresholding(const Vec &q_vec, const double &val=M_PI/180/20)
Vec follow_the_leader_2(const std::vector< Vec3d, Eigen::aligned_allocator< Vec3d >> path, const Vec &desired_shape, const double &translation)
std::string m_file_name_read
std::ofstream m_file_write
Mat mask_resize(const Mat &mat)
bool m_apply_weighted_solution
Virtual Snake Robot Class.
Mat get_Jacobian()
Get the Jacobian matrix of the robot in the current configuration.
void set_mask(const Vec &mask)
Set DOF reduction mask if your robot/instrument has less than 6 DOF. The mask is a 6x1 vector x,...
void iterative_solve_equation()
volatile bool m_start_solver
bool is_leq(const double &a, const double &b, const double &tolerance=1E-4)
std::chrono::high_resolution_clock::time_point Time_point
Vec3d sphere_line_intersection(const double &radius, const Vec3d ¢er, const Vec3d &A, const Vec3d &B)
Sphere line intersection.
uint m_instantiation_index
This is the main Class: EndoRob that you can use to control your own weird looking robot....
Mat get_coupling_matrix(void)
Get the joint coupling matrix.
Vec m_full_body_vec_desired
Vec3d project_point_onto_line(const Vec3d &P, const Vec3d &A, const Vec3d &B)
Project point P onto line defined by AB (orthogonal projection)
Vec3d get_rpy(const Mat &mat)
Get Roll Pitch and Yaw angles.
std::vector< double > m_input_timing
Full body Jacobian approach for full joint control.
bool solver_has_converged()
Vec solve_with_tentacle(Mat T_)
void set_desired_curve(const Vec &curve)
Set desired curve.
void load_DH(std::string filename)
Load DH entries from file.
void calculate_joint_LUT()
void get_full_mobile_body_error()
void set_flex_resolution(const uint &res)
Setup flex resolution for continuum robots: sampling/division into smaller revolute joints.
Mat4d get_transform_increment(const Mat4d &start, const Mat4d &goal)
Get increment between two transformation matrices (rotation and translation)
bool m_overwrite_file_period
void get_error(const Mat4d &Td, const Mat4d &Te)
static bool m_cpu_info_dispayed
Virtual_Snake follow_the_leader_weighted(Snake_Path path, const Virtual_Snake &desired_shape, const double &translation)
void load_file(const std::string &file)
Vec follow_the_leader(const std::vector< Vec3d, Eigen::aligned_allocator< Vec3d >> path, const Vec &desired_shape, const double &translation)
void calculte_dof_after_coupling()
void calculate_full_body_jacobian()
void pseudo_inverse_null_space()
Standard prismatic joint.
Vec get_weights_vector(const uint &size)
std::vector< std::string > split(const std::string &s, char delimiter, bool remove_empty)
Vec get_full_body_error()
Vec3d & operator[](uint x)
volatile bool m_wait_for_sync
double get_RMS_error()
Get the RMS per joint error between the desired and current position.
void modify_error_with_f()
void set(const uint &index1, const uint &index2, const uint &block1, const uint &block2, const Vec &val)
volatile bool m_solver_pending
void(Endorob::* p_solver_type)(void)
void set_solver_type(Solver_type solver, const double &lambda=1)
Set iterative solver type.
void set_robot_reference_frame(const Mat4d &T)
Mat3d rot_y(const double &angle)
Get the desired rotation matrix around the Y axis rotated by a desired angle:
Vec get_body_vec()
Get full-body vector.
void apply_joint_limits()
Multi-stage flexible joint with Rolling-joints (two circular surfaces rolling against each other,...
std::vector< Vec3d, Eigen::aligned_allocator< Vec3d > > m_robot_path
static uint m_file_counter
void motion_RW_loop(int a, int b)
bool is_almost_equal(const double &a, const double &b, const double &tolerance=1E-4)
void set_joint_coupling(const Vec &coupling)
Set joint coupling if multiple joint are moving together (coupled) whether for mechanical coupling or...
Mat4d base_transformation_matrix(DH_table_entry DH, double q)
bool m_iteration_overflow
Endorob()
Default constructor.
void jacobian_transpose()
std::vector< double > m_error_data
void write_once(const Virtual_Snake &curv, const Mat4d &Ttip)
void set_q_vec(const Vec &q)
Set robot's joint vector.
void set_file_name_write(const std::string &file)
Vec m_full_body_vec_current
volatile bool m_start_loop
void calculate_pseudo_inverse_masked()
volatile bool m_converged
uint get_flex_resolution()
void set_weights(const Vec &weights)
Solver_type
Currently supported solvers.
void set_write_frequency(const double &freq)
Modified DH approach (better than standard!)
std::ifstream m_file_read
double & operator()(uint x)
std::chrono::duration< double > Delta_t
void disable_fault_tolerance()
Disable joint fault tolerance.
void calculate_pseudo_inverse()
void pseudo_inverse_normal()
double get_weight(const uint &index)
void check_for_convergence()
Vec get_joint_limit_scalar()
void set_read_frequency(const double &freq)
void initialize()
Once all parameters set, initialize robot and start solver.
void threaded_solver(int a, int b)
Vec get_error_vector()
Get the current error between the desired and current position.
void calculate_full_mobile_body_jacobian()
Vec get_random_q_vec()
Get random feasible joint vector.
std::vector< Mat, Eigen::aligned_allocator< Mat > > m_T_data
std::atomic< bool > m_apply_fault_tolerance
Vec3d block(const uint &index)
void set_joint_limits(const double &min, const double &max)
Mat m_joint_coupling_matrix
void calculate_full_forward_kinematics()
unsigned dof()
Get robot number of DOF (different to the number of joints if coupling is used)
std::vector< bool > m_faulty_joint_vec
DH_type
DH two typical standards:
void calculate_coupling_matrix_increase()
std::vector< Vec > m_virtual_snake_data
static volatile bool m_assigning_CPU
void set_joint_limits(const double &min, const double &max)
Set joint limits for current joint, radians for revolute or rolling joints, meters for prismatic.
void set_solver_target(const Mat4d &T)
Set solver's target 4x4 homegenous matrix.
Vec set_vec_relative_to_base(const Vec &vec)
void benchmark_virtual_snake_file(const std::string &file)
std::vector< DH_table_entry > m_DH_table
std::ofstream m_benchmark_check_file
void set_solver_weight_mat(const uint &index, const double &val)
Set the solver's weights value for a desired joint at a specific index.
std::ofstream m_benchmark_file
void calculate_coupling_matrix_reduce()
Joint_type get_joint_type()
Vec get_q_vec()
Get joint vector.
void calculate_jacobian()
DH_table_entry(const double &a, const double &alpha, const double &d, const double &theta, const Joint_type &type)
Vec angle_modulus(const Vec &q_vec)
void load_virtual_snake_file(const std::string &file)
~Endorob()
Default destructor.
Vec3d get_orientation_error(const Mat4d &Td, const Mat4d &Te)
void set_base_frame(const Mat4d &T)
Set base frame.
Vec get_instant_IK_solution()
Request for solver's current solution,if solver is still running, the solution may not be valid.
void set_flex_gradient(const Vec &vec)
Mat m_joint_coupling_reduce_dimension
void benchmark_virtual_snake_vec(const std::vector< Vec > &virtual_vec, const std::vector< Mat4d > &Td_vec)
Mat4d invert_transform(const Mat4d &mat)
Invert homogeneous matrix for opposite transformation.
Mat3d get_rotation_increment(const Mat3d &start, const Mat3d &goal)
Get increment between two rotation matrices.
void save_DH(std::string filename)
Save DH entries to file.
std::vector< Vec3d, Eigen::aligned_allocator< Vec3d > > m_path
static Vec m_virtual_robot
void set_endorob_pointer(Endorob *robot)
Virtual_Snake * pvirt_snake
Mat4d m_robot_frame_to_global_increment
std::vector< double > m_weights
bool m_check_joint_limit_jacobian
void pseudo_inverse_simple()
std::vector< Mat4d > m_tip_data
double get_error_norm()
Get the error norm between the desired and current position.
Mat4d rotate_transform_around_axis_and_P(const Mat4d &T, const double &angle, const Vec3d &axis, const Vec &P)
Rotate transform around arbitrary axis and point.
std::chrono::high_resolution_clock chrono_time
bool check_joint_in_limit(const Vec &q)
void apply_joint_coupling()
Mat4d set_rpy(const Mat &mat, Vec3d rpy)
Set the roll pitch and yaw angles into a 4x4 homogeneous matrix.
Damped least square approach.
void calculate_pseudo_inverse_DLS()
Mat4d get_tip_pose()
Get the tip pose / homogeneous matrix (forward kinematics)
Vec get_desired_curve()
Get desired curve.
void set_tool_frame(const Mat4d &T)
Set tool frame.
Mat3d rot_z(const double &angle)
Get the desired rotation matrix around the Z axis rotated by a desired angle:
void set_offset(const double &offset)
std::vector< DH_table_entry > get_DH_table()
Get the full DH table of the robot.
Vec3d get_tip_position()
Get the tip position / 3x1 vector (forward kinematics)
void enforce_joint_limits_mode(void)
Enforce joint limit mode. In this mode the joint cannot exceed their joint limit.
Vec get_full_q_vec()
Get complete joint vector before coupling.
Vec get_vector_increment(const Vec &start, const Vec &goal)
Get increment between two vectors.
unsigned m_joint_index_offset
Joint_type
Currently supported joint types:
Mat4d rotate_transform_around_P(const Mat4d &T, const Mat3d &rot, const Vec &P)
Rotate transform around arbitrary point.
Mat3d rot_xyz(const double &angle, const Vec3d &axis)
Get the desired rotation matrix formed by the angle and axis representation.
void set_faulty_joint(const uint &joint, const double &val)
Set a joint as faulty for Jacobian Compensation.
static uint m_instantiations
void push_back(const Vec3d &point)
bool m_rolling_joint_present
void set_weight(const uint &index, const double &val)
void set_flex_resolution(const uint &res)
void null_space_constraint_calculation()