def setup(self): # create the Local Perceptiual Space window units = self.robot.range.units self.robot.range.units = 'MM' sizeMM = self.robot.range.getMaxvalue() * 3 + \ self.robot.radius self.robot.range.units = units self.lps = LPS(20, 20, widthMM=sizeMM, heightMM=sizeMM) self.gps = GPS(400, 300, widthMM=sizeMM * 5, heightMM=sizeMM * 5) self.stick = Joystick()
class Map(Brain): def setup(self): # We want our map to measure in MM, so we first store our current unit of measure units = self.robot.range.units # We then reset our measurements to MMs self.robot.range.units = 'MM' # Calculate the maximum range of our sensors rangeMaxMM = self.robot.range.getMaxvalue() sizeMM = rangeMaxMM * 3 + (self.robot.radius / 1000.0) # in MMs # Reset our unit of measure self.robot.range.units = units # Now, we create our Local Perceptual Space window - this will hold our local map # Map will be 20px by 20px and will represent a height and width of sizeMM (total sensor range) self.lps = LPS( 40, 40, widthMM = sizeMM, heightMM = sizeMM) # Then create our Global Perceptual Space window - this will hold our global map # This map will be 500px by 500px and will represent an area N times the size of our maximum range self.gps = GPS( cols=300, rows=300, heightMM = sizeMM * 5, widthMM = sizeMM * 5) self.joystick = Joystick(share.gui) self.need_redraw = False self.lock = thread.allocate_lock() def step(self): if not self.lock.acquire(False): return #print "Stepping...", # First we clear out all our old LPS data self.lps.reset() # Next we update our LPS with current 'range' sensor readings self.lps.sensorHits(self.robot, 'range') # Now redraw our LPS window - the LPS redraw can be improve performance # Then update our GPS with the new information in the LPS self.gps.updateFromLPS(self.lps, self.robot) # Finally, we redraw the GPS window self.need_redraw = True self.move(self.joystick.translate, self.joystick.rotate) self.lock.release() #print "done stepping!" def redraw(self): if (not self.lock.acquire(False)): return #print "Redrawing...", if self.need_redraw: self.lps.redraw(drawLabels=False) self.gps.update() self.gps.redraw() self.need_redraw = False self.lock.release() #print "done redrawing!" def destroy(self): # Make sure we close down cleanly self.lps.destroy() self.gps.destroy() self.joystick.destroy()
class SimpleBrain(Brain): def setup(self): # create the Local Perceptiual Space window units = self.robot.range.units self.robot.range.units = 'MM' sizeMM = self.robot.range.getMaxvalue() * 3 + \ self.robot.radius self.robot.range.units = units self.lps = LPS(20, 20, widthMM=sizeMM, heightMM=sizeMM) self.gps = GPS(400, 300, widthMM=sizeMM * 5, heightMM=sizeMM * 5) self.stick = Joystick() def destroy(self): self.lps.destroy() self.gps.destroy() self.stick.destroy() def step(self): robot = self.robot self.lps.reset() # reset counts self.lps.sensorHits(robot, 'range') self.lps.redraw() self.gps.updateFromLPS(self.lps, robot) self.gps.redraw() self.robot.move(self.stick.translate, self.stick.rotate)
class Map(Brain): def setup(self): # We want our map to measure in MM, so we first store our current unit of measure units = self.robot.range.units # We then reset our measurements to MMs self.robot.range.units = "MM" # Calculate the maximum range of our sensors rangeMaxMM = self.robot.range.getMaxvalue() sizeMM = rangeMaxMM * 3 + (self.robot.radius / 1000.0) # in MMs # Reset our unit of measure self.robot.range.units = units # Now, we create our Local Perceptual Space window - this will hold our local map # Map will be 20px by 20px and will represent a height and width of sizeMM (total sensor range) self.lps = LPS(40, 40, widthMM=sizeMM, heightMM=sizeMM) # Then create our Global Perceptual Space window - this will hold our global map # This map will be 500px by 500px and will represent an area N times the size of our maximum range self.gps = GPS(cols=300, rows=300, heightMM=sizeMM * 5, widthMM=sizeMM * 5) self.joystick = Joystick(share.gui) self.need_redraw = False self.lock = thread.allocate_lock() def step(self): if not self.lock.acquire(False): return # print "Stepping...", # First we clear out all our old LPS data self.lps.reset() # Next we update our LPS with current 'range' sensor readings self.lps.sensorHits(self.robot, "range") # Now redraw our LPS window - the LPS redraw can be improve performance # Then update our GPS with the new information in the LPS self.gps.updateFromLPS(self.lps, self.robot) # Finally, we redraw the GPS window self.need_redraw = True self.move(self.joystick.translate, self.joystick.rotate) self.lock.release() # print "done stepping!" def redraw(self): if not self.lock.acquire(False): return # print "Redrawing...", if self.need_redraw: self.lps.redraw(drawLabels=False) self.gps.update() self.gps.redraw() self.need_redraw = False self.lock.release() # print "done redrawing!" def destroy(self): # Make sure we close down cleanly self.lps.destroy() self.gps.destroy() self.joystick.destroy()
def setup(self): # create the Local Perceptiual Space window units = self.robot.range.units self.robot.range.units = "MM" sizeMM = self.robot.range.getMaxvalue() * 3 + self.robot.radius self.robot.range.units = units self.lps = LPS(20, 20, widthMM=sizeMM, heightMM=sizeMM) self.gps = GPS(400, 300, widthMM=sizeMM * 5, heightMM=sizeMM * 5) self.stick = Joystick()
def setup(self): # We want our map to measure in MM, so we first store our current unit of measure units = self.robot.range.units # We then reset our measurements to MMs self.robot.range.units = 'MM' # Calculate the maximum range of our sensors rangeMaxMM = self.robot.range.getMaxvalue() sizeMM = rangeMaxMM * 3 + (self.robot.radius / 1000.0) # in MMs # Reset our unit of measure self.robot.range.units = units # Now, we create our Local Perceptual Space window - this will hold our local map # Map will be 20px by 20px and will represent a height and width of sizeMM (total sensor range) self.lps = LPS( 40, 40, widthMM = sizeMM, heightMM = sizeMM) # Then create our Global Perceptual Space window - this will hold our global map # This map will be 500px by 500px and will represent an area N times the size of our maximum range self.gps = GPS( cols=300, rows=300, heightMM = sizeMM * 5, widthMM = sizeMM * 5) self.joystick = Joystick(share.gui) self.need_redraw = False self.lock = thread.allocate_lock()
def setup(self): # We want our map to measure in MM, so we first store our current unit of measure units = self.robot.range.units # We then reset our measurements to MMs self.robot.range.units = "MM" # Calculate the maximum range of our sensors rangeMaxMM = self.robot.range.getMaxvalue() sizeMM = rangeMaxMM * 3 + (self.robot.radius / 1000.0) # in MMs # Reset our unit of measure self.robot.range.units = units # Now, we create our Local Perceptual Space window - this will hold our local map # Map will be 20px by 20px and will represent a height and width of sizeMM (total sensor range) self.lps = LPS(40, 40, widthMM=sizeMM, heightMM=sizeMM) # Then create our Global Perceptual Space window - this will hold our global map # This map will be 500px by 500px and will represent an area N times the size of our maximum range self.gps = GPS(cols=300, rows=300, heightMM=sizeMM * 5, widthMM=sizeMM * 5) self.joystick = Joystick(share.gui) self.need_redraw = False self.lock = thread.allocate_lock()
class SimpleBrain(Brain): def setup(self): # create the Local Perceptiual Space window units = self.robot.range.units self.robot.range.units = "MM" sizeMM = self.robot.range.getMaxvalue() * 3 + self.robot.radius self.robot.range.units = units self.lps = LPS(20, 20, widthMM=sizeMM, heightMM=sizeMM) self.gps = GPS(400, 300, widthMM=sizeMM * 5, heightMM=sizeMM * 5) self.stick = Joystick() def destroy(self): self.lps.destroy() self.gps.destroy() self.stick.destroy() def step(self): robot = self.robot self.lps.reset() # reset counts self.lps.sensorHits(robot, "range") self.lps.redraw() self.gps.updateFromLPS(self.lps, robot) self.gps.redraw() self.robot.move(self.stick.translate, self.stick.rotate)