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


Python Motor.setPID方法代码示例

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


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

示例1: parameters

# 需要导入模块: from motor import Motor [as 别名]
# 或者: from motor.Motor import setPID [as 别名]
class Robot:

	######################
	### Initialisation ###
	######################

	"""
	Sets up the standard motor parameters (excluding PID values)
	"""
	def initMotorParams(self, motorParams):
		motorParams.maxRotationAcceleration = 10
		motorParams.maxRotationSpeed = 20
		motorParams.feedForwardGain = 255/20
		motorParams.minPWM = 18
		motorParams.pidParameters.minOutput = -255
		motorParams.pidParameters.maxOutput = 255
	
	"""
	Reads robot configuration from the config file
	"""
	def initConfig(self):
		config = RawConfigParser()
		config.optionxform = str
		config.read('robot.cfg')
		for (item, value) in config.items('Robot'):
			setattr(self, item, float(value))
		print("Robot config loaded")
	
	"""
	Sets default configuration values - call this before `initConfig`
	"""
	def setDefaults(self):
		# The time between successive `check` calls
		self.deltaTime = 0.1
		# Overall power coefficient to the motors
		self.powerL = 1
		self.powerR = 1
		# Overall coefficient for rotation
		self.rotatePower = 0.95

		# Number of radians to one metre of movement
		self.movementCoeff = 36.363636
		# The centre-to-wheel distance of the robot
		self.botRadius = 0.08
		
		# Motor PID values
		self.pidk_p = 600
		self.pidk_i = 100
		self.pidk_d = 20

	def __init__(self):
		self.logging = False
		self.setDefaults()
		self.interface = brickpi.Interface()
		self.interface.initialize()
		self.events = Events()
		self.motorL = Motor(self.interface, self.events, 0)
		self.motorR = Motor(self.interface, self.events, 1)
		self.initMotorParams(self.motorL.motorParams)
		self.initMotorParams(self.motorR.motorParams)

		self.initConfig()
		self.touchSensorL = PushSensor('left',  self.interface, 0, self.events, brickpi.SensorType.SENSOR_TOUCH)
		self.touchSensorR = PushSensor('right', self.interface, 1, self.events, brickpi.SensorType.SENSOR_TOUCH)
		Bumper(self.events)
		self.ultraSonic = UltraSonicSensor(self.interface, 2, self.events, brickpi.SensorType.SENSOR_ULTRASONIC)
		self.setPID(self.pidk_p, self.pidk_i, self.pidk_d)

		self.events.add(EventType.SENSOR_TOUCH, self.sensorAction)
	
	###############
	### Logging ###
	###############

	"""
	Set whether to enable logging
	"""
	def setLogging(self, log):
		self.logging = log

	"""
	Starts logging on the current interface
	`optargs` is a list of identifying values for the log file name
	"""
	def startLogging(self, optargs):
		if self.logging:
			optargs = [optarg for optarg in optargs if optarg is not None]
			optargs_str = '_'.join(str(optarg) for optarg in optargs)
			self.logName = './logs/' + \
				str(int(time.time())) +'_p' + \
				str(self.pidk_p) + '_i' + \
				str(self.pidk_i) + '_d' + \
				str(self.pidk_d) + '_' + optargs_str + '.log'
			self.interface.startLogging(self.logName)

	"""
	Stops all logging
	"""
	def stopLogging(self):
		self.interface.stopLogging()
#.........这里部分代码省略.........
开发者ID:patengelbert,项目名称:robotics-CO333,代码行数:103,代码来源:robot.py


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