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


Python PID.constraint方法代码示例

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


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

示例1: PositionController

# 需要导入模块: from pid import PID [as 别名]
# 或者: from pid.PID import constraint [as 别名]
class PositionController():

    def __init__(self, autopilot, state_estimation, **kwargs):
        self.sm = SensorModel()
        self.heading = None
        self.targets = {}
        self.autopilot = autopilot
        self.state_estimation = state_estimation
        self.maximum_thrust = 1850
        self.minimum_thrust = 1350
       # self.altitude_pid = kwargs.get('altitude_pid')
        p = 25
        i = 0.6
        d = 0
        max_t = 50
        min_t = -5

        self.altitude_pid = PID(
            P=p,
            I=i,
            D=d,
            Derivator=0,
            Integrator=0,
            Integrator_max=25,
            Integrator_min=-25,
            maximum_thrust=max_t,
            minimum_thrust=min_t,
        )
        self.heading_pid = PID(
            P=1,
            I=0,
            D=0,
            Derivator=0,
            Integrator=0,
            Integrator_max=25,
            Integrator_min=-25,
            maximum_thrust=25,
            minimum_thrust=-25,
        )

    def headingHold(self):
        if not self.targets.get('heading'):
            #self.targets['heading'] = self.state_estimation.getHeading()
            self.targets['heading'] = self.autopilot.heading
            self.heading_pid.setPoint(self.targets.get('heading'))
        thrust_correction = self.altitude_pid.update(self.autopilot.heading)
       # thrust_correction = self.althold_pid.constraint(thrust_correction)
        self.autopilot.yaw = self.autopilot.yaw + thrust_correction

    def holdAltitude(self):
        if not self.targets.get('altitude'):
            self.targets['altitude'] = self.state_estimation.getAltitude()
            self.altitude_pid.setPoint(self.targets.get('altitude'))
            self.autopilot.meta_pid = MetaPid(
                P=self.altitude_pid.Kp,
                I=self.altitude_pid.Ki,
                D=self.altitude_pid.Kd,
                maximum_thrust=self.altitude_pid.maximum_thrust,
                minimum_thrust=self.altitude_pid.minimum_thrust,
                )
        altitude = self.state_estimation.getAltitude()
        thrust_correction = self.altitude_pid.update(altitude)
        thrust_correction = self.altitude_pid.constraint(thrust_correction)
        thrust = self.autopilot.throttle + thrust_correction
        print 'target: %f altitude: %f  corretion: %d current: %d new thrust: %d ' % (self.altitude_pid.set_point, self.state_estimation.getAltitude(), thrust_correction, thrust, self.autopilot.throttle)
        self.autopilot.throttle = self.constraint(thrust)
        self.autopilot.pid_log(
            PIDlog(
                corretion=thrust_correction,
                altitude=altitude,
                #  altitude_raw=self.autopilot.altitude_barometer,
                altitude_raw=self.autopilot.altitude_barometer,
                target=self.altitude_pid.set_point,
                thrust=self.autopilot.throttle,
                error=self.altitude_pid.error,
            )
        )
       # print 'target: %f altitude: %f' % (self.altitude_pid.set_point,
       # self.state_estimation.getAltitude())

    def reset_targets(self):
        self.targets.clear()

    def set_target_altitude(self, altitude):
        self.targets['altitude'] = altitude

    def constraint(self, value):
        if value > self.maximum_thrust:
            return self.maximum_thrust
        elif value < self.minimum_thrust:
            return self.minimum_thrust
        else:
            return int(round(value))
开发者ID:marvelousmishig,项目名称:drone,代码行数:95,代码来源:position_controller.py


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