Skip to content

Commit 4f32004

Browse files
authored
Merge pull request #106 from ModiaSim/improve_cut_joint_message
Improve corner cases and error messages
2 parents 1223fbb + 044e432 commit 4f32004

File tree

13 files changed

+54
-30
lines changed

13 files changed

+54
-30
lines changed

src/Composition/dynamics.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ function getJointsAndForceElementsAndObject3DsWithoutParents!(evaluatedParameter
1212
if typeof(value.feature) <: Scene
1313
push!(object3DWithoutParents, value)
1414
else
15-
error("\n", value.path, " is an Object3D that has no parent, but no feature=Scene(..)!\n")
15+
error("\n", value.path, " is an Object3D that has no parent, but no feature=Scene(..)!\nThis means no Scene is defined (exactly one Object3D must have feature=Scene(..))!")
1616
end
1717
elseif typeof(value.feature) <: Scene
18-
error("\n", value.path, " is an Object3D that has feature=Scene(..) and has a parent (= ", value.parent.path, ")!\n")
18+
error("\n", value.path, " is an Object3D that has feature=Scene(..) and has a parent (= ", value.parent.path, ")!\nThe Object3D with feature=Scene(..) is not allowed to have a parent!")
1919
end
2020

2121
elseif typeof(value) <: Modia3D.Composition.Revolute

src/Composition/joints/Fix.jl

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,7 @@ struct Fix{F <: Modia3D.VarFloatType}
3434
translation::AbstractVector = Modia3D.ZeroVector3D(F),
3535
rotation::AbstractVector = Modia3D.ZeroVector3D(F)) where F <: Modia3D.VarFloatType
3636

37-
(parent, child, cutJoint) = attach(obj1, obj2)
38-
if cutJoint
39-
error("\nError from Fix joint connecting ", Modia3D.fullName(obj1), " with ", Modia3D.fullName(obj2), ":",
40-
"\nThis joint is a cut-joint which is not allowed.")
41-
end
37+
(parent, child, cutJoint) = attach(obj1, obj2, name = "Fix joint") # an error is triggered if cutJoint=true
4238

4339
r_rel = Modia3D.convertAndStripUnit(SVector{3,F}, u"m", translation)
4440
rot = Modia3D.convertAndStripUnit(SVector{3,F}, u"rad", rotation)

src/Composition/joints/Prismatic.jl

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ get_eAxis(::Type{F}, axis::Int) where F <: Modia3D.VarFloatType = axis== 1 ? SV
1616
error("Modia3D.Composition.Prismatic: axis = ", axis, " but must be 1, 2, 3, -1, -2, or -3.")
1717

1818
"""
19-
joint = Prismatic(; obj1, obj2, path="", axis=1, s=0, v=0, canCollide=true)
19+
joint = Prismatic(; obj1, obj2, axis=1, s=0, v=0, canCollide=true)
2020
2121
Return a `joint` that translates `obj2::`[`Object3D`](@ref) with respect to
2222
`obj1::`[`Object3D`](@ref) along coordinate axis `axis` (`axis = 1,2,3,-1,-2,-3`)
@@ -52,11 +52,7 @@ mutable struct Prismatic{F <: Modia3D.VarFloatType} <: Modia3D.AbstractJoint
5252
v::Real = F(0.0),
5353
canCollide::Bool = true) where F <: Modia3D.VarFloatType
5454

55-
(parent,obj,cutJoint) = attach(obj1, obj2)
56-
if cutJoint
57-
error("\nError from Prismatic joint connecting ", Modia3D.fullName(obj1), " with ", Modia3D.fullName(obj2), ":\n",
58-
" This joint is a cut-joint which is currently not supported.!")
59-
end
55+
(parent,obj,cutJoint) = attach(obj1, obj2, name = "Prismatic joint") # an error is triggered if cutJoint=true
6056

6157
if !(1 <= abs(axis) <= 3)
6258
error("\nError from Prismatic joint connecting ", Modia3D.fullName(obj1), " with ", Modia3D.fullName(obj2), ":\n",

src/Composition/joints/Revolute.jl

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import Modia3D.Frames
88

99

1010
"""
11-
joint = Revolute(;obj1, obj2, path="", axis=3, phi=0, w=0, canCollide=false)
11+
joint = Revolute(;obj1, obj2, axis=3, phi=0, w=0, canCollide=false)
1212
1313
Return a Revolute `joint` that rotates `obj1::`[`Object3D`](@ref) into
1414
`obj2::`[`Object3D`](@ref) along the axis `axis` of `obj1` (`axis = 1,2,3,-1,-2,-3`).
@@ -43,11 +43,7 @@ mutable struct Revolute{F <: Modia3D.VarFloatType} <: Modia3D.AbstractJoint
4343
w::Real = F(0.0),
4444
canCollide::Bool = false) where F <: Modia3D.VarFloatType
4545

46-
(parent,obj,cutJoint) = attach(obj1, obj2)
47-
if cutJoint
48-
error("\nError from Revolute joint connecting ", Modia3D.fullName(obj1), " with ", Modia3D.fullName(obj2), ":\n",
49-
" This joint is a cut-joint which is currently not supported.!")
50-
end
46+
(parent,obj,cutJoint) = attach(obj1, obj2, name = "Revolute joint") # an error is triggered if cutJoint=true
5147

5248
if !(1 <= abs(axis) <= 3)
5349
error("\nError from Revolute joint connecting ", Modia3D.fullName(obj1), " with ", Modia3D.fullName(obj2), ":\n",

src/Composition/joints/joints.jl

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,8 @@ function attachAndReverseParents(newParent::Object3D{F}, obj::Object3D{F})::Noth
120120
end
121121

122122

123+
getParents(obj,rootPath) = "\"" * Modia3D.fullName(obj) * "\" has " * (length(rootPath) == 0 ? "no parents" : "parents: $rootPath")
124+
123125
"""
124126
(obj1, obj2, cutJoint) = attach(frame_a, frame_b)
125127
@@ -128,7 +130,7 @@ and cutJoint = false is returned.
128130
129131
If they have the same root, the tree is not modified and cutJoint=true is returned.
130132
"""
131-
function attach(obj1::Object3D, obj2::Object3D)
133+
function attach(obj1::Object3D, obj2::Object3D; name = "")
132134
root1 = rootObject3D(obj1)
133135
root2 = rootObject3D(obj2)
134136
#println("attach: obj1 = ", Modia3D.fullName(obj1), ", root = ", Modia3D.fullName(root1))
@@ -137,6 +139,16 @@ function attach(obj1::Object3D, obj2::Object3D)
137139
if root1 root2
138140
# Compute absolute positions
139141
# updatePosition!(root1)
142+
143+
if name != ""
144+
# Collect all objects that form a loop
145+
rootPath1 = rootObject3DPath(obj1)
146+
rootPath2 = rootObject3DPath(obj2)
147+
error("\nError from $name connecting \"", Modia3D.fullName(obj1), "\" with \"", Modia3D.fullName(obj2), "\":\n",
148+
" ", getParents(obj1,rootPath1), "\n",
149+
" ", getParents(obj2,rootPath2), "\n",
150+
" Therefore, a closed kinematic loop is defined, which is currently not supported.")
151+
end
140152
return (obj1,obj2,true)
141153
end
142154

src/Composition/joints/object3DMotion.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ end
1414

1515

1616
"""
17-
joint = FreeMotion(; obj1, obj2, path="", r, rot, v, w)
17+
joint = FreeMotion(; obj1, obj2, r, rot, v, w)
1818
1919
Return a `joint` that describes the free movement of `obj2::`[`Object3D`](@ref)
2020
with respect to `obj1::`[`Object3D`](@ref). The initial position is `r`

src/Composition/massPropertiesComputation.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ function addOrSubtractMassPropertiesOfChildToRoot!(obj_root::Object3D{F}, obj_ch
104104
m = m_root + m_child
105105

106106
# common center of mass (parent + child)
107-
@assert(m > 0.0)
107+
@assert(m >= 0.0)
108108
rCM = (m_root * rCM_root + m_child * rCM_child_new)/m
109109

110110
# I: substract new common mass multiplied with skew matrices of

src/Composition/object3D.jl

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -551,6 +551,18 @@ function rootObject3D(obj::Object3D{F}) where F <: Modia3D.VarFloatType
551551
end
552552

553553

554+
""" path = rootObject3DPath(obj) - returns a vector of Object3D names of all objects from obj to root"""
555+
function rootObject3DPath(obj::Object3D{F}) where F <: Modia3D.VarFloatType
556+
path = String[]
557+
obj1 = obj
558+
while hasParent(obj1)
559+
obj1 = obj1.parent
560+
push!(path, obj1.path)
561+
end
562+
return path
563+
end
564+
565+
554566
""" removeChild!(obj, child) - Remove child from obj.children"""
555567
function removeChild!(obj::Object3D{F}, child::Object3D{F})::Nothing where F <: Modia3D.VarFloatType
556568
children = obj.children

src/ModiaInterface/buildModia3D.jl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,8 @@ function buildModia3D!(model::AbstractDict, FloatType::Type, TimeType::Type,
9797
jointStatesFreeMotion_isrot123 = Expr[]
9898
freeMotionIndices = OrderedCollections.OrderedDict{String,Int}()
9999

100+
println("modelPath = $modelPath")
101+
100102
modelPathAsString = isnothing(modelPath) ? "" : string(modelPath)
101103

102104
i=1
@@ -243,6 +245,9 @@ function buildModia3D!(model::AbstractDict, FloatType::Type, TimeType::Type,
243245
else
244246
@error "Error should not occur (buildOption = $buildOption)"
245247
end
248+
else
249+
# ndofTotal == 0
250+
mbsCode = mbs_variables | Model(equations = :[$(mbs_equations...)])
246251
end
247252

248253
# Store info in buildDict

src/Shapes/massProperties.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ struct MassProperties{F <: Modia3D.VarFloatType} <: Modia3D.AbstractMassProperti
1515
#---------------- different constructors for MassProperties -----------------
1616
# Constructor 0: takes mass, centerOfMass and inertiaMatrix as input values
1717
function MassProperties{F}(mass::Number, centerOfMass::AbstractVector, inertiaMatrix::AbstractMatrix) where F <: Modia3D.VarFloatType
18-
@assert(mass > 0.0)
18+
@assert(mass >= 0.0)
1919
new(mass, centerOfMass, inertiaMatrix)
2020
end
2121
end

0 commit comments

Comments
 (0)