Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Next, we would like to visualize any given state of a robot arm, as well as its environment. We will do this via matplotlib. Implement

Next, we would like to visualize any given state of a robot arm, as well as its environment. We will do this via matplotlib. Implement the method plot_robot_state which takes in a required argument, the joint angles, as well as an optional value target representing an (x,y) target point in the environment. It should output a plot to the input file name with a visualization of the following: The vertical walls of the environment (if any) If target is not None, a single point with the target location. You may choose whatever marker you wish for the target so long as it is clearly visible. The links of the robot. If a link is in collision with any of the walls, you should distinguish the link by coloring it differently and plotting it as a dashed line. The joints should also be visible via some sort of marker, even if the arm is at its zero-angle configuration. The x and y bounds should be set so that if the robot is fully stretched out in one direction, it will still fit within the plot. (Whats the maximum value the arm can be stretched out?) If the target or walls fall outside of these bounds, they do not have to show up on the plot. No need for a title or axis labels. Then for the robot RobotArm(2, 1, 2, obstacles=[VerticalWall(3.2)]), run plot_robot_state([0.2, 0.4, 0.6], target=[1.5, 1.5]) , and place the plot into the document here.

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 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 VerticalWall: def __init__(self, loc): """  A VerticalWall represents a vertical line in space in the XY plane, of the form x = loc.  :param loc: A scalar value  """  self.loc = loc def __repr__(self): return ''.format(self.loc)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Practical Database Programming With Visual Basic.NET

Authors: Ying Bai

1st Edition

0521712351, 978-0521712354

More Books

Students also viewed these Databases questions