Skip to content

Dexter.Vector.DCM_to_quaternion() returns [undefined, undefined, undefined, undefined] for a particular input. #97

@JamesNewton

Description

@JamesNewton

Dexter.Vector.DCM_to_quaternion() returns [undefined, undefined, undefined, undefined] for a particular input. This bug breaks DH inverse kinematics.It looks like there are a series of if else statements in Dexter.Vector.DCM_to_quaternion() and it is missing a final else statement as a catch all.
I have no idea what the correct math would be for this catch all though. However there are known working methods which are used in current firmware.

The following code reproduces the issue:

//Vector.DCM_to_quaternion() bug:

var DCM

//This case works:
DCM = [
    [1, 0, 0],
    [0, 1, 0],
    [0, 0, 1]
]
out(Vector.DCM_to_quaternion(DCM))

//This case works:
DCM = Vector.make_DCM([30, 45, 60])
out(Vector.DCM_to_quaternion(DCM))

//This case fails 
DCM = [
    [-0.7195571193772048, 0.6909849857540601, -0.06911802526143601],
    [-0.13159082483727083, -0.2334028122649974, -0.9634349910842126],
    [-0.6818514550635101, -0.6841512089364833, 0.2588739394734867]
]
out(Vector.DCM_to_quaternion(DCM))

//Roughly 28% of randomized DCMs fail:
var N = 100000
var fail_count = 0
for(let i = 0; i < N; i++){
	DCM = Vector.make_DCM([Math.random()*180-180, Math.random()*180-180, Math.random()*180-180])
	let quat = Vector.DCM_to_quaternion(DCM)
    if(quat[0] === undefined){
    	fail_count++
    }
}
out(Math.round(fail_count / N * 100) + "% out of " + N + " cases fail.")

static DCM_to_quaternion(DCM = Vector.make_DCM()){

Metadata

Metadata

Labels

No labels
No labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions