00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 
00019 
00020 
00021 
00022 
00023 
00024 
00025 
00026 
00032 #include <haptic_rendering_funx.h>
00033 
00034 hduVector3Dd CalculateWorkspaceDemoForce(void *pUserData)
00035 {
00036   shared_vars_t*RobotVars=(shared_vars_t*)pUserData;
00037   
00038   hduVector3Dd forceDirection;
00039   
00040   hduVector3Dd sent_force(0.0,0.0,0.0);
00041   
00042   static hduVector3Dd phantom_position;
00043   
00044   
00045   
00046   if( (RobotVars->parameters.kinematic_model>=1 && RobotVars->parameters.kinematic_model<=3) && RobotVars->parameters.manual_speed_control)
00047   {
00048     
00049     
00050     double min_sphereRadius = ((double)sqrt(13327.) / (double)RobotVars->parameters.pos_coord_scale); 
00051     RobotVars->haptics_data.arm_main_sphere_min_Radius = min_sphereRadius;
00052     
00053     double max_sphereRadius = (RobotVars->humanoid_f->GetRobotDimension(ARM_LENGTH)+RobotVars->humanoid_f->GetRobotDimension(FOREARM_LENGTH))
00054                               /
00055                               ((double)RobotVars->parameters.pos_coord_scale); 
00056     RobotVars->haptics_data.arm_main_sphere_max_Radius = max_sphereRadius;
00057     
00058     double back_sphereRadius = RobotVars->humanoid_f->GetRobotDimension(FOREARM_LENGTH) / ((double)RobotVars->parameters.pos_coord_scale); 
00059     RobotVars->haptics_data.arm_back_sphereRadius = back_sphereRadius;
00060     
00061     
00062     
00063     hduVector3Dd main_spheresPosition = RobotVars->haptics_data.arm_main_spheresPosition;
00064     
00065     hduVector3Dd back_spheresPosition = RobotVars->haptics_data.arm_back_spherePosition;
00066     
00067     
00068     phantom_position = RobotVars->phantom_data.m_devicePosition;
00069     
00070     
00071     if(RobotVars->parameters.kinematic_model==1)
00072     {
00073       forceDirection = TransformWorldCoordinatesToPHaNToMCoordinates(hduVector3Dd(0.,-1.,0.));
00074       
00075       sent_force = sent_force + (CalculatePolyForceMagnitude(-(phantom_position[1] - main_spheresPosition[1])/ (double)RobotVars->parameters.pos_coord_scale) * forceDirection);
00076     }
00077     else
00078     {
00079       forceDirection = TransformWorldCoordinatesToPHaNToMCoordinates(hduVector3Dd(0.,1.,0.));
00080       
00081       sent_force = sent_force + (CalculatePolyForceMagnitude((phantom_position[1] - main_spheresPosition[1])/ (double)RobotVars->parameters.pos_coord_scale) * forceDirection);
00082     }
00083     
00084     
00085     double radius = (phantom_position - main_spheresPosition).magnitude();
00086     
00087     forceDirection = TransformWorldCoordinatesToPHaNToMCoordinates(((phantom_position - main_spheresPosition)/radius));
00088     sent_force = sent_force + ((CalculatePolyForceMagnitude(radius - min_sphereRadius)) * forceDirection);
00089     
00090     forceDirection = TransformWorldCoordinatesToPHaNToMCoordinates((-1. * (phantom_position - main_spheresPosition)/radius));
00091     sent_force = sent_force + ((CalculatePolyForceMagnitude(max_sphereRadius - radius)) * forceDirection);
00092     
00093     radius = (phantom_position - back_spheresPosition).magnitude();
00094     forceDirection = TransformWorldCoordinatesToPHaNToMCoordinates(((phantom_position - back_spheresPosition)/radius));
00095     sent_force = sent_force + ((CalculatePolyForceMagnitude(radius - back_sphereRadius)) * forceDirection);
00096   }
00097   else if((RobotVars->parameters.kinematic_model>=4 && RobotVars->parameters.kinematic_model<=5) && RobotVars->parameters.manual_speed_control)
00098   {
00099     
00100     
00101     double max_sphereRadius = ((RobotVars->humanoid_f->GetRobotDimension(THIGH_LENGTH)
00102                                 +
00103                                 RobotVars->humanoid_f->GetRobotDimension(LEG_LENGTH)) / (double)RobotVars->parameters.pos_coord_scale); 
00104     RobotVars->haptics_data.leg_main_sphere_max_Radius = max_sphereRadius;
00105     
00106     double min_sphereRadius = ((double)119.233 / (double)RobotVars->parameters.pos_coord_scale); 
00107     RobotVars->haptics_data.leg_main_sphere_min_Radius = min_sphereRadius;
00108     
00109     double min_front_sphereRadius = (RobotVars->humanoid_f->GetRobotDimension(LEG_LENGTH) / (double)RobotVars->parameters.pos_coord_scale); 
00110     RobotVars->haptics_data.leg_back_sphereRadius = min_front_sphereRadius;
00111     
00112     double max_back_sphereRadius = (RobotVars->humanoid_f->GetRobotDimension(LEG_LENGTH) / (double)RobotVars->parameters.pos_coord_scale); 
00113     if(max_back_sphereRadius){}
00114     
00115     phantom_position = RobotVars->phantom_data.m_devicePosition;
00116     
00117     
00118     hduVector3Dd main_spheresPosition = RobotVars->haptics_data.leg_main_spheresPosition;
00119     hduVector3Dd back_spheresPosition = RobotVars->haptics_data.leg_back_spherePosition;
00120     hduVector3Dd front_spheresPosition = RobotVars->haptics_data.leg_front_spherePosition;
00121     
00122     
00123     double radius = (phantom_position - main_spheresPosition).magnitude();
00124     forceDirection = TransformWorldCoordinatesToPHaNToMCoordinates((-1. * (phantom_position - main_spheresPosition)/radius));
00125     sent_force = sent_force + ((CalculatePolyForceMagnitude(max_sphereRadius - radius)) * forceDirection);
00126     
00127     forceDirection = TransformWorldCoordinatesToPHaNToMCoordinates(((phantom_position - main_spheresPosition)/radius));
00128     sent_force = sent_force + ((CalculatePolyForceMagnitude(radius - min_sphereRadius)) * forceDirection);
00129     
00130     
00131     hduVector3Dd u = hduVector3Dd(1.0,0.0,0.0);
00132     
00133     hduVector3Dd v30 = hduVector3Dd(0.0,-sin(DegToRad(30.0)),cos(DegToRad(30.0)));
00134     
00135     hduVector3Dd v45 = hduVector3Dd(0.0,sin(DegToRad(45.0)),cos(DegToRad(45.0)));    
00136 
00137 
00138 
00139 
00140 
00141 
00142 
00143 
00144 
00145 
00146 
00147 
00148 
00149 
00150 
00151 
00152 
00153 
00154 
00155 
00156 
00157 
00158       
00159 
00160 
00161 
00162 
00163 
00164 
00165 
00166 
00167 
00168 
00169 
00170 
00171 
00172 
00173 
00174   }
00175   else
00176   {
00177     
00178   }
00179   
00180   return (sent_force);
00181 }
00182 
00183 hduVector3Dd CalculatePlaneDrawingDemoForce(void *pUserData)
00184 {
00185   shared_vars_t*RobotVars=(shared_vars_t*)pUserData;
00186   
00187   hduVector3Dd joystick_position = RobotVars->phantom_data.m_devicePosition;
00188   
00189   HDdouble s = RobotVars->haptics_data.demo_2_Plane.perpDistance(joystick_position);
00190   
00191   RobotVars->haptics_data.demo2_distance_to_plane  = fabs((double)s / (double)RobotVars->parameters.pos_coord_scale);
00192   hduVector3Dd n = RobotVars->haptics_data.demo_2_Plane.normal();
00193   n.normalize();
00194   
00195   
00196   return TransformWorldCoordinatesToPHaNToMCoordinates(CalculatePlaneForceMagnitude(RobotVars->haptics_data.demo2_distance_to_plane) * -n);
00197 }
00198 
00199 void Demo2_BuildPlane(void *pUserData)
00200 {
00201   shared_vars_t*RobotVars=(shared_vars_t*)pUserData;
00202   
00203   RobotVars->haptics_data.demo_2_Plane = hduPlaned(RobotVars->haptics_data.demo_2_point_1,
00204                                                    RobotVars->haptics_data.demo_2_point_2,
00205                                                    RobotVars->haptics_data.demo_2_point_3);  
00206 }
00207 
00208 hduVector3Dd Leg_COP_Monitoring(void *pUserData)
00209 {
00210   shared_vars_t*RobotVars=(shared_vars_t*)pUserData;
00211   hduVector3Dd Fx,Fy;
00212   double x,y;
00213   static double x_border_p, x_border_m, y_border_p, y_border_m;
00214   
00215   if(RobotVars->parameters.kinematic_model==4)
00216   {
00217     x = RobotVars->robot_kin_data.COG_detached_leg_left[0];
00218     y = RobotVars->robot_kin_data.COG_detached_leg_left[1];    
00219   }
00220   else if(RobotVars->parameters.kinematic_model==5)
00221   {
00222     x = RobotVars->robot_kin_data.COG_detached_leg_right[0];
00223     y = RobotVars->robot_kin_data.COG_detached_leg_right[1];
00224   }
00225   else
00226     return hduVector3Dd(0.0,0.0,0.0);
00227   
00228   std::cout<<"X: "<<x<<std::endl;
00229   std::cout<<"Y: "<<y<<std::endl;
00230   
00231   if( fabs(y) >= 10.0)
00232   {
00233     Fy = hduVector3Dd(0.0,-CalculateExponentialForceMagnitude(0.0),0.0);
00234   }
00235   if( fabs(x) >= 35.0)
00236   {
00237     Fx = hduVector3Dd(CalculateExponentialForceMagnitude(1),0.0,0.0);
00238   }
00239   
00240 
00241 
00242 
00243 
00244 
00245 
00246 
00247 
00248 
00249 
00250 
00251 
00252 
00253 
00254 
00255 
00256 
00257 
00258 
00259   
00260   return Fx+Fy;
00261 }
00262 
00263 
00264 
00265