Code: Select all
...
for i in range(len(targets)):
print('i: ', i)
pose = sim.getObjectPose(targets[i], simBase)
simIK.setObjectPose(ikEnv, ikTarget, pose, ikBase)
config = None
while not config:
config = simIK.findConfig(ikEnv, ikGroup, ikJointHandles, 0.65, 0.1, [1, 1, 1, 0.1],
lambda x: configuration_validation_callback(sim, simJointHandles, roboCollection,
x))
if not config:
print("No valid config found. Retrying...")
if config:
config = [round(num, 6) for num in config]
print('config: ', config)
task = simOMPL.createTask('task')
# print(task)
# simOMPL.setAlgorithm(task, simOMPL.Algorithm.RRTConnect)
simOMPL.setAlgorithm(task, algorithm)
# simOMPL.setCollisionPairs(task, [roboCollection, collisionCollection])
# simOMPL.setCollisionPairs(task, [roboCollection, sim.handle_all])
simOMPL.setCollisionPairs(task, [roboCollection, roboCollection, roboCollection, sim.handle_all])
# simOMPL.setCollisionPairs(task, [roboCollection, roboCollection, roboCollection, collisionCollection])
simOMPL.setStateSpaceForJoints(task, simJointHandles, useForProjection)
simOMPL.setStartState(task, get_config(sim, simJointHandles))
simOMPL.setGoalState(task, config)
simOMPL.setup(task)
# simOMPL.simplifyPath(task, -1.0)
valid = simOMPL.isStateValid(task, config)
print('valid: ', valid)
solution = False
res = False
path = False
while not solution:
res, path = simOMPL.compute(task, 6, -1, 300)
print('OMPL res: ', res)
solution = simOMPL.hasExactSolution(task)
print('Exact_solution: ', solution)
# config = None
if res and path:
followPathScript = None
fkVel = 20
fkAccel = 20
fkJerk = 80
fkMaxVel = [fkVel*math.pi/180,fkVel*math.pi/180,fkVel*math.pi/180,fkVel*math.pi/180,fkVel*math.pi/180,fkVel*math.pi/180,fkVel*math.pi/180]
fkMaxAccel = [fkAccel*math.pi/180,fkAccel*math.pi/180,fkAccel*math.pi/180,fkAccel*math.pi/180,fkAccel*math.pi/180,fkAccel*math.pi/180,fkAccel*math.pi/180]
minMaxVel= (-fkMaxVel[0],fkMaxVel[0],-fkMaxVel[1],fkMaxVel[1],-fkMaxVel[2],fkMaxVel[2],-fkMaxVel[3],fkMaxVel[3],-fkMaxVel[4],fkMaxVel[4],-fkMaxVel[5],fkMaxVel[5],-fkMaxVel[6],fkMaxVel[6])
minMaxAccel = (-fkMaxAccel[0],fkMaxAccel[0],-fkMaxAccel[1],fkMaxAccel[1],-fkMaxAccel[2],fkMaxAccel[2],-fkMaxAccel[3],fkMaxAccel[3],-fkMaxAccel[4],fkMaxAccel[4],-fkMaxAccel[5],fkMaxAccel[5],-fkMaxAccel[6],fkMaxAccel[6])
pl = sim.getPathLengths(path,7)
print('pl: ', pl)
if followPathScript == None:
followPathScript = -1
pathPts = False
times = False
pathPts, times, followPathScript = sim.generateTimeOptimalTrajectory(path, pl[0], minMaxVel, minMaxAccel, 1000, 'not-a-knot', 5, followPathScript)
st = sim.getSimulationTime()
dt = 0
sw = sim.setStepping(True)
while dt<times[-1]:
print('dt: ', dt, 'times[-1]: ', times[-1])
p = sim.getPathInterpolatedConfig(pathPts, times, dt)
set_config(sim, simJointHandles, p, 1)
sim.step()
dt = sim.getSimulationTime()-st
p = sim.getPathInterpolatedConfig(pathPts, times, times[-1])
set_config(sim, simJointHandles, p, 1)
sim.setStepping(sw)
simOMPL.destroyTask(task)
joint_config = get_config(sim, simJointHandles)
I want to know the reason for this phenomenon and how to solve this problem. I speculate that in environments with obstacles, the path planning algorithm used by ompl may generate paths that are too winding or have abrupt turns, leading to suboptimal trajectories generated by toppra. However, I don't know how to resolve this issue. I have tried increasing the number of waypoints for toppra and extending the computation time, but these measures have not improved the situation.