当前位置: 首页>>代码示例>>Python>>正文


Python PID.set_k_values方法代码示例

本文整理汇总了Python中pid.PID.set_k_values方法的典型用法代码示例。如果您正苦于以下问题:Python PID.set_k_values方法的具体用法?Python PID.set_k_values怎么用?Python PID.set_k_values使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pid.PID的用法示例。


在下文中一共展示了PID.set_k_values方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: Side

# 需要导入模块: from pid import PID [as 别名]
# 或者: from pid.PID import set_k_values [as 别名]
class Side(object):
    """
    Side of the robot with 2 IR sensors
    """

    def __init__(self, sensor1, sensor2, ir_device_func, diff_k_values=(0,0,0), dist_k_values=(0,0,0)):
        self.sensor1 = sensor1
        self.sensor2 = sensor2
        self.get_values = ir_device_func
        self.diff_pid = PID()
        p1,d1,i1 = diff_k_values
        # self.diff_pid.set_k_values(1.1, 0.04, 0.0)
        self.diff_pid.set_k_values(p1, d1, i1)
        self.dist_pid = PID()
        p2,d2,i2 = dist_k_values
        self.dist_pid.set_k_values(p2, d2, i2)

    def get_diff(self):
        """
        Get the difference between the 2 sensors
        """
        vals = self.get_values()
        sens1 = vals[self.sensor1]
        sens2 = vals[self.sensor2]
        return sens1 - sens2

    @lib.api_call
    def get_diff_correction(self, timestep, threshold=1000000):
        """
        ::TODO:: Finish the actual processing
        get the motor correction values
        """
        diff = self.get_diff()
        error = self.diff_pid.pid(0, diff, timestep)
        #print threshold, error
        if abs(error) < threshold:
            return error
        else:
            print "OUT OF THRESHOLD"
            return 0

    def get_dist_correction(self, target, timestep):
        dist = self.get_distance()
        error = self.dist_pid.pid(target, dist, timestep)

        return error

    def get_distance(self, style="avg"):
        vals = self.get_values()
        sens1 = vals[self.sensor1]
        sens2 = vals[self.sensor2]
        if style=="avg":
            return (sens1+sens2)/2
        elif style == "max":
            return max(sens1, sens2)
        elif style == "min":
            return min(sens1, sens2)
开发者ID:AhmedSamara,项目名称:bot-1,代码行数:59,代码来源:side.py

示例2: move_smooth_until_wall

# 需要导入模块: from pid import PID [as 别名]
# 或者: from pid.PID import set_k_values [as 别名]
    def move_smooth_until_wall(self, direction, side, target, dist=150, t_type="avg"):
        direction = direction.lower()
        mov_side = self.sides[direction]
        mov_target = dist
        self.moving = True
        time_elapsed = time()
        speed = 0
        speed_pid = PID()
        speed_pid.set_k_values(4, 0.01, 0)
        while self.moving:
            timestep = time() - time_elapsed
            time_elapsed = time()
            speed = speed_pid.pid(0, target - mov_side.get_distance(), timestep)
            if direction == "east" or direction == "west":
                speed = bound(speed, -65, 65)
            else:
                speed = bound(speed, -65, 65)

            self.move_correct(direction, side, mov_target, speed, timestep)
            if mov_side.get_distance(t_type) <= target:
                self.stop()
开发者ID:AhmedSamara,项目名称:bot-1,代码行数:23,代码来源:nav.py


注:本文中的pid.PID.set_k_values方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。