我正在使用Reach RS +设备来捕获GPS位置数据以及IMU数据(侧倾,俯仰和偏航);请参阅制造商的website上的“积分收集”图片。
我正在尝试确定底点(接收器固定在其上的杆的空端)的GPS坐标。
为了能够以米为单位进行计算,我将经度( X )和纬度( Y )转换为UTM,同时保持高度( Z < / em>)保持不变。
当杆直立时, X 和 Y 保持不变,而
Z1 = Z - ROD_LENGTH
但是,当杆倾斜时,所有坐标都会受到影响,我需要一种方法来计算杆的最终位置。
我已经根据实验观察了旋转矩阵,三角方程,我自己的 sin 和 cos 公式,但是我没有3D几何背景,并且我没有确定走哪条路线(例如,我不知道如何将杆长与旋转矩阵一起使用)。
基本上,我需要以下公式:
X1 = X + ROD_LENGTH * func_X(roll, pitch, yaw)
Y1 = Y + ROD_LENGTH * func_Y(roll, pitch, yaw)
Z1 = Z + ROD_LENGTH * func_Z(roll, pitch, yaw)
滚动,俯仰和偏航的值介于-180°和180°之间。
答案 0 :(得分:1)
我必须说,事实证明这比我预期的要复杂得多。我想我已经很直截了当了,但是请在任何更正的评论中告知我,我将尝试修复。
在看下面的代码之前,请注意!这些假设很重要,您需要验证它们是否适用。有数十种(至少!)定义空间方向和位置的方法。您需要确保与设备对齐的主要假设是我们在其中进行操作的空间框架。 This article将使您感激这为何如此重要!最明显的是如何标记轴,即向上标记(正Z号,如我在下面选择的,但是例如,在谈论潜艇时,我们可能会选择负Z号)。
框架假设:想象一下一架飞机(我知道它不是飞机,但用这种方式更容易解释),直立地悬挂着一根长杆。我们将Z轴定义为向上(正)和向下(负)。 X轴指向前(正)和后(负)。 Y轴是绕机翼旋转的轴,左翼为正,右翼为负-这是“ right handed coordinate system”。因此,轴相交在飞机的中间,大约是机翼所在的位置。旋转定义为绕轴逆时针旋转为正角,顺时针旋转为负。所以...
所有这些都非常重要,尤其是与您的角度相关的符号(+/-)-尝试将其倾斜并滚动约30度,并确保结果与输出一致-否则更改符号角度。进行偏航时,您需要同时更改航向以及俯仰和横滚,因为航向本身不会影响杆端的位置(如果杆是向上或向下的话)。 如上所述,您描述“飞机”的数据是位置(三个数字),位于相同的XYZ框架中,三个角度(度数为-180到180度)。
代码:
我遗留了一些不必要的东西(可能需要重新构造它),并且也没有尝试使其变得更有效率(例如,不断地重新计算相同的正弦和余弦)来使其变得更有效。清楚一点。我留下了闭包编译器的类型,既有一些文档说明,也有待以后缩小的地方。 rodloc
是您想要的功能...
function presentresult(location, length, yaw, pitch, roll) {
console.log("Starting point");
console.log(location);
console.log("Rod length = " + length);
console.log("Yaw = " + yaw + ", Pitch = " + pitch + ", Roll = " + roll);
console.log("Result:");
console.log(rodloc(location, length, yaw, pitch, roll));
}
presentresult([100, 100, 100], 2, 0, 0, 0); // Result: [100, 100, 98] (3)
presentresult([100, 100, 100], 2, 30, 0, 0); // Result: [100, 100, 98] (3)
presentresult([100, 100, 100], 2, -30, 0, 0); // Result: [100, 100, 98] (3)
presentresult([100, 100, 100], 2, 0, 30, 0); // Result: [99, 100, 98.26794919243112] (3)
presentresult([100, 100, 100], 2, 0, -30, 0); // Result: [101, 100, 98.26794919243112] (3)
presentresult([100, 100, 100], 2, 0, 0, 30); // Result: [100, 101, 98.26794919243112] (3)
presentresult([100, 100, 100], 2, 0, 0, -30); // Result: [100, 99, 98.26794919243112] (3)
presentresult([100, 100, 100], 2, 30, 30, 30); // Result: [98.75, 100.43301270189222, 98.5] (3)
presentresult([100, 100, 100], 2, -30, -30, -30); // Result: [100.25, 98.70096189432334, 98.5] (3)
presentresult([100, 100, 100], 2, -30, 30, -30); // Result: [98.75, 99.56698729810778, 98.5] (3)
/** @typedef {Array<number,number,number>} */ var Vector3D;
/** @typedef {Array<Vector3D,vector3D,Vector3D>} */ var Matrix3D;
/**
* @param {Vector3D} location - The location (3 coordinates) of the "plane"
* @param {number} length - The length of the rod
* @param {number} yaw - the yaw (heading) in degrees
* @param {number} pitch - the pitch in degrees
* @param {number} roll - the roll in degrees
* @returns {Vector3D} - the location of the end of the rod
*/
function rodloc(location, length, yaw, pitch, roll) {
let ryaw = yaw * Math.PI / 180.0; // Convert to radians
let rpitch = pitch * Math.PI / 180.0;
let rroll = roll * Math.PI / 180.0;
// This is where our axes start
let x = [1, 0, 0];
let y = [0, 1, 0];
let z = [0, 0, 1];
// NOTE: ORDER MATTERS - your data may mean different things (see
// assumptions in answer!
// Rotate axes around z by yaw
let yprime = rotatearound([0, 1, 0], [0, 0, 1], ryaw);
let xprime = rotatearound([1, 0, 0], [0, 0, 1], ryaw);
let zprime = z; // rotating around itself
// Next we need to rotate for pitch (around the Y axis...)
let x2prime = rotatearound(xprime, yprime, rpitch);
let y2prime = yprime; // dont need this
let z2prime = rotatearound(zprime, yprime, rpitch);
// Now we need to roll around the new x axis...
let x3prime = x2prime // dont need this
let y3prime = rotatearound(y2prime, x2prime, rroll); // dont need this
let z3prime = rotatearound(z2prime, x2prime, rroll);
// now take what started out as [0, 0, 1] and place the end of the rod
// (at what started out as [0, 0, -length])
let rotend = [0,1,2].map(n=>-length*z3prime[n]);
// now take that and add it to the original location of the plane
// and return it as the result
return [0,1,2].map(n=>location[n]+rotend[n]);
}
/** Multiply a vector times a matrix
* @param {Vector3D} offset - The vector of the offset
* @param {Matrix3D} rotate - The rotation vector
* @returns {Vector3D} - The new offset vector
*/
function vmmult(offset, rotate) {
return [0,1,2].map(x=>xmult(offset,rotate[x]));
}
/** dot product of two vectors
* @param {Vector3D} col
* @param {Vector3D} row
* @returns {number}
*/
function xmult(col, row) {
return [0,1,2].reduce((a,c)=>a+col[c]*row[c],0);
}
/** Rotate a point around a vector projecting from the origin
* @param {Vector3D} point - the we want to rotate
* @param {Vector3D} vec - the vector (from origin to here) to rotate around
* @param {number} angle - the angle (in radians) to rotate
* @returns {Vector3D} - the new point location
*/
function rotatearound(point, vec, angle) {
let rotmat = setuprotationmatrix(angle, vec);
return vmmult(point, rotmat);
}
/**
* Adapted from C courtesy of Bibek Subedi
* https://www.programming-techniques.com/2012/03/3d-rotation-algorithm-about-arbitrary.html
* @param {number} angle - the angle to rotate around the vector
* @param {Vector3D} vec - the vector around which to rotate
* @returns {Matrix3D} - the rotation matrix
*/
function setuprotationmatrix(angle, vec) {
// Leaving L in for reusability, but it should always be 1 in our case
let u = vec[0], v = vec[1], w = vec[2];
let L = (u*u + v * v + w * w);
let u2 = u * u;
let v2 = v * v;
let w2 = w * w;
let rotmat = [[],[],[]];
rotmat[0][0] = (u2 + (v2 + w2) * Math.cos(angle)) / L;
rotmat[0][1] = (u * v * (1 - Math.cos(angle)) - w * Math.sqrt(L) * Math.sin(angle)) / L;
rotmat[0][2] = (u * w * (1 - Math.cos(angle)) + v * Math.sqrt(L) * Math.sin(angle)) / L;
rotmat[1][0] = (u * v * (1 - Math.cos(angle)) + w * Math.sqrt(L) * Math.sin(angle)) / L;
rotmat[1][1] = (v2 + (u2 + w2) * Math.cos(angle)) / L;
rotmat[1][2] = (v * w * (1 - Math.cos(angle)) - u * Math.sqrt(L) * Math.sin(angle)) / L;
rotmat[2][0] = (u * w * (1 - Math.cos(angle)) - v * Math.sqrt(L) * Math.sin(angle)) / L;
rotmat[2][1] = (v * w * (1 - Math.cos(angle)) + u * Math.sqrt(L) * Math.sin(angle)) / L;
rotmat[2][2] = (w2 + (u2 + v2) * Math.cos(angle)) / L;
return rotmat;
}
答案 1 :(得分:0)
目前,我正在测试基于three.js的解决方案,该解决方案可以按照以下方式工作:
function getCorrectedPosition(x, y, z, dist, roll, pitch, yaw) {
let matrix = new THREE.Matrix4().makeRotationFromEuler(new THREE.Euler(toRadians(pitch), toRadians(roll), toRadians(yaw)));
let moveVector = new THREE.Vector3(0, 0, -dist);
moveVector.applyMatrix4(matrix);
let position = new THREE.Vector3(z, y, x).add(moveVector);
return [position.x, position.y, position.z]
}
获得结果后,我将发布结果的更新。
答案 2 :(得分:-1)
我不认为您的问题碰巧是万向节锁定,因为您说杆直立时X和Y相同。您确定IMU与地面平行吗?我建议首先尝试仅测量IMU的结果,当确定可以提供准确的结果后,再将其与RS挂钩。
如果要测量GPS坐标和偏航俯仰角,则建议将GPS模块和MPU-6050与Arduino mini一起使用。它很小,可以挂任何东西,而且与非常昂贵的RS +相比,便宜很多。同样,使用这种小工具,您会发现比使用RS +更有效的支持。