]> git.tdb.fi Git - r2c2.git/commitdiff
Handle reversing in a way that allows backing out of a dead end
authorMikko Rasa <tdb@tdb.fi>
Fri, 23 Apr 2010 18:21:12 +0000 (18:21 +0000)
committerMikko Rasa <tdb@tdb.fi>
Fri, 23 Apr 2010 18:21:12 +0000 (18:21 +0000)
source/libmarklin/aicontrol.cpp
source/libmarklin/aicontrol.h
source/libmarklin/controlmodel.h
source/libmarklin/simplephysics.h
source/libmarklin/train.cpp

index b97b0374add45037a986ca047d7e9354c0d4a528..d5a29c0e540b2ceafbee82151db6e1153c5006ab 100644 (file)
@@ -61,6 +61,14 @@ float AIControl::get_speed() const
        return next_model->get_speed();
 }
 
+bool AIControl::get_reverse() const
+{
+       if(float ns = next_model->get_speed())
+               return ns<0;
+       else
+               return target_speed.value<0;
+}
+
 float AIControl::get_braking_distance() const
 {
        return next_model->get_braking_distance();
index d02011f60a55186627ecca7c500cbab9144bacd5..465d2ab95251f1c5a9fb184d9066886a734debff 100644 (file)
@@ -32,6 +32,7 @@ public:
        virtual const TrainControl &get_control(const std::string &) const;
 
        virtual float get_speed() const;
+       virtual bool get_reverse() const;
        virtual float get_braking_distance() const;
 
        virtual void tick(const Msp::Time::TimeDelta &);
index a45a30e74e11c69b45f691fe91c0fe9f46e7d821..17bb72ba94253db0b82b73d6d85bbd22d00aa516 100644 (file)
@@ -30,6 +30,7 @@ public:
        virtual const TrainControl &get_control(const std::string &) const = 0;
 
        virtual float get_speed() const = 0;
+       virtual bool get_reverse() const = 0;
        virtual float get_braking_distance() const = 0;
 
        virtual void tick(const Msp::Time::TimeDelta &) = 0;
index 6e33e4e83baaccd2bc771157c45cee12577d3d5c..64d961b1b54f5dbcf3a97491db786ed83d2c2864 100644 (file)
@@ -28,6 +28,7 @@ public:
        virtual const TrainControl &get_control(const std::string &) const;
 
        virtual float get_speed() const { return speed; }
+       virtual bool get_reverse() const { return speed<0; }
        virtual float get_braking_distance() const;
 
        virtual void tick(const Msp::Time::TimeDelta &);
index 44f9298d142daf72682594148476699a0ce89554..1abf535c06b6d03a0649c95162b7264da1802c73 100644 (file)
@@ -322,10 +322,10 @@ void Train::tick(const Time::TimeStamp &t, const Time::TimeDelta &dt)
        float speed = control->get_speed();
        unsigned speed_notch = find_speed(abs(speed));
 
-       if(speed && (speed<0)!=reverse)
+       if(control->get_reverse()!=reverse)
        {
-               driver.set_loco_reverse(address, speed<0);
-               reverse = speed<0;
+               reverse = control->get_reverse();
+               driver.set_loco_reverse(address, reverse);
 
                release_blocks(rsv_blocks);
                reverse_blocks(cur_blocks);