When a vessel has motors from breaking ground on it, reading the ship's angular velocity using the angularvel suffix returns values that are incorrect.
The rotation does not have to be caused by a motor, but the motor must be rotating this for it to occur.
As a simple example, I built the following test craft (it is also uploaded to this bug report, but I had to change the extension to .txt for it to upload):
And I then run the following test script on it.
function get_roll {
local pointing is ship:facing.
local trig_x is vdot(pointing:topvector,ship:up:vector).
if abs(trig_x) < 0.0035 {//this is the dead zone for roll when within 0.2 degrees of vertical
return 0.
} else {
local vec_y is vcrs(ship:up:vector,ship:facing:forevector).
local trig_y is vdot(pointing:topvector,vec_y).
return arctan2(trig_y,trig_x).
}
}
local t_last is time:seconds.
local roll_last is get_roll().
until false {
// Only run the rest of the logic if t has changed
// So we don't have a divide by zero issue.
if (time:seconds <> t_last) {
local now is time:seconds.
local roll is get_roll().
local derived is (roll_last - roll) / (now - t_last).
set calculated to vdot(ship:angularvel, ship:facing:forevector) * constant:radtodeg.
clearscreen.
print derived.
print calculated.
print abs(derived - calculated).
set t_last to now.
set roll_last to roll.
}
}
The script finds the roll rate in two ways
- Finding the rate as the change in angle between loop updates with respect to time.
- Reading
ship:angularvel and transforming it into the navball coordinate system.
I then lock the motor and engage its brake, and start spinning the craft using the Q or E key.
With the motor locked so that it cannot spin, the rate measured using the two methods is pretty much the same (with some variation given due to noise in the measurement method).
But if I stop spinning, then unlock the motor and release the brake so that it can freely spin, then start spinning again, the values are drastically different.
Alternatively, if I hold the craft still and engage the motor, the first method properly shows 0 rotation, while the second reads a large value.
Rotation Test Craft.craft.txt
When a vessel has motors from breaking ground on it, reading the ship's angular velocity using the
angularvelsuffix returns values that are incorrect.The rotation does not have to be caused by a motor, but the motor must be rotating this for it to occur.
As a simple example, I built the following test craft (it is also uploaded to this bug report, but I had to change the extension to .txt for it to upload):
And I then run the following test script on it.
The script finds the roll rate in two ways
ship:angularveland transforming it into the navball coordinate system.I then lock the motor and engage its brake, and start spinning the craft using the
QorEkey.With the motor locked so that it cannot spin, the rate measured using the two methods is pretty much the same (with some variation given due to noise in the measurement method).
But if I stop spinning, then unlock the motor and release the brake so that it can freely spin, then start spinning again, the values are drastically different.
Alternatively, if I hold the craft still and engage the motor, the first method properly shows 0 rotation, while the second reads a large value.
Rotation Test Craft.craft.txt