Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
JamesNewton opened this issue Dec 13, 2023 · 0 comments
Assignees

Comments

@JamesNewton
Copy link
Collaborator

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()){

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants