Class: DrivingPhysics::Disk
- Inherits:
-
Object
- Object
- DrivingPhysics::Disk
- Defined in:
- lib/driving_physics/disk.rb
Direct Known Subclasses
Constant Summary collapse
- DENSITY =
kg / L
1.0
Instance Attribute Summary collapse
-
#base_friction ⇒ Object
Returns the value of attribute base_friction.
-
#density ⇒ Object
Returns the value of attribute density.
-
#env ⇒ Object
readonly
Returns the value of attribute env.
-
#omega_friction ⇒ Object
Returns the value of attribute omega_friction.
-
#radius ⇒ Object
Returns the value of attribute radius.
-
#width ⇒ Object
Returns the value of attribute width.
Class Method Summary collapse
-
.alpha(torque, inertia) ⇒ Object
angular acceleration.
- .density(mass, volume_l) ⇒ Object
-
.force(axle_torque, radius) ⇒ Object
torque = force * distance.
- .mass(radius, width, density) ⇒ Object
-
.moment_of_inertia ⇒ Object
I = 1/2 (m)(r^2) for a disk.
-
.rotational(tangential, radius) ⇒ Object
convert acc/vel/pos to alpha/omega/theta.
-
.rotational_inertia(radius, mass) ⇒ Object
I = 1/2 (m)(r^2) for a disk.
-
.tangential(rotational, radius) ⇒ Object
convert alpha/omega/theta to acc/vel/pos.
-
.volume(radius, width) ⇒ Object
in m^3.
-
.volume_l(radius, width) ⇒ Object
in L.
Instance Method Summary collapse
- #alpha(torque, omega: 0, normal_force: nil) ⇒ Object
-
#energy(omega) ⇒ Object
E = (1/2) (I) (omega^2).
- #force(axle_torque) ⇒ Object
- #implied_torque(alpha) ⇒ Object
-
#initialize(env) {|_self| ... } ⇒ Disk
constructor
A new instance of Disk.
- #mass ⇒ Object
- #mass=(val) ⇒ Object
- #normal_force ⇒ Object
-
#rotating_friction(omega, normal_force: nil) ⇒ Object
modeled as a tiny but increasing torque opposing omega also scales with normal force maybe not physically faithful but close enough.
- #rotational_inertia ⇒ Object (also: #moment_of_inertia)
- #tangential(rotational) ⇒ Object
- #to_s ⇒ Object
-
#volume ⇒ Object
in m^3.
-
#volume_l ⇒ Object
in L.
Constructor Details
#initialize(env) {|_self| ... } ⇒ Disk
Returns a new instance of Disk.
86 87 88 89 90 91 92 93 94 |
# File 'lib/driving_physics/disk.rb', line 86 def initialize(env) @env = env @radius = 0.35 @width = 0.2 @density = DENSITY @base_friction = 5.0/100_000 # constant resistance to rotation @omega_friction = 5.0/100_000 # scales with omega yield self if block_given? end |
Instance Attribute Details
#base_friction ⇒ Object
Returns the value of attribute base_friction.
84 85 86 |
# File 'lib/driving_physics/disk.rb', line 84 def base_friction @base_friction end |
#density ⇒ Object
Returns the value of attribute density.
84 85 86 |
# File 'lib/driving_physics/disk.rb', line 84 def density @density end |
#env ⇒ Object (readonly)
Returns the value of attribute env.
83 84 85 |
# File 'lib/driving_physics/disk.rb', line 83 def env @env end |
#omega_friction ⇒ Object
Returns the value of attribute omega_friction.
84 85 86 |
# File 'lib/driving_physics/disk.rb', line 84 def omega_friction @omega_friction end |
#radius ⇒ Object
Returns the value of attribute radius.
84 85 86 |
# File 'lib/driving_physics/disk.rb', line 84 def radius @radius end |
#width ⇒ Object
Returns the value of attribute width.
84 85 86 |
# File 'lib/driving_physics/disk.rb', line 84 def width @width end |
Class Method Details
.alpha(torque, inertia) ⇒ Object
angular acceleration
69 70 71 |
# File 'lib/driving_physics/disk.rb', line 69 def self.alpha(torque, inertia) torque / inertia end |
.density(mass, volume_l) ⇒ Object
52 53 54 |
# File 'lib/driving_physics/disk.rb', line 52 def self.density(mass, volume_l) mass.to_f / volume_l end |
.force(axle_torque, radius) ⇒ Object
torque = force * distance
38 39 40 |
# File 'lib/driving_physics/disk.rb', line 38 def self.force(axle_torque, radius) axle_torque / radius.to_f end |
.mass(radius, width, density) ⇒ Object
56 57 58 |
# File 'lib/driving_physics/disk.rb', line 56 def self.mass(radius, width, density) volume_l(radius, width) * density end |
.moment_of_inertia ⇒ Object
I = 1/2 (m)(r^2) for a disk
65 66 67 |
# File 'lib/driving_physics/disk.rb', line 65 def self.rotational_inertia(radius, mass) mass * radius**2 / 2.0 end |
.rotational(tangential, radius) ⇒ Object
convert acc/vel/pos to alpha/omega/theta
79 80 81 |
# File 'lib/driving_physics/disk.rb', line 79 def self.rotational(tangential, radius) tangential.to_f / radius end |
.rotational_inertia(radius, mass) ⇒ Object
I = 1/2 (m)(r^2) for a disk
61 62 63 |
# File 'lib/driving_physics/disk.rb', line 61 def self.rotational_inertia(radius, mass) mass * radius**2 / 2.0 end |
.tangential(rotational, radius) ⇒ Object
convert alpha/omega/theta to acc/vel/pos
74 75 76 |
# File 'lib/driving_physics/disk.rb', line 74 def self.tangential(rotational, radius) rotational * radius end |
.volume(radius, width) ⇒ Object
in m^3
43 44 45 |
# File 'lib/driving_physics/disk.rb', line 43 def self.volume(radius, width) Math::PI * radius ** 2 * width end |
.volume_l(radius, width) ⇒ Object
in L
48 49 50 |
# File 'lib/driving_physics/disk.rb', line 48 def self.volume_l(radius, width) volume(radius, width) * 1000 end |
Instance Method Details
#alpha(torque, omega: 0, normal_force: nil) ⇒ Object
113 114 115 116 |
# File 'lib/driving_physics/disk.rb', line 113 def alpha(torque, omega: 0, normal_force: nil) (torque - self.rotating_friction(omega, normal_force: normal_force)) / self.rotational_inertia end |
#energy(omega) ⇒ Object
E = (1/2) (I) (omega^2)
109 110 111 |
# File 'lib/driving_physics/disk.rb', line 109 def energy(omega) 0.5 * self.rotational_inertia * omega ** 2 end |
#force(axle_torque) ⇒ Object
146 147 148 |
# File 'lib/driving_physics/disk.rb', line 146 def force(axle_torque) self.class.force(axle_torque, @radius) end |
#implied_torque(alpha) ⇒ Object
118 119 120 |
# File 'lib/driving_physics/disk.rb', line 118 def implied_torque(alpha) alpha * self.rotational_inertia end |
#mass ⇒ Object
122 123 124 |
# File 'lib/driving_physics/disk.rb', line 122 def mass self.class.mass(@radius, @width, @density) end |
#mass=(val) ⇒ Object
126 127 128 129 |
# File 'lib/driving_physics/disk.rb', line 126 def mass=(val) @density = self.class.density(val, self.volume_l) @normal_force = nil # force update end |
#normal_force ⇒ Object
103 104 105 106 |
# File 'lib/driving_physics/disk.rb', line 103 def normal_force @normal_force ||= self.mass * @env.g @normal_force end |
#rotating_friction(omega, normal_force: nil) ⇒ Object
modeled as a tiny but increasing torque opposing omega also scales with normal force maybe not physically faithful but close enough
157 158 159 160 161 162 163 |
# File 'lib/driving_physics/disk.rb', line 157 def rotating_friction(omega, normal_force: nil) return omega if omega.zero? normal_force = self.normal_force if normal_force.nil? mag = omega.abs sign = omega / mag -1 * sign * normal_force * (@base_friction + mag * @omega_friction) end |
#rotational_inertia ⇒ Object Also known as: moment_of_inertia
141 142 143 |
# File 'lib/driving_physics/disk.rb', line 141 def rotational_inertia self.class.rotational_inertia(@radius, self.mass) end |
#tangential(rotational) ⇒ Object
150 151 152 |
# File 'lib/driving_physics/disk.rb', line 150 def tangential(rotational) self.class.tangential(rotational, @radius) end |
#to_s ⇒ Object
96 97 98 99 100 101 |
# File 'lib/driving_physics/disk.rb', line 96 def to_s [[format("%d mm x %d mm (RxW)", @radius * 1000, @width * 1000), format("%.1f kg %.2f kg/L", self.mass, @density), ].join(" | "), ].join("\n") end |
#volume ⇒ Object
in m^3
132 133 134 |
# File 'lib/driving_physics/disk.rb', line 132 def volume self.class.volume(@radius, @width) end |
#volume_l ⇒ Object
in L
137 138 139 |
# File 'lib/driving_physics/disk.rb', line 137 def volume_l self.class.volume_l(@radius, @width) end |