demo/motor.rb in driving_physics-0.0.1.2 vs demo/motor.rb in driving_physics-0.0.2.1
- old
+ new
@@ -80,16 +80,15 @@
# Motor#alpha incorporates inertia and friction
alpha = motor.alpha(torque, omega: omega)
omega += alpha * env.tick
theta += omega * env.tick
- net_torque = motor.implied_torque(alpha)
+ # prevent silly oscillations due to ticks or tiny floating point errors
+ omega = 0 if omega < 0.0001
- # prevent silly oscillations due to tiny floating point errors
- omega = 0 if omega < 0.00001
+ net_torque = motor.implied_torque(alpha)
rpm = DrivingPhysics.rpm(omega)
-
power = DrivingPhysics.power(net_torque, omega)
if rpm > motor.idle_rpm and status == :ignition
status = :running
flag = true
@@ -120,18 +119,18 @@
(i < 100 and i % 10 == 0) or
(i < 1000 and i % 100 == 0) or
(i < 10_000 and i % 500 == 0) or
(i % 5000 == 0) or
(status == :idling and i % 100 == 0)
- puts Timer.display(i)
+ puts Timer.display(ms: i)
puts format("Throttle: %.1f%%", motor.throttle * 100)
puts format("%d RPM %.1f Nm (%d Nm) %.1f kW Friction: %.1f Nm",
DrivingPhysics.rpm(omega),
net_torque,
torque,
power / 1000,
motor.spinner.rotating_friction(omega))
- puts format("%d rad %.1f rad/s %.1f rad/s/s", theta, omega, alpha)
+ puts format("%.3f rad/s/s %.2f rad/s %.1f rad", alpha, omega, theta)
puts
paused += CLI.pause if flag
flag = false
end