Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # transform.py
- # ---------------
- # Licensing Information: You are free to use or extend this projects for
- # educational purposes provided that (1) you do not distribute or publish
- # solutions, (2) you retain this notice, and (3) you provide clear
- # attribution to the University of Illinois at Urbana-Champaign
- #
- # Created by Jongdeog Lee (jlee700@illinois.edu) on 09/12/2018
- """
- This file contains the transform function that converts the robot arm map
- to the maze.
- """
- import copy
- from arm import Arm
- from maze import Maze
- from search import *
- from geometry import *
- from const import *
- from util import *
- def transformToMaze(arm, goals, obstacles, window, granularity):
- """This function transforms the given 2D map to the maze in MP1.
- Args:
- arm (Arm): arm instance
- goals (list): [(x, y, r)] of goals
- obstacles (list): [(x, y, r)] of obstacles
- window (tuple): (width, height) of the window
- granularity (int): unit of increasing/decreasing degree for angles
- Return:
- Maze: the maze instance generated based on input arguments.
- """
- # arm = arm
- alphaRange, betaRange = arm.getArmLimit()
- startPos = arm.getArmAngle()
- # alphaRange = angleRange[0]
- # betaRange = angleRange[1]
- offsets = [alphaRange[0], betaRange[0]]
- startIdx = angleToIdx(startPos, offsets , granularity)
- numRows = math.floor((alphaRange[1] - alphaRange[0])/granularity) + 1
- numCols = math.floor((betaRange[1] - betaRange[0])/granularity) + 1
- maze = [['' for i in range(numCols)] for j in range(numRows)]
- maze[startIdx[0]][startIdx[1]] = START_CHAR
- for alpha in range(alphaRange[0], alphaRange[1]+1):
- for beta in range(betaRange[0], betaRange[1]+1):
- arm.setArmAngle([alpha, beta])
- armPos = arm.getArmPosDist()
- armWindow = arm.getArmPos()
- end = arm.getEnd()
- # print(armPos)
- index = angleToIdx([alpha,beta], offsets, granularity)
- if index[0] == startIdx[0] and index[1] == startIdx[1]:
- continue
- else:
- if doesArmTouchObjects(armPos, obstacles, False) \
- or not isArmWithinWindow(armWindow, window):
- # print('yoof')
- maze[index[0]][index[1]] = WALL_CHAR
- elif doesArmTouchObjects(armPos, goals, True) and not doesArmTipTouchGoals(end, goals):
- maze[index[0]][index[1]] = WALL_CHAR
- elif doesArmTipTouchGoals(end, goals):
- maze[index[0]][index[1]] = OBJECTIVE_CHAR
- else:
- maze[index[0]][index[1]] = SPACE_CHAR
- return Maze(maze, offsets, granularity)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement