Question: First, implement the check_wall_collision method of the Link class. It should take in an instance of a VerticalWall and return True if the link intersects

First, implement the check_wall_collision method of the Link class. It should take in an instance of a VerticalWall and return True if the link intersects the vertical wall at the corresponding objects x-location, and False otherwise.Example:my_link = Link((1.1, 5.0), (3.0, 3.3))my_link.check_wall_collision(VerticalWall(2.1)) # Truemy_link.check_wall_collision(VerticalWall(-0.3)) # False Next, implement the get_collision_score method of the RobotArm class. For each link, it should count the number of walls in the robot arms environment which the link is in collision with. It should then sum up all of those numbers and return the negative of the sum. So when there are no collisions, the score is 0; when there is 1 link colliding with 1 wall, the score is -1; when there is 1 link colliding with 2 walls or 2 links colliding with 1 wall each, the score is -2; etc.Example:my_arm = RobotArm(1, 1, 1, obstacles=[VerticalWall(1.5)])# Arm is vertical, should be 0my_arm.get_collision_score([np.pi/2, 0, 0]) # Arm is horizontal but then folds back, should be -2my_arm.get_collision_score([0, 0, np.pi]) Comment: Yes, the first part is as easy as it seems. The point of this is that in general, you can have arbitrary representations of obstacles in the environment and have a check to see if your link collides with those walls. Simulating such collisions can begin to be quite computationally expensive when dealing with 3D models of robot links and environments, but thankfully were not asking you to implement anything like that.

class Link: def __init__(self, start, end): """  Represents a finite line segment in the XY plane, with start and ends given as 2-vectors  :param start: A length 2 Numpy array  :param end: A length 2 Numpy array  """  self.start = start self.end = end def __repr__(self): return ''.format(self.start[0], self.start[1], self.end[0], self.end[1]) def __str__(self): return self.__repr__() def check_wall_collision(self, wall): if not isinstance(wall, VerticalWall): raise ValueError('Please input a valid Wall object to check for collision.') raise NotImplementedError

class RobotArm: def __init__(self, *arm_lengths, obstacles=None): """  Represents an N-link arm with the arm lengths given.  Example of initializing a 3-link robot with a single obstacle:   my_arm = RobotArm(0.58, 0.14, 0.43, obstacles=[VerticalWall(0.45)])   :param arm_lengths: Float values representing arm lengths of the robot.  :param obstacles:  """  self.arm_lengths = np.array(arm_lengths) if np.any(self.arm_lengths < 0): raise ValueError("Cannot have negative arm length!") self.obstacles = [] if obstacles is not None: self.obstacles = obstacles def __repr__(self): msg = '' return msg def __str__(self): return self.__repr__() def get_links(self, thetas): """  Returns all of the link locations of the robot as Link objects.  :param thetas: A list or array of scalars matching the number of arms.  :return: A list of Link objects.  """   cum_theta = np.cumsum(thetas) results = np.zeros((self.arm_lengths.shape[0] + 1, 2)) results[1:, 0] = np.cumsum(self.arm_lengths * np.cos(cum_theta)) results[1:, 1] = np.cumsum(self.arm_lengths * np.sin(cum_theta)) links = [Link(start, end) for start, end in zip(results[:-1], results[1:])] return links def get_ee_location(self, thetas): """  Returns the location of the end effector as a length 2 Numpy array.  :param thetas: A list or array of scalars matching the number of arms.  :return: A length 2 Numpy array of the x,y coordinate.  """  return self.get_links(thetas)[-1].end def ik_grid_search(self, target, intervals): raise NotImplementedError def ik_fmin_search(self, target, thetas_guess, max_calls=100): raise NotImplementedError def get_collision_score(self, thetas): raise NotImplementedError def ik_constrained_search(self, target, thetas_guess, max_iters=100): raise NotImplementedError def plot_robot_state(self, thetas, target=None, filename='robot_arm_state.png'): raise NotImplementedError

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!