aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authororwell96 <orwell@bleipb.de>2019-01-23 15:35:58 +0100
committerorwell96 <orwell@bleipb.de>2019-01-23 15:37:18 +0100
commit1c3ea960415fcbd63c5f1b2cd8a5b25f79d2879f (patch)
tree2dffb9f8ad35c7eac66752a405f1796a23eba2fe
parentf6f922c90cfc2c5795110a5b2c0bdbee927a67ed (diff)
downloadadvtrains-1c3ea960415fcbd63c5f1b2cd8a5b25f79d2879f.tar.gz
advtrains-1c3ea960415fcbd63c5f1b2cd8a5b25f79d2879f.tar.bz2
advtrains-1c3ea960415fcbd63c5f1b2cd8a5b25f79d2879f.zip
Possible fix for braking problems + debug outputs
-rw-r--r--advtrains/init.lua24
-rw-r--r--advtrains/path.lua2
-rw-r--r--advtrains/trainlogic.lua42
3 files changed, 45 insertions, 23 deletions
diff --git a/advtrains/init.lua b/advtrains/init.lua
index cc54c02..21b414e 100644
--- a/advtrains/init.lua
+++ b/advtrains/init.lua
@@ -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)
diff --git a/advtrains/path.lua b/advtrains/path.lua
index 64e0d1c..825e59b 100644
--- a/advtrains/path.lua
+++ b/advtrains/path.lua
@@ -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
diff --git a/advtrains/trainlogic.lua b/advtrains/trainlogic.lua
index 205f4d8..94d5980 100644
--- a/advtrains/trainlogic.lua
+++ b/advtrains/trainlogic.lua
@@ -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