Skip to content

Commit 7c6b3d5

Browse files
committed
add world torque component
1 parent 15ce572 commit 7c6b3d5

File tree

2 files changed

+48
-1
lines changed

2 files changed

+48
-1
lines changed

src/Multibody.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ export Revolute, Prismatic, Planar, Spherical, Universal, GearConstraint, Rollin
158158
RollingWheel, FreeMotion, RevolutePlanarLoopConstraint
159159
include("joints.jl")
160160

161-
export Spring, Damper, SpringDamperParallel, Torque, Force, WorldForce
161+
export Spring, Damper, SpringDamperParallel, Torque, Force, WorldForce, WorldTorque
162162
include("forces.jl")
163163

164164
export PartialCutForceBaseSensor, BasicCutForce, BasicCutTorque, CutTorque, CutForce, Power

src/forces.jl

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,53 @@ Torque acting between two frames, defined by 3 input signals and resolved in fra
7575
extend(ODESystem(eqs, t, name = name, systems = [torque, basicTorque]), ptf)
7676
end
7777

78+
@component function BasicWorldTorque(; name, resolve_frame = :world)
79+
@named torque = Blocks.RealInput(; nin = 3)
80+
@named frame_b = Frame()
81+
eqs = if resolve_frame == :world
82+
collect(frame_b.tau) .~ -resolve2(ori(frame_b), collect(torque.u))
83+
elseif resolve_frame == :frame_b
84+
collect(frame_b.tau) .~ -torque.u
85+
else
86+
collect(frame_b.tau) .~ zeros(3)
87+
end |> collect
88+
append!(eqs, collect(frame_b.f) .~ zeros(3))
89+
ODESystem(eqs, t; name, systems = [torque, frame_b])
90+
end
91+
92+
"""
93+
WorldTorque(; name, resolve_frame = :world)
94+
95+
External torque acting at `frame_b`, defined by 3 input signals and resolved in frame `:world` or `:frame_b`.
96+
97+
# Connectors:
98+
- `frame_b`: Frame at which the torque is acting
99+
- `torque`: Of type `Blocks.RealInput(3)`. x-, y-, z-coordinates of torque resolved in frame defined by `resolve_frame`.
100+
101+
# Rendering options
102+
- `scale = 0.1`: scaling factor for the force [m/N]
103+
- `color = [0,1,0,0.5]`: color of the force arrow in rendering
104+
- `radius = 0.05`: radius of the force arrow in rendering
105+
"""
106+
@component function WorldTorque(; name, resolve_frame = :world, scale = 0.1, color = [0, 1, 0, 0.5], radius = 0.05)
107+
@named begin
108+
torque = Blocks.RealInput(; nin = 3)
109+
frame_b = Frame()
110+
basicWorldTorque = BasicWorldTorque(; resolve_frame)
111+
end
112+
pars = @parameters begin
113+
scale = scale, [description = "scaling factor for the force [m/N]"]
114+
color[1:4] = color, [description = "color of the force arrow in rendering"]
115+
radius = radius, [description = "radius of the force arrow in rendering"]
116+
end
117+
eqs = [
118+
connect(basicWorldTorque.frame_b, frame_b)
119+
connect(basicWorldTorque.torque, torque)
120+
]
121+
ODESystem(eqs, t, [], pars; name, systems = [torque, basicWorldTorque, frame_b])
122+
end
123+
124+
78125
@component function BasicForce(; name, resolve_frame = :frame_b)
79126
@named ptf = PartialTwoFrames()
80127
@named force = Blocks.RealInput(; nin = 3)

0 commit comments

Comments
 (0)