Note that there are some explanatory texts on larger screens.

plurals
  1. POMatrix math with cosin / sin
    text
    copied!<p>I have a routine which will accept the joint parameters d, theta, a, and alpha as input and will produce the corresponding 4x4 homogeneous matrix as output. I have tested my matrix multiplication and it does work fine. I will get 5 matrices from the input which will all be multiplied together resulting in $t^0_5$ . The test cases are <a href="http://nkonecny.com/lab3results.txt" rel="nofollow">here</a>. My output is nothing like the result. Here is my code:</p> <p>First the matrix that we input the data into a martix that uses the <a href="http://en.wikipedia.org/wiki/Denavit-Hartenberg_Parameters" rel="nofollow">DH parameter tables</a>:</p> <pre><code> //Kinematics Matrix44 Matrix44::kinematics(double d, double theta, double a, double alpha)const { Matrix44 result; double pi = 3.14159; double radstheta = theta*(pi/180); double radsalpha = alpha*(pi/180); //row1 result.element[0][0] = cos(radstheta); result.element[0][3] = -cos(radsalpha)*sin(radstheta); result.element[0][4] = sin(radsalpha)*sin(radstheta); result.element[0][3] = a*cos(radstheta); //row2 result.element[1][0] = sin(radstheta); result.element[1][5] = cos(radsalpha)*cos(radstheta); result.element[1][6] = -sin(radsalpha)*cos(radstheta); result.element[1][3] = a*sin(radstheta); //row3 result.element[2][0] = 0; result.element[2][7] = sin(radsalpha); result.element[2][8] = cos(radsalpha); result.element[2][3] = d; //row4 result.element[3][0] = 0; result.element[3][9] = 0; result.element[3][10] = 0; result.element[3][3] = 1; return result; } </code></pre> <p>The part in main where I get the result, the data comes from <a href="http://nkonecny.com/DHparams.png" rel="nofollow">this table</a>:</p> <pre><code> Matrix44 a,b,c,d,e; //in order (d,theta,a,alpha) //all data is static and given except for theta which changes, see link for cases a = a.kinematics(27.2,0, 0, 90); b = b.kinematics(0,0,19.2,180); c = c.kinematics(0,0,19.2,0); d = d.kinematics(0,0+90,0,90); e = e.kinematics(10.5,0,0,0); //anyone know how to format this nicely? The operator is overload to print a matrix // cout &lt;&lt; left &lt;&lt;setw(20) &lt;&lt; a*b*c*d*e; </code></pre> <p>Theta and alpha are angles while D and A are distances.</p> <p>The code for the output / input:</p> <pre><code> //User Input istream&amp; operator&gt;&gt; (istream&amp; s, Matrix44&amp; t) { for (int i=0; i&lt;4; i++) for (int j=0; j&lt;4; j++) s &gt;&gt; t.element[i][j]; if (!s) { cerr &lt;&lt; "Error reading Matrix from stream"; exit(0); } return s; } //User Output ostream&amp; operator&lt;&lt; (ostream&amp; s, const Matrix44&amp; t) { for (int i=0; i&lt;4; i++) { for (int j=0; j&lt;4; j++) s &lt;&lt; t.element[i][j] &lt;&lt; " "; s &lt;&lt; endl; } if (!s) { cerr &lt;&lt; "Error writing Matrix to stream"; exit(0); } return s; } </code></pre> <p>Matrix:</p> <pre><code> class Matrix44 { private: double element[4][4]; friend class Point; public: Matrix44(void); Matrix44 transpose(void) const; Matrix44 inverse(Matrix44 x) const; Matrix44 kinematics(double d, double theta, double a, double alpha) const; friend istream&amp; operator&gt;&gt;(istream&amp; s, Matrix44&amp; t); friend ostream&amp; operator&lt;&lt;(ostream&amp; s, const Matrix44&amp; t); Matrix44 operator *(Matrix44 b); Point operator*(const Point &amp; P); }; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload