本文整理汇总了Python中driver.Driver.turn方法的典型用法代码示例。如果您正苦于以下问题:Python Driver.turn方法的具体用法?Python Driver.turn怎么用?Python Driver.turn使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类driver.Driver
的用法示例。
在下文中一共展示了Driver.turn方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from driver import Driver [as 别名]
# 或者: from driver.Driver import turn [as 别名]
#.........这里部分代码省略.........
for action in code:
self.robot.insideFiled = True
print "================= ACTION ", action, "================="
print "battery:", self.robot.battery
while not row.endOfRow:
# sprayer( self.robot, True, True )
for (speed, angularSpeed) in self.driver.followLineG( row.line ):
# print "TEST %.2f" % (math.degrees(normalizeAnglePIPI(row.line.angle - self.robot.localisation.pose()[2])))
if abs(normalizeAnglePIPI(row.line.angle - self.robot.localisation.pose()[2])) > SLOW_DOWN_ANGLE:
speed *= 0.9
if self.robot.laserData:
self.robot.toDisplay = 'OK'
else:
self.robot.toDisplay = '--'
speed, angularSpeed = 0.0, 0.0
# if detectBlockedRow and row.collisionAhead[1] < 0.25:
blockedCamCount = 0
if detectBlockedRow and self.robot.cameraData:
camDat, fileName = self.robot.cameraData
if camDat:
blockedCamCount = int(camDat.split()[0])
if blockedCamCount > RED_ALERT:
print "CAMERA BLOCKED!!", blockedCamCount
# print self.robot.cameraData
# if detectBlockedRow and row.collisionAhead[2]:
if detectBlockedRow and row.collisionAhead[3] and blockedCamCount > RED_ALERT:
# if detectBlockedRow and blocked:
print "---------- COLLISON -> TURN 180 -------------"
self.robot.beep = 1
self.driver.stop()
# self.driver.goStraight( -0.5 )
self.driver.turn( math.radians(90), radius = 0.12, angularSpeed=math.radians(120), withStop=False )
self.driver.turn( math.radians(90), radius = -0.12, angularSpeed=math.radians(120) )
self.robot.beep = 0
# self.driver.turn( math.radians(180), radius = 0.075 )
# self.driver.turn( math.radians(180), radius = 0.0 )
# self.driver.turn( math.radians(20), radius = 0.37, angularSpeed=math.radians(20) )
# self.driver.turn( math.radians(70), radius = 0.08, angularSpeed=math.radians(20) )
# self.driver.turn( math.radians(70), radius = -0.08, angularSpeed=math.radians(20) )
# self.driver.turn( math.radians(20), radius = -0.37, angularSpeed=math.radians(20) )
self.robot.setSpeedPxPa( 0.0, 0.0 )
row.reset( self.robot.localisation.pose(), offsetDeg = None ) # instead of turning shift search
else:
# if detectBlockedRow and (row.collisionAhead[0] < 0.5 or row.collisionAhead[1] < 0.7):
# if self.verbose:
# print "!!SLOW DOWN!!"
# speed, angularSpeed = speed/2.0, angularSpeed/2.0 # slow down
self.robot.setSpeedPxPa( speed, angularSpeed )
self.robot.update()
if row.newData:
row.newData = False
break
# sprayer( self.robot, False, False )
# handle action after row termination
self.robot.insideField = False
self.robot.beep = 1
self.driver.stop()
self.robot.beep = 0
if action == 0:
self.driver.goStraight( 0.2 )
prevAngle = self.robot.localisation.pose()[2]
if not self.driver.turn( math.radians(180), timeout=7.0 ):
self.driver.goStraight( -0.2 )
示例2: __init__
# 需要导入模块: from driver import Driver [as 别名]
# 或者: from driver.Driver import turn [as 别名]
class SICKRobotDay2016:
def __init__(self, robot, code, verbose = False):
self.random = random.Random(0).uniform
self.robot = robot
self.verbose = verbose
self.code = code
self.robot.attachEmergencyStopButton()
# change robot wheel calibration
wd = 427.0 / 445.0 * 0.26/4.0 # with gear 1:4
delta = -0.00015
self.robot._WHEEL_DIAMETER = {SIDE_LEFT: wd+delta, SIDE_RIGHT: wd-delta}
self.robot.attachCamera(sleep=0.5)
self.robot.attachLaser( remission=True, pose=((0.24, -0.13, 0.08), (0,math.radians(180),0)) )
self.robot.attachRFU620()
self.driver = Driver( self.robot, maxSpeed = 0.5, maxAngularSpeed = math.radians(180) )
self.robot.localisation = SimpleOdometry()
self.robot.last_valid_rfid = None, None # tag, position
self.robot.addExtension(draw_rfu620_extension)
self.robot.addExtension(draw_cubes_extension)
self.robot.laser.stopOnExit = False # for faster boot-up
def load_cube(self):
print "load cube (time = {:.1f}s)".format(self.robot.time - self.start_time)
self.driver.goStraight(0.3, timeout=30)
gripperClose(self.robot)
def place_cube(self):
pos = combinedPose(self.robot.localisation.pose(), (0.2, 0, 0))[:2] # TODO check proper offset
print "place cube at ({:.2f}, {:.2f} (time = {:.1f}))".format(pos[0], pos[1], self.robot.time - self.start_time)
viewlog.dumpBeacon(pos, color=(255, 255, 255))
viewlog.dumpObstacles([[pos]])
gripperOpen(self.robot)
self.driver.goStraight(-0.4, timeout=30)
def game_over(self):
print 'Game over (battery status = {}V)'.format(self.robot.battery)
for k in xrange(10):
self.robot.setSpeedPxPa(0.0, 0.0)
self.robot.update()
raise EmergencyStopException() # TODO: Introduce GameOverException as in Eurobot
def find_cube(self, timeout):
print "find_cube-v1"
prev = None
cd = CubeDetector(self.robot.laser.pose)
startTime = self.robot.time
while self.robot.time < startTime + timeout:
self.robot.update()
if prev != self.robot.laserData:
prev = self.robot.laserData
cubes = cd.detect_cubes_xy(self.robot.laserData, limit=4)
if len(cubes) > 0:
for i, (cube_x, cube_y) in enumerate(cubes):
goal = combinedPose(self.robot.localisation.pose(), (cube_x, cube_y, 0))[:2]
viewlog.dumpBeacon(goal, color=(200, 200, 0) if i > 0 else (255, 255, 0))
cube_x, cube_y = cubes[0]
cube_y += 0.05 # hack for bended(?) laser
print "{:.2f}\t{:.2f}".format(cube_x, cube_y)
speed = 0.0
tolerance = 0.01
if cube_x > 0.5:
tolerance = 0.05
angle = math.atan2(cube_y, cube_x)
turnStep = math.radians(10)
if abs(angle) > math.radians(10):
turnStep = math.radians(50)
if cube_y > tolerance:
angularSpeed = turnStep
elif cube_y < -tolerance:
angularSpeed = -turnStep
else:
angularSpeed = 0
speed = 0.1
if cube_x > 0.5:
speed = 0.3 # move faster toward further goals
if cube_x < 0.30:
return True
self.robot.setSpeedPxPa(speed, angularSpeed)
else:
self.robot.setSpeedPxPa(0.0, 0.0)
print "TIMEOUT"
return False
def ver0( self, verbose=False ):
# Go straight for 2 meters
print "ver0", self.robot.battery
#.........这里部分代码省略.........