Beispiel #1
0
    def run(self, img_arr):
        # Prepare image array.
        img_arr = img_arr.reshape((1, ) + img_arr.shape)

        # NN angle prediction.
        angle_binned, _ = self.model.predict(img_arr)
        angle_unbinned = dkutil.linear_unbin(angle_binned[0])
        # TODO: Compute average (SMA) confidence.
        angle_confidence = max(angle_binned[0])

        # Fallback mode. If enabled, do obstacle detection.
        if self.obstacle:
            angle_obstacle = self.compute_angle_obstacle(img_arr)
            # In case we detected obstacle use fallback angle.
            if angle_obstacle:
                angle_unbinned = angle_obstacle
                print('obstacle detected, using fallback mode.')

        # Angle postprocessing.
        angle = self.compute_angle(angle_unbinned)

        # By default we always run at failsafe speed.
        throttle = self.config['throttle_failsafe']

        # Speed-up if NN is confident in what it saw.
        if float(angle_confidence) > float(
                self.config['acceleration_confidence']):
            throttle = self.compute_throttle(angle)

        # Workaround to make car slower.
        if self.skip_throttle():
            throttle = 0

        print('throttle:', throttle, 'angle:', angle)
        return angle, throttle
 def test_illegal_list(self):
     with pytest.raises(ValueError):
         linear_unbin([0] * 10)
 def test_empty_list(self):
     res = linear_unbin([0] * 15)
     assert res == -1.0
 def test_negative(self):
     l = create_lbin(0)
     res = linear_unbin(l)
     assert res == -1.0
 def test_positive(self):
     l = create_lbin(14)
     res = linear_unbin(l)
     assert res == 1.0
 def test_zero(self):
     l = create_lbin(7)
     res = linear_unbin(l)
     assert res == 0.0