Hi guys
Back again with reverse transformations for my RLG INS simulation:
In the above image, an aircraft is depicted by the set of axes on the left, at 29.54233° latitude on the earth, with a heading of 150.12° and a pitch and bank of 0. The RLGs detect the earth's rotation rate of 15°/hr and the P/R/Y rate values indicate the earth rate sensed by each RLG in its respective axis.
By reversing the pitch and roll transformation, and then taking the atan2 of the resulting pitch and roll rates, I can calculate the aircraft true heading (the CH value. Ignore the difference between it and actual heading. That's due to a normally distributed error applied to the calculation to simulate gyro inaccuracies). However, by taking the sin^-1 of the yaw rate/earth rate, I can calculate the aircraft latitude. This works all well and fine when pitch is 0, but quickly goes haywire if I change pitch. I know my other transforms are correct because the calculated heading is always consistent with the actual heading. Could someone spot the error in my reverse transformation for the yaw rate in the code below?
Thanks
JB
double cp = cos(D2A(att1[0])), sp = sin(D2A(att1[0]));//pitch
double cb = cos(D2A(att1[1])), sb = sin(D2A(att1[1]));//bank
double ch = cos(D2A(att1[2])), sh = sin(D2A(att1[2]));//heading
double clat = cos(D2A(lat - 90.0)), slat = sin(D2A(lat - 90.0));
double mat1[3][3];
double mat2[3][3];
mat1[0][0] = cp*cb;
mat1[1][0] = cp*sb;
mat1[2][0] = -sp;
mat1[0][1] = sh*sp*cb - ch*sb;
mat1[1][1] = sh*sp*sb + ch*cb;
mat1[2][1] = sh*cp;
mat1[0][2] = ch*sp*cb + sh*sb;
mat1[1][2] = ch*sp*sb - sh*cb;
mat1[2][2] = ch*cp;
mat2[0][0] = clat;
mat2[1][0] = 0;
mat2[2][0] = -slat;
mat2[0][1] = 0;
mat2[1][1] = 0;
mat2[2][1] = 0;
mat2[0][2] = 0;
mat2[1][2] = 0;
mat2[2][2] = 0;
//Transform pitch/roll/yaw matrix by latitude matrix
double mat3[3][3] =
{
mat1[0][0]*mat2[0][0] + mat1[0][1]*mat2[1][0] + mat1[0][2]*mat2[2][0], mat1[0][0]*mat2[0][1] + mat1[0][1]*mat2[1][1] + mat1[0][2]*mat2[2][1], mat1[0][0]*mat2[0][2] + mat1[0][1]*mat2[1][2] + mat1[0][2]*mat2[2][2],
mat1[1][0]*mat2[0][0] + mat1[1][1]*mat2[1][0] + mat1[1][2]*mat2[2][0], mat1[1][0]*mat2[0][1] + mat1[1][1]*mat2[1][1] + mat1[1][2]*mat2[2][1], mat1[1][0]*mat2[0][2] + mat1[1][1]*mat2[1][2] + mat1[1][2]*mat2[2][2],
mat1[2][0]*mat2[0][0] + mat1[2][1]*mat2[1][0] + mat1[2][2]*mat2[2][0], mat1[2][0]*mat2[0][1] + mat1[2][1]*mat2[1][1] + mat1[2][2]*mat2[2][1], mat1[2][0]*mat2[0][2] + mat1[2][1]*mat2[1][2] + mat1[2][2]*mat2[2][2]
};
//Transform earth rate by pitch/roll/yaw/heading matrix
double rate[3] =
{
15.0 * mat3[1][0] + 15.0 * mat3[1][1] + 15.0 * mat3[1][2],//Pitch rate
15.0 * mat3[0][0] + 15.0 * mat3[0][1] + 15.0 * mat3[0][2],//Yaw rate
15.0 * mat3[2][0] + 15.0 * mat3[2][1] + 15.0 * mat3[2][2],//Roll rate
};
double pr = rate[0] * cb - rate[1] * sb;//This one is fine
double rr = rate[2] * cp + rate[1] * sp*cb + rate[0] * sb*sp;//This one is fine
double yr = (rate[0] * sb + rate[1] * cb) * (1.0/cp);//This one is faulty. Any ideas?
//Calculate latitude from yaw rate
double _calclat = A2D(asin(yr / 15.0));