RigidBodyDynamics.jl icon indicating copy to clipboard operation
RigidBodyDynamics.jl copied to clipboard

Symbolic Derivatives with SymPy do not work

Open traikodinev opened this issue 3 years ago • 3 comments

As of the latest version, the example is broken.

https://github.com/JuliaRobotics/RigidBodyDynamics.jl/blob/master/examples/6.%20Symbolics%20using%20SymPy/6.%20Symbolics%20using%20SymPy.jl

Using version 2.2.0 works.

The issue is that Quaternion does not support type Sym. I can update later with more info.

traikodinev avatar Mar 21 '22 17:03 traikodinev

@blegat, I was exploring the source of Dionysos.jl and came across BipedRobot/src/piracy.jl. Is that somehow correlated to this issue? Was the type piracy a workaround? Thanks in advance and sorry for the unsolicited tag... :P

ferrolho avatar Nov 08 '24 13:11 ferrolho

The issue can be fixed with

# Type piracy needed in order to make Symbolics.jl types interact well with Quaternions.jl.
# This should be avoided — see https://docs.julialang.org/en/v1/manual/style-guide/#avoid-type-piracy.
function Base.:/(q::Quaternions.Quaternion, x::Symbolics.Num)
    return Quaternions.Quaternion(q.s / x.val, q.v1 / x.val, q.v2 / x.val, q.v3 / x.val)
end

which should be included with #648 when that gets merged.

I took the snippet from BipedRobot/src/piracy.jl.

ferrolho avatar Nov 10 '24 12:11 ferrolho

Yes, we tried RigidBodyDynamics with SymPy but then ended up using Symbolics.jl We had a similar issue (see also https://github.com/JuliaGeometry/Quaternions.jl/issues/128 which shows that it can get tricky) and we ended up deciding to do some type piracy :innocent: I assume our method could solve it, maybe by replacing Symbolic.Num to something like SymPy.Num.

blegat avatar Nov 11 '24 09:11 blegat