Sha256: 7704e4b5aeb176b31ad844f96e272b1259d5ca9c1e195d85f8732b6f227e2236
Contents?: true
Size: 1.12 KB
Versions: 1
Compression:
Stored size: 1.12 KB
Contents
require 'driving_physics/gearbox' require 'driving_physics/cli' include DrivingPhysics env = Environment.new gearbox = Gearbox.new(env) torque = 30 duration = 30 puts env puts gearbox puts puts "Spin up the gearbox with #{torque} Nm of input torque" puts "How fast will it go in #{duration} seconds?" CLI.pause # rotational kinematics alpha = 0.0 omega = 0.0 theta = 0.0 (duration * env.hz + 1).times { |i| # just for info, not used in the simulation friction = gearbox.spinner.rotating_friction(omega) # update rotational kinematics # gearbox.alpha incorporates friction and inertia alpha = gearbox.alpha(torque, omega: omega) omega += alpha * env.tick theta += omega * env.tick net_torque = gearbox.implied_torque(alpha) # periodic output if i < 10 or (i < 100 and i % 10 == 0) or (i < 1000 and i % 100 == 0) or i % 1000 == 0 puts DrivingPhysics.elapsed_display(i) puts format("RPM %d Torque: %.3f Nm (%d Nm) Friction: %.3f Nm", DrivingPhysics.rpm(omega), net_torque, torque, friction) puts format("%.1f rad %.1f rad/s %.1f rad/s/s", theta, omega, alpha) puts end }
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
driving_physics-0.0.1.1 | demo/gearbox.rb |