Go to the documentation of this file.00001 #ifndef OPENTISSUE_DYNAMICS_MBD_UTIL_MOTORS_MBD_LINEAR_JOINT_MOTOR_H
00002 #define OPENTISSUE_DYNAMICS_MBD_UTIL_MOTORS_MBD_LINEAR_JOINT_MOTOR_H
00003
00004
00005
00006
00007
00008
00009
00010 #include <OpenTissue/configuration.h>
00011
00012 #include <OpenTissue/dynamics/mbd/interfaces/mbd_sub_constraint_interface.h>
00013 #include <OpenTissue/core/math/math_constants.h>
00014
00015
00016 namespace OpenTissue
00017 {
00018 namespace mbd
00019 {
00020
00021 template< typename mbd_types >
00022 class LinearJointMotor
00023 : public SubConstraintInterface<mbd_types>
00024 {
00025 public:
00026
00027 typedef typename mbd_types::math_policy::real_type real_type;
00028 typedef typename mbd_types::math_policy::size_type size_type;
00029 typedef typename mbd_types::math_policy::value_traits value_traits;
00030 typedef typename mbd_types::math_policy::vector3_type vector3_type;
00031 typedef typename mbd_types::math_policy::vector_range vector_range;
00032 typedef typename mbd_types::math_policy::idx_vector_range idx_vector_range;
00033 typedef typename mbd_types::math_policy::matrix_range matrix_range;
00034
00035 protected:
00036
00037 real_type m_f_max;
00038 real_type m_v_desired;
00039 vector3_type m_s_wcs;
00040 vector3_type m_c;
00041 vector3_type m_half_cXs;
00042 size_type m_rows;
00043 real_type m_gamma;
00044 real_type m_solution;
00045
00046 public:
00047
00048 void set_maximum_force(real_type const & f_max) { m_f_max = f_max; }
00049 real_type get_maximum_force() const { return m_f_max; }
00050 void set_desired_speed(real_type const & v_desired) { m_v_desired = v_desired; }
00051 real_type get_desired_speed() const { return m_v_desired; }
00052
00053 public:
00054
00055 LinearJointMotor()
00056 : m_f_max(value_traits::zero())
00057 , m_v_desired(value_traits::zero())
00058 , m_rows(0)
00059 , m_gamma(value_traits::zero())
00060 , m_solution(value_traits::zero())
00061 {}
00062
00063 virtual ~LinearJointMotor() {}
00064
00065 public:
00066
00075 void evaluate(vector3_type const & s_wcs,vector3_type const & r_A,vector3_type const & r_B )
00076 {
00077 m_rows = 0;
00078 if(m_v_desired == OpenTissue::math::detail::lowest<real_type>() || m_v_desired == OpenTissue::math::detail::highest<real_type>() )
00079 return;
00080 if(m_f_max==0)
00081 return;
00082
00083 m_rows = 1;
00084
00085 m_s_wcs = s_wcs;
00086 m_c = r_B - r_A;
00087 m_half_cXs = cross(m_c , m_s_wcs) / value_traits::two();
00088 }
00089
00090 size_type get_number_of_jacobian_rows() const { return m_rows; }
00091
00092 void get_linear_jacobian_A(matrix_range & J,size_type const & offset)const
00093 {
00094 J(offset,0) = -m_s_wcs(0); J(offset,1) = -m_s_wcs(1); J(offset,2) = -m_s_wcs(2);
00095 }
00096
00097 void get_linear_jacobian_B(matrix_range & J,size_type const & offset)const
00098 {
00099 J(offset,0) = m_s_wcs(0); J(offset,1) = m_s_wcs(1); J(offset,2) = m_s_wcs(2);
00100 }
00101
00102 void get_angular_jacobian_A(matrix_range & J,size_type const & offset)const
00103 {
00104 J(offset,0) = m_half_cXs(0); J(offset,1) = m_half_cXs(1); J(offset,2) = m_half_cXs(2);
00105 }
00106
00107 void get_angular_jacobian_B(matrix_range & J,size_type const & offset)const
00108 {
00109 J(offset,0) = -m_half_cXs(0); J(offset,1) = -m_half_cXs(1); J(offset,2) = -m_half_cXs(2);
00110 }
00111
00112 void get_stabilization_term(vector_range & b_error,size_type const & offset) const
00113 {
00114 b_error(offset) = m_v_desired;
00115 }
00116
00117 void get_low_limits(vector_range & lo,size_type const & offset) const
00118 {
00119 lo(offset) = -m_f_max/this->get_frames_per_second();
00120 }
00121
00122 void get_high_limits(vector_range & hi,size_type const & offset)const
00123 {
00124 hi(offset) = m_f_max/this->get_frames_per_second();
00125 }
00126
00127 void get_dependency_indices(idx_vector_range & dep,size_type const & offset) const
00128 {
00129 dep(offset) = OpenTissue::math::detail::highest<size_type>();
00130 }
00131
00132 void get_dependency_factors(vector_range & factors,size_type const & offset) const
00133 {
00134 factors(offset) = value_traits::zero();
00135 }
00136
00137 void set_regularization(vector_range const & gamma,size_type const & offset)
00138 {
00139 m_gamma = gamma(offset);
00140 }
00141
00142 void get_regularization(vector_range & gamma,size_type const & offset) const
00143 {
00144 gamma(offset) = m_gamma;
00145 }
00146
00147 void set_solution(vector_range const & solution,size_type const & offset)
00148 {
00149 m_solution = solution(offset);
00150 }
00151
00152 void get_solution(vector_range & solution,size_type const & offset) const
00153 {
00154 solution(offset) = m_solution;
00155 }
00156
00157 };
00158
00159 }
00160 }
00161 #endif // OPENTISSUE_DYNAMICS_MBD_UTIL_MOTORS_MBD_LINEAR_JOINT_MOTOR_H