Possible fix for braking problems + debug outputs
parent
f6f922c90c
commit
1c3ea96041
|
@ -12,6 +12,7 @@ end
|
|||
--advtrains
|
||||
|
||||
DUMP_DEBUG_SAVE = false
|
||||
GENERATE_ATRICIFIAL_LAG = false
|
||||
|
||||
--Constant for maximum connection value/division of the circle
|
||||
AT_CMAX = 16
|
||||
|
@ -365,6 +366,8 @@ local save_interval=20
|
|||
local save_timer=save_interval
|
||||
advtrains.mainloop_runcnt=0
|
||||
|
||||
|
||||
local t = 0
|
||||
minetest.register_globalstep(function(dtime_mt)
|
||||
return advtrains.pcall(function()
|
||||
advtrains.mainloop_runcnt=advtrains.mainloop_runcnt+1
|
||||
|
@ -373,11 +376,22 @@ minetest.register_globalstep(function(dtime_mt)
|
|||
if not init_load then
|
||||
advtrains.load()
|
||||
end
|
||||
--limit dtime: if trains move too far in one step, automation may cause stuck and wrongly braking trains
|
||||
local dtime=dtime_mt
|
||||
if dtime>0.2 then
|
||||
atprint("Limiting dtime to 0.2!")
|
||||
dtime=0.2
|
||||
|
||||
local dtime
|
||||
if GENERATE_ATRICIFIAL_LAG then
|
||||
dtime = 0.2
|
||||
if os.clock()<t then
|
||||
return
|
||||
end
|
||||
|
||||
t = os.clock()+0.2
|
||||
else
|
||||
--limit dtime: if trains move too far in one step, automation may cause stuck and wrongly braking trains
|
||||
dtime=dtime_mt
|
||||
if dtime>0.2 then
|
||||
atprint("Limiting dtime to 0.2!")
|
||||
dtime=0.2
|
||||
end
|
||||
end
|
||||
|
||||
advtrains.mainloop_trainlogic(dtime)
|
||||
|
|
|
@ -130,7 +130,7 @@ end
|
|||
-- Prints a path using the passed print function
|
||||
-- This function should be 'atprint', 'atlog', 'atwarn' or 'atdebug', because it needs to use print_concat_table
|
||||
function advtrains.path_print(train, printf)
|
||||
printf("path_print: tid =",train.train_id," index =",train.index," end_index =",train.end_index," vel =",train.velocity)
|
||||
printf("path_print: tid =",train.id," index =",train.index," end_index =",train.end_index," vel =",train.velocity)
|
||||
if not train.path then
|
||||
printf("path_print: Path is invalidated/inexistant.")
|
||||
return
|
||||
|
|
|
@ -431,27 +431,35 @@ function advtrains.train_step_b(id, train, dtime)
|
|||
local accel = advtrains.get_acceleration(train, tmp_lever)
|
||||
local vdiff = accel*dtime
|
||||
|
||||
-- ATC control exception: don't cross tarvelocity if
|
||||
-- atc provided a target_vel
|
||||
if train.tarvelocity then
|
||||
local tvdiff = train.tarvelocity - trainvelocity
|
||||
if tvdiff~=0 and math.abs(vdiff) > math.abs(tvdiff) then
|
||||
--applying this change would cross tarvelocity
|
||||
--atdebug("In Tvdiff condition, clipping",vdiff,"to",tvdiff)
|
||||
--atdebug("vel=",trainvelocity,"tvel=",train.tarvelocity)
|
||||
vdiff=tvdiff
|
||||
-- This should only be executed when we are accelerating
|
||||
-- I suspect that this causes the braking bugs
|
||||
if tmp_lever == 4 then
|
||||
|
||||
-- ATC control exception: don't cross tarvelocity if
|
||||
-- atc provided a target_vel
|
||||
if train.tarvelocity then
|
||||
local tvdiff = train.tarvelocity - trainvelocity
|
||||
if tvdiff~=0 and math.abs(vdiff) > math.abs(tvdiff) then
|
||||
--applying this change would cross tarvelocity
|
||||
--atdebug("In Tvdiff condition, clipping",vdiff,"to",tvdiff)
|
||||
--atdebug("vel=",trainvelocity,"tvel=",train.tarvelocity)
|
||||
vdiff=tvdiff
|
||||
end
|
||||
end
|
||||
if tarvel_cap and trainvelocity<=tarvel_cap and trainvelocity+vdiff>tarvel_cap then
|
||||
vdiff = tarvel_cap - train.velocity
|
||||
end
|
||||
local mspeed = (train.max_speed or 10)
|
||||
if trainvelocity+vdiff > mspeed then
|
||||
vdiff = mspeed - trainvelocity
|
||||
end
|
||||
end
|
||||
if tarvel_cap and trainvelocity<=tarvel_cap and trainvelocity+vdiff>tarvel_cap then
|
||||
vdiff = tarvel_cap - train.velocity
|
||||
end
|
||||
|
||||
if trainvelocity+vdiff < 0 then
|
||||
vdiff = - trainvelocity
|
||||
end
|
||||
local mspeed = (train.max_speed or 10)
|
||||
if trainvelocity+vdiff > mspeed then
|
||||
vdiff = mspeed - trainvelocity
|
||||
end
|
||||
|
||||
|
||||
train.acceleration=vdiff
|
||||
train.velocity=train.velocity+vdiff
|
||||
--if train.ctrl.user then
|
||||
|
@ -467,7 +475,7 @@ function advtrains.train_step_b(id, train, dtime)
|
|||
local distance = (train.velocity*dtime) / pdist
|
||||
|
||||
--TODO debugging code
|
||||
train.debug = "step_dist: "..math.floor(distance*1000)
|
||||
train.debug = atdump(train.ctrl).."step_dist: "..math.floor(distance*1000)
|
||||
|
||||
train.index=train.index+distance
|
||||
|
||||
|
|
Loading…
Reference in New Issue