ctrl-utils
|
Classes | |
class | Args |
class | Atomic |
class | AtomicQueue |
class | AtomicBuffer |
struct | ExpMapJacobianReturnType |
struct | ExpMapJacobianReturnType< 1 > |
class | RedisClient |
class | ThreadPool |
class | Timer |
class | Tree |
Functions | |
PYBIND11_MODULE (ctrlutils, m) | |
template<typename Derived > | |
std::optional< Derived > | ParseArgs (int argc, char *argv[]) |
std::ostream & | operator<< (std::ostream &os, const Args &args) |
template<typename Derived1 , typename Derived2 , typename Derived3 , typename Derived5 > | |
Derived1::PlainObject | PdControl (const ::Eigen::MatrixBase< Derived1 > &x, const ::Eigen::MatrixBase< Derived2 > &x_des, const ::Eigen::MatrixBase< Derived3 > &dx, const ::Eigen::MatrixBase< Derived5 > &kp_kv, double ddx_max=0., typename Derived1::PlainObject *x_err_out=nullptr) |
template<typename Derived1 , typename Derived2 , typename Derived3 , typename Derived4 , typename Derived5 > | |
Derived1::PlainObject | PdControl (const ::Eigen::MatrixBase< Derived1 > &x, const ::Eigen::MatrixBase< Derived2 > &x_des, const ::Eigen::MatrixBase< Derived3 > &dx, const ::Eigen::MatrixBase< Derived4 > &dx_des, const ::Eigen::MatrixBase< Derived5 > &kp_kv, double ddx_max=0., typename Derived1::PlainObject *x_err_out=nullptr, typename Derived3::PlainObject *dx_err_out=nullptr) |
template<typename Derived1 , typename Derived3 > | |
Derived1::PlainObject | PdControl (const ::Eigen::Quaterniond &quat, const ::Eigen::Quaterniond &quat_des, const ::Eigen::MatrixBase< Derived1 > &w, const ::Eigen::MatrixBase< Derived3 > &kp_kv, double dw_max=0., typename Derived1::PlainObject *ori_err_out=nullptr) |
template<typename Derived1 , typename Derived2 , typename Derived3 > | |
Derived1::PlainObject | PdControl (const ::Eigen::Quaterniond &quat, const ::Eigen::Quaterniond &quat_des, const ::Eigen::MatrixBase< Derived1 > &w, const ::Eigen::MatrixBase< Derived2 > &w_des, const ::Eigen::MatrixBase< Derived3 > &kp_kv, double dw_max=0., typename Derived1::PlainObject *ori_err_out=nullptr, typename Derived2::PlainObject *w_err_out=nullptr) |
template<typename Derived1 , typename Derived2 , typename Derived3 , typename Derived4 > | |
Derived1::PlainObject | LookatPdControl (const ::Eigen::MatrixBase< Derived1 > &vec, const ::Eigen::MatrixBase< Derived2 > &vec_des, const ::Eigen::MatrixBase< Derived3 > &w, const ::Eigen::MatrixBase< Derived4 > &kp_kv, double dw_max=0., typename Derived1::PlainObject *ori_err_out=nullptr) |
template<typename Derived > | |
Eigen::MatrixBase< Derived >::PlainObject | PseudoInverse (const Eigen::MatrixBase< Derived > &A, double svd_epsilon=0, bool *is_singular=nullptr) |
double | Cross (Eigen::Ref< const Eigen::Vector2d > a, Eigen::Ref< const Eigen::Vector2d > b) |
template<typename Scalar > | |
Eigen::Matrix< Scalar, 3, 3 > | RotationX (Scalar angle) |
template<typename Scalar > | |
Eigen::Matrix< Scalar, 3, 3 > | RotationY (Scalar angle) |
template<typename Scalar > | |
Eigen::Matrix< Scalar, 3, 3 > | RotationZ (Scalar angle) |
template<typename Derived > | |
Eigen::Matrix< typename Derived::Scalar, 3, 3 > | CrossMatrix (const Eigen::DenseBase< Derived > &x) |
template<typename Derived > | |
Eigen::Matrix< typename Derived::Scalar, 3, 3 > | DoubleCrossMatrix (const Eigen::DenseBase< Derived > &x) |
template<typename Derived > | |
Eigen::Matrix< typename Derived::Scalar, 4, 4 > | LeftProductMatrix (const Eigen::QuaternionBase< Derived > &quat) |
template<typename Derived > | |
Eigen::Matrix< typename Derived::Scalar, 4, 4 > | RightProductMatrix (const Eigen::QuaternionBase< Derived > &quat) |
template<typename Derived1 , typename Derived2 > | |
Eigen::MatrixBase< Derived1 >::PlainObject | Projection (const Eigen::MatrixBase< Derived1 > &v1, const Eigen::MatrixBase< Derived2 > &v2) |
template<typename Derived1 , typename Derived2 > | |
Eigen::MatrixBase< Derived1 >::PlainObject | OrthogonalProjection (const Eigen::MatrixBase< Derived1 > &v1, const Eigen::MatrixBase< Derived2 > &v2) |
template<typename Derived > | |
bool | IsNan (const Eigen::ArrayBase< Derived > &a) |
template<typename Derived > | |
bool | IsNan (const Eigen::MatrixBase< Derived > &m) |
template<typename Derived > | |
bool | IsNan (const Eigen::QuaternionBase< Derived > &q) |
template<typename Derived > | |
Derived | DecodeMatlab (const std::string &str) |
template<typename Derived > | |
std::string | EncodeMatlab (const Eigen::DenseBase< Derived > &matrix) |
template<typename Derived > | |
Derived | DecodeJson (const std::string &str) |
template<typename Derived > | |
std::string | EncodeJson (const Eigen::DenseBase< Derived > &matrix) |
Eigen::Vector3d | OrientationError (const Eigen::Quaterniond &quat, const Eigen::Quaterniond &quat_des) |
Eigen::Vector3d | LookatError (const Eigen::Vector3d &vec, const Eigen::Vector3d &vec_des) |
Eigen::Quaterniond | NearQuaternion (const Eigen::Quaterniond &quat, const Eigen::Quaterniond &quat_reference) |
Eigen::Quaterniond | NearQuaternion (Eigen::Ref< const Eigen::Matrix3d > ori, const Eigen::Quaterniond &quat_reference) |
Eigen::Quaterniond | FarQuaternion (const Eigen::Quaterniond &quat, const Eigen::Quaterniond &quat_reference) |
Eigen::Quaterniond | FarQuaternion (const Eigen::Ref< const Eigen::Matrix3d > ori, const Eigen::Quaterniond &quat_reference) |
template<typename Derived > | |
Eigen::Vector3d | Log (const Eigen::RotationBase< Derived, 3 > &ori) |
Eigen::Matrix3d | Exp (const Eigen::Vector3d &w) |
Eigen::Matrix3d | ExpMapDerivative (const Eigen::AngleAxisd &aa) |
Eigen::Matrix3d | LogMapDerivative (const Eigen::AngleAxisd &aa) |
template<typename Derived > | |
ExpMapJacobianReturnType< Eigen::MatrixBase< Derived >::ColsAtCompileTime >::type | ExpMapJacobian (const Eigen::AngleAxisd &aa, const Eigen::MatrixBase< Derived > &X) |
ExpMapJacobianReturnType< 3 >::type | ExpMapJacobian (const Eigen::AngleAxisd &aa) |
Eigen::Vector6d | Log (const Eigen::Isometry3d &T) |
Eigen::Matrix6d | ExpMapDerivative (const Eigen::Isometry3d &T) |
Eigen::Matrix6d | LogMapDerivative (const Eigen::Isometry3d &T) |
Eigen::Matrix< double, 9, 3 > | LogMapHessian (const Eigen::AngleAxisd &aa) |
template<int Cols> | |
ExpMapJacobianReturnType< Cols >::type | ExpCoordsJacobianImpl (const Eigen::Matrix3d &R, const Eigen::AngleAxisd &aa, const Eigen::Matrix< double, 3, Cols > &X) |
template<> | |
Eigen::Matrix3d | ExpCoordsJacobianImpl< 1 > (const Eigen::Matrix3d &R, const Eigen::AngleAxisd &aa, const Eigen::Vector3d &p) |
template<> | |
Eigen::Matrix< double, 9, 3 > | ExpCoordsJacobianImpl< 3 > (const Eigen::Matrix3d &R, const Eigen::AngleAxisd &aa, const Eigen::Matrix3d &I) |
template<typename Derived > | |
ExpMapJacobianReturnType< Eigen::MatrixBase< Derived >::ColsAtCompileTime >::type | ExpMapJacobianOld (const Eigen::AngleAxisd &aa, const Eigen::MatrixBase< Derived > &X) |
ExpMapJacobianReturnType< 3 >::type | ExpMapJacobianOld (const Eigen::AngleAxisd &aa) |
Eigen::Matrix3d | ExpMapDerivativeCrossTerm (const Eigen::AngleAxisd &aa, Eigen::Ref< const Eigen::Vector3d > x) |
template<> | |
std::string | ToString (const nlohmann::json &value) |
template<> | |
nlohmann::json | FromString (const std::string &str) |
template<typename T > | |
T | Signum (T x, T epsilon=T(0)) |
template<typename T > | |
T | Clip (T x, T max) |
template<typename T > | |
T | Power (T x, size_t exp) |
template<> | |
void | FromString (const std::string &str, cv::Mat &image) |
std::string | ToString (const cv::Mat &image) |
template<typename T > | |
std::string | ToString (const T &value) |
template<> | |
std::string | ToString (const std::string &value) |
template<typename T > | |
void | ToString (std::string &str, const T &value) |
template<typename T > | |
void | FromString (const std::string &str, T &value) |
template<> | |
void | FromString (const std::string &str, std::string &value) |
std::ostream & | bold (std::ostream &os) |
std::ostream & | underline (std::ostream &os) |
std::ostream & | bold_underline (std::ostream &os) |
std::ostream & | normal (std::ostream &os) |
eigen.cc
Copyright 2018. All Rights Reserved.
Created: September 8, 2018 Authors: Toki Migimatsu
Copyright 2021. All Rights Reserved.
Created: May 27, 2021 Authors: Toki Migimatsu
Copyright 2019. All Rights Reserved.
Created: August 10, 2019 Authors: Toki Migimatsu
Copyright 2018. All Rights Reserved.
Created: November 18, 2018 Authors: Toki Migimatsu
Copyright 2019. All Rights Reserved.
Created: February 07, 2019 Authors: Toki Migimatsu
Copyright 2018. All Rights Reserved.
Created: July 1, 2018 Authors: Toki Migimatsu
Copyright 2019. All Rights Reserved.
Created: May 16, 2019 Authors: Toki Migimatsu
Copyright 2019. All Rights Reserved.
Created: January 31, 2019 Authors: Toki Migimatsu
Copyright 2018. All Rights Reserved.
Created: October 7, 2018 Authors: Toki Migimatsu
Copyright 2019. All Rights Reserved.
Created: May 9, 2019 Authors: Toki Migimatsu
Copyright 2018. All Rights Reserved.
Created: July 1, 2018 Authors: Toki Migimatsu
Copyright 2019. All Rights Reserved.
Created: January 22, 2019 Authors: Toki Migimatsu
Copyright 2021. All Rights Reserved.
Created: May 25, 2021 Authors: Toki Migimatsu
Copyright 2018. All Rights Reserved.
Created: July 2, 2018 Authors: Toki Migimatsu
Copyright 2018. All Rights Reserved.
Created: November 12, 2018 Authors: Toki Migimatsu
Copyright 2019. All Rights Reserved.
Created: February 27, 2019 Authors: Toki Migimatsu
Derived ctrl_utils::DecodeJson | ( | const std::string & | str | ) |
Decode an Eigen matrix from Json format:
Usage: Eigen::Vector3d x = DecodeJson<Eigen::Vector3d>("[1, 2, 3]"); Eigen::MatrixXd A = DecodeJson<Eigen::MatrixXd>("[[1, 2, 3], [4, 5, 6]]");
Derived ctrl_utils::DecodeMatlab | ( | const std::string & | str | ) |
Decode an Eigen matrix from Matlab format:
Usage: Eigen::Vector3d x = DecodeMatlab<Eigen::Vector3d>("1 2 3"); Eigen::MatrixXd A = DecodeMatlab<Eigen::MatrixXd>("1 2 3; 4 5 6");
std::string ctrl_utils::EncodeJson | ( | const Eigen::DenseBase< Derived > & | matrix | ) |
Encode an Eigen matrix to Json format:
Usage: std::string x = EncodeMatlab(Eigen::Vector3d(1, 2, 3)); // "[1, 2, 3]" std::string A = EncodeMatlab(Eigen::Matrix2d(1, 2, 3, 4)); // "[[1, 2], [3, 4]]"
std::string ctrl_utils::EncodeMatlab | ( | const Eigen::DenseBase< Derived > & | matrix | ) |
Encode an Eigen matrix to Matlab format:
Usage: std::string x = EncodeMatlab(Eigen::Vector3d(1, 2, 3)); // "1 2 3" std::string A = EncodeMatlab(Eigen::Matrix2d(1, 2, 3, 4)); // "1 2; 3 4"
|
inline |
d/dx exp(x) = d/de|e=0 log(f(x+e) f(x)^{-1})
|
inline |
Compute the Jacobian of a rotated matrix R * X with respect to the rotation's exponential coordinates (angle axis representation).
If X is a vector, the Jacobian returned is d(Rx)/dw. If X is a matrix, the Jacobian tensor is stacked into a matrix [d(RX)/dw_x; d(RX)/dw_y; d(RX)/dw_z].
d/dx exp(x) p = d/dexp(x) exp(x) p * d/dx exp(x) d/dx exp(x) p = d/dk (I + ad_k) Rp * d/de log(f(x+e) f(-x)) = d/dk Rp + [k]x Rp = d/dk Rp - [Rp]x k = -[Rp]x d/dx exp(x) p = d/dexp(x) Ad_exp(x) p * d/dx exp(x) = d/dexp(x) exp(ad_x) p * d/dx exp(x)
|
inline |
Computes the quaternion for the given orientation that is farther from the reference quaternion.
quat | Quaternion representing the desired orientation. |
quat_ref | Reference quaternion. |
quat
but has a negative dot product with quat_ref
.
|
inline |
Computes the quaternion for the given orientation that is farther from the reference quaternion.
ori | 3D matrix representing the desired orientation. |
quat_ref | Reference quaternion. |
ori
but has a negative dot product with quat_ref
.
|
inline |
Converts the string to a value using stringstream.
|
inline |
Decode a cv::Mat from a string for Redis.
Format: "nrows ncols cvtype bytedata"
|
inline |
Template specialization for strings.
|
inline |
Converts the string to a value using stringstream.
|
inline |
Computes the orientation error between two lookat vectors.
Unlike ctrl_utils::OrientationError()
, this error ignores rotations about the lookat vectors, producing the shortest rotation between the two.
quat | Current orientation. |
quat_des | Desired orientation. |
|
inline |
Computes the quaternion for the given orientation that is closer to the reference quaternion.
Each 3D orientation can be represented by two quaternions, where one quaternion has the same 4 elements as the other but negated. Of these two quaternions, the one that is "closer" to the reference is the one that has a positive dot product with the reference.
This function may be used in orientation control, where quat
is the goal orientation, and quat_reference
is the current orientation of the controlled body. The effect of controlling the body to the closer quaternion is that it will rotate the shortest way to the goal orientation. Using the farther quarternion will cause it to rotate the long way around, which may be desired to avoid singularities, for example.
quat | Quaternion representing the desired orientation. |
quat_ref | Reference quaternion. |
quat
but has a positive dot product with quat_ref
.
|
inline |
Computes the quaternion for the given orientation that is closer to the reference quaternion.
ori | 3D matrix representing the desired orientation. |
quat_ref | Reference quaternion. |
ori
but has a positive dot product with quat_ref
.
|
inline |
Prints the parsed fields of the Args object.
|
inline |
Computes the quaternion error between the given orientations.
This quaternion error is equivalent to the angular velocity required to go from quat_des
to quat
in one second. Following this angular velocity also produces the SLERP interpolation between the two orientations.
For orientation control, a control law might look like the following:
quat | Current orientation. |
quat_des | Desired orientation. |
std::optional< Derived > ctrl_utils::ParseArgs | ( | int | argc, |
char * | argv[] | ||
) |
Parses the arguments.
Example:
|
inline |
General PD control law for reaching a goal position with velocity damping.
Outputs a desired acceleration given a desired position, as well as the current position and velocity. This behaves like a damped spring-mass system.
Control law: ddx = -kp (x - x_des) - kv dx
x | Current position as an N-D vector. |
x_des | Desired position as an N-D vector. |
dx | Current velocity as an N-D vector. |
kp_kv | Gains matrix as a 2D vector [kp, kv] or an N x 2 matrix, where the first and second columns correspond to kp and kv, respectively, and the N rows represent per-dimension gains. |
ddx_max | Optional maximum acceleration due to the position error. This value clips the acceleration when the distance to the goal is large and is ignored when less than or equal to 0. |
x_err_out | Optional output of the position error. |
|
inline |
Special PD control law for 3D orientations.
Outputs a desired acceleration given a desired orientation, as well as the current orientation and angular velocity. This behaves like a damped spring-mass system.
Control law: dw = -kp (quat - quat_des) - kv w
quat | Current orientation as a quaternion. |
quat_des | Desired orientation as a quaternion. |
w | Current angular velocity as a 4D vector. |
kp_kv | Gains matrix as a 2D vector [kp, kv] or a 3 x 2 matrix, where the first and second columns correspond to kp and kv, respectively, and the 3 rows represent per-dimension (x, y, z) gains. |
dw_max | Optional maximum acceleration due to the orientation error. This value clips the acceleration when the distance to the goal is large and is ignored when less than or equal to 0. |
ori_err_out | Optional output of the orientation error. |
|
inline |
Encode a cv::Mat into a string for Redis.
Format: "nrows ncols cvtype bytedata"
|
inline |
Template specialization for strings.
|
inline |
Converts the value to a string using stringstream.
|
inline |
Converts the value to a preallocated string.