Chen Huan
/
StewartOlatform
StewartOlatform
StewartPlatform.cpp@0:2b80f11eb1d3, 2017-10-11 (annotated)
- Committer:
- heroistired
- Date:
- Wed Oct 11 07:05:25 2017 +0000
- Revision:
- 0:2b80f11eb1d3
stewart platform
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
heroistired | 0:2b80f11eb1d3 | 1 | #include "StewartPlatform.h" |
heroistired | 0:2b80f11eb1d3 | 2 | |
heroistired | 0:2b80f11eb1d3 | 3 | //******************************************** |
heroistired | 0:2b80f11eb1d3 | 4 | //功能:计算矩阵乘法 C=A*B |
heroistired | 0:2b80f11eb1d3 | 5 | //输入参数:A、B:参加运算的矩阵 |
heroistired | 0:2b80f11eb1d3 | 6 | //输出参数:C:运算结果 |
heroistired | 0:2b80f11eb1d3 | 7 | //返回值:计算是否成功 成功返回0 否则返回1 |
heroistired | 0:2b80f11eb1d3 | 8 | //调用外部函数:无 |
heroistired | 0:2b80f11eb1d3 | 9 | //作者:陈欢 h-che14@mails.tsinghua.edu.cn |
heroistired | 0:2b80f11eb1d3 | 10 | //******************************************** |
heroistired | 0:2b80f11eb1d3 | 11 | int MatrixDot(MatrixType* A, MatrixType* B, MatrixType* C) |
heroistired | 0:2b80f11eb1d3 | 12 | { |
heroistired | 0:2b80f11eb1d3 | 13 | int i, j, k; //循环控制变量 |
heroistired | 0:2b80f11eb1d3 | 14 | int posA, posB, posC; //矩阵下标索引 |
heroistired | 0:2b80f11eb1d3 | 15 | |
heroistired | 0:2b80f11eb1d3 | 16 | //判断异常 |
heroistired | 0:2b80f11eb1d3 | 17 | if(A->Size[1] != B->Size[0]) //维度不匹配 |
heroistired | 0:2b80f11eb1d3 | 18 | return 1; |
heroistired | 0:2b80f11eb1d3 | 19 | if(A->Size[0] * B->Size[1] > 50) //C矩阵规模太大 |
heroistired | 0:2b80f11eb1d3 | 20 | return 1; |
heroistired | 0:2b80f11eb1d3 | 21 | |
heroistired | 0:2b80f11eb1d3 | 22 | //计算矩阵乘法 |
heroistired | 0:2b80f11eb1d3 | 23 | C->Size[0] = A->Size[0]; //得到C的行列数 |
heroistired | 0:2b80f11eb1d3 | 24 | C->Size[1] = B->Size[1]; |
heroistired | 0:2b80f11eb1d3 | 25 | for(i = 1; i <= C->Size[0]; i++) //行循环 |
heroistired | 0:2b80f11eb1d3 | 26 | { |
heroistired | 0:2b80f11eb1d3 | 27 | for(j = 1; j <= C->Size[1]; j++) //列循环 |
heroistired | 0:2b80f11eb1d3 | 28 | { |
heroistired | 0:2b80f11eb1d3 | 29 | posC = f2(i,j,C->Size[1]); |
heroistired | 0:2b80f11eb1d3 | 30 | C->Elements[posC] = 0; |
heroistired | 0:2b80f11eb1d3 | 31 | for(k = 1; k <= A->Size[1]; k++) //计算乘法结果 |
heroistired | 0:2b80f11eb1d3 | 32 | { |
heroistired | 0:2b80f11eb1d3 | 33 | posA = f2(i,k,A->Size[1]); |
heroistired | 0:2b80f11eb1d3 | 34 | posB = f2(k,j,B->Size[1]); |
heroistired | 0:2b80f11eb1d3 | 35 | C->Elements[posC] += A->Elements[posA] * B->Elements[posB]; |
heroistired | 0:2b80f11eb1d3 | 36 | } |
heroistired | 0:2b80f11eb1d3 | 37 | } |
heroistired | 0:2b80f11eb1d3 | 38 | } |
heroistired | 0:2b80f11eb1d3 | 39 | return 0; |
heroistired | 0:2b80f11eb1d3 | 40 | } |
heroistired | 0:2b80f11eb1d3 | 41 | |
heroistired | 0:2b80f11eb1d3 | 42 | //******************************************** |
heroistired | 0:2b80f11eb1d3 | 43 | //功能:计算矩阵转置 |
heroistired | 0:2b80f11eb1d3 | 44 | //输入参数:A:被转置的矩阵 |
heroistired | 0:2b80f11eb1d3 | 45 | //输出参数:B:转置后的矩阵 |
heroistired | 0:2b80f11eb1d3 | 46 | //返回值:无 |
heroistired | 0:2b80f11eb1d3 | 47 | //调用外部函数:无 |
heroistired | 0:2b80f11eb1d3 | 48 | //作者:陈欢 h-che14@mails.tsinghua.edu.cn |
heroistired | 0:2b80f11eb1d3 | 49 | //******************************************** |
heroistired | 0:2b80f11eb1d3 | 50 | void MatrixTransposition(MatrixType* A, MatrixType* B) |
heroistired | 0:2b80f11eb1d3 | 51 | { |
heroistired | 0:2b80f11eb1d3 | 52 | int i, j; |
heroistired | 0:2b80f11eb1d3 | 53 | int posA, posB; |
heroistired | 0:2b80f11eb1d3 | 54 | |
heroistired | 0:2b80f11eb1d3 | 55 | B->Size[0] = A->Size[1]; |
heroistired | 0:2b80f11eb1d3 | 56 | B->Size[1] = A->Size[0]; |
heroistired | 0:2b80f11eb1d3 | 57 | |
heroistired | 0:2b80f11eb1d3 | 58 | for(i = 1; i <= A->Size[0]; i++) |
heroistired | 0:2b80f11eb1d3 | 59 | { |
heroistired | 0:2b80f11eb1d3 | 60 | for(j = 1; j <= A->Size[1]; j++) |
heroistired | 0:2b80f11eb1d3 | 61 | { |
heroistired | 0:2b80f11eb1d3 | 62 | posA = f2(i,j,A->Size[1]); |
heroistired | 0:2b80f11eb1d3 | 63 | posB = f2(j,i,B->Size[1]); |
heroistired | 0:2b80f11eb1d3 | 64 | B->Elements[posB] = A->Elements[posA]; |
heroistired | 0:2b80f11eb1d3 | 65 | } |
heroistired | 0:2b80f11eb1d3 | 66 | } |
heroistired | 0:2b80f11eb1d3 | 67 | } |
heroistired | 0:2b80f11eb1d3 | 68 | |
heroistired | 0:2b80f11eb1d3 | 69 | //******************************************** |
heroistired | 0:2b80f11eb1d3 | 70 | //功能:获得矩阵的子阵 |
heroistired | 0:2b80f11eb1d3 | 71 | //输入参数:A:原矩阵 StartRow、StartColumn、EndRow、EndColumn:子阵起始元素 子阵终了元素 |
heroistired | 0:2b80f11eb1d3 | 72 | //输出参数:B:子阵 |
heroistired | 0:2b80f11eb1d3 | 73 | //返回值:无 |
heroistired | 0:2b80f11eb1d3 | 74 | //调用外部函数:无 |
heroistired | 0:2b80f11eb1d3 | 75 | //作者:陈欢 h-che14@mails.tsinghua.edu.cn |
heroistired | 0:2b80f11eb1d3 | 76 | //******************************************** |
heroistired | 0:2b80f11eb1d3 | 77 | void MatrixSub(MatrixType* A,int StartRow, int StartColumn, int EndRow, int EndColumn, MatrixType* B) |
heroistired | 0:2b80f11eb1d3 | 78 | { |
heroistired | 0:2b80f11eb1d3 | 79 | int i, j; //循环控制变量 |
heroistired | 0:2b80f11eb1d3 | 80 | int posA, posB; //矩阵索引 |
heroistired | 0:2b80f11eb1d3 | 81 | |
heroistired | 0:2b80f11eb1d3 | 82 | B->Size[0] = EndRow - StartRow + 1; //计算子阵的维度 |
heroistired | 0:2b80f11eb1d3 | 83 | B->Size[1] = EndColumn - StartColumn + 1; |
heroistired | 0:2b80f11eb1d3 | 84 | for(i = 1; i <= B->Size[0]; i++) |
heroistired | 0:2b80f11eb1d3 | 85 | { |
heroistired | 0:2b80f11eb1d3 | 86 | for(j = 1; j <= B->Size[1]; j++) |
heroistired | 0:2b80f11eb1d3 | 87 | { |
heroistired | 0:2b80f11eb1d3 | 88 | posA = f2(StartRow + i - 1, StartColumn + j - 1, A->Size[1]); |
heroistired | 0:2b80f11eb1d3 | 89 | posB = f2(i, j, B->Size[1]); |
heroistired | 0:2b80f11eb1d3 | 90 | B->Elements[posB] = A->Elements[posA]; |
heroistired | 0:2b80f11eb1d3 | 91 | } |
heroistired | 0:2b80f11eb1d3 | 92 | } |
heroistired | 0:2b80f11eb1d3 | 93 | } |
heroistired | 0:2b80f11eb1d3 | 94 | |
heroistired | 0:2b80f11eb1d3 | 95 | //******************************************** |
heroistired | 0:2b80f11eb1d3 | 96 | //功能:填充矩阵 将一个矩阵填充到另一个矩阵中 |
heroistired | 0:2b80f11eb1d3 | 97 | //输入参数:A:被填充的矩阵 Row、Column:矩阵填充的位置 B:要填充到被填充矩阵的矩阵 |
heroistired | 0:2b80f11eb1d3 | 98 | //输出参数:A:被填充的矩阵 |
heroistired | 0:2b80f11eb1d3 | 99 | //返回值:0 代表成功 1代表失败 |
heroistired | 0:2b80f11eb1d3 | 100 | //调用外部函数:无 |
heroistired | 0:2b80f11eb1d3 | 101 | //作者:陈欢 h-che14@mails.tsinghua.edu.cn |
heroistired | 0:2b80f11eb1d3 | 102 | //******************************************** |
heroistired | 0:2b80f11eb1d3 | 103 | int MatrixFill(MatrixType* A,int Row, int Column, MatrixType* B) |
heroistired | 0:2b80f11eb1d3 | 104 | { |
heroistired | 0:2b80f11eb1d3 | 105 | int i, j, posA, posB; |
heroistired | 0:2b80f11eb1d3 | 106 | |
heroistired | 0:2b80f11eb1d3 | 107 | if((Row + B->Size[0] - 1) > A->Size[0]) |
heroistired | 0:2b80f11eb1d3 | 108 | { |
heroistired | 0:2b80f11eb1d3 | 109 | return 1; |
heroistired | 0:2b80f11eb1d3 | 110 | } |
heroistired | 0:2b80f11eb1d3 | 111 | else if((Column + B->Size[1] - 1) > A->Size[1]) |
heroistired | 0:2b80f11eb1d3 | 112 | { |
heroistired | 0:2b80f11eb1d3 | 113 | return 1; |
heroistired | 0:2b80f11eb1d3 | 114 | } |
heroistired | 0:2b80f11eb1d3 | 115 | else |
heroistired | 0:2b80f11eb1d3 | 116 | { |
heroistired | 0:2b80f11eb1d3 | 117 | for(i = 1; i <= B->Size[0]; i++) |
heroistired | 0:2b80f11eb1d3 | 118 | { |
heroistired | 0:2b80f11eb1d3 | 119 | for(j = 1; j <= B->Size[1]; j++) |
heroistired | 0:2b80f11eb1d3 | 120 | { |
heroistired | 0:2b80f11eb1d3 | 121 | posA = f2(Row + i - 1, Column + j - 1, A->Size[1]); |
heroistired | 0:2b80f11eb1d3 | 122 | posB = f2(i, j, B->Size[1]); |
heroistired | 0:2b80f11eb1d3 | 123 | A->Elements[posA] = B->Elements[posB]; |
heroistired | 0:2b80f11eb1d3 | 124 | } |
heroistired | 0:2b80f11eb1d3 | 125 | } |
heroistired | 0:2b80f11eb1d3 | 126 | return 0; |
heroistired | 0:2b80f11eb1d3 | 127 | } |
heroistired | 0:2b80f11eb1d3 | 128 | } |
heroistired | 0:2b80f11eb1d3 | 129 | |
heroistired | 0:2b80f11eb1d3 | 130 | //******************************************** |
heroistired | 0:2b80f11eb1d3 | 131 | //功能:指定动平台变换矩阵参数x,y,z,a,b,c,计算动平台上的点A在绝对坐标系下的坐标B A可以是多个点 一行一个点 |
heroistired | 0:2b80f11eb1d3 | 132 | //输入参数:x,y,z,a,b,c:动平台变换矩阵参数 A:动平台上点的相对坐标 |
heroistired | 0:2b80f11eb1d3 | 133 | //输出参数:B:点在绝对坐标系下的坐标 |
heroistired | 0:2b80f11eb1d3 | 134 | //返回值:无 |
heroistired | 0:2b80f11eb1d3 | 135 | //调用外部函数:无 |
heroistired | 0:2b80f11eb1d3 | 136 | //作者:陈欢 h-che14@mails.tsinghua.edu.cn |
heroistired | 0:2b80f11eb1d3 | 137 | //******************************************** |
heroistired | 0:2b80f11eb1d3 | 138 | void Inverse(float x, float y, float z, float a, float b, float c, MatrixType* A, MatrixType* B) |
heroistired | 0:2b80f11eb1d3 | 139 | { |
heroistired | 0:2b80f11eb1d3 | 140 | int i; |
heroistired | 0:2b80f11eb1d3 | 141 | |
heroistired | 0:2b80f11eb1d3 | 142 | MatrixType T; //原点平移 |
heroistired | 0:2b80f11eb1d3 | 143 | MatrixType Ra; //俯仰 YAW |
heroistired | 0:2b80f11eb1d3 | 144 | MatrixType Rb; //横滚 ROLL |
heroistired | 0:2b80f11eb1d3 | 145 | MatrixType Rc; //偏航 PITCH |
heroistired | 0:2b80f11eb1d3 | 146 | MatrixType temp1, temp2, temp3; |
heroistired | 0:2b80f11eb1d3 | 147 | |
heroistired | 0:2b80f11eb1d3 | 148 | T.Size[0] = 4; |
heroistired | 0:2b80f11eb1d3 | 149 | T.Size[1] = 4; |
heroistired | 0:2b80f11eb1d3 | 150 | T.Elements[f2(1,1,T.Size[1])] = 1; |
heroistired | 0:2b80f11eb1d3 | 151 | T.Elements[f2(1,2,T.Size[1])] = 0; |
heroistired | 0:2b80f11eb1d3 | 152 | T.Elements[f2(1,3,T.Size[1])] = 0; |
heroistired | 0:2b80f11eb1d3 | 153 | T.Elements[f2(1,4,T.Size[1])] = x; |
heroistired | 0:2b80f11eb1d3 | 154 | T.Elements[f2(2,1,T.Size[1])] = 0; |
heroistired | 0:2b80f11eb1d3 | 155 | T.Elements[f2(2,2,T.Size[1])] = 1; |
heroistired | 0:2b80f11eb1d3 | 156 | T.Elements[f2(2,3,T.Size[1])] = 0; |
heroistired | 0:2b80f11eb1d3 | 157 | T.Elements[f2(2,4,T.Size[1])] = y; |
heroistired | 0:2b80f11eb1d3 | 158 | T.Elements[f2(3,1,T.Size[1])] = 0; |
heroistired | 0:2b80f11eb1d3 | 159 | T.Elements[f2(3,2,T.Size[1])] = 0; |
heroistired | 0:2b80f11eb1d3 | 160 | T.Elements[f2(3,3,T.Size[1])] = 1; |
heroistired | 0:2b80f11eb1d3 | 161 | T.Elements[f2(3,4,T.Size[1])] = z; |
heroistired | 0:2b80f11eb1d3 | 162 | T.Elements[f2(4,1,T.Size[1])] = 0; |
heroistired | 0:2b80f11eb1d3 | 163 | T.Elements[f2(4,2,T.Size[1])] = 0; |
heroistired | 0:2b80f11eb1d3 | 164 | T.Elements[f2(4,3,T.Size[1])] = 0; |
heroistired | 0:2b80f11eb1d3 | 165 | T.Elements[f2(4,4,T.Size[1])] = 1; |
heroistired | 0:2b80f11eb1d3 | 166 | |
heroistired | 0:2b80f11eb1d3 | 167 | Ra.Size[0] = 4; |
heroistired | 0:2b80f11eb1d3 | 168 | Ra.Size[1] = 4; |
heroistired | 0:2b80f11eb1d3 | 169 | Ra.Elements[f2(1,1,Ra.Size[1])] = 1; |
heroistired | 0:2b80f11eb1d3 | 170 | Ra.Elements[f2(1,2,Ra.Size[1])] = 0; |
heroistired | 0:2b80f11eb1d3 | 171 | Ra.Elements[f2(1,3,Ra.Size[1])] = 0; |
heroistired | 0:2b80f11eb1d3 | 172 | Ra.Elements[f2(1,4,Ra.Size[1])] = 0; |
heroistired | 0:2b80f11eb1d3 | 173 | Ra.Elements[f2(2,1,Ra.Size[1])] = 0; |
heroistired | 0:2b80f11eb1d3 | 174 | Ra.Elements[f2(2,2,Ra.Size[1])] = cosd(a); |
heroistired | 0:2b80f11eb1d3 | 175 | Ra.Elements[f2(2,3,Ra.Size[1])] = -sind(a); |
heroistired | 0:2b80f11eb1d3 | 176 | Ra.Elements[f2(2,4,Ra.Size[1])] = 0; |
heroistired | 0:2b80f11eb1d3 | 177 | Ra.Elements[f2(3,1,Ra.Size[1])] = 0; |
heroistired | 0:2b80f11eb1d3 | 178 | Ra.Elements[f2(3,2,Ra.Size[1])] = sind(a); |
heroistired | 0:2b80f11eb1d3 | 179 | Ra.Elements[f2(3,3,Ra.Size[1])] = cosd(a); |
heroistired | 0:2b80f11eb1d3 | 180 | Ra.Elements[f2(3,4,Ra.Size[1])] = 0; |
heroistired | 0:2b80f11eb1d3 | 181 | Ra.Elements[f2(4,1,Ra.Size[1])] = 0; |
heroistired | 0:2b80f11eb1d3 | 182 | Ra.Elements[f2(4,2,Ra.Size[1])] = 0; |
heroistired | 0:2b80f11eb1d3 | 183 | Ra.Elements[f2(4,3,Ra.Size[1])] = 0; |
heroistired | 0:2b80f11eb1d3 | 184 | Ra.Elements[f2(4,4,Ra.Size[1])] = 1; |
heroistired | 0:2b80f11eb1d3 | 185 | |
heroistired | 0:2b80f11eb1d3 | 186 | Rb.Size[0] = 4; |
heroistired | 0:2b80f11eb1d3 | 187 | Rb.Size[1] = 4; |
heroistired | 0:2b80f11eb1d3 | 188 | Rb.Elements[f2(1,1,Rb.Size[1])] = cosd(b); |
heroistired | 0:2b80f11eb1d3 | 189 | Rb.Elements[f2(1,2,Rb.Size[1])] = 0; |
heroistired | 0:2b80f11eb1d3 | 190 | Rb.Elements[f2(1,3,Rb.Size[1])] = sind(b); |
heroistired | 0:2b80f11eb1d3 | 191 | Rb.Elements[f2(1,4,Rb.Size[1])] = 0; |
heroistired | 0:2b80f11eb1d3 | 192 | Rb.Elements[f2(2,1,Rb.Size[1])] = 0; |
heroistired | 0:2b80f11eb1d3 | 193 | Rb.Elements[f2(2,2,Rb.Size[1])] = 1; |
heroistired | 0:2b80f11eb1d3 | 194 | Rb.Elements[f2(2,3,Rb.Size[1])] = 0; |
heroistired | 0:2b80f11eb1d3 | 195 | Rb.Elements[f2(2,4,Rb.Size[1])] = 0; |
heroistired | 0:2b80f11eb1d3 | 196 | Rb.Elements[f2(3,1,Rb.Size[1])] = -sind(b); |
heroistired | 0:2b80f11eb1d3 | 197 | Rb.Elements[f2(3,2,Rb.Size[1])] = 0; |
heroistired | 0:2b80f11eb1d3 | 198 | Rb.Elements[f2(3,3,Rb.Size[1])] = cosd(b); |
heroistired | 0:2b80f11eb1d3 | 199 | Rb.Elements[f2(3,4,Rb.Size[1])] = 0; |
heroistired | 0:2b80f11eb1d3 | 200 | Rb.Elements[f2(4,1,Rb.Size[1])] = 0; |
heroistired | 0:2b80f11eb1d3 | 201 | Rb.Elements[f2(4,2,Rb.Size[1])] = 0; |
heroistired | 0:2b80f11eb1d3 | 202 | Rb.Elements[f2(4,3,Rb.Size[1])] = 0; |
heroistired | 0:2b80f11eb1d3 | 203 | Rb.Elements[f2(4,4,Rb.Size[1])] = 1; |
heroistired | 0:2b80f11eb1d3 | 204 | |
heroistired | 0:2b80f11eb1d3 | 205 | Rc.Size[0] = 4; |
heroistired | 0:2b80f11eb1d3 | 206 | Rc.Size[1] = 4; |
heroistired | 0:2b80f11eb1d3 | 207 | Rc.Elements[f2(1,1,Rc.Size[1])] = cosd(c); |
heroistired | 0:2b80f11eb1d3 | 208 | Rc.Elements[f2(1,2,Rc.Size[1])] = -sind(c); |
heroistired | 0:2b80f11eb1d3 | 209 | Rc.Elements[f2(1,3,Rc.Size[1])] = 0; |
heroistired | 0:2b80f11eb1d3 | 210 | Rc.Elements[f2(1,4,Rc.Size[1])] = 0; |
heroistired | 0:2b80f11eb1d3 | 211 | Rc.Elements[f2(2,1,Rc.Size[1])] = sind(c); |
heroistired | 0:2b80f11eb1d3 | 212 | Rc.Elements[f2(2,2,Rc.Size[1])] = cosd(c); |
heroistired | 0:2b80f11eb1d3 | 213 | Rc.Elements[f2(2,3,Rc.Size[1])] = 0; |
heroistired | 0:2b80f11eb1d3 | 214 | Rc.Elements[f2(2,4,Rc.Size[1])] = 0; |
heroistired | 0:2b80f11eb1d3 | 215 | Rc.Elements[f2(3,1,Rc.Size[1])] = 0; |
heroistired | 0:2b80f11eb1d3 | 216 | Rc.Elements[f2(3,2,Rc.Size[1])] = 0; |
heroistired | 0:2b80f11eb1d3 | 217 | Rc.Elements[f2(3,3,Rc.Size[1])] = 1; |
heroistired | 0:2b80f11eb1d3 | 218 | Rc.Elements[f2(3,4,Rc.Size[1])] = 0; |
heroistired | 0:2b80f11eb1d3 | 219 | Rc.Elements[f2(4,1,Rc.Size[1])] = 0; |
heroistired | 0:2b80f11eb1d3 | 220 | Rc.Elements[f2(4,2,Rc.Size[1])] = 0; |
heroistired | 0:2b80f11eb1d3 | 221 | Rc.Elements[f2(4,3,Rc.Size[1])] = 0; |
heroistired | 0:2b80f11eb1d3 | 222 | Rc.Elements[f2(4,4,Rc.Size[1])] = 1; |
heroistired | 0:2b80f11eb1d3 | 223 | |
heroistired | 0:2b80f11eb1d3 | 224 | B->Size[0] = A->Size[0]; |
heroistired | 0:2b80f11eb1d3 | 225 | B->Size[1] = A->Size[1]; |
heroistired | 0:2b80f11eb1d3 | 226 | MatrixDot(&T, &Rc, &temp1); //相当于T * Rc * Rb * Ra |
heroistired | 0:2b80f11eb1d3 | 227 | MatrixDot(&temp1, &Rb, &temp2); |
heroistired | 0:2b80f11eb1d3 | 228 | MatrixDot(&temp2, &Ra, &temp1); |
heroistired | 0:2b80f11eb1d3 | 229 | for(i = 1; i <= B->Size[0]; i++) |
heroistired | 0:2b80f11eb1d3 | 230 | { |
heroistired | 0:2b80f11eb1d3 | 231 | MatrixSub(A, i, 1, i, A->Size[1], &temp2); |
heroistired | 0:2b80f11eb1d3 | 232 | MatrixTransposition(&temp2, &temp3); |
heroistired | 0:2b80f11eb1d3 | 233 | MatrixDot(&temp1, &temp3, &temp2); |
heroistired | 0:2b80f11eb1d3 | 234 | MatrixTransposition(&temp2, &temp3); |
heroistired | 0:2b80f11eb1d3 | 235 | MatrixFill(B, i, 1, &temp3); |
heroistired | 0:2b80f11eb1d3 | 236 | } |
heroistired | 0:2b80f11eb1d3 | 237 | } |
heroistired | 0:2b80f11eb1d3 | 238 | |
heroistired | 0:2b80f11eb1d3 | 239 | //******************************************** |
heroistired | 0:2b80f11eb1d3 | 240 | //功能:计算矩阵行向量所表示的坐标点之间的距离 |
heroistired | 0:2b80f11eb1d3 | 241 | //输入参数:A, B:要计算距离的矩阵 |
heroistired | 0:2b80f11eb1d3 | 242 | //输出参数:C:包含距离值信息的列向量 |
heroistired | 0:2b80f11eb1d3 | 243 | //返回值:无 |
heroistired | 0:2b80f11eb1d3 | 244 | //调用外部函数:无 |
heroistired | 0:2b80f11eb1d3 | 245 | //作者:陈欢 h-che14@mails.tsinghua.edu.cn |
heroistired | 0:2b80f11eb1d3 | 246 | //******************************************** |
heroistired | 0:2b80f11eb1d3 | 247 | int Distance2Point(MatrixType* A, MatrixType* B, MatrixType* C) |
heroistired | 0:2b80f11eb1d3 | 248 | { |
heroistired | 0:2b80f11eb1d3 | 249 | float distance = 0; |
heroistired | 0:2b80f11eb1d3 | 250 | int i = 0, j = 0; |
heroistired | 0:2b80f11eb1d3 | 251 | if((A->Size[0] != B->Size[0]) || (A->Size[1] != 4) || (B->Size[1] != 4)) |
heroistired | 0:2b80f11eb1d3 | 252 | { |
heroistired | 0:2b80f11eb1d3 | 253 | return 1; |
heroistired | 0:2b80f11eb1d3 | 254 | } |
heroistired | 0:2b80f11eb1d3 | 255 | else |
heroistired | 0:2b80f11eb1d3 | 256 | { |
heroistired | 0:2b80f11eb1d3 | 257 | C->Size[0] = A->Size[0]; |
heroistired | 0:2b80f11eb1d3 | 258 | C->Size[1] = 1; |
heroistired | 0:2b80f11eb1d3 | 259 | for(i = 1; i <= A->Size[0]; i++) |
heroistired | 0:2b80f11eb1d3 | 260 | { |
heroistired | 0:2b80f11eb1d3 | 261 | for(j = 1; j <= A->Size[1]; j++) |
heroistired | 0:2b80f11eb1d3 | 262 | { |
heroistired | 0:2b80f11eb1d3 | 263 | distance = distance + (A->Elements[f2(i,j,A->Size[1])] - B->Elements[f2(i,j,B->Size[1])]) * (A->Elements[f2(i,j,A->Size[1])] - B->Elements[f2(i,j,B->Size[1])]); |
heroistired | 0:2b80f11eb1d3 | 264 | } |
heroistired | 0:2b80f11eb1d3 | 265 | C->Elements[f2(i,1,C->Size[1])] = sqrt(distance); |
heroistired | 0:2b80f11eb1d3 | 266 | distance = 0; |
heroistired | 0:2b80f11eb1d3 | 267 | } |
heroistired | 0:2b80f11eb1d3 | 268 | return 0; |
heroistired | 0:2b80f11eb1d3 | 269 | } |
heroistired | 0:2b80f11eb1d3 | 270 | } |
heroistired | 0:2b80f11eb1d3 | 271 | |
heroistired | 0:2b80f11eb1d3 | 272 | //******************************************** |
heroistired | 0:2b80f11eb1d3 | 273 | //功能:解析动感平台 |
heroistired | 0:2b80f11eb1d3 | 274 | //输入参数:Platform:动感平台数据结构 包含各种输入输出 |
heroistired | 0:2b80f11eb1d3 | 275 | //输出参数:无 |
heroistired | 0:2b80f11eb1d3 | 276 | //返回值:无 |
heroistired | 0:2b80f11eb1d3 | 277 | //调用外部函数:无 |
heroistired | 0:2b80f11eb1d3 | 278 | //作者:陈欢 h-che14@mails.tsinghua.edu.cn |
heroistired | 0:2b80f11eb1d3 | 279 | //******************************************** |
heroistired | 0:2b80f11eb1d3 | 280 | void CalStewartPlatform(StewartPlatformType* Platform) |
heroistired | 0:2b80f11eb1d3 | 281 | { |
heroistired | 0:2b80f11eb1d3 | 282 | int x, y, z, a, b, c; //动平台变换矩阵参数 |
heroistired | 0:2b80f11eb1d3 | 283 | float xx, yy, zz, r, l, AA, BB, CC, DD, EE, delta, mytheta1, mytheta2, d, e, f, l1, l2, l3, l4; //计算电机角度用的参数 |
heroistired | 0:2b80f11eb1d3 | 284 | float theta1, theta2, theta3, theta4, theta5, theta6; |
heroistired | 0:2b80f11eb1d3 | 285 | float topRadius, topInterval, bottomRadius, bottomInterval, lengthOfSteelWheel, lengthOfCardan, lengthOfBar; |
heroistired | 0:2b80f11eb1d3 | 286 | //平台机械尺寸定义 |
heroistired | 0:2b80f11eb1d3 | 287 | float theta0; //舵盘结构的倾角 |
heroistired | 0:2b80f11eb1d3 | 288 | MatrixType temp1, temp2; |
heroistired | 0:2b80f11eb1d3 | 289 | |
heroistired | 0:2b80f11eb1d3 | 290 | MatrixType topPlatform; //动平台上的6个参考点 |
heroistired | 0:2b80f11eb1d3 | 291 | MatrixType Rc; |
heroistired | 0:2b80f11eb1d3 | 292 | MatrixType bottomPlatform; //定平台上的6个参考点 |
heroistired | 0:2b80f11eb1d3 | 293 | MatrixType lengthOfBar1; |
heroistired | 0:2b80f11eb1d3 | 294 | |
heroistired | 0:2b80f11eb1d3 | 295 | topRadius = Platform->topRadius; //平台参数初始化 |
heroistired | 0:2b80f11eb1d3 | 296 | topInterval = Platform->topInterval; |
heroistired | 0:2b80f11eb1d3 | 297 | bottomRadius = Platform->bottomRadius; |
heroistired | 0:2b80f11eb1d3 | 298 | bottomInterval = Platform->bottomInterval; |
heroistired | 0:2b80f11eb1d3 | 299 | lengthOfSteelWheel = Platform->lengthOfSteelWheel; |
heroistired | 0:2b80f11eb1d3 | 300 | lengthOfCardan = Platform->lengthOfCardan; |
heroistired | 0:2b80f11eb1d3 | 301 | lengthOfBar = Platform->lengthOfBar; |
heroistired | 0:2b80f11eb1d3 | 302 | |
heroistired | 0:2b80f11eb1d3 | 303 | topPlatform.Size[0] = 6; |
heroistired | 0:2b80f11eb1d3 | 304 | topPlatform.Size[1] = 4; |
heroistired | 0:2b80f11eb1d3 | 305 | topPlatform.Elements[f2(1,1,topPlatform.Size[1])] = -topInterval / 2; |
heroistired | 0:2b80f11eb1d3 | 306 | topPlatform.Elements[f2(1,2,topPlatform.Size[1])] = -topRadius; |
heroistired | 0:2b80f11eb1d3 | 307 | topPlatform.Elements[f2(1,3,topPlatform.Size[1])] = 0; |
heroistired | 0:2b80f11eb1d3 | 308 | topPlatform.Elements[f2(1,4,topPlatform.Size[1])] = 1; |
heroistired | 0:2b80f11eb1d3 | 309 | topPlatform.Elements[f2(2,1,topPlatform.Size[1])] = topInterval / 2; |
heroistired | 0:2b80f11eb1d3 | 310 | topPlatform.Elements[f2(2,2,topPlatform.Size[1])] = -topRadius; |
heroistired | 0:2b80f11eb1d3 | 311 | topPlatform.Elements[f2(2,3,topPlatform.Size[1])] = 0; |
heroistired | 0:2b80f11eb1d3 | 312 | topPlatform.Elements[f2(2,4,topPlatform.Size[1])] = 1; |
heroistired | 0:2b80f11eb1d3 | 313 | |
heroistired | 0:2b80f11eb1d3 | 314 | Rc.Size[0] = 4; |
heroistired | 0:2b80f11eb1d3 | 315 | Rc.Size[1] = 4; |
heroistired | 0:2b80f11eb1d3 | 316 | Rc.Elements[f2(1,1,Rc.Size[1])] = cosd(120); |
heroistired | 0:2b80f11eb1d3 | 317 | Rc.Elements[f2(1,2,Rc.Size[1])] = -sind(120); |
heroistired | 0:2b80f11eb1d3 | 318 | Rc.Elements[f2(1,3,Rc.Size[1])] = 0; |
heroistired | 0:2b80f11eb1d3 | 319 | Rc.Elements[f2(1,4,Rc.Size[1])] = 0; |
heroistired | 0:2b80f11eb1d3 | 320 | Rc.Elements[f2(2,1,Rc.Size[1])] = sind(120); |
heroistired | 0:2b80f11eb1d3 | 321 | Rc.Elements[f2(2,2,Rc.Size[1])] = cosd(120); |
heroistired | 0:2b80f11eb1d3 | 322 | Rc.Elements[f2(2,3,Rc.Size[1])] = 0; |
heroistired | 0:2b80f11eb1d3 | 323 | Rc.Elements[f2(2,4,Rc.Size[1])] = 0; |
heroistired | 0:2b80f11eb1d3 | 324 | Rc.Elements[f2(3,1,Rc.Size[1])] = 0; |
heroistired | 0:2b80f11eb1d3 | 325 | Rc.Elements[f2(3,2,Rc.Size[1])] = 0; |
heroistired | 0:2b80f11eb1d3 | 326 | Rc.Elements[f2(3,3,Rc.Size[1])] = 1; |
heroistired | 0:2b80f11eb1d3 | 327 | Rc.Elements[f2(3,4,Rc.Size[1])] = 0; |
heroistired | 0:2b80f11eb1d3 | 328 | Rc.Elements[f2(4,1,Rc.Size[1])] = 0; |
heroistired | 0:2b80f11eb1d3 | 329 | Rc.Elements[f2(4,2,Rc.Size[1])] = 0; |
heroistired | 0:2b80f11eb1d3 | 330 | Rc.Elements[f2(4,3,Rc.Size[1])] = 0; |
heroistired | 0:2b80f11eb1d3 | 331 | Rc.Elements[f2(4,4,Rc.Size[1])] = 1; |
heroistired | 0:2b80f11eb1d3 | 332 | |
heroistired | 0:2b80f11eb1d3 | 333 | MatrixSub(&topPlatform, 1, 1, 1, 4, &temp1); //等效于topPlatform(3,:) = (Rc * topPlatform(1, :)')'; |
heroistired | 0:2b80f11eb1d3 | 334 | MatrixTransposition(&temp1, &temp2); |
heroistired | 0:2b80f11eb1d3 | 335 | MatrixDot(&Rc, &temp2, &temp1); |
heroistired | 0:2b80f11eb1d3 | 336 | MatrixTransposition(&temp1, &temp2); |
heroistired | 0:2b80f11eb1d3 | 337 | MatrixFill(&topPlatform, 3, 1, &temp2); |
heroistired | 0:2b80f11eb1d3 | 338 | MatrixSub(&topPlatform, 2, 1, 2, 4, &temp1); //等效于topPlatform(4,:) = (Rc * topPlatform(2, :)')'; |
heroistired | 0:2b80f11eb1d3 | 339 | MatrixTransposition(&temp1, &temp2); |
heroistired | 0:2b80f11eb1d3 | 340 | MatrixDot(&Rc, &temp2, &temp1); |
heroistired | 0:2b80f11eb1d3 | 341 | MatrixTransposition(&temp1, &temp2); |
heroistired | 0:2b80f11eb1d3 | 342 | MatrixFill(&topPlatform, 4, 1, &temp2); |
heroistired | 0:2b80f11eb1d3 | 343 | MatrixSub(&topPlatform, 3, 1, 3, 4, &temp1); //等效于topPlatform(5,:) = (Rc * topPlatform(3, :)')'; |
heroistired | 0:2b80f11eb1d3 | 344 | MatrixTransposition(&temp1, &temp2); |
heroistired | 0:2b80f11eb1d3 | 345 | MatrixDot(&Rc, &temp2, &temp1); |
heroistired | 0:2b80f11eb1d3 | 346 | MatrixTransposition(&temp1, &temp2); |
heroistired | 0:2b80f11eb1d3 | 347 | MatrixFill(&topPlatform, 5, 1, &temp2); |
heroistired | 0:2b80f11eb1d3 | 348 | MatrixSub(&topPlatform, 4, 1, 4, 4, &temp1); //等效于topPlatform(5,:) = (Rc * topPlatform(3, :)')'; |
heroistired | 0:2b80f11eb1d3 | 349 | MatrixTransposition(&temp1, &temp2); |
heroistired | 0:2b80f11eb1d3 | 350 | MatrixDot(&Rc, &temp2, &temp1); |
heroistired | 0:2b80f11eb1d3 | 351 | MatrixTransposition(&temp1, &temp2); |
heroistired | 0:2b80f11eb1d3 | 352 | MatrixFill(&topPlatform, 6, 1, &temp2); |
heroistired | 0:2b80f11eb1d3 | 353 | |
heroistired | 0:2b80f11eb1d3 | 354 | x = Platform->x; |
heroistired | 0:2b80f11eb1d3 | 355 | y = Platform->y; |
heroistired | 0:2b80f11eb1d3 | 356 | z = Platform->z; |
heroistired | 0:2b80f11eb1d3 | 357 | a = Platform->a; |
heroistired | 0:2b80f11eb1d3 | 358 | b = Platform->b; |
heroistired | 0:2b80f11eb1d3 | 359 | c = Platform->c; |
heroistired | 0:2b80f11eb1d3 | 360 | Inverse(x, y, z, a, b, c, &topPlatform, &temp1); //计算出动平台参考点的实际位置 |
heroistired | 0:2b80f11eb1d3 | 361 | MatrixFill(&topPlatform, 1, 1, &temp1); |
heroistired | 0:2b80f11eb1d3 | 362 | |
heroistired | 0:2b80f11eb1d3 | 363 | bottomPlatform.Size[0] = 6; |
heroistired | 0:2b80f11eb1d3 | 364 | bottomPlatform.Size[1] = 4; |
heroistired | 0:2b80f11eb1d3 | 365 | bottomPlatform.Elements[f2(1,1,bottomPlatform.Size[1])] = -bottomInterval / 2; |
heroistired | 0:2b80f11eb1d3 | 366 | bottomPlatform.Elements[f2(1,2,bottomPlatform.Size[1])] = -bottomRadius; |
heroistired | 0:2b80f11eb1d3 | 367 | bottomPlatform.Elements[f2(1,3,bottomPlatform.Size[1])] = 0; |
heroistired | 0:2b80f11eb1d3 | 368 | bottomPlatform.Elements[f2(1,4,bottomPlatform.Size[1])] = 1; |
heroistired | 0:2b80f11eb1d3 | 369 | bottomPlatform.Elements[f2(2,1,bottomPlatform.Size[1])] = bottomInterval / 2; |
heroistired | 0:2b80f11eb1d3 | 370 | bottomPlatform.Elements[f2(2,2,bottomPlatform.Size[1])] = -bottomRadius; |
heroistired | 0:2b80f11eb1d3 | 371 | bottomPlatform.Elements[f2(2,3,bottomPlatform.Size[1])] = 0; |
heroistired | 0:2b80f11eb1d3 | 372 | bottomPlatform.Elements[f2(2,4,bottomPlatform.Size[1])] = 1; |
heroistired | 0:2b80f11eb1d3 | 373 | |
heroistired | 0:2b80f11eb1d3 | 374 | MatrixSub(&bottomPlatform, 1, 1, 1, 4, &temp1); //等效于bottomPlatform(3,:) = (Rc * bottomPlatform(1, :)')'; |
heroistired | 0:2b80f11eb1d3 | 375 | MatrixTransposition(&temp1, &temp2); |
heroistired | 0:2b80f11eb1d3 | 376 | MatrixDot(&Rc, &temp2, &temp1); |
heroistired | 0:2b80f11eb1d3 | 377 | MatrixTransposition(&temp1, &temp2); |
heroistired | 0:2b80f11eb1d3 | 378 | MatrixFill(&bottomPlatform, 3, 1, &temp2); |
heroistired | 0:2b80f11eb1d3 | 379 | MatrixSub(&bottomPlatform, 2, 1, 2, 4, &temp1); //等效于bottomPlatform(4,:) = (Rc * bottomPlatform(2, :)')'; |
heroistired | 0:2b80f11eb1d3 | 380 | MatrixTransposition(&temp1, &temp2); |
heroistired | 0:2b80f11eb1d3 | 381 | MatrixDot(&Rc, &temp2, &temp1); |
heroistired | 0:2b80f11eb1d3 | 382 | MatrixTransposition(&temp1, &temp2); |
heroistired | 0:2b80f11eb1d3 | 383 | MatrixFill(&bottomPlatform, 4, 1, &temp2); |
heroistired | 0:2b80f11eb1d3 | 384 | MatrixSub(&bottomPlatform, 3, 1, 3, 4, &temp1); //等效于bottomPlatform(5,:) = (Rc * bottomPlatform(3, :)')'; |
heroistired | 0:2b80f11eb1d3 | 385 | MatrixTransposition(&temp1, &temp2); |
heroistired | 0:2b80f11eb1d3 | 386 | MatrixDot(&Rc, &temp2, &temp1); |
heroistired | 0:2b80f11eb1d3 | 387 | MatrixTransposition(&temp1, &temp2); |
heroistired | 0:2b80f11eb1d3 | 388 | MatrixFill(&bottomPlatform, 5, 1, &temp2); |
heroistired | 0:2b80f11eb1d3 | 389 | MatrixSub(&bottomPlatform, 4, 1, 4, 4, &temp1); //等效于bottomPlatform(6,:) = (Rc * bottomPlatform(3, :)')'; |
heroistired | 0:2b80f11eb1d3 | 390 | MatrixTransposition(&temp1, &temp2); |
heroistired | 0:2b80f11eb1d3 | 391 | MatrixDot(&Rc, &temp2, &temp1); |
heroistired | 0:2b80f11eb1d3 | 392 | MatrixTransposition(&temp1, &temp2); |
heroistired | 0:2b80f11eb1d3 | 393 | MatrixFill(&bottomPlatform, 6, 1, &temp2); |
heroistired | 0:2b80f11eb1d3 | 394 | |
heroistired | 0:2b80f11eb1d3 | 395 | Distance2Point(&topPlatform, &bottomPlatform, &lengthOfBar1); |
heroistired | 0:2b80f11eb1d3 | 396 | |
heroistired | 0:2b80f11eb1d3 | 397 | Platform->BarLength[0] = lengthOfBar1.Elements[f2(1,1,lengthOfBar1.Size[1])]; //赋值计算出的杆长 |
heroistired | 0:2b80f11eb1d3 | 398 | Platform->BarLength[1] = lengthOfBar1.Elements[f2(2,1,lengthOfBar1.Size[1])]; |
heroistired | 0:2b80f11eb1d3 | 399 | Platform->BarLength[2] = lengthOfBar1.Elements[f2(3,1,lengthOfBar1.Size[1])]; |
heroistired | 0:2b80f11eb1d3 | 400 | Platform->BarLength[3] = lengthOfBar1.Elements[f2(4,1,lengthOfBar1.Size[1])]; |
heroistired | 0:2b80f11eb1d3 | 401 | Platform->BarLength[4] = lengthOfBar1.Elements[f2(5,1,lengthOfBar1.Size[1])]; |
heroistired | 0:2b80f11eb1d3 | 402 | Platform->BarLength[5] = lengthOfBar1.Elements[f2(6,1,lengthOfBar1.Size[1])]; |
heroistired | 0:2b80f11eb1d3 | 403 | |
heroistired | 0:2b80f11eb1d3 | 404 | //计算角度 |
heroistired | 0:2b80f11eb1d3 | 405 | r = sqrt(lengthOfCardan * lengthOfCardan + lengthOfSteelWheel * lengthOfSteelWheel); |
heroistired | 0:2b80f11eb1d3 | 406 | l = lengthOfBar; |
heroistired | 0:2b80f11eb1d3 | 407 | //点1 |
heroistired | 0:2b80f11eb1d3 | 408 | xx = topPlatform.Elements[f2(1,1,topPlatform.Size[1])] - bottomPlatform.Elements[f2(1,1,bottomPlatform.Size[1])]; |
heroistired | 0:2b80f11eb1d3 | 409 | yy = topPlatform.Elements[f2(1,2,topPlatform.Size[1])] - bottomPlatform.Elements[f2(1,2,bottomPlatform.Size[1])]; |
heroistired | 0:2b80f11eb1d3 | 410 | zz = topPlatform.Elements[f2(1,3,topPlatform.Size[1])] - bottomPlatform.Elements[f2(1,3,bottomPlatform.Size[1])]; |
heroistired | 0:2b80f11eb1d3 | 411 | AA = -(l * l - xx * xx - yy * yy - r * r - zz * zz) / (2 * r * zz); |
heroistired | 0:2b80f11eb1d3 | 412 | BB = 2 * r * xx / (2 * r * zz); |
heroistired | 0:2b80f11eb1d3 | 413 | CC = BB * BB + 1; |
heroistired | 0:2b80f11eb1d3 | 414 | DD = 2 * AA * BB; |
heroistired | 0:2b80f11eb1d3 | 415 | EE = AA * AA - 1; |
heroistired | 0:2b80f11eb1d3 | 416 | delta = DD * DD - 4 * CC * EE; |
heroistired | 0:2b80f11eb1d3 | 417 | mytheta1 = acos((-DD + sqrt(delta)) / 2 / CC); |
heroistired | 0:2b80f11eb1d3 | 418 | mytheta2 = acos((-DD - sqrt(delta)) / 2 / CC); |
heroistired | 0:2b80f11eb1d3 | 419 | d = (xx + r * cos(mytheta1)) * (xx + r * cos(mytheta1)); |
heroistired | 0:2b80f11eb1d3 | 420 | e = yy * yy; |
heroistired | 0:2b80f11eb1d3 | 421 | f = (zz - r * sin(mytheta1)) * (zz - r * sin(mytheta1)); |
heroistired | 0:2b80f11eb1d3 | 422 | l1 = sqrt(d + e + f); |
heroistired | 0:2b80f11eb1d3 | 423 | d = (xx + r * cos(mytheta1)) * (xx + r * cos(mytheta1)); |
heroistired | 0:2b80f11eb1d3 | 424 | e = yy * yy; |
heroistired | 0:2b80f11eb1d3 | 425 | f = (zz - r * sin(-mytheta1)) * (zz - r * sin(-mytheta1)); |
heroistired | 0:2b80f11eb1d3 | 426 | l2 = sqrt(d + e + f); |
heroistired | 0:2b80f11eb1d3 | 427 | d = (xx + r * cos(mytheta2)) * (xx + r * cos(mytheta2)); |
heroistired | 0:2b80f11eb1d3 | 428 | e = yy * yy; |
heroistired | 0:2b80f11eb1d3 | 429 | f = (zz - r * sin(mytheta2)) * (zz - r * sin(mytheta2)); |
heroistired | 0:2b80f11eb1d3 | 430 | l3 = sqrt(d + e + f); |
heroistired | 0:2b80f11eb1d3 | 431 | d = (xx + r * cos(mytheta2)) * (xx + r * cos(mytheta2)); |
heroistired | 0:2b80f11eb1d3 | 432 | e = yy * yy; |
heroistired | 0:2b80f11eb1d3 | 433 | f = (zz - r * sin(-mytheta2)) * (zz - r * sin(-mytheta2)); |
heroistired | 0:2b80f11eb1d3 | 434 | l4 = sqrt(d + e + f); |
heroistired | 0:2b80f11eb1d3 | 435 | mytheta1 = mytheta1 / 3.1415926 * 180; |
heroistired | 0:2b80f11eb1d3 | 436 | mytheta2 = mytheta2 / 3.1415926 * 180; |
heroistired | 0:2b80f11eb1d3 | 437 | if(abs(l1 - l) <= 0.0001) |
heroistired | 0:2b80f11eb1d3 | 438 | { |
heroistired | 0:2b80f11eb1d3 | 439 | theta1 = mytheta1; |
heroistired | 0:2b80f11eb1d3 | 440 | } |
heroistired | 0:2b80f11eb1d3 | 441 | else if(abs(l2 - l) <= 0.0001) |
heroistired | 0:2b80f11eb1d3 | 442 | { |
heroistired | 0:2b80f11eb1d3 | 443 | theta1 = -mytheta1; |
heroistired | 0:2b80f11eb1d3 | 444 | } |
heroistired | 0:2b80f11eb1d3 | 445 | else if(abs(l3 - l) <= 0.0001) |
heroistired | 0:2b80f11eb1d3 | 446 | { |
heroistired | 0:2b80f11eb1d3 | 447 | theta1 = mytheta2; |
heroistired | 0:2b80f11eb1d3 | 448 | } |
heroistired | 0:2b80f11eb1d3 | 449 | else |
heroistired | 0:2b80f11eb1d3 | 450 | { |
heroistired | 0:2b80f11eb1d3 | 451 | theta1 = -mytheta2; |
heroistired | 0:2b80f11eb1d3 | 452 | } |
heroistired | 0:2b80f11eb1d3 | 453 | //点2 |
heroistired | 0:2b80f11eb1d3 | 454 | xx = topPlatform.Elements[f2(2,1,topPlatform.Size[1])] - bottomPlatform.Elements[f2(2,1,bottomPlatform.Size[1])]; |
heroistired | 0:2b80f11eb1d3 | 455 | yy = topPlatform.Elements[f2(2,2,topPlatform.Size[1])] - bottomPlatform.Elements[f2(2,2,bottomPlatform.Size[1])]; |
heroistired | 0:2b80f11eb1d3 | 456 | zz = topPlatform.Elements[f2(2,3,topPlatform.Size[1])] - bottomPlatform.Elements[f2(2,3,bottomPlatform.Size[1])]; |
heroistired | 0:2b80f11eb1d3 | 457 | AA = -(l * l - xx * xx - yy * yy - r * r - zz * zz) / (2 * r * zz); |
heroistired | 0:2b80f11eb1d3 | 458 | BB = -2 * r * xx / (2 * r * zz); |
heroistired | 0:2b80f11eb1d3 | 459 | CC = BB * BB + 1; |
heroistired | 0:2b80f11eb1d3 | 460 | DD = 2 * AA * BB; |
heroistired | 0:2b80f11eb1d3 | 461 | EE = AA * AA - 1; |
heroistired | 0:2b80f11eb1d3 | 462 | delta = DD * DD - 4 * CC * EE; |
heroistired | 0:2b80f11eb1d3 | 463 | mytheta1 = acos((-DD + sqrt(delta)) / 2 / CC); |
heroistired | 0:2b80f11eb1d3 | 464 | mytheta2 = acos((-DD - sqrt(delta)) / 2 / CC); |
heroistired | 0:2b80f11eb1d3 | 465 | d = (xx - r * cos(mytheta1)) * (xx - r * cos(mytheta1)); |
heroistired | 0:2b80f11eb1d3 | 466 | e = yy * yy; |
heroistired | 0:2b80f11eb1d3 | 467 | f = (zz - r * sin(mytheta1)) * (zz - r * sin(mytheta1)); |
heroistired | 0:2b80f11eb1d3 | 468 | l1 = sqrt(d + e + f); |
heroistired | 0:2b80f11eb1d3 | 469 | d = (xx - r * cos(mytheta1)) * (xx - r * cos(mytheta1)); |
heroistired | 0:2b80f11eb1d3 | 470 | e = yy * yy; |
heroistired | 0:2b80f11eb1d3 | 471 | f = (zz - r * sin(-mytheta1)) * (zz - r * sin(-mytheta1)); |
heroistired | 0:2b80f11eb1d3 | 472 | l2 = sqrt(d + e + f); |
heroistired | 0:2b80f11eb1d3 | 473 | d = (xx - r * cos(mytheta2)) * (xx - r * cos(mytheta2)); |
heroistired | 0:2b80f11eb1d3 | 474 | e = yy * yy; |
heroistired | 0:2b80f11eb1d3 | 475 | f = (zz - r * sin(mytheta2)) * (zz - r * sin(mytheta2)); |
heroistired | 0:2b80f11eb1d3 | 476 | l3 = sqrt(d + e + f); |
heroistired | 0:2b80f11eb1d3 | 477 | d = (xx - r * cos(mytheta2)) * (xx - r * cos(mytheta2)); |
heroistired | 0:2b80f11eb1d3 | 478 | e = yy * yy; |
heroistired | 0:2b80f11eb1d3 | 479 | f = (zz - r * sin(-mytheta2)) * (zz - r * sin(-mytheta2)); |
heroistired | 0:2b80f11eb1d3 | 480 | l4 = sqrt(d + e + f); |
heroistired | 0:2b80f11eb1d3 | 481 | mytheta1 = mytheta1 / 3.1415926 * 180; |
heroistired | 0:2b80f11eb1d3 | 482 | mytheta2 = mytheta2 / 3.1415926 * 180; |
heroistired | 0:2b80f11eb1d3 | 483 | if(abs(l1 - l) <= 0.0001) |
heroistired | 0:2b80f11eb1d3 | 484 | { |
heroistired | 0:2b80f11eb1d3 | 485 | theta2 = mytheta1; |
heroistired | 0:2b80f11eb1d3 | 486 | } |
heroistired | 0:2b80f11eb1d3 | 487 | else if(abs(l2 - l) <= 0.0001) |
heroistired | 0:2b80f11eb1d3 | 488 | { |
heroistired | 0:2b80f11eb1d3 | 489 | theta2 = -mytheta1; |
heroistired | 0:2b80f11eb1d3 | 490 | } |
heroistired | 0:2b80f11eb1d3 | 491 | else if(abs(l4 - l) <= 0.0001) |
heroistired | 0:2b80f11eb1d3 | 492 | { |
heroistired | 0:2b80f11eb1d3 | 493 | theta2 = mytheta2; |
heroistired | 0:2b80f11eb1d3 | 494 | } |
heroistired | 0:2b80f11eb1d3 | 495 | else |
heroistired | 0:2b80f11eb1d3 | 496 | { |
heroistired | 0:2b80f11eb1d3 | 497 | theta2 = -mytheta2; |
heroistired | 0:2b80f11eb1d3 | 498 | } |
heroistired | 0:2b80f11eb1d3 | 499 | //点3 |
heroistired | 0:2b80f11eb1d3 | 500 | MatrixSub(&topPlatform, 3, 1, 3, 4, &temp1); //等效于bottomPlatform(6,:) = (Rc * Rc * bottomPlatform(3, :)')'; |
heroistired | 0:2b80f11eb1d3 | 501 | MatrixTransposition(&temp1, &temp2); |
heroistired | 0:2b80f11eb1d3 | 502 | MatrixDot(&Rc, &temp2, &temp1); |
heroistired | 0:2b80f11eb1d3 | 503 | MatrixDot(&Rc, &temp1, &temp2); |
heroistired | 0:2b80f11eb1d3 | 504 | MatrixTransposition(&temp2, &temp1); |
heroistired | 0:2b80f11eb1d3 | 505 | xx = temp1.Elements[f2(1,1,temp1.Size[1])] - bottomPlatform.Elements[f2(1,1,bottomPlatform.Size[1])]; |
heroistired | 0:2b80f11eb1d3 | 506 | yy = temp1.Elements[f2(1,2,temp1.Size[1])] - bottomPlatform.Elements[f2(1,2,bottomPlatform.Size[1])]; |
heroistired | 0:2b80f11eb1d3 | 507 | zz = temp1.Elements[f2(1,3,temp1.Size[1])] - bottomPlatform.Elements[f2(1,3,bottomPlatform.Size[1])]; |
heroistired | 0:2b80f11eb1d3 | 508 | AA = -(l * l - xx * xx - yy * yy - r * r - zz * zz) / (2 * r * zz); |
heroistired | 0:2b80f11eb1d3 | 509 | BB = 2 * r * xx / (2 * r * zz); |
heroistired | 0:2b80f11eb1d3 | 510 | CC = BB * BB + 1; |
heroistired | 0:2b80f11eb1d3 | 511 | DD = 2 * AA * BB; |
heroistired | 0:2b80f11eb1d3 | 512 | EE = AA * AA - 1; |
heroistired | 0:2b80f11eb1d3 | 513 | delta = DD * DD - 4 * CC * EE; |
heroistired | 0:2b80f11eb1d3 | 514 | mytheta1 = acos((-DD + sqrt(delta)) / 2 / CC); |
heroistired | 0:2b80f11eb1d3 | 515 | mytheta2 = acos((-DD - sqrt(delta)) / 2 / CC); |
heroistired | 0:2b80f11eb1d3 | 516 | d = (xx + r * cos(mytheta1)) * (xx + r * cos(mytheta1)); |
heroistired | 0:2b80f11eb1d3 | 517 | e = yy * yy; |
heroistired | 0:2b80f11eb1d3 | 518 | f = (zz - r * sin(mytheta1)) * (zz - r * sin(mytheta1)); |
heroistired | 0:2b80f11eb1d3 | 519 | l1 = sqrt(d + e + f); |
heroistired | 0:2b80f11eb1d3 | 520 | d = (xx + r * cos(mytheta1)) * (xx + r * cos(mytheta1)); |
heroistired | 0:2b80f11eb1d3 | 521 | e = yy * yy; |
heroistired | 0:2b80f11eb1d3 | 522 | f = (zz - r * sin(-mytheta1)) * (zz - r * sin(-mytheta1)); |
heroistired | 0:2b80f11eb1d3 | 523 | l2 = sqrt(d + e + f); |
heroistired | 0:2b80f11eb1d3 | 524 | d = (xx + r * cos(mytheta2)) * (xx + r * cos(mytheta2)); |
heroistired | 0:2b80f11eb1d3 | 525 | e = yy * yy; |
heroistired | 0:2b80f11eb1d3 | 526 | f = (zz - r * sin(mytheta2)) * (zz - r * sin(mytheta2)); |
heroistired | 0:2b80f11eb1d3 | 527 | l3 = sqrt(d + e + f); |
heroistired | 0:2b80f11eb1d3 | 528 | d = (xx + r * cos(mytheta2)) * (xx + r * cos(mytheta2)); |
heroistired | 0:2b80f11eb1d3 | 529 | e = yy * yy; |
heroistired | 0:2b80f11eb1d3 | 530 | f = (zz - r * sin(-mytheta2)) * (zz - r * sin(-mytheta2)); |
heroistired | 0:2b80f11eb1d3 | 531 | l4 = sqrt(d + e + f); |
heroistired | 0:2b80f11eb1d3 | 532 | mytheta1 = mytheta1 / 3.1415926 * 180; |
heroistired | 0:2b80f11eb1d3 | 533 | mytheta2 = mytheta2 / 3.1415926 * 180; |
heroistired | 0:2b80f11eb1d3 | 534 | if(abs(l1 - l) <= 0.0001) |
heroistired | 0:2b80f11eb1d3 | 535 | { |
heroistired | 0:2b80f11eb1d3 | 536 | theta3 = mytheta1; |
heroistired | 0:2b80f11eb1d3 | 537 | } |
heroistired | 0:2b80f11eb1d3 | 538 | else if(abs(l2 - l) <= 0.0001) |
heroistired | 0:2b80f11eb1d3 | 539 | { |
heroistired | 0:2b80f11eb1d3 | 540 | theta3 = -mytheta1; |
heroistired | 0:2b80f11eb1d3 | 541 | } |
heroistired | 0:2b80f11eb1d3 | 542 | else if(abs(l4 - l) <= 0.0001) |
heroistired | 0:2b80f11eb1d3 | 543 | { |
heroistired | 0:2b80f11eb1d3 | 544 | theta3 = mytheta2; |
heroistired | 0:2b80f11eb1d3 | 545 | } |
heroistired | 0:2b80f11eb1d3 | 546 | else |
heroistired | 0:2b80f11eb1d3 | 547 | { |
heroistired | 0:2b80f11eb1d3 | 548 | theta3 = -mytheta2; |
heroistired | 0:2b80f11eb1d3 | 549 | } |
heroistired | 0:2b80f11eb1d3 | 550 | //点4 |
heroistired | 0:2b80f11eb1d3 | 551 | MatrixSub(&topPlatform, 4, 1, 4, 4, &temp1); //等效于bottomPlatform(6,:) = (Rc * Rc * bottomPlatform(3, :)')'; |
heroistired | 0:2b80f11eb1d3 | 552 | MatrixTransposition(&temp1, &temp2); |
heroistired | 0:2b80f11eb1d3 | 553 | MatrixDot(&Rc, &temp2, &temp1); |
heroistired | 0:2b80f11eb1d3 | 554 | MatrixDot(&Rc, &temp1, &temp2); |
heroistired | 0:2b80f11eb1d3 | 555 | MatrixTransposition(&temp2, &temp1); |
heroistired | 0:2b80f11eb1d3 | 556 | xx = temp1.Elements[f2(1,1,temp1.Size[1])] - bottomPlatform.Elements[f2(2,1,bottomPlatform.Size[1])]; |
heroistired | 0:2b80f11eb1d3 | 557 | yy = temp1.Elements[f2(1,2,temp1.Size[1])] - bottomPlatform.Elements[f2(2,2,bottomPlatform.Size[1])]; |
heroistired | 0:2b80f11eb1d3 | 558 | zz = temp1.Elements[f2(1,3,temp1.Size[1])] - bottomPlatform.Elements[f2(2,3,bottomPlatform.Size[1])]; |
heroistired | 0:2b80f11eb1d3 | 559 | AA = -(l * l - xx * xx - yy * yy - r * r - zz * zz) / (2 * r * zz); |
heroistired | 0:2b80f11eb1d3 | 560 | BB = -2 * r * xx / (2 * r * zz); |
heroistired | 0:2b80f11eb1d3 | 561 | CC = BB * BB + 1; |
heroistired | 0:2b80f11eb1d3 | 562 | DD = 2 * AA * BB; |
heroistired | 0:2b80f11eb1d3 | 563 | EE = AA * AA - 1; |
heroistired | 0:2b80f11eb1d3 | 564 | delta = DD * DD - 4 * CC * EE; |
heroistired | 0:2b80f11eb1d3 | 565 | mytheta1 = acos((-DD + sqrt(delta)) / 2 / CC); |
heroistired | 0:2b80f11eb1d3 | 566 | mytheta2 = acos((-DD - sqrt(delta)) / 2 / CC); |
heroistired | 0:2b80f11eb1d3 | 567 | d = (xx - r * cos(mytheta1)) * (xx - r * cos(mytheta1)); |
heroistired | 0:2b80f11eb1d3 | 568 | e = yy * yy; |
heroistired | 0:2b80f11eb1d3 | 569 | f = (zz - r * sin(mytheta1)) * (zz - r * sin(mytheta1)); |
heroistired | 0:2b80f11eb1d3 | 570 | l1 = sqrt(d + e + f); |
heroistired | 0:2b80f11eb1d3 | 571 | d = (xx - r * cos(mytheta1)) * (xx - r * cos(mytheta1)); |
heroistired | 0:2b80f11eb1d3 | 572 | e = yy * yy; |
heroistired | 0:2b80f11eb1d3 | 573 | f = (zz - r * sin(-mytheta1)) * (zz - r * sin(-mytheta1)); |
heroistired | 0:2b80f11eb1d3 | 574 | l2 = sqrt(d + e + f); |
heroistired | 0:2b80f11eb1d3 | 575 | d = (xx - r * cos(mytheta2)) * (xx - r * cos(mytheta2)); |
heroistired | 0:2b80f11eb1d3 | 576 | e = yy * yy; |
heroistired | 0:2b80f11eb1d3 | 577 | f = (zz - r * sin(mytheta2)) * (zz - r * sin(mytheta2)); |
heroistired | 0:2b80f11eb1d3 | 578 | l3 = sqrt(d + e + f); |
heroistired | 0:2b80f11eb1d3 | 579 | d = (xx - r * cos(mytheta2)) * (xx - r * cos(mytheta2)); |
heroistired | 0:2b80f11eb1d3 | 580 | e = yy * yy; |
heroistired | 0:2b80f11eb1d3 | 581 | f = (zz - r * sin(-mytheta2)) * (zz - r * sin(-mytheta2)); |
heroistired | 0:2b80f11eb1d3 | 582 | l4 = sqrt(d + e + f); |
heroistired | 0:2b80f11eb1d3 | 583 | mytheta1 = mytheta1 / 3.1415926 * 180; |
heroistired | 0:2b80f11eb1d3 | 584 | mytheta2 = mytheta2 / 3.1415926 * 180; |
heroistired | 0:2b80f11eb1d3 | 585 | if(abs(l1 - l) <= 0.0001) |
heroistired | 0:2b80f11eb1d3 | 586 | { |
heroistired | 0:2b80f11eb1d3 | 587 | theta4 = mytheta1; |
heroistired | 0:2b80f11eb1d3 | 588 | } |
heroistired | 0:2b80f11eb1d3 | 589 | else if(abs(l2 - l) <= 0.0001) |
heroistired | 0:2b80f11eb1d3 | 590 | { |
heroistired | 0:2b80f11eb1d3 | 591 | theta4 = -mytheta1; |
heroistired | 0:2b80f11eb1d3 | 592 | } |
heroistired | 0:2b80f11eb1d3 | 593 | else if(abs(l4 - l) <= 0.0001) |
heroistired | 0:2b80f11eb1d3 | 594 | { |
heroistired | 0:2b80f11eb1d3 | 595 | theta4 = mytheta2; |
heroistired | 0:2b80f11eb1d3 | 596 | } |
heroistired | 0:2b80f11eb1d3 | 597 | else |
heroistired | 0:2b80f11eb1d3 | 598 | { |
heroistired | 0:2b80f11eb1d3 | 599 | theta4 = -mytheta2; |
heroistired | 0:2b80f11eb1d3 | 600 | } |
heroistired | 0:2b80f11eb1d3 | 601 | //点5 |
heroistired | 0:2b80f11eb1d3 | 602 | MatrixSub(&topPlatform, 5, 1, 5, 4, &temp1); //等效于bottomPlatform(6,:) = (Rc * Rc * bottomPlatform(3, :)')'; |
heroistired | 0:2b80f11eb1d3 | 603 | MatrixTransposition(&temp1, &temp2); |
heroistired | 0:2b80f11eb1d3 | 604 | MatrixDot(&Rc, &temp2, &temp1); |
heroistired | 0:2b80f11eb1d3 | 605 | MatrixTransposition(&temp1, &temp2); |
heroistired | 0:2b80f11eb1d3 | 606 | xx = temp2.Elements[f2(1,1,temp2.Size[1])] - bottomPlatform.Elements[f2(1,1,bottomPlatform.Size[1])]; |
heroistired | 0:2b80f11eb1d3 | 607 | yy = temp2.Elements[f2(1,2,temp2.Size[1])] - bottomPlatform.Elements[f2(1,2,bottomPlatform.Size[1])]; |
heroistired | 0:2b80f11eb1d3 | 608 | zz = temp2.Elements[f2(1,3,temp2.Size[1])] - bottomPlatform.Elements[f2(1,3,bottomPlatform.Size[1])]; |
heroistired | 0:2b80f11eb1d3 | 609 | AA = -(l * l - xx * xx - yy * yy - r * r - zz * zz) / (2 * r * zz); |
heroistired | 0:2b80f11eb1d3 | 610 | BB = 2 * r * xx / (2 * r * zz); |
heroistired | 0:2b80f11eb1d3 | 611 | CC = BB * BB + 1; |
heroistired | 0:2b80f11eb1d3 | 612 | DD = 2 * AA * BB; |
heroistired | 0:2b80f11eb1d3 | 613 | EE = AA * AA - 1; |
heroistired | 0:2b80f11eb1d3 | 614 | delta = DD * DD - 4 * CC * EE; |
heroistired | 0:2b80f11eb1d3 | 615 | mytheta1 = acos((-DD + sqrt(delta)) / 2 / CC); |
heroistired | 0:2b80f11eb1d3 | 616 | mytheta2 = acos((-DD - sqrt(delta)) / 2 / CC); |
heroistired | 0:2b80f11eb1d3 | 617 | d = (xx + r * cos(mytheta1)) * (xx + r * cos(mytheta1)); |
heroistired | 0:2b80f11eb1d3 | 618 | e = yy * yy; |
heroistired | 0:2b80f11eb1d3 | 619 | f = (zz - r * sin(mytheta1)) * (zz - r * sin(mytheta1)); |
heroistired | 0:2b80f11eb1d3 | 620 | l1 = sqrt(d + e + f); |
heroistired | 0:2b80f11eb1d3 | 621 | d = (xx + r * cos(mytheta1)) * (xx + r * cos(mytheta1)); |
heroistired | 0:2b80f11eb1d3 | 622 | e = yy * yy; |
heroistired | 0:2b80f11eb1d3 | 623 | f = (zz - r * sin(-mytheta1)) * (zz - r * sin(-mytheta1)); |
heroistired | 0:2b80f11eb1d3 | 624 | l2 = sqrt(d + e + f); |
heroistired | 0:2b80f11eb1d3 | 625 | d = (xx + r * cos(mytheta2)) * (xx + r * cos(mytheta2)); |
heroistired | 0:2b80f11eb1d3 | 626 | e = yy * yy; |
heroistired | 0:2b80f11eb1d3 | 627 | f = (zz - r * sin(mytheta2)) * (zz - r * sin(mytheta2)); |
heroistired | 0:2b80f11eb1d3 | 628 | l3 = sqrt(d + e + f); |
heroistired | 0:2b80f11eb1d3 | 629 | d = (xx + r * cos(mytheta2)) * (xx + r * cos(mytheta2)); |
heroistired | 0:2b80f11eb1d3 | 630 | e = yy * yy; |
heroistired | 0:2b80f11eb1d3 | 631 | f = (zz - r * sin(-mytheta2)) * (zz - r * sin(-mytheta2)); |
heroistired | 0:2b80f11eb1d3 | 632 | l4 = sqrt(d + e + f); |
heroistired | 0:2b80f11eb1d3 | 633 | mytheta1 = mytheta1 / 3.1415926 * 180; |
heroistired | 0:2b80f11eb1d3 | 634 | mytheta2 = mytheta2 / 3.1415926 * 180; |
heroistired | 0:2b80f11eb1d3 | 635 | if(abs(l1 - l) <= 0.0001) |
heroistired | 0:2b80f11eb1d3 | 636 | { |
heroistired | 0:2b80f11eb1d3 | 637 | theta5 = mytheta1; |
heroistired | 0:2b80f11eb1d3 | 638 | } |
heroistired | 0:2b80f11eb1d3 | 639 | else if(abs(l2 - l) <= 0.0001) |
heroistired | 0:2b80f11eb1d3 | 640 | { |
heroistired | 0:2b80f11eb1d3 | 641 | theta5 = -mytheta1; |
heroistired | 0:2b80f11eb1d3 | 642 | } |
heroistired | 0:2b80f11eb1d3 | 643 | else if(abs(l4 - l) <= 0.0001) |
heroistired | 0:2b80f11eb1d3 | 644 | { |
heroistired | 0:2b80f11eb1d3 | 645 | theta5 = mytheta2; |
heroistired | 0:2b80f11eb1d3 | 646 | } |
heroistired | 0:2b80f11eb1d3 | 647 | else |
heroistired | 0:2b80f11eb1d3 | 648 | { |
heroistired | 0:2b80f11eb1d3 | 649 | theta5 = -mytheta2; |
heroistired | 0:2b80f11eb1d3 | 650 | } |
heroistired | 0:2b80f11eb1d3 | 651 | //点6 |
heroistired | 0:2b80f11eb1d3 | 652 | MatrixSub(&topPlatform, 6, 1, 6, 4, &temp1); //等效于bottomPlatform(6,:) = (Rc * Rc * bottomPlatform(3, :)')'; |
heroistired | 0:2b80f11eb1d3 | 653 | MatrixTransposition(&temp1, &temp2); |
heroistired | 0:2b80f11eb1d3 | 654 | MatrixDot(&Rc, &temp2, &temp1); |
heroistired | 0:2b80f11eb1d3 | 655 | MatrixTransposition(&temp1, &temp2); |
heroistired | 0:2b80f11eb1d3 | 656 | xx = temp2.Elements[f2(1,1,temp2.Size[1])] - bottomPlatform.Elements[f2(2,1,bottomPlatform.Size[1])]; |
heroistired | 0:2b80f11eb1d3 | 657 | yy = temp2.Elements[f2(1,2,temp2.Size[1])] - bottomPlatform.Elements[f2(2,2,bottomPlatform.Size[1])]; |
heroistired | 0:2b80f11eb1d3 | 658 | zz = temp2.Elements[f2(1,3,temp2.Size[1])] - bottomPlatform.Elements[f2(2,3,bottomPlatform.Size[1])]; |
heroistired | 0:2b80f11eb1d3 | 659 | AA = -(l * l - xx * xx - yy * yy - r * r - zz * zz) / (2 * r * zz); |
heroistired | 0:2b80f11eb1d3 | 660 | BB = -2 * r * xx / (2 * r * zz); |
heroistired | 0:2b80f11eb1d3 | 661 | CC = BB * BB + 1; |
heroistired | 0:2b80f11eb1d3 | 662 | DD = 2 * AA * BB; |
heroistired | 0:2b80f11eb1d3 | 663 | EE = AA * AA - 1; |
heroistired | 0:2b80f11eb1d3 | 664 | delta = DD * DD - 4 * CC * EE; |
heroistired | 0:2b80f11eb1d3 | 665 | mytheta1 = acos((-DD + sqrt(delta)) / 2 / CC); |
heroistired | 0:2b80f11eb1d3 | 666 | mytheta2 = acos((-DD - sqrt(delta)) / 2 / CC); |
heroistired | 0:2b80f11eb1d3 | 667 | d = (xx - r * cos(mytheta1)) * (xx - r * cos(mytheta1)); |
heroistired | 0:2b80f11eb1d3 | 668 | e = yy * yy; |
heroistired | 0:2b80f11eb1d3 | 669 | f = (zz - r * sin(mytheta1)) * (zz - r * sin(mytheta1)); |
heroistired | 0:2b80f11eb1d3 | 670 | l1 = sqrt(d + e + f); |
heroistired | 0:2b80f11eb1d3 | 671 | d = (xx - r * cos(mytheta1)) * (xx - r * cos(mytheta1)); |
heroistired | 0:2b80f11eb1d3 | 672 | e = yy * yy; |
heroistired | 0:2b80f11eb1d3 | 673 | f = (zz - r * sin(-mytheta1)) * (zz - r * sin(-mytheta1)); |
heroistired | 0:2b80f11eb1d3 | 674 | l2 = sqrt(d + e + f); |
heroistired | 0:2b80f11eb1d3 | 675 | d = (xx - r * cos(mytheta2)) * (xx - r * cos(mytheta2)); |
heroistired | 0:2b80f11eb1d3 | 676 | e = yy * yy; |
heroistired | 0:2b80f11eb1d3 | 677 | f = (zz - r * sin(mytheta2)) * (zz - r * sin(mytheta2)); |
heroistired | 0:2b80f11eb1d3 | 678 | l3 = sqrt(d + e + f); |
heroistired | 0:2b80f11eb1d3 | 679 | d = (xx - r * cos(mytheta2)) * (xx - r * cos(mytheta2)); |
heroistired | 0:2b80f11eb1d3 | 680 | e = yy * yy; |
heroistired | 0:2b80f11eb1d3 | 681 | f = (zz - r * sin(-mytheta2)) * (zz - r * sin(-mytheta2)); |
heroistired | 0:2b80f11eb1d3 | 682 | l4 = sqrt(d + e + f); |
heroistired | 0:2b80f11eb1d3 | 683 | mytheta1 = mytheta1 / 3.1415926 * 180; |
heroistired | 0:2b80f11eb1d3 | 684 | mytheta2 = mytheta2 / 3.1415926 * 180; |
heroistired | 0:2b80f11eb1d3 | 685 | if(abs(l1 - l) <= 0.0001) |
heroistired | 0:2b80f11eb1d3 | 686 | { |
heroistired | 0:2b80f11eb1d3 | 687 | theta6 = mytheta1; |
heroistired | 0:2b80f11eb1d3 | 688 | } |
heroistired | 0:2b80f11eb1d3 | 689 | else if(abs(l2 - l) <= 0.0001) |
heroistired | 0:2b80f11eb1d3 | 690 | { |
heroistired | 0:2b80f11eb1d3 | 691 | theta6 = -mytheta1; |
heroistired | 0:2b80f11eb1d3 | 692 | } |
heroistired | 0:2b80f11eb1d3 | 693 | else if(abs(l4 - l) <= 0.0001) |
heroistired | 0:2b80f11eb1d3 | 694 | { |
heroistired | 0:2b80f11eb1d3 | 695 | theta6 = mytheta2; |
heroistired | 0:2b80f11eb1d3 | 696 | } |
heroistired | 0:2b80f11eb1d3 | 697 | else |
heroistired | 0:2b80f11eb1d3 | 698 | { |
heroistired | 0:2b80f11eb1d3 | 699 | theta6 = -mytheta2; |
heroistired | 0:2b80f11eb1d3 | 700 | } |
heroistired | 0:2b80f11eb1d3 | 701 | Platform->theta[0] = theta1; |
heroistired | 0:2b80f11eb1d3 | 702 | Platform->theta[1] = theta2; |
heroistired | 0:2b80f11eb1d3 | 703 | Platform->theta[2] = theta3; |
heroistired | 0:2b80f11eb1d3 | 704 | Platform->theta[3] = theta4; |
heroistired | 0:2b80f11eb1d3 | 705 | Platform->theta[4] = theta5; |
heroistired | 0:2b80f11eb1d3 | 706 | Platform->theta[5] = theta6; |
heroistired | 0:2b80f11eb1d3 | 707 | theta0 = atan(lengthOfCardan / lengthOfSteelWheel) / 3.1415926 * 180; |
heroistired | 0:2b80f11eb1d3 | 708 | Platform->theta_servo[0] = theta1 - theta0; |
heroistired | 0:2b80f11eb1d3 | 709 | Platform->theta_servo[1] = theta2 - theta0; |
heroistired | 0:2b80f11eb1d3 | 710 | Platform->theta_servo[2] = theta3 - theta0; |
heroistired | 0:2b80f11eb1d3 | 711 | Platform->theta_servo[3] = theta4 - theta0; |
heroistired | 0:2b80f11eb1d3 | 712 | Platform->theta_servo[4] = theta5 - theta0; |
heroistired | 0:2b80f11eb1d3 | 713 | Platform->theta_servo[5] = theta6 - theta0; |
heroistired | 0:2b80f11eb1d3 | 714 | } |
heroistired | 0:2b80f11eb1d3 | 715 | |
heroistired | 0:2b80f11eb1d3 | 716 | |
heroistired | 0:2b80f11eb1d3 | 717 | |
heroistired | 0:2b80f11eb1d3 | 718 | //******************************************** |
heroistired | 0:2b80f11eb1d3 | 719 | //功能:角度制的三角函数 余弦 |
heroistired | 0:2b80f11eb1d3 | 720 | //输入参数:angle:角度 |
heroistired | 0:2b80f11eb1d3 | 721 | //输出参数:无 |
heroistired | 0:2b80f11eb1d3 | 722 | //返回值:三角函数值 |
heroistired | 0:2b80f11eb1d3 | 723 | //调用外部函数:无 |
heroistired | 0:2b80f11eb1d3 | 724 | //作者:陈欢 h-che14@mails.tsinghua.edu.cn |
heroistired | 0:2b80f11eb1d3 | 725 | //******************************************** |
heroistired | 0:2b80f11eb1d3 | 726 | float cosd(float angle) |
heroistired | 0:2b80f11eb1d3 | 727 | { |
heroistired | 0:2b80f11eb1d3 | 728 | return cos(angle/180*3.1415926); |
heroistired | 0:2b80f11eb1d3 | 729 | } |
heroistired | 0:2b80f11eb1d3 | 730 | |
heroistired | 0:2b80f11eb1d3 | 731 | //******************************************** |
heroistired | 0:2b80f11eb1d3 | 732 | //功能:角度制的三角函数 正弦 |
heroistired | 0:2b80f11eb1d3 | 733 | //输入参数:angle:角度 |
heroistired | 0:2b80f11eb1d3 | 734 | //输出参数:无 |
heroistired | 0:2b80f11eb1d3 | 735 | //返回值:三角函数值 |
heroistired | 0:2b80f11eb1d3 | 736 | //调用外部函数:无 |
heroistired | 0:2b80f11eb1d3 | 737 | //作者:陈欢 h-che14@mails.tsinghua.edu.cn |
heroistired | 0:2b80f11eb1d3 | 738 | //******************************************** |
heroistired | 0:2b80f11eb1d3 | 739 | float sind(float angle) |
heroistired | 0:2b80f11eb1d3 | 740 | { |
heroistired | 0:2b80f11eb1d3 | 741 | return sin(angle/180*3.1415926); |
heroistired | 0:2b80f11eb1d3 | 742 | } |
heroistired | 0:2b80f11eb1d3 | 743 | |
heroistired | 0:2b80f11eb1d3 | 744 | |
heroistired | 0:2b80f11eb1d3 | 745 | //******************************************** |
heroistired | 0:2b80f11eb1d3 | 746 | //功能:在命令行打印矩阵 |
heroistired | 0:2b80f11eb1d3 | 747 | //输入参数:A:要打印的矩阵 |
heroistired | 0:2b80f11eb1d3 | 748 | //输出参数:无 |
heroistired | 0:2b80f11eb1d3 | 749 | //返回值:无 |
heroistired | 0:2b80f11eb1d3 | 750 | //调用外部函数:无 |
heroistired | 0:2b80f11eb1d3 | 751 | //作者:陈欢 h-che14@mails.tsinghua.edu.cn |
heroistired | 0:2b80f11eb1d3 | 752 | //******************************************** |
heroistired | 0:2b80f11eb1d3 | 753 | void PrintMatrix(MatrixType* A) |
heroistired | 0:2b80f11eb1d3 | 754 | { |
heroistired | 0:2b80f11eb1d3 | 755 | int i, j; |
heroistired | 0:2b80f11eb1d3 | 756 | int pos2 = 0; |
heroistired | 0:2b80f11eb1d3 | 757 | printf("\r\nThe Matrix is:\r\n"); |
heroistired | 0:2b80f11eb1d3 | 758 | for(i = 1; i <= A->Size[0]; i++) |
heroistired | 0:2b80f11eb1d3 | 759 | { |
heroistired | 0:2b80f11eb1d3 | 760 | for(j = 1; j <= A->Size[1]; j++) |
heroistired | 0:2b80f11eb1d3 | 761 | { |
heroistired | 0:2b80f11eb1d3 | 762 | pos2 = f2(i,j,A->Size[1]); |
heroistired | 0:2b80f11eb1d3 | 763 | printf(" %f ", A->Elements[pos2]); |
heroistired | 0:2b80f11eb1d3 | 764 | } |
heroistired | 0:2b80f11eb1d3 | 765 | printf("\r\n"); |
heroistired | 0:2b80f11eb1d3 | 766 | } |
heroistired | 0:2b80f11eb1d3 | 767 | } |
heroistired | 0:2b80f11eb1d3 | 768 |