|
您好,我的定位代码是这样的
int zuixiao3d(vec3d* report,int use4thAnchor,vec3d* anchorArray,int* distanceArray)
{
if (use4thAnchor == 1)
{
float Res[4];
float BS1[3] = { anchorArray[0].x, anchorArray[0].y, anchorArray[0].z};
float BS2[3] = { anchorArray[1].x, anchorArray[1].y, anchorArray[1].z };
float BS3[3] = { anchorArray[2].x, anchorArray[2].y, anchorArray[2].z };
float BS4[3] = { anchorArray[3].x, anchorArray[3].y, anchorArray[3].z};
float pack_r_measure[4];
float A[16] = {
1, -2 * BS1[0], -2 * BS1[1], -2 * BS1[2],
1, -2 * BS2[0], -2 * BS2[1], -2 * BS2[2],
1, -2 * BS3[0], -2 * BS3[1], -2 * BS3[2],
1, -2 * BS4[0], -2 * BS4[1], -2 * BS4[2]
};
float B[4];
for (int i = 0; i < 4; i++) {
pack_r_measure = distanceArray / 1000.0 ;
}
B[0] = pack_r_measure[0] * pack_r_measure[0] - BS1[0] * BS1[0] - BS1[1] * BS1[1] - BS1[2] * BS1[2];
B[1] = pack_r_measure[1] * pack_r_measure[1] - BS2[0] * BS2[0] - BS2[1] * BS2[1] - BS2[2] * BS2[2];
B[2] = pack_r_measure[2] * pack_r_measure[2] - BS3[0] * BS3[0] - BS3[1] * BS3[1] - BS3[2] * BS3[2];
B[3] = pack_r_measure[3] * pack_r_measure[3] - BS4[0] * BS4[0] - BS4[1] * BS4[1] - BS4[2] * BS4[2];
// ?????? At ???
float At[16];
// ?????? Ax ???
float Ax[16];
// ?????? A_ ???
float A_[16];
// ?????? Ac ???
float Ac[16];
// ?????? Res ???
//Res[4]= (float *)malloc(4 * sizeof(float));
MatrixTrans(A, At,4,4);
MatrixMul(At, A, Ax,4, 4, 4 );
MatrixInv1(Ax, A_,4,4);
MatrixMul(A_, At, Ac,4, 4, 4 );
MatrixMul( Ac, B, Res,4, 4, 1);
report->x=Res[1];
report->y=Res[2];
report->z=Res[3];
}
else
{
float Res[2];
float BS1[3] = { anchorArray[0].x, anchorArray[0].y};
float BS2[3] = { anchorArray[1].x, anchorArray[1].y};
float BS3[3] = { anchorArray[2].x, anchorArray[2].y};
//float BS4[3] = { anchorArray[3].x, anchorArray[3].y};
float pack_r_measure[3];
float B[2];
for (int i = 0; i < 3; i++) {
pack_r_measure = distanceArray / 1000.0 ;
}
float A[4] = {
2 * (BS1[0] -BS2[0]), 2 * (BS1[1]-BS2[1]),
2 * (BS1[0] -BS3[0]), 2 * (BS1[1]-BS3[1])
};
B[0] = pack_r_measure[1] * pack_r_measure[1]-pack_r_measure[0] * pack_r_measure[0] - BS2[0] * BS2[0] - BS2[1] * BS2[1]+ BS1[0] * BS1[0] + BS1[1] * BS1[1];
B[1] = pack_r_measure[2] * pack_r_measure[2]-pack_r_measure[0] * pack_r_measure[0] - BS3[0] * BS3[0] - BS3[1] * BS3[1]+ BS1[0] * BS1[0] + BS1[1] * BS1[1];
// ?????? At ???
float At[4];
// ?????? Ax ???
float Ax[4];
// ?????? A_ ???
float A_[4];
// ?????? Ac ???
float Ac[4];
// ?????? Res ???
//Res[4]= (float *)malloc(4 * sizeof(float));
MatrixTrans(A, At,2,2);
MatrixMul(At, A, Ax,2, 2, 2 );
MatrixInv1(Ax, A_,2,2);
MatrixMul(A_, At, Ac,2, 2, 2 );
MatrixMul( Ac, B, Res,2, 2, 1);
report->x=Res[0];
report->y=Res[1];
report->z=0;
}
return 1;
}
distance_mange有关的使用是这样的
zuixiao3d(&Res,i,AnchorList,Anthordistance);
sprintf(dist_str, "x:%3.2f", (float)Res.x);
OLED_ShowString(0, 2,dist_str);
sprintf(dist_str, "y:%3.2f", (float)Res.y);
OLED_ShowString(0, 4,dist_str);
sprintf(dist_str, "z:%3.2f", (float)Res.z);
OLED_ShowString(0, 6,dist_str);
但是不知道为什么总是连接不到标签,删除掉就没有问题,所以能不能帮忙看一下哪里有问题呀 |
|