demo/motor.rb in driving_physics-0.0.2.1 vs demo/motor.rb in driving_physics-0.0.3.1
- old
+ new
@@ -46,11 +46,11 @@
}
puts
puts "Now, the simulation begins..."
puts "---"
-puts "* Spin the motor up to #{motor.idle_rpm} RPM with the starter motor."
+puts "* Spin the motor up to #{motor.idle} RPM with the starter motor."
puts "* Rev it up with the throttle."
puts "* Let it die."
CLI.pause
alpha = 0.0
@@ -87,11 +87,11 @@
net_torque = motor.implied_torque(alpha)
rpm = DrivingPhysics.rpm(omega)
power = DrivingPhysics.power(net_torque, omega)
- if rpm > motor.idle_rpm and status == :ignition
+ if rpm > motor.idle and status == :ignition
status = :running
flag = true
end
if rpm > 7000 and status == :running
@@ -104,13 +104,16 @@
status = :idling
motor.throttle = 0.06
flag = true
end
+ # we don't need no PID control
if status == :idling
- if rpm < 999
+ if rpm.round <= 999
motor.throttle += (1.0 - motor.throttle) * 0.005
- elsif rpm > 1001
+ elsif rpm.round == 1000
+ motor.throttle += (rand - 0.5) * 0.0005
+ else
motor.throttle -= motor.throttle * 0.005
end
end
if flag or