Question: Let's now use A * to plan a path for a simple planar robot arm with 2 rotational joints to catch a moving target with
Let's now use A to plan a path for a simple planar robot arm with rotational joints to catch a moving target with known trajectory, while avoiding static obstacles in the workspace.
The skeleton code is provided. Your job is to implement the following function:def yourplannerworkspace obstacles, robotinit, target, speedlimitThe function takes the workspace, the polygonal obstacles, the robot initial configuration, the target trajectory and the joint speed limit as input arguments, and returns a path of the robot to catch the target. The planner should try to catch the target as quick as possible. Forward kinematics, goal checking and some other helper functions are provided.
You planner needs the following components:
Discretization of the configuration space the graph
A search over the graph to find the path
Collision checking between the robot and the obstacles the pruning function during the search
Your planner should be complete and optimal with respect to the grid discretization, and be able to handle any initial configuration, any target trajectory and any polygonal obstacles.
You should also do your best to make your planner run as fast as you can, since in practice, the objects on the conveyer belt move fast and your planner only has limited amount of time to plan its motion.
The skeleton code:
import numpy as np
import matplotlib.pyplot as plt
# catch a moving target
def fkRRa:
out npeye
out npcosa npcosaa
out npsina npsinaa
out npcosaa
outnpsinaa
out npsinaa
out npcosaa
return out
def plotArmtheta:
Tsd fkRRtheta
pltplotTsdTsdro pltplotTsdTsdTsdTsdTsdTsdr
a theta
a theta pltplotnpcosanpsinak
# pltplotnpcosanpsinabo
pltplotnpcosanpcosanpcosaanpsinanpsinanpsinaak pltplotnpcosanpcosaanpsinanpsinaabo
# pltaxisequal
return
def plotObstobstacles:
for o in obstacles:
pltploto: o:k
pltploto oook
return
def yourplannerworkspace obstacles, robotinit, target, speedlimit:
# TODO #
comment out the following lines and replace it with your algorithm
examplesol
for i in range:
examplesol.appendrobotinit nparrayispeedlimitispeedlimit
return examplesol, lenexamplesol
def ifReachGoaltheta targetxy:
T fkRRtheta
error absTtargetxy absT targetxy
printerror: error
if error :
return True
return False
def exampletest:
# environment and obstacles
workspace nparray
obstacles
obstacles.append nparray obstacles.append nparray
# initial position of the robot and joint speed limits
robotinit nparray
speedlimit nparray
# moving targets
target
for j in range:
target.appendnpsinjnpcosj
target nparraytarget
solpath, solcost yourplannerworkspace obstacles, robotinit, target, speedlimit printsolpath
fig pltfigurefigsize
for i in rangelentarget:
pltclf
# PlotGridsgrid
pltxlim
pltylim
pltxticksnparange
pltyticksnparange
pltplottarget:target:r:
pltplottargetitargetiro
plotObstobstacles
if i lensolpath:
plotArmsolpathi
pltdraw pltpause
if i lensolpath and ifReachGoalsolpathi targeti:
printThe robot catch the target!"
break
return
if namemain:
# Two test instances are provided. You can design more instances by yourself. exampletest
# exampletest
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
