libxr  1.0
Want to be the best embedded framework
Loading...
Searching...
No Matches
LibXR::Kinematic::EndPoint< Scalar > Class Template Reference

机器人末端点(EndPoint)类,继承自 Object。 EndPoint class representing the end effector of a robotic system, inheriting from Object. More...

#include <kinematic.hpp>

Inheritance diagram for LibXR::Kinematic::EndPoint< Scalar >:
[legend]
Collaboration diagram for LibXR::Kinematic::EndPoint< Scalar >:
[legend]

Public Member Functions

 EndPoint (Inertia< Scalar > &inertia)
 构造 EndPoint 末端点对象。 Constructs an EndPoint object.
 
void SetTargetQuaternion (const Quaternion< Scalar > &quat)
 设置目标四元数方向。 Sets the target quaternion orientation.
 
void SetTargetPosition (const Position< Scalar > &pos)
 设置目标位置。 Sets the target position.
 
void SetErrorWeight (const Eigen::Matrix< Scalar, 6, 1 > &weight)
 设置误差权重矩阵。 Sets the error weight matrix.
 
void SetMaxAngularVelocity (Scalar velocity)
 设置最大角速度。 Sets the maximum angular velocity.
 
Eigen::Matrix< Scalar, 3, 1 > GetPositionError ()
 获取末端点位置误差。 Gets the position error of the end effector.
 
Eigen::Quaternion< Scalar > GetQuaternionError ()
 获取末端点方向误差。 Gets the orientation error of the end effector.
 
void SetMaxLineVelocity (Scalar velocity)
 设置最大线速度。 Sets the maximum linear velocity.
 
Eigen::Matrix< Scalar, 6, 1 > CalcBackward (Scalar dt, int max_step=10, Scalar max_err=1e-3, Scalar step_size=1.0)
 计算逆运动学(IK),调整关节角度以达到目标位置和方向。 Computes inverse kinematics (IK) to adjust joint angles for reaching the target position and orientation.
 
- Public Member Functions inherited from LibXR::Kinematic::Object< Scalar >
 Object (Inertia< Scalar > &inertia)
 使用惯性参数构造 Object 对象。 Constructs an Object using inertia parameters.
 
void SetPosition (const Position< Scalar > &pos)
 设置物体的位置信息。 Sets the position of the object.
 
void SetQuaternion (const Quaternion< Scalar > &quat)
 设置物体的旋转信息(四元数表示)。 Sets the rotation of the object using a quaternion.
 
virtual void CalcBackward ()
 

Private Attributes

Eigen::Matrix< Scalar, 6, Eigen::Dynamic > * jacobian_matrix_
 
Eigen::Matrix< Scalar, Eigen::Dynamic, 1 > * delta_theta_
 关节角度调整量。 Joint angle adjustments.
 
Eigen::Matrix< Scalar, 6, 1 > err_weight_
 误差权重矩阵。 Error weight matrix.
 
int joint_num_ = 0
 
Quaternion< Scalar > target_quat_
 目标四元数方向。 Target quaternion orientation.
 
Position< Scalar > target_pos_
 目标位置。 Target position.
 
Scalar max_angular_velocity_
 
Scalar max_line_velocity_ = -1.0
 

Additional Inherited Members

- Public Types inherited from LibXR::Kinematic::Object< Scalar >
typedef List::Node< Joint< Scalar > * > Link
 关节链接类型。 Type for linking joints.
 
- Data Fields inherited from LibXR::Kinematic::Object< Scalar >
List joints
 物体的关节列表。 List of joints associated with the object.
 
Joint< Scalar > * parent = nullptr
 指向父关节的指针。 Pointer to the parent joint.
 
Param param_
 物体参数。 Object parameters.
 
Runtime runtime_
 物体运行时状态。 Object runtime data.
 

Detailed Description

template<typename Scalar>
class LibXR::Kinematic::EndPoint< Scalar >

机器人末端点(EndPoint)类,继承自 Object。 EndPoint class representing the end effector of a robotic system, inheriting from Object.

该类用于处理机器人末端的目标位置与方向, 并计算逆运动学(IK)以调整关节角度,使末端达到期望位置。 This class handles the target position and orientation of the robot's end effector and computes inverse kinematics (IK) to adjust joint angles to reach the desired position.

Template Parameters
Scalar角度和位置的存储类型。 The storage type for angles and positions.

Definition at line 267 of file kinematic.hpp.

Constructor & Destructor Documentation

◆ EndPoint()

template<typename Scalar >
LibXR::Kinematic::EndPoint< Scalar >::EndPoint ( Inertia< Scalar > & inertia)
inline

构造 EndPoint 末端点对象。 Constructs an EndPoint object.

Parameters
inertia物体的惯性参数。 The inertia parameters of the object.

Definition at line 295 of file kinematic.hpp.

295: Object<Scalar>(inertia) {}
Object(Inertia< Scalar > &inertia)
使用惯性参数构造 Object 对象。 Constructs an Object using inertia parameters.

Member Function Documentation

◆ CalcBackward()

template<typename Scalar >
Eigen::Matrix< Scalar, 6, 1 > LibXR::Kinematic::EndPoint< Scalar >::CalcBackward ( Scalar dt,
int max_step = 10,
Scalar max_err = 1e-3,
Scalar step_size = 1.0 )
inline

计算逆运动学(IK),调整关节角度以达到目标位置和方向。 Computes inverse kinematics (IK) to adjust joint angles for reaching the target position and orientation.

该函数采用雅可比矩阵求解最优关节角度调整量,并进行迭代优化。 This function uses the Jacobian matrix to compute optimal joint angle adjustments and performs iterative optimization.

Parameters
dt时间步长。 Time step.
max_step最大迭代步数。 Maximum number of iterations.
max_err允许的最大误差。 Maximum allowable error.
step_size逆运动学步长。 Step size for inverse kinematics.
Returns
计算后的误差向量。 The computed error vector.

Definition at line 393 of file kinematic.hpp.

395 {
396 Eigen::Matrix<Scalar, 6, 1> error;
397
398 /* Initialize */
399 if (jacobian_matrix_ == nullptr)
400 {
401 Object<Scalar> *tmp = this;
402 for (int i = 0;; i++)
403 {
404 if (tmp->parent == nullptr)
405 {
406 joint_num_ = i;
407 break;
408 }
409 tmp = tmp->parent->parent;
410 }
411
412 jacobian_matrix_ = new Eigen::Matrix<Scalar, 6, Eigen::Dynamic>(6, joint_num_);
413
414 delta_theta_ = new Eigen::Matrix<Scalar, Eigen::Dynamic, 1>(joint_num_);
415 }
416
417 /* Apply Limition */
418 Position<Scalar> target_pos = target_pos_;
419 Quaternion<Scalar> target_quat = target_quat_;
421 {
422 Scalar max_pos_delta = max_angular_velocity_ * dt;
423 Scalar max_angle_delta = max_line_velocity_ * dt;
424
425 Position<Scalar> pos_err =
426 Position<Scalar>(target_pos_ - this->runtime_.target.translation);
427 Eigen::AngleAxis<Scalar> angle_err(
428 Quaternion<Scalar>(target_quat_ / this->runtime_.target.rotation));
429
430 Scalar pos_err_norm = pos_err.norm();
431
432 if (pos_err_norm > max_pos_delta)
433 {
434 pos_err = (max_pos_delta / pos_err_norm) * pos_err;
435 target_pos = this->runtime_.target.translation + pos_err;
436 }
437 else
438 {
439 target_pos = target_pos_;
440 }
441
442 if (angle_err.angle() > max_angle_delta)
443 {
444 angle_err.angle() = max_angle_delta;
445 target_quat = this->runtime_.target.rotation * angle_err;
446 }
447 else
448 {
449 target_quat = target_quat_;
450 }
451 }
452
453 for (int step = 0; step < max_step; ++step)
454 {
455 /* Calculate Error */
456 error.template head<3>() = target_pos - this->runtime_.target.translation;
457 error.template tail<3>() =
458 (Eigen::Quaternion<Scalar>(this->runtime_.target.rotation).conjugate() *
459 target_quat)
460 .vec();
461
462 error = err_weight_.array() * error.array();
463
464 auto err_norm = error.norm();
465
466 if (err_norm < max_err)
467 {
468 break;
469 }
470
471 /* Calculate Jacobian */
472 do
473 {
474 Joint<Scalar> *joint = this->parent;
475 for (int joint_index = 0; joint_index < joint_num_; joint_index++)
476 {
477 /* J = [translation[3], rotation[3]] */
478 Eigen::Matrix<Scalar, 6, 1> d_transform;
479 d_transform.template head<3>() = joint->runtime_.target_axis.cross(
480 this->runtime_.target.translation - joint->runtime_.target.translation);
481
482 d_transform.template tail<3>() = joint->runtime_.target_axis;
483
484 jacobian_matrix_->col(joint_index) = d_transform;
485
486 joint = joint->parent->parent;
487 }
488 } while (0);
489
490 /* Calculate delta_theta: delta_theta = J^+ * error */
491 *delta_theta_ =
492 jacobian_matrix_->completeOrthogonalDecomposition().pseudoInverse() * error *
493 step_size / std::sqrt(err_norm);
494
495 /* Update Joint Angle */
496 do
497 {
498 Joint<Scalar> *joint = this->parent;
499
500 for (int joint_index = 0; joint_index < joint_num_; joint_index++)
501 {
502 Eigen::AngleAxis<Scalar> target_angle_axis_delta((*delta_theta_)(joint_index),
503 joint->runtime_.target_axis);
504
505 target_angle_axis_delta =
506 Quaternion<Scalar>(Eigen::Quaternion<Scalar>(target_angle_axis_delta)) /
507 joint->runtime_.target.rotation;
508
509 joint->SetTarget(joint->runtime_.target_angle.angle() +
510 (*delta_theta_)(joint_index)*joint->param_.ik_mult);
511
512 joint = joint->parent->parent;
513 }
514 } while (0);
515
516 /* Recalculate Forward Kinematics */
517 do
518 {
519 Joint<Scalar> *joint = this->parent;
520
521 for (int joint_index = 0; joint_index < joint_num_; joint_index++)
522 {
523 if (joint_index == joint_num_ - 1)
524 {
525 auto start_point = reinterpret_cast<StartPoint<Scalar> *>(joint->parent);
526 start_point->CalcTargetForward();
527 break;
528 }
529
530 joint = joint->parent->parent;
531 }
532 } while (0);
533 }
534
535 return error;
536 }
Eigen::Matrix< Scalar, 6, 1 > err_weight_
误差权重矩阵。 Error weight matrix.
Quaternion< Scalar > target_quat_
目标四元数方向。 Target quaternion orientation.
Eigen::Matrix< Scalar, 6, Eigen::Dynamic > * jacobian_matrix_
Eigen::Matrix< Scalar, Eigen::Dynamic, 1 > * delta_theta_
关节角度调整量。 Joint angle adjustments.
Position< Scalar > target_pos_
目标位置。 Target position.
Runtime runtime_
物体运行时状态。 Object runtime data.
Joint< Scalar > * parent
指向父关节的指针。 Pointer to the parent joint.
Quaternion< Scalar > rotation
Position< Scalar > translation
Transform< Scalar > target
物体的目标状态变换矩阵。 Transformation matrix of the target state.

◆ GetPositionError()

template<typename Scalar >
Eigen::Matrix< Scalar, 3, 1 > LibXR::Kinematic::EndPoint< Scalar >::GetPositionError ( )
inline

获取末端点位置误差。 Gets the position error of the end effector.

该误差表示当前状态与目标位置之间的差值。 This error represents the difference between the current state and the target position.

Returns
位置误差向量。 The position error vector.

Definition at line 347 of file kinematic.hpp.

◆ GetQuaternionError()

template<typename Scalar >
Eigen::Quaternion< Scalar > LibXR::Kinematic::EndPoint< Scalar >::GetQuaternionError ( )
inline

获取末端点方向误差。 Gets the orientation error of the end effector.

计算当前方向和目标方向的四元数误差。 Computes the quaternion error between the current and target orientations.

Returns
方向误差的四元数。 The quaternion representing the orientation error.

Definition at line 361 of file kinematic.hpp.

◆ SetErrorWeight()

template<typename Scalar >
void LibXR::Kinematic::EndPoint< Scalar >::SetErrorWeight ( const Eigen::Matrix< Scalar, 6, 1 > & weight)
inline

设置误差权重矩阵。 Sets the error weight matrix.

该矩阵用于调整不同方向上的误差贡献权重。 This matrix is used to adjust the contribution weights of errors in different directions.

Parameters
weight误差权重矩阵。 The error weight matrix.

Definition at line 323 of file kinematic.hpp.

323{ err_weight_ = weight; }

◆ SetMaxAngularVelocity()

template<typename Scalar >
void LibXR::Kinematic::EndPoint< Scalar >::SetMaxAngularVelocity ( Scalar velocity)
inline

设置最大角速度。 Sets the maximum angular velocity.

该函数用于限制末端点旋转变化的速率。 This function limits the rate of rotational changes at the end effector.

Parameters
velocity角速度上限(负值表示无限制)。 The maximum angular velocity (negative value means no limit).

Definition at line 335 of file kinematic.hpp.

335{ max_angular_velocity_ = velocity; }

◆ SetMaxLineVelocity()

template<typename Scalar >
void LibXR::Kinematic::EndPoint< Scalar >::SetMaxLineVelocity ( Scalar velocity)
inline

设置最大线速度。 Sets the maximum linear velocity.

该函数用于限制末端点线性移动的速率。 This function limits the rate of linear movement at the end effector.

Parameters
velocity线速度上限(负值表示无限制)。 The maximum linear velocity (negative value means no limit).

Definition at line 376 of file kinematic.hpp.

376{ max_line_velocity_ = velocity; }

◆ SetTargetPosition()

template<typename Scalar >
void LibXR::Kinematic::EndPoint< Scalar >::SetTargetPosition ( const Position< Scalar > & pos)
inline

设置目标位置。 Sets the target position.

Parameters
pos目标位置。 The target position.

Definition at line 311 of file kinematic.hpp.

311{ target_pos_ = pos; }

◆ SetTargetQuaternion()

template<typename Scalar >
void LibXR::Kinematic::EndPoint< Scalar >::SetTargetQuaternion ( const Quaternion< Scalar > & quat)
inline

设置目标四元数方向。 Sets the target quaternion orientation.

Parameters
quat目标四元数。 The target quaternion.

Definition at line 303 of file kinematic.hpp.

303{ target_quat_ = quat; }

Field Documentation

◆ delta_theta_

template<typename Scalar >
Eigen::Matrix<Scalar, Eigen::Dynamic, 1>* LibXR::Kinematic::EndPoint< Scalar >::delta_theta_
private
Initial value:
=
nullptr

关节角度调整量。 Joint angle adjustments.

Definition at line 273 of file kinematic.hpp.

◆ err_weight_

template<typename Scalar >
Eigen::Matrix<Scalar, 6, 1> LibXR::Kinematic::EndPoint< Scalar >::err_weight_
private
Initial value:
=
Eigen::Matrix<Scalar, 6, 1>::Constant(1)

误差权重矩阵。 Error weight matrix.

Definition at line 275 of file kinematic.hpp.

◆ jacobian_matrix_

template<typename Scalar >
Eigen::Matrix<Scalar, 6, Eigen::Dynamic>* LibXR::Kinematic::EndPoint< Scalar >::jacobian_matrix_
private
Initial value:
=
nullptr

雅可比矩阵,用于逆运动学计算。 Jacobian matrix for inverse kinematics calculations.

Definition at line 270 of file kinematic.hpp.

◆ joint_num_

template<typename Scalar >
int LibXR::Kinematic::EndPoint< Scalar >::joint_num_ = 0
private

机器人末端至基座的关节数量。 Number of joints from the end effector to the base.

Definition at line 277 of file kinematic.hpp.

◆ max_angular_velocity_

template<typename Scalar >
Scalar LibXR::Kinematic::EndPoint< Scalar >::max_angular_velocity_
private
Initial value:
=
-1.0

最大角速度(若小于 0 则无约束)。 Maximum angular velocity (negative value means no limit).

Definition at line 282 of file kinematic.hpp.

◆ max_line_velocity_

template<typename Scalar >
Scalar LibXR::Kinematic::EndPoint< Scalar >::max_line_velocity_ = -1.0
private

最大线速度(若小于 0 则无约束)。 Maximum linear velocity (negative value means no limit).

Definition at line 285 of file kinematic.hpp.

◆ target_pos_

template<typename Scalar >
Position<Scalar> LibXR::Kinematic::EndPoint< Scalar >::target_pos_
private

目标位置。 Target position.

Definition at line 281 of file kinematic.hpp.

◆ target_quat_

template<typename Scalar >
Quaternion<Scalar> LibXR::Kinematic::EndPoint< Scalar >::target_quat_
private

目标四元数方向。 Target quaternion orientation.

Definition at line 280 of file kinematic.hpp.


The documentation for this class was generated from the following file: