Class: DrivingPhysics::Powertrain

Inherits:
Object
  • Object
show all
Defined in:
lib/driving_physics/powertrain.rb

Overview

Powertrain right now is pretty simple. It combines the motor with the gearbox. It is focused on operations that require or involve both components. It does not pass through operations to the motor or gearbox. Instead, it provides direct access to each component.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(motor:, gearbox:) ⇒ Powertrain

Returns a new instance of Powertrain.



13
14
15
16
# File 'lib/driving_physics/powertrain.rb', line 13

def initialize(motor:, gearbox:)
  @motor = motor
  @gearbox = gearbox
end

Instance Attribute Details

#gearboxObject (readonly)

Returns the value of attribute gearbox.



11
12
13
# File 'lib/driving_physics/powertrain.rb', line 11

def gearbox
  @gearbox
end

#motorObject (readonly)

Returns the value of attribute motor.



11
12
13
# File 'lib/driving_physics/powertrain.rb', line 11

def motor
  @motor
end

Instance Method Details

#axle_omega(rpm, axle_omega: nil) ⇒ Object



37
38
39
# File 'lib/driving_physics/powertrain.rb', line 37

def axle_omega(rpm, axle_omega: nil)
  @gearbox.axle_omega(rpm, axle_omega: axle_omega)
end

#axle_torque(rpm, axle_omega: nil) ⇒ Object



32
33
34
35
# File 'lib/driving_physics/powertrain.rb', line 32

def axle_torque(rpm, axle_omega: nil)
  @gearbox.output_torque(@motor.output_torque(rpm), rpm,
                         axle_omega: axle_omega)
end

#crank_rpm(axle_omega, crank_rpm: nil) ⇒ Object



41
42
43
# File 'lib/driving_physics/powertrain.rb', line 41

def crank_rpm(axle_omega, crank_rpm: nil)
  @gearbox.crank_rpm(axle_omega, crank_rpm: crank_rpm)
end

#massObject



18
19
20
# File 'lib/driving_physics/powertrain.rb', line 18

def mass
  @motor.mass + @gearbox.mass
end

#output(rpm) ⇒ Object

returns [power, torque, omega]



27
28
29
30
# File 'lib/driving_physics/powertrain.rb', line 27

def output(rpm)
  t, o = self.axle_torque(rpm), self.axle_omega(rpm)
  [t * o, t, o]
end

#to_sObject



22
23
24
# File 'lib/driving_physics/powertrain.rb', line 22

def to_s
  ["\t[MOTOR]", @motor, "\t[GEARBOX]", @gearbox].join("\n")
end