Skip to content

Commit 979705e

Browse files
baggepinnenclaude
andcommitted
Use BodyShape for the 3D bot bodies now that its CoM offset is fixed
JuliaComputing/MultibodyComponents.jl#150 fixed BodyShape placing the center of mass at twice the requested r_cm offset, so both 3D plants can use the idiomatic BodyShape instead of the plain-Body workaround. Both bodies follow the planar bot's convention of a rod extending to twice the center-of-mass height with the mass in the middle; dynamics are unchanged (CoM at L and body_height respectively). Note: this requires a MultibodyComponents build containing the fix; the compat bound should be raised from "0.2" to the first release that includes it once one is registered. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
1 parent 28de12f commit 979705e

3 files changed

Lines changed: 7 additions & 13 deletions

File tree

dyad/segway_3d.dyad

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,8 @@ component DyadBot3D
2525
rod_right = MultibodyComponents.FixedTranslation(r = [0, 0, -track / 2]) {^rod_right}
2626
"Small mass at the center of the axle"
2727
axis_body = MultibodyComponents.Body(m = 0.01, r_cm = [0, 0, 0]) {^axis_body}
28-
"Main body extending upward from the axle"
29-
# A plain Body with an explicit r_cm is used instead of BodyShape, which
30-
# places the center of mass at twice the requested r_cm offset
31-
# (JuliaComputing/MultibodyComponents.jl issue 149).
32-
body = MultibodyComponents.Body(m = body_mass, r_cm = [0, body_height, 0], I_11 = 0.01 * 0.05 ^ 2, I_22 = 0.01 * 0.03 ^ 2, I_33 = 0.01 * 0.05 ^ 2) {^body}
28+
"Main body extending upward from the axle, with its center of mass in the middle"
29+
body = MultibodyComponents.BodyShape(m = body_mass, r = [0, 2 * body_height, 0], r_cm = [0, body_height, 0], I_11 = 0.01 * 0.05 ^ 2, I_22 = 0.01 * 0.03 ^ 2, I_33 = 0.01 * 0.05 ^ 2) {^body}
3330
damper_left = RotationalComponents.Components.Damper(d = d_wheel) {^damper_left}
3431
damper_right = RotationalComponents.Components.Damper(d = d_wheel) {^damper_right}
3532
"Use a compliant (elastic) vertical wheel-ground contact instead of a rigid contact constraint"
@@ -221,10 +218,7 @@ component RollingDyadBot3D
221218
wheels = MultibodyComponents.RollingWheelSet(radius = R, m_wheel = m / 2, I_axis = Iw / 2, I_long = Iw / 4, track = track) {^wheels}
222219
"Body tilt joint about the axle axis"
223220
pitch = MultibodyComponents.Revolute(n = [0, 0, 1]) {^pitch}
224-
# A plain Body with an explicit r_cm is used instead of BodyShape, which
225-
# places the center of mass at twice the requested r_cm offset
226-
# (JuliaComputing/MultibodyComponents.jl issue 149).
227-
body = MultibodyComponents.Body(color = [0.2, 0.2, 0.2, 0.9], m = M, r_cm = [0, L, 0], I_11 = Ib, I_22 = Ib / 10, I_33 = Ib) {^body}
221+
body = MultibodyComponents.BodyShape(color = [0.2, 0.2, 0.2, 0.9], m = M, r = [0, 2 * L, 0], r_cm = [0, L, 0], I_11 = Ib, I_22 = Ib / 10, I_33 = Ib, radius = 0.03) {^body}
228222
"Splits the motor torque equally between the two wheels"
229223
gain_half = BlockComponents.Math.Gain(k = 0.5) {^gain_half}
230224
torque_left = RotationalComponents.Sources.TorqueSource() {^torque_left}

generated/DyadBot3D_definition.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,9 +130,9 @@ stacks, with both rigid and compliant vertical contact.
130130
# Subcomponent axis_body of type MultibodyComponents.Body
131131
axis_body_overrides = __pop_subcomponent_overrides!(__overrides, "axis_body")
132132
push!(__systems, @named axis_body = MultibodyComponents.Body(; m=0.01, r_cm=[Float64(0), Float64(0), Float64(0)], axis_body_overrides...))
133-
# Subcomponent body of type MultibodyComponents.Body
133+
# Subcomponent body of type MultibodyComponents.BodyShape
134134
body_overrides = __pop_subcomponent_overrides!(__overrides, "body")
135-
push!(__systems, @named body = MultibodyComponents.Body(; m=body_mass, r_cm=[Float64(0), body_height, Float64(0)], I_11=0.01 * 0.05 ^ 2, I_22=0.01 * 0.03 ^ 2, I_33=0.01 * 0.05 ^ 2, body_overrides...))
135+
push!(__systems, @named body = MultibodyComponents.BodyShape(; m=body_mass, r=[Float64(0), 2 * body_height, Float64(0)], r_cm=[Float64(0), body_height, Float64(0)], I_11=0.01 * 0.05 ^ 2, I_22=0.01 * 0.03 ^ 2, I_33=0.01 * 0.05 ^ 2, body_overrides...))
136136
# Subcomponent damper_left of type RotationalComponents.Components.Damper
137137
damper_left_overrides = __pop_subcomponent_overrides!(__overrides, "damper_left")
138138
push!(__systems, @named damper_left = RotationalComponents.Components.Damper(; d=d_wheel, damper_left_overrides...))

generated/RollingDyadBot3D_definition.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,9 +136,9 @@ the top level of the enclosing model.
136136
# Subcomponent pitch of type MultibodyComponents.Revolute
137137
pitch_overrides = __pop_subcomponent_overrides!(__overrides, "pitch")
138138
push!(__systems, @named pitch = MultibodyComponents.Revolute(; n=[Float64(0), Float64(0), Float64(1)], pitch_overrides...))
139-
# Subcomponent body of type MultibodyComponents.Body
139+
# Subcomponent body of type MultibodyComponents.BodyShape
140140
body_overrides = __pop_subcomponent_overrides!(__overrides, "body")
141-
push!(__systems, @named body = MultibodyComponents.Body(; color=[0.2, 0.2, 0.2, 0.9], m=M, r_cm=[Float64(0), L, Float64(0)], I_11=Ib, I_22=Ib / 10, I_33=Ib, body_overrides...))
141+
push!(__systems, @named body = MultibodyComponents.BodyShape(; color=[0.2, 0.2, 0.2, 0.9], m=M, r=[Float64(0), 2 * L, Float64(0)], r_cm=[Float64(0), L, Float64(0)], I_11=Ib, I_22=Ib / 10, I_33=Ib, radius=0.03, body_overrides...))
142142
# Subcomponent gain_half of type BlockComponents.Math.Gain
143143
gain_half_overrides = __pop_subcomponent_overrides!(__overrides, "gain_half")
144144
push!(__systems, @named gain_half = BlockComponents.Math.Gain(; k=0.5, gain_half_overrides...))

0 commit comments

Comments
 (0)