Follow this link to skip to the main content

claraty::Joint_Constraint Class Reference

#include <me_joint.h>

Collaboration diagram for claraty::Joint_Constraint:

Collaboration graph
[legend]
List of all members.

Public Member Functions

 Joint_Constraint ()
 Joint_Constraint (const Joint_Constraint &jc)
void set_parameters (std::string joint_constr_expr)
std::string get_parameters ()
bool evaluate_constraint_expression ()
double get_slope ()
double get_offset ()
int get_dependent_joint_index ()
std::string get_dependent_body_name ()

Private Attributes

double _offset
double _slope
std::string s_expr_attribute
std::string _dependent_body_name
long _dependent_body_joint_value_index

Detailed Description

Joint_Constraint class This class maintains joint constraint attributes.

Definition at line 122 of file me_joint.h.


Constructor & Destructor Documentation

claraty::Joint_Constraint::Joint_Constraint (  )  [inline]

Definition at line 124 of file me_joint.h.

00124 : _offset(0), _slope(0), s_expr_attribute("") {}

claraty::Joint_Constraint::Joint_Constraint ( const Joint_Constraint jc  )  [inline]

Definition at line 125 of file me_joint.h.

00126     : _offset(0), _slope(0), s_expr_attribute(jc.s_expr_attribute){}


Member Function Documentation

void claraty::Joint_Constraint::set_parameters ( std::string  joint_constr_expr  )  [inline]

Definition at line 127 of file me_joint.h.

References s_expr_attribute.

Referenced by claraty::ME_Joint::set_constraint_expression().

00128   {
00129     s_expr_attribute = joint_constr_expr;
00130   }

std::string claraty::Joint_Constraint::get_parameters (  )  [inline]

Definition at line 131 of file me_joint.h.

References s_expr_attribute.

Referenced by claraty::ME_Joint::get_constraint_expression().

00132   {
00133     return s_expr_attribute;
00134   }

bool claraty::Joint_Constraint::evaluate_constraint_expression (  ) 

Evaluates the constraint expression and assigns the parts of the constraint equation to their respective elements. The constraint expression should have the form: [-]slope * dependent_body_name[(joint_value_index)] [+/- offset] where slope is the required multiplication factor for the dependence. slope may have an optional negative sign before it. dependent_body_name is the required name of the body that this joint's constraint depends on [(joint_value_index)] is optional and designates the index of the joint value to depend on for multi-dof joints. The default if joint_value_index is not specified is 0. [+/- offset] is the optional positive or negative offset value in the constraint equation.

Returns:
true if successfully parsed the string expression, false if failed.

Definition at line 58 of file me_joint.cc.

References _dependent_body_joint_value_index, _dependent_body_name, _offset, _slope, s_expr_attribute, claraty::string_eat_double(), claraty::string_eat_long(), and claraty::string_get_tokens().

Referenced by claraty::ME_Joint::set_constraint_expression().

00059 {
00060   double slope_sign = 1.0;
00061   _dependent_body_joint_value_index = 0;
00062 
00063   // Make a copy of the string expression
00064   std::string string_expression(s_expr_attribute);
00065 
00066   // Remove white space from the expression and make a copy
00067   for (unsigned int i=0; i<string_expression.length(); ++i)
00068     {
00069       if ((string_expression[i] == ' ')||(string_expression[i] == '\t')
00070           ||(string_expression[i] == '\n')||(string_expression[i] == '\r'))
00071         {
00072           string_expression.erase(i, 1);
00073           --i;
00074         }
00075     }
00076 
00077   if (string_expression[0] == '-')
00078     {
00079       slope_sign = -1.0;
00080       string_expression.erase(0,1);
00081     }
00082 
00083   std::string string_expression_copy = string_expression;
00084 
00085   // if the expression is empty, return false
00086   if (string_expression.length() == 0)
00087     {
00088     return false;
00089     }
00090   // If there is no * char in the string, return false
00091   if (string_expression.find("*", 0) == std::string::npos)
00092     {
00093 
00094     return false;
00095     }
00096   string delims("*+-)( \t\n\r");
00097   string tokens("");
00098   vector<string> out_list = string_get_tokens(string_expression,
00099                                               delims,
00100                                               tokens);
00101 
00102   // Check that the correst number of elements were found in the expression
00103   if ((out_list.size() > 4) || (out_list.size() < 2))
00104     {
00105       return false;
00106     }
00107 
00108   // Check that the multiplication factor was in the right place
00109   if (string_expression_copy[string_expression_copy.find(out_list[1])-1] != '*')
00110     {
00111       return false;
00112     }
00113 
00114   if (out_list.size() == 3)
00115     {
00116       if (string_expression_copy[string_expression_copy.find(out_list[2])-1]
00117           == '(')
00118         {
00119           string_eat_long(out_list[2], _dependent_body_joint_value_index);
00120         }
00121       else if (string_expression_copy[
00122                      string_expression_copy.find(out_list[2])-1] == '+')
00123         {
00124           string_eat_double(out_list[2], _offset);
00125         }
00126       else if (string_expression_copy[
00127                     string_expression_copy.find(out_list[2])-1] == '-')
00128         {
00129           string_eat_double(out_list[2], _offset);
00130           _offset = - _offset;
00131         }
00132       else
00133         {
00134           return false;
00135         }
00136     }
00137 
00138   if (out_list.size() == 4)
00139     {
00140       if (string_expression_copy[string_expression_copy.find(out_list[2])-1]
00141           == '(')
00142         {
00143           string_eat_long(out_list[2], _dependent_body_joint_value_index);
00144         }
00145       else
00146         {
00147           return false;
00148         }
00149 
00150       if (string_expression_copy[string_expression_copy.find(out_list[3])-1]
00151           == '+')
00152         {
00153           string_eat_double(out_list[3], _offset);
00154         }
00155       else if (string_expression_copy[
00156                      string_expression_copy.find(out_list[3])-1] == '-')
00157         {
00158           string_eat_double(out_list[3], _offset);
00159           _offset = - _offset;
00160         }
00161       else
00162         {
00163           return false;
00164         }
00165     }
00166 
00167   string_eat_double(out_list[0], _slope);
00168   _slope *= slope_sign;
00169 
00170   _dependent_body_name = out_list[1];
00171 
00172   return true;
00173 
00174 }

Here is the call graph for this function:

double claraty::Joint_Constraint::get_slope (  )  [inline]

Definition at line 136 of file me_joint.h.

References _slope.

Referenced by claraty::ME_Joint::get_value().

00136 { return _slope;};

double claraty::Joint_Constraint::get_offset (  )  [inline]

Definition at line 137 of file me_joint.h.

References _offset.

Referenced by claraty::ME_Joint::get_value().

00137 { return _offset;};

int claraty::Joint_Constraint::get_dependent_joint_index (  )  [inline]

Definition at line 138 of file me_joint.h.

References _dependent_body_joint_value_index.

Referenced by claraty::ME_Joint::get_value().

std::string claraty::Joint_Constraint::get_dependent_body_name (  )  [inline]

Definition at line 139 of file me_joint.h.

References _dependent_body_name.

Referenced by claraty::ME_Joint::get_value().

00139 { return _dependent_body_name;}


Member Data Documentation

Definition at line 142 of file me_joint.h.

Referenced by evaluate_constraint_expression(), and get_offset().

Definition at line 143 of file me_joint.h.

Referenced by evaluate_constraint_expression(), and get_slope().


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