Go to the documentation of this file.00001 #ifndef OPENTISSUE_DYNAMICS_MBD_UTIL_MOTORS_MBD_ANGULAR_JOINT_MOTOR_H
00002 #define OPENTISSUE_DYNAMICS_MBD_UTIL_MOTORS_MBD_ANGULAR_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 AngularJointMotor
00023 : public SubConstraintInterface<mbd_types>
00024 {
00025 public:
00026
00027 typedef typename mbd_types::math_policy::index_type size_type;
00028 typedef typename mbd_types::math_policy::value_traits value_traits;
00029 typedef typename mbd_types::math_policy::real_type real_type;
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 bool m_eval_active;
00041 size_type m_rows;
00042 real_type m_gamma;
00043 real_type m_solution;
00044
00045 public:
00046
00047 void set_maximum_force(real_type const & f_max) { m_f_max = f_max; }
00048 real_type get_maximum_force() const { return m_f_max; }
00049 void set_desired_speed(real_type const & v_desired) { m_v_desired = v_desired; }
00050 real_type get_desired_speed() const { return m_v_desired; }
00051
00052 public:
00053
00054 AngularJointMotor()
00055 : m_f_max(value_traits::zero())
00056 , m_v_desired(value_traits::zero())
00057 , m_rows(0)
00058 , m_gamma(value_traits::zero())
00059 , m_solution(value_traits::zero())
00060 {}
00061
00062 virtual ~AngularJointMotor(){}
00063
00064 public:
00065
00066 void evaluate(vector3_type const & s_wcs)
00067 {
00068 m_rows = 0;
00069 if(m_v_desired == OpenTissue::math::detail::lowest<real_type>() || m_v_desired == OpenTissue::math::detail::highest<real_type>() )
00070 return;
00071 if(m_f_max==0)
00072 return;
00073 m_rows = 1;
00074 m_s_wcs = s_wcs;
00075 }
00076
00077 size_type get_number_of_jacobian_rows() const { return m_rows; }
00078
00079 void get_linear_jacobian_A(matrix_range & J, size_type const & offset) const
00080 {
00081 J(offset,0) = value_traits::zero();
00082 J(offset,1) = value_traits::zero();
00083 J(offset,2) = value_traits::zero();
00084 }
00085
00086 void get_linear_jacobian_B(matrix_range & J, size_type const & offset) const
00087 {
00088 J(offset,0) = value_traits::zero();
00089 J(offset,1) = value_traits::zero();
00090 J(offset,2) = value_traits::zero();
00091 }
00092
00093 void get_angular_jacobian_A(matrix_range & J, size_type const & offset) const
00094 {
00095 J(offset,0) = -m_s_wcs(0); J(offset,1) = -m_s_wcs(1); J(offset,2) = -m_s_wcs(2);
00096 }
00097
00098 void get_angular_jacobian_B(matrix_range & J, size_type const & offset) const
00099 {
00100 J(offset,0) = m_s_wcs(0); J(offset,1) = m_s_wcs(1); J(offset,2) = m_s_wcs(2);
00101 }
00102
00103 void get_stabilization_term(vector_range & b_error, size_type const & offset) const
00104 {
00105 b_error(offset) = m_v_desired;
00106 }
00107
00108 void get_low_limits(vector_range & lo,size_type const & offset) const
00109 {
00110 lo(offset) = -m_f_max/this->get_frames_per_second();
00111 }
00112
00113 void get_high_limits(vector_range & hi,size_type const & offset) const
00114 {
00115 hi(offset) = m_f_max/this->get_frames_per_second();
00116 }
00117
00118 void get_dependency_indices(idx_vector_range & dep,size_type const & offset) const
00119 {
00120 dep(offset) = OpenTissue::math::detail::highest<size_type>();
00121 }
00122
00123 void get_dependency_factors(vector_range & factors,size_type const & offset) const
00124 {
00125 factors(offset) = value_traits::zero();
00126 }
00127
00128 void set_regularization(vector_range const & gamma,size_type const & offset)
00129 {
00130 m_gamma = gamma(offset);
00131 }
00132
00133 void get_regularization(vector_range & gamma,size_type const & offset) const
00134 {
00135 gamma(offset) = m_gamma;
00136 }
00137
00138 void set_solution(vector_range const & solution,size_type const & offset)
00139 {
00140 m_solution = solution(offset);
00141 }
00142
00143 void get_solution(vector_range & solution,size_type const & offset) const
00144 {
00145 solution(offset) = m_solution;
00146 }
00147
00148 };
00149
00150 }
00151 }
00152
00153 #endif