SHARE
TWEET

transform

a guest Feb 17th, 2020 99 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. # transform.py
  3. # ---------------
  4. # Licensing Information:  You are free to use or extend this projects for
  5. # educational purposes provided that (1) you do not distribute or publish
  6. # solutions, (2) you retain this notice, and (3) you provide clear
  7. # attribution to the University of Illinois at Urbana-Champaign
  8. #
  9. # Created by Jongdeog Lee (jlee700@illinois.edu) on 09/12/2018
  10.  
  11. """
  12. This file contains the transform function that converts the robot arm map
  13. to the maze.
  14. """
  15. import copy
  16. from arm import Arm
  17. from maze import Maze
  18. from search import *
  19. from geometry import *
  20. from const import *
  21. from util import *
  22.  
  23. def transformToMaze(arm, goals, obstacles, window, granularity):
  24.     """This function transforms the given 2D map to the maze in MP1.
  25.  
  26.         Args:
  27.             arm (Arm): arm instance
  28.             goals (list): [(x, y, r)] of goals
  29.             obstacles (list): [(x, y, r)] of obstacles
  30.             window (tuple): (width, height) of the window
  31.             granularity (int): unit of increasing/decreasing degree for angles
  32.  
  33.         Return:
  34.             Maze: the maze instance generated based on input arguments.
  35.  
  36.     """
  37.     # arm = arm
  38.     alphaRange, betaRange = arm.getArmLimit()
  39.     startPos = arm.getArmAngle()
  40.     # alphaRange = angleRange[0]
  41.     # betaRange = angleRange[1]
  42.     offsets = [alphaRange[0], betaRange[0]]
  43.     startIdx = angleToIdx(startPos, offsets , granularity)
  44.     numRows = math.floor((alphaRange[1] - alphaRange[0])/granularity) + 1
  45.     numCols = math.floor((betaRange[1] - betaRange[0])/granularity) + 1
  46.     maze = [['' for i in range(numCols)] for j in range(numRows)]
  47.     maze[startIdx[0]][startIdx[1]] = START_CHAR
  48.     for alpha in range(alphaRange[0], alphaRange[1]+1):
  49.         for beta in range(betaRange[0], betaRange[1]+1):
  50.             arm.setArmAngle([alpha, beta])
  51.             armPos = arm.getArmPosDist()
  52.             armWindow = arm.getArmPos()
  53.             end = arm.getEnd()
  54.             # print(armPos)
  55.             index = angleToIdx([alpha,beta], offsets, granularity)
  56.             if index[0] == startIdx[0] and index[1] == startIdx[1]:
  57.                 continue
  58.             else:
  59.                 if doesArmTouchObjects(armPos, obstacles, False) \
  60.                 or not isArmWithinWindow(armWindow, window):
  61.                     # print('yoof')
  62.                     maze[index[0]][index[1]] = WALL_CHAR
  63.                 elif doesArmTouchObjects(armPos, goals, True) and not doesArmTipTouchGoals(end, goals):
  64.                     maze[index[0]][index[1]] = WALL_CHAR
  65.                 elif doesArmTipTouchGoals(end, goals):
  66.                     maze[index[0]][index[1]] = OBJECTIVE_CHAR
  67.                 else:
  68.                     maze[index[0]][index[1]] = SPACE_CHAR
  69.     return Maze(maze, offsets, granularity)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top