Пример #1
0
    def run(self, value, variable, current, error=0, modulo_error=False):
        """
        :param value: A Number that represents the value to be targeted.
        :param variable: A SHM variable (object with a set method) that will be called with a single argument to target.
        :param current: A function that when called with no arguments returns the current value as a Number.
        :param error: A Number representing the allowed error before a wrapper is finished.
        :param modulo_error: a Boolean that is true only if the error calculated should be with respect to modulo 360.
        """

        value, current = evaluate_or_call(value), evaluate_or_call(current)
        variable.set(value)

        if within_deadband(value, current, error, use_mod_error=modulo_error):
            self._finish()
Пример #2
0
 def run(self,
         point,
         deadband=(15, 15),
         px=.0005,
         ix=0,
         dx=0,
         py=.001,
         iy=0,
         dy=0,
         target=(512, 384),
         min_out=None):
     point = evaluate_or_call(point)
     self.pid_loop_x(input_value=point[0],
                     p=px,
                     i=ix,
                     d=dx,
                     target=target[0],
                     deadband=deadband[0],
                     min_out=min_out)
     self.pid_loop_y(input_value=point[1],
                     p=py,
                     i=iy,
                     d=dy,
                     target=target[1],
                     deadband=deadband[1],
                     min_out=min_out)
     if finished(self.pid_loop_x, self.pid_loop_y):
         self._finish()
Пример #3
0
    def run(self,
            point,
            deadband=(15, 15),
            px=.001,
            ix=0,
            dx=0,
            py=.001,
            iy=0,
            dy=0,
            target=(510, 510),
            modulo_error=False):
        point = evaluate_or_call(point)
        self.log('Running ForwardTarget on ({0}, {1}).'.format(
            point[0], point[1]))
        self.pid_loop_x(input_value=point[0],
                        p=px,
                        i=ix,
                        d=dx,
                        target=target[0],
                        deadband=deadband[0],
                        negate=True)
        self.pid_loop_y(input_value=point[1],
                        p=py,
                        i=iy,
                        d=dy,
                        target=target[1],
                        deadband=deadband[1],
                        negate=True)

        if finished(self.pid_loop_x, self.pid_loop_y):
            self._finish()
Пример #4
0
 def firstrun(self,
              value,
              variable,
              current,
              error=0,
              delta=False,
              modulo_error=False):
     self.initial_value = evaluate_or_call(current)
Пример #5
0
    def run(self,
            input_value,
            output_function,
            p=0.2,
            d=0,
            i=0,
            target=0,
            deadband=0,
            modulo_error=False,
            negate=False,
            debug=False,
            min_out=None):
        input_value = evaluate_or_call(input_value)

        # Don't do anything if the current value (input_value) is within the deadband of the target.
        if within_deadband(input_value,
                           target,
                           deadband,
                           use_mod_error=modulo_error):
            # TODO: Should we set the output to the target as we don't know what the current target is?
            self._finish()
            return

        err = (-1 if negate else 1) * (target - input_value)
        self.error = err
        # P, I and D loops
        output_value = p * err

        self.total_error += err * (self.this_run - self.last_run)
        output_value += i * self.total_error

        output_value += d * (self.last_value - input_value) / (self.this_run -
                                                               self.last_run)

        if debug:
            print(output_value)
            print()

        if min_out is not None and output_value < min_out:
            output_function(min_out * (-1 if output_value < 0 else 1))
        else:
            output_function(output_value)

        self.log({
            'p': p,
            'i': i,
            'd': d,
            'in': input_value,
            'out': output_value,
            'negate': negate
        })
Пример #6
0
 def run(self,
         angle,
         deadband=3,
         p=.001,
         i=0,
         d=0,
         target=0,
         modulo_error=True):
     angle = evaluate_or_call(angle)
     self.pid_loop_heading(input_value=angle,
                           p=p,
                           i=i,
                           d=d,
                           target=target,
                           deadband=deadband,
                           negate=True)
     if finished(self.pid_loop_heading):
         self._finish()
Пример #7
0
    def run(self, distance, deadband=.1, p=1, i=0, d=0):
        """
        :param distance: The distance to move. Positive values will move the sub right.
        :param deadband: The accepted error for when the task should finish. If the sub has moved forward in the range
            [distance - deadband, distance + deadband], then the task will finish.
        """

        self.total_distance += kalman.vely.get() * (self.this_run -
                                                    self.last_run)

        distance = evaluate_or_call(distance)
        self.pid_loop_y(input_value=self.total_distance,
                        p=p,
                        i=i,
                        d=d,
                        deadband=deadband,
                        target=distance)

        if finished(self.pid_loop_y):
            self._finish()
Пример #8
0
 def firstrun(self, input_value, output_function, *args, **kwargs):
     self.total_error = 0
     self.last_value = evaluate_or_call(input_value)
     self.out = output_function
     self.error = 0
Пример #9
0
 def run(self, condition, task1, task2):
     task1() if evaluate_or_call(condition) else task2()