本文整理汇总了Python中motor.Motor.rotate方法的典型用法代码示例。如果您正苦于以下问题:Python Motor.rotate方法的具体用法?Python Motor.rotate怎么用?Python Motor.rotate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类motor.Motor
的用法示例。
在下文中一共展示了Motor.rotate方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: str
# 需要导入模块: from motor import Motor [as 别名]
# 或者: from motor.Motor import rotate [as 别名]
addr = rfid.getaddr()
if addr:
#print "Address: %s" % addr
found, entry = db.checkaddr(addr)
# Found is the number of entries that occur with address
if found:
ld.setstate(ld.GREEN)
user = entry[USERNAME] # if found > 1, this may log incorrect user. shouldnt happen.
motor.power(ON)
# Hardcoded
# motor.open()
turning = True
while turning:
p0 = encoder.getpulses()
motor.rotate(num_steps=50, speed=0.2)
motor.steps += 50
p1 = encoder.getpulses()
if (p1 - p0) < # clk pulses equivalent to 50 steps
turning = False
sleep(4) # delay between release
steps = motor.steps - 50 # always release less than we take
motor.close(num_rotations=1, rotation_precision=steps)
motor.power(OFF)
else:
ld.setstate(ld.RED)
user = str()
sleep(2) # make illegal user wait
db.loguser(addr, user)
示例2: parameters
# 需要导入模块: from motor import Motor [as 别名]
# 或者: from motor.Motor import rotate [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()
#.........这里部分代码省略.........