borglab / borglab/SwiftFusion

Creating better solvers like LM and Dogleg

Open
#36 14 comments 0 reactions 1 assignee Claimed by @ProfFan View on GitHub
enhancement urgent
Dominant language
Swift
Stars
118
Forks
14
PR merge metrics
No merged PRs in 30d

Description

As illustrated by our attempt in using SwiftFusion for motion planning, I discovered that the NLCG solver cannot deal with a 40-point long dynamic planning problem:
```swift
func planning(_ p_target: Pose2, _ u_all: [[Double]], q0: [Double]) -> [[Double]] {
var u_final = u_all
let p0 = fwd_kinematics(q: q0)

@differentiable
func e_pose2(_ ŷ: Pose2) -> Double {
ŷ.t.x * ŷ.t.x + ŷ.t.y * ŷ.t.y
}

@differentiable
func error(_ u: [[Double]]) -> Double {
var e_total = 0.0
let e = between(fwd_kinematics(q: u.differentiableReduce(q0,
{ q, u in
precondition(u.count == 7)
return (Tensor(q) + Tensor(u)).scalars
}
)), p_target)
/// error + control effort
e_total += e_pose2(e)
e_total += 400 * u.differentiableReduce(0, { $0+$1.differentiableReduce(0, {e0, v in e0 + v*v })}) // change 400 to anything else to make this boom
return e_total
}

// change 100 to anything else also make this kaboom
let optimizer = NLCG(for: u_final, max_iteration: 100)

optimizer.optimize(loss: error, model: &u_final)
print(error(u_final))
print(fwd_kinematics(q:(Tensor(q0) + Tensor(u_final[0])).scalars))
// print(proj) // [u0, u1, u2, proj[3], proj[4],proj[5], proj[6]]
return u_final
}
```

Solving this will probably need LM and dogleg.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.