ContactFunctions.cpp
Go to the documentation of this file.
00001 
00018 #include <vector>
00019 #include <math.h>
00020 
00021 void setUpFrictionEllipsoid(unsigned int numLatitudes, unsigned int numDirs[], double phi[],
00022                             double eccen[], unsigned int& numFrictionEdges, std::vector<double>& frictionEdges)
00023 {
00024     numFrictionEdges = 0;
00025     for (unsigned int i = 0; i < numLatitudes; i++)
00026     {
00027         numFrictionEdges += numDirs[i];
00028     }
00029 
00030     frictionEdges.resize(6 * numFrictionEdges, 0);
00031 
00032     unsigned int col = 0;
00033     for (unsigned int i = 0; i < numLatitudes; i++)
00034     {
00035         double cosphi = cos(phi[i]);
00036         double sinphi = sin(phi[i]);
00037         for (unsigned int j = 0; j < numDirs[i]; j++)
00038         {
00039             double theta = j * 2 * M_PI / numDirs[i];
00040 
00041             double num = cos(theta) * cosphi;
00042             double denom = num * num / (eccen[0] * eccen[0]);
00043             num = sin(theta) * cosphi;
00044             denom += num * num / (eccen[1] * eccen[1]);
00045             num = sinphi;
00046             denom += num * num / (eccen[2] * eccen[2]);
00047             denom = sqrt(denom);
00048 
00049             frictionEdges[col * 6]   = cos(theta) * cosphi / denom;
00050             frictionEdges[col * 6 + 1] = sin(theta) * cosphi / denom;
00051             frictionEdges[col * 6 + 2] = 0;
00052             frictionEdges[col * 6 + 3] = 0;
00053             frictionEdges[col * 6 + 4] = 0;
00054             frictionEdges[col * 6 + 5] = sinphi / denom;
00055             col++;
00056         }
00057     }
00058 }
00059 
00060 void setUpSoftFrictionEdges(unsigned int& numEdges, std::vector<double>& frictionEdges)
00061 {
00062     // ROS_INFO("Setting up SOFT contact friction edges");
00063 
00064     double eccen[3];
00065 
00066     // magnitude of tangential friction:
00067     // in the original graspit code, this is influenced by the collision with another body
00068     // to obtain the torque as well. This is skipped in this implementation here.
00069     eccen[0] = 1;
00070     eccen[1] = 1;
00071     eccen[2] = 1;
00072 
00073 
00074     // XXX check original SoftContact::setUpFrictionEdges() for other stuff done
00075     // with the eccen field which could be worth doing for this purpose here as well
00076 
00077     // various possible approximations for the friction ellipsoid
00078 
00079     /*
00080     int numDirs[9] = {1,3,5,7,8,7,5,3,1};
00081     double phi[9] = {M_PI_2, M_PI_2*0.6, M_PI_2*0.3, M_PI_2*0.15, 0.0,
00082                      -M_PI_2*0.15, -M_PI_2*0.3, -M_PI_2*0.6, -M_PI_2};
00083     return Contact::setUpFrictionEdges(9,numDirs,phi,eccen);
00084     */
00085 
00086     /*
00087     int numDirs[9] = {1,8,8,8,8,8,8,8,1};
00088     double phi[9] = {M_PI_2, M_PI_2*0.66, M_PI_2*0.33, M_PI_2*0.165, 0.0,
00089                   -M_PI_2*0.165, -M_PI_2*0.33, -M_PI_2*0.66, -M_PI_2};
00090     return Contact::setUpFrictionEdges(9,numDirs,phi,eccen);
00091     */
00092 
00093     unsigned int numDirs[5] = {1, 5, 8, 5, 1};
00094     double phi[5] = {M_PI_2, M_PI_2 * 0.50, 0.0, -M_PI_2 * 0.50, -M_PI_2};
00095     return setUpFrictionEllipsoid(5, numDirs, phi, eccen , numEdges, frictionEdges);
00096 }
00097 
00098 
00099 void setUpFrictionEdges(unsigned int& numEdges, std::vector<double>& frictionEdges)
00100 {
00101     double eccen[3] = {1, 1, 1};
00102     unsigned int numDirs[1] = {8};
00103     double phi[1] = {0.0};
00104     setUpFrictionEllipsoid(1, numDirs, phi, eccen, numEdges, frictionEdges);
00105 }


urdf2graspit
Author(s): Jennifer Buehler
autogenerated on Wed May 8 2019 02:53:45