本文整理汇总了Python中config.Configuration.getInstance方法的典型用法代码示例。如果您正苦于以下问题:Python Configuration.getInstance方法的具体用法?Python Configuration.getInstance怎么用?Python Configuration.getInstance使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类config.Configuration
的用法示例。
在下文中一共展示了Configuration.getInstance方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from config import Configuration [as 别名]
# 或者: from config.Configuration import getInstance [as 别名]
def __init__(self):
self._config = Configuration.getInstance().getConfig()
self._driver = Driver()
self._createSensor(self._config[Configuration.KEY_IMU_CLASS])
#PID constants must have the same length
self._pidAnglesSpeedKP = self._config[Configuration.PID_ANGLES_SPEED_KP]
self._pidAnglesSpeedKI = self._config[Configuration.PID_ANGLES_SPEED_KI]
self._pidAnglesSpeedKD = self._config[Configuration.PID_ANGLES_SPEED_KD]
#PID constants must have the same length
self._pidAnglesKP = self._config[Configuration.PID_ANGLES_KP]
self._pidAnglesKI = self._config[Configuration.PID_ANGLES_KI]
self._pidAnglesKD = self._config[Configuration.PID_ANGLES_KD]
self._pidAccelKP = self._config[Configuration.PID_ACCEL_KP]
self._pidAccelKI = self._config[Configuration.PID_ACCEL_KI]
self._pidAccelKD = self._config[Configuration.PID_ACCEL_KD]
#PID
self._pidKP = self._pidAnglesSpeedKP + self._pidAnglesKP + self._pidAccelKP
self._pidKI = self._pidAnglesSpeedKI + self._pidAnglesKI + self._pidAccelKI
self._pidKD = self._pidAnglesSpeedKD + self._pidAnglesKD + self._pidAccelKD
self._pid = PID(FlightController.PID_PERIOD, \
self._pidKP, self._pidKI, self._pidKD, \
self._readPIDInput, self._setPIDOutput, \
"stabilization-pid")
self._pid.setTargets([0.0]*len(self._pidKP))
self._isRunning = False
示例2: __init__
# 需要导入模块: from config import Configuration [as 别名]
# 或者: from config.Configuration import getInstance [as 别名]
def __init__(self):
'''
Constructor
'''
self._lock = Lock()
self._config = Configuration.getInstance().getConfig()
self._motors = []
self._baseThrottle = 0.0
self._motorIncrements = [0.0] * Driver.NUM_MOTORS
for motorId in range(Driver.NUM_MOTORS):
motor = self._createMotor(motorId, self._config[Configuration.KEY_MOTOR_CLASS])
self._motors.append(motor)
示例3: __init__
# 需要导入模块: from config import Configuration [as 别名]
# 或者: from config.Configuration import getInstance [as 别名]
def __init__(self):
self._config = Configuration.getInstance().getConfig()
self._driver = Driver()
self._createSensor(self._config[Configuration.KEY_IMU_CLASS])
#PID constants must have the same length
self._pidAnglesSpeedKP = [k / FlightController.ANGLE_SPEED_FACTOR for k \
in self._config[Configuration.PID_ANGLES_SPEED_KP]]
self._pidAnglesSpeedKI = [k / FlightController.ANGLE_SPEED_FACTOR for k \
in self._config[Configuration.PID_ANGLES_SPEED_KI]]
self._pidAnglesSpeedKD = [k / FlightController.ANGLE_SPEED_FACTOR for k \
in self._config[Configuration.PID_ANGLES_SPEED_KD]]
#PID constants must have the same length
self._pidAnglesKP = self._config[Configuration.PID_ANGLES_KP]
self._pidAnglesKI = self._config[Configuration.PID_ANGLES_KI]
self._pidAnglesKD = self._config[Configuration.PID_ANGLES_KD]
self._pidAccelKP = self._config[Configuration.PID_ACCEL_KP]
self._pidAccelKI = self._config[Configuration.PID_ACCEL_KI]
self._pidAccelKD = self._config[Configuration.PID_ACCEL_KD]
#PID
self._pidKP = self._pidAnglesSpeedKP + self._pidAnglesKP + self._pidAccelKP
self._pidKI = self._pidAnglesSpeedKI + self._pidAnglesKI + self._pidAccelKI
self._pidKD = self._pidAnglesSpeedKD + self._pidAnglesKD + self._pidAccelKD
self._pid = PID(FlightController.PID_PERIOD, \
self._pidKP, self._pidKI, self._pidKD, \
self._readPIDInput, self._setPIDOutput, \
"stabilization-pid")
self._pid.setTargets([0.0]*len(self._pidKP))
self._isRunning = False
self._pidThrottleThreshold = 0
self._maxAngleX = self._config[Configuration.KEY_MAX_ANGLE_X]
self._maxAngleY = self._config[Configuration.KEY_MAX_ANGLE_Y]
#TODO: Rate mode
#self._maxAngleSpeedX = self._config[Configuration.KEY_MAX_ANGLE_SPEED_X] #used for rate mode when implemented
#self._maxAngleSpeedY = self._config[Configuration.KEY_MAX_ANGLE_SPEED_Y] #used for rate mode when implemented
self._maxAngleSpeedZ = self._config[Configuration.KEY_MAX_ANGLE_SPEED_Z]
#TODO: Read initial flight mode from configuration
self._flightMode = FlightController.FLIGHT_MODE_ANGLE
示例4: _dispatch
# 需要导入模块: from config import Configuration [as 别名]
# 或者: from config.Configuration import getInstance [as 别名]
def _dispatch(self, message):
if self._started and message["key"] == "target":
newTargets = message["data"]
self._controller.setTargets(newTargets)
# elif self._started and message["key"] == "throttle":
#
# newThrottle = message["data"]
#
# if newThrottle > 0:
# dThrottle = newThrottle - self._throttle
#
# if dThrottle != 0:
# self._throttle = newThrottle
#
# self._controller.addThrottle(dThrottle)
# else:
# self._throttle = 0
# self._controller.standBy()
elif message["key"] == "is-started":
self._started = message["data"]
self._throttle = 0
if self._started:
self._controller.standBy()
self._controller.startPid()
else:
self._controller.stopPid()
self._controller.idle()
elif message["key"] == "integrals":
enable = message["data"]
if enable:
self._controller.enableIntegrals()
else:
self._controller.disableIntegrals()
elif message["key"] == "pid-calibration":
data = message["data"]
axisSwitcher = {
"X": 0,
"Y": 1,
"Z": 2
}
axisIndex = axisSwitcher.get(data["axis"])
constantP = data["p"]
constantI = data["i"]
constantD = data["d"]
pidLevel = data["pid"]
if pidLevel == "ang-speed":
self._controller.alterPidAnglesSpeedConstants(axisIndex, constantP, constantI, constantD)
elif pidLevel == "angles":
self._controller.alterPidAnglesConstants(axisIndex, constantP, constantI, constantD)
else: #accel
self._controller.alterPidAccelConstants(axisIndex, constantP, constantI, constantD)
elif message["key"] == "read-drone-config":
config = Configuration.getInstance().getConfig()
self._send(message["key"], config)
elif message["key"] == "read-drone-state":
state = self._controller.readState()
self._send(message["key"], state.__dict__)
示例5: _dispatch
# 需要导入模块: from config import Configuration [as 别名]
# 或者: from config.Configuration import getInstance [as 别名]
def _dispatch(self, message):
if self._started and message["key"] == "target":
controlData = message["data"]
newTargets = [controlData[0] * Dispatcher.MAX_ANGLE / 100.0,
controlData[1] * Dispatcher.MAX_ANGLE / 100.0,
controlData[2] * Dispatcher.MAX_ANGLE_SPEED / 100.0,
controlData[3] * Dispatcher.MAX_ACCEL_Z / 100.0]
self._controller.setTargets(newTargets)
elif self._started and message["key"] == "throttle":
if not self._throttleByUser:
#Disable Z-accel stabilization
self._controller.alterPidAccelConstants(2, 0.0, 0.0, 0.0)
self._throttle = 0
self._controller.standBy()
self._throttleByUser = True
newThrottle = message["data"]
if newThrottle > 0:
dThrottle = newThrottle - self._throttle
if dThrottle != 0:
self._throttle = newThrottle
self._controller.addThrottle(dThrottle)
else:
self._throttle = 0
self._controller.standBy()
elif message["key"] == "is-started":
self._started = message["data"]
self._throttle = 0
if self._started:
self._controller.standBy()
else:
self._controller.idle()
# elif message["key"] == "integrals":
#
# enable = message["data"]
#
# if enable:
# self._controller.enableIntegrals()
# else:
# self._controller.disableIntegrals()
elif message["key"] == "pid-calibration":
data = message["data"]
axisSwitcher = {
"X": 0,
"Y": 1,
"Z": 2
}
axisIndex = axisSwitcher.get(data["axis"])
constantP = data["p"]
constantI = data["i"]
constantD = data["d"]
pidLevel = data["pid"]
if pidLevel == "ang-speed":
self._controller.alterPidAnglesSpeedConstants(axisIndex, constantP, constantI, constantD)
elif pidLevel == "angles":
self._controller.alterPidAnglesConstants(axisIndex, constantP, constantI, constantD)
else: #accel
self._controller.alterPidAccelConstants(axisIndex, constantP, constantI, constantD)
elif message["key"] == "read-drone-config":
config = Configuration.getInstance().getConfig()
self._send(message["key"], config)
elif message["key"] == "read-drone-state":
state = self._controller.readState()
self._send(message["key"], state.__dict__)