Exemple #1
0
def placement(x=0, y=0, z=0, rx=0, ry=0, rz=0):
    m = se3.SE3.Identity()
    m.translation = np.matrix([[float(i)] for i in [x, y, z]])
    m.rotation *= rotate('x', rx)
    m.rotation *= rotate('y', ry)
    m.rotation *= rotate('z', rz)
    return m
Exemple #2
0
def placement(x=0, y=0, z=0, rx=0, ry=0, rz=0):
    m = pin.SE3.Identity()
    m.translation = np.matrix([[float(i)] for i in [x, y, z]])
    m.rotation *= rotate('x', rx)
    m.rotation *= rotate('y', ry)
    m.rotation *= rotate('z', rz)
    return m
def rotatePlacement(placement, axis, angle):
    """
    Rotate the given placement of the desired angle along the given axis
    :param placement: a pinocchio.SE3 object
    :param axis: either 'x' , 'y' or 'z'
    :param angle: desired rotation (in radian)
    :return: the updated placement
    """
    T = rotate(axis, angle)
    placement.rotation = placement.rotation @ T
    return placement
Exemple #4
0
    and add the corresponding visuals in gepetto viewer with name prefix given by string <name>.
    It returns the robot wrapper (model,data).
    '''
    robot = RobotWrapper(urdf, [PKG])
    robot.model.jointPlacements[1] = M0 * robot.model.jointPlacements[1]
    robot.visual_model.geometryObjects[0].placement = M0 * robot.visual_model.geometryObjects[0].placement
    robot.visual_data.oMg[0] = M0 * robot.visual_data.oMg[0]
    robot.initDisplay(loadModel=True, viewerRootNodeName="world/" + name)
    return robot


robots = []
# Load 4 Ur5 robots, placed at 0.3m from origin in the 4 directions x,y,-x,-y.
Mt = SE3(eye(3), np.matrix([.3, 0, 0]).T)  # First robot is simply translated
for i in range(4):
    robots.append(loadRobot(SE3(rotate('z', np.pi / 2 * i), zero(3)) * Mt, "robot%d" % i))

# Set up the robots configuration with end effector pointed upward.
q0 = np.matrix([np.pi / 4, -np.pi / 4, -np.pi / 2, np.pi / 4, np.pi / 2, 0]).T
for i in range(4):
    robots[i].display(q0)

# Add a new object featuring the parallel robot tool plate.
gepettoViewer = robots[0].viewer.gui
w, h, d = 0.25, 0.25, 0.005
color = [red, green, blue, transparency] = [1, 1, 0.78, 1.0]
gepettoViewer.addBox('world/toolplate', w, h, d, color)
Mtool = SE3(rotate('z', 1.268), np.matrix([0, 0, .77]).T)
gepettoViewer.applyConfiguration('world/toolplate', se3ToXYZQUATtuple(Mtool))
gepettoViewer.refresh()
    def createHand(self, root_id=0, prefix='', joint_placement=None):
        def trans(x, y, z):
            return pin.SE3(eye(3), np.matrix([x, y, z]).T)

        def inertia(m, c):
            return pin.Inertia(m, np.matrix(c, np.double).T, eye(3) * m ** 2)

        def joint_name(body):
            return prefix + body + '_joint'

        def body_name(body):
            return 'world/' + prefix + body

        color = [red, green, blue, transparency] = [1, 1, 0.78, 1.0]
        joint_id = root_id
        cm = 1e-2

        joint_placement = joint_placement if joint_placement is not None else pin.SE3.Identity()
        joint_id = self.model.addJoint(joint_id, pin.JointModelRY(), joint_placement, joint_name('wrist'))
        self.model.appendBodyToJoint(joint_id, inertia(3, [0, 0, 0]), pin.SE3.Identity())

        L, W, H = 3 * cm, 5 * cm, 1 * cm
        self.viewer.viewer.gui.addSphere(body_name('wrist'), .02, color)
        self.viewer.viewer.gui.addBox(body_name('wpalm'), L / 2, W / 2, H, color)
        self.visuals.append(Visual(body_name('wpalm'), joint_id, trans(L / 2, 0, 0)))

        self.viewer.viewer.gui.addCapsule(body_name('wpalmb'), H, W, color)
        self.visuals.append(Visual(body_name('wpalmb'), joint_id, pin.SE3(rotate('x', pi / 2), zero(3)), H, W))

        self.viewer.viewer.gui.addCapsule(body_name('wpalmt'), H, W, color)
        pos = pin.SE3(rotate('x', pi / 2), np.matrix([L, 0, 0]).T)
        self.visuals.append(Visual(body_name('wpalmt'), joint_id, pos, H, W))

        self.viewer.viewer.gui.addCapsule(body_name('wpalml'), H, L, color)
        pos = pin.SE3(rotate('y', pi / 2), np.matrix([L / 2, -W / 2, 0]).T)
        self.visuals.append(Visual(body_name('wpalml'), joint_id, pos, H, L))

        self.viewer.viewer.gui.addCapsule(body_name('wpalmr'), H, L, color)
        pos = pin.SE3(rotate('y', pi / 2), np.matrix([L / 2, +W / 2, 0]).T)
        self.visuals.append(Visual(body_name('wpalmr'), joint_id, pos, H, L))

        joint_placement = pin.SE3(eye(3), np.matrix([5 * cm, 0, 0]).T)
        joint_id = self.model.addJoint(joint_id, pin.JointModelRY(), joint_placement, joint_name('palm'))
        self.model.appendBodyToJoint(joint_id, inertia(2, [0, 0, 0]), pin.SE3.Identity())
        self.viewer.viewer.gui.addCapsule(body_name('palm2'), 1 * cm, W, color)
        self.visuals.append(Visual(body_name('palm2'), joint_id, pin.SE3(rotate('x', pi / 2), zero(3)), H, W))

        FL = 4 * cm
        palmIdx = joint_id

        joint_placement = pin.SE3(eye(3), np.matrix([2 * cm, W / 2, 0]).T)
        joint_id = self.model.addJoint(palmIdx, pin.JointModelRY(), joint_placement, joint_name('finger11'))
        self.model.appendBodyToJoint(joint_id, inertia(.5, [0, 0, 0]), pin.SE3.Identity())
        self.viewer.viewer.gui.addCapsule(body_name('finger11'), H, FL - 2 * H, color)
        pos = pin.SE3(rotate('y', pi / 2), np.matrix([FL / 2 - H, 0, 0]).T)
        self.visuals.append(Visual(body_name('finger11'), joint_id, pos, H, FL - 2 * H))

        joint_placement = pin.SE3(eye(3), np.matrix([FL, 0, 0]).T)
        joint_id = self.model.addJoint(joint_id, pin.JointModelRY(), joint_placement, joint_name('finger12'))
        self.model.appendBodyToJoint(joint_id, inertia(.5, [0, 0, 0]), pin.SE3.Identity())

        self.viewer.viewer.gui.addCapsule(body_name('finger12'), H, FL - 2 * H, color)
        pos = pin.SE3(rotate('y', pi / 2), np.matrix([FL / 2 - H, 0, 0]).T)
        self.visuals.append(Visual(body_name('finger12'), joint_id, pos, H, FL - 2 * H))

        joint_placement = pin.SE3(eye(3), np.matrix([FL - 2 * H, 0, 0]).T)
        joint_id = self.model.addJoint(joint_id, pin.JointModelRY(), joint_placement, joint_name('finger13'))
        self.model.appendBodyToJoint(joint_id, inertia(.3, [0, 0, 0]), pin.SE3.Identity())
        self.viewer.viewer.gui.addSphere(body_name('finger13'), H, color)
        self.visuals.append(Visual(body_name('finger13'), joint_id, trans(2 * H, 0, 0), H, 0))

        joint_placement = pin.SE3(eye(3), np.matrix([2 * cm, 0, 0]).T)
        joint_id = self.model.addJoint(palmIdx, pin.JointModelRY(), joint_placement, joint_name('finger21'))
        self.model.appendBodyToJoint(joint_id, inertia(.5, [0, 0, 0]), pin.SE3.Identity())
        self.viewer.viewer.gui.addCapsule(body_name('finger21'), H, FL - 2 * H, color)
        pos = pin.SE3(rotate('y', pi / 2), np.matrix([FL / 2 - H, 0, 0]).T)
        self.visuals.append(Visual(body_name('finger21'), joint_id, pos, H, FL - 2 * H))

        joint_placement = pin.SE3(eye(3), np.matrix([FL, 0, 0]).T)
        joint_id = self.model.addJoint(joint_id, pin.JointModelRY(), joint_placement, joint_name('finger22'))
        self.model.appendBodyToJoint(joint_id, inertia(.5, [0, 0, 0]), pin.SE3.Identity())
        self.viewer.viewer.gui.addCapsule(body_name('finger22'), H, FL - 2 * H, color)
        pos = pin.SE3(rotate('y', pi / 2), np.matrix([FL / 2 - H, 0, 0]).T)
        self.visuals.append(Visual(body_name('finger22'), joint_id, pos, H, FL - 2 * H))

        joint_placement = pin.SE3(eye(3), np.matrix([FL - H, 0, 0]).T)
        joint_id = self.model.addJoint(joint_id, pin.JointModelRY(), joint_placement, joint_name('finger23'))
        self.model.appendBodyToJoint(joint_id, inertia(.3, [0, 0, 0]), pin.SE3.Identity())
        self.viewer.viewer.gui.addSphere(body_name('finger23'), H, color)
        self.visuals.append(Visual(body_name('finger23'), joint_id, trans(H, 0, 0), H, 0))

        joint_placement = pin.SE3(eye(3), np.matrix([2 * cm, -W / 2, 0]).T)
        joint_id = self.model.addJoint(palmIdx, pin.JointModelRY(), joint_placement, joint_name('finger31'))
        self.model.appendBodyToJoint(joint_id, inertia(.5, [0, 0, 0]), pin.SE3.Identity())
        self.viewer.viewer.gui.addCapsule(body_name('finger31'), H, FL - 2 * H, color)
        pos = pin.SE3(rotate('y', pi / 2), np.matrix([FL / 2 - H, 0, 0]).T)
        self.visuals.append(Visual(body_name('finger31'), joint_id, pos, H, FL - 2 * H))

        joint_placement = pin.SE3(eye(3), np.matrix([FL, 0, 0]).T)
        joint_id = self.model.addJoint(joint_id, pin.JointModelRY(), joint_placement, joint_name('finger32'))
        self.model.appendBodyToJoint(joint_id, inertia(.5, [0, 0, 0]), pin.SE3.Identity())
        self.viewer.viewer.gui.addCapsule(body_name('finger32'), H, FL - 2 * H, color)
        pos = pin.SE3(rotate('y', pi / 2), np.matrix([FL / 2 - H, 0, 0]).T)
        self.visuals.append(Visual(body_name('finger32'), joint_id, pos, H, FL - 2 * H))

        joint_placement = pin.SE3(eye(3), np.matrix([FL - 2 * H, 0, 0]).T)
        joint_id = self.model.addJoint(joint_id, pin.JointModelRY(), joint_placement, joint_name('finger33'))
        self.model.appendBodyToJoint(joint_id, inertia(.3, [0, 0, 0]), pin.SE3.Identity())
        self.viewer.viewer.gui.addSphere(body_name('finger33'), H, color)
        self.visuals.append(Visual(body_name('finger33'), joint_id, trans(2 * H, 0, 0), H, 0))

        joint_placement = pin.SE3(eye(3), np.matrix([1 * cm, -W / 2 - H * 1.5, 0]).T)
        joint_id = self.model.addJoint(1, pin.JointModelRY(), joint_placement, joint_name('thumb1'))
        self.model.appendBodyToJoint(joint_id, inertia(.5, [0, 0, 0]), pin.SE3.Identity())
        self.viewer.viewer.gui.addCapsule(body_name('thumb1'), H, 2 * cm, color)
        pos = pin.SE3(rotate('z', pi / 3) * rotate('x', pi / 2), np.matrix([1 * cm, -1 * cm, 0]).T)
        self.visuals.append(Visual(body_name('thumb1'), joint_id, pos, 2 * cm))

        joint_placement = pin.SE3(rotate('z', pi / 3) * rotate('x', pi), np.matrix([3 * cm, -1.8 * cm, 0]).T)
        joint_id = self.model.addJoint(joint_id, pin.JointModelRZ(), joint_placement, joint_name('thumb2'))
        self.model.appendBodyToJoint(joint_id, inertia(.4, [0, 0, 0]), pin.SE3.Identity())
        self.viewer.viewer.gui.addCapsule(body_name('thumb2'), H, FL - 2 * H, color)
        pos = pin.SE3(rotate('x', pi / 3), np.matrix([-0.7 * cm, .8 * cm, -0.5 * cm]).T)
        self.visuals.append(Visual(body_name('thumb2'), joint_id, pos, H, FL - 2 * H))

        # Prepare some patches to represent collision points. Yet unvisible.
        for i in range(10):
            self.viewer.viewer.gui.addCylinder('world/wa%i' % i, .01, .003, [1.0, 0, 0, 1])
            self.viewer.viewer.gui.addCylinder('world/wb%i' % i, .01, .003, [1.0, 0, 0, 1])
            self.viewer.viewer.gui.setVisibility('world/wa%i' % i, 'OFF')
            self.viewer.viewer.gui.setVisibility('world/wb%i' % i, 'OFF')
    def createHand(self, root_id=0, prefix='', joint_placement=None):
        def trans(x, y, z):
            return pin.SE3(eye(3), np.matrix([x, y, z]).T)

        def inertia(m, c):
            return pin.Inertia(m, np.matrix(c, np.double).T, eye(3) * m**2)

        def joint_name(body):
            return prefix + body + '_joint'

        def body_name(body):
            return 'world/' + prefix + body

        color = [red, green, blue, transparency] = [1, 1, 0.78, 1.0]
        joint_id = root_id
        cm = 1e-2

        joint_placement = joint_placement if joint_placement is not None else pin.SE3.Identity(
        )
        joint_id = self.model.addJoint(joint_id, pin.JointModelRY(),
                                       joint_placement, joint_name('wrist'))
        self.model.appendBodyToJoint(joint_id, inertia(3, [0, 0, 0]),
                                     pin.SE3.Identity())

        L, W, H = 3 * cm, 5 * cm, 1 * cm
        self.viewer.viewer.gui.addSphere(body_name('wrist'), .02, color)
        self.viewer.viewer.gui.addBox(body_name('wpalm'), L / 2, W / 2, H,
                                      color)
        self.visuals.append(
            Visual(body_name('wpalm'), joint_id, trans(L / 2, 0, 0)))

        self.viewer.viewer.gui.addCapsule(body_name('wpalmb'), H, W, color)
        self.visuals.append(
            Visual(body_name('wpalmb'), joint_id,
                   pin.SE3(rotate('x', pi / 2), zero(3)), H, W))

        self.viewer.viewer.gui.addCapsule(body_name('wpalmt'), H, W, color)
        pos = pin.SE3(rotate('x', pi / 2), np.matrix([L, 0, 0]).T)
        self.visuals.append(Visual(body_name('wpalmt'), joint_id, pos, H, W))

        self.viewer.viewer.gui.addCapsule(body_name('wpalml'), H, L, color)
        pos = pin.SE3(rotate('y', pi / 2), np.matrix([L / 2, -W / 2, 0]).T)
        self.visuals.append(Visual(body_name('wpalml'), joint_id, pos, H, L))

        self.viewer.viewer.gui.addCapsule(body_name('wpalmr'), H, L, color)
        pos = pin.SE3(rotate('y', pi / 2), np.matrix([L / 2, +W / 2, 0]).T)
        self.visuals.append(Visual(body_name('wpalmr'), joint_id, pos, H, L))

        joint_placement = pin.SE3(eye(3), np.matrix([5 * cm, 0, 0]).T)
        joint_id = self.model.addJoint(joint_id, pin.JointModelRY(),
                                       joint_placement, joint_name('palm'))
        self.model.appendBodyToJoint(joint_id, inertia(2, [0, 0, 0]),
                                     pin.SE3.Identity())
        self.viewer.viewer.gui.addCapsule(body_name('palm2'), 1 * cm, W, color)
        self.visuals.append(
            Visual(body_name('palm2'), joint_id,
                   pin.SE3(rotate('x', pi / 2), zero(3)), H, W))

        FL = 4 * cm
        palmIdx = joint_id

        joint_placement = pin.SE3(eye(3), np.matrix([2 * cm, W / 2, 0]).T)
        joint_id = self.model.addJoint(palmIdx, pin.JointModelRY(),
                                       joint_placement, joint_name('finger11'))
        self.model.appendBodyToJoint(joint_id, inertia(.5, [0, 0, 0]),
                                     pin.SE3.Identity())
        self.viewer.viewer.gui.addCapsule(body_name('finger11'), H, FL - 2 * H,
                                          color)
        pos = pin.SE3(rotate('y', pi / 2), np.matrix([FL / 2 - H, 0, 0]).T)
        self.visuals.append(
            Visual(body_name('finger11'), joint_id, pos, H, FL - 2 * H))

        joint_placement = pin.SE3(eye(3), np.matrix([FL, 0, 0]).T)
        joint_id = self.model.addJoint(joint_id, pin.JointModelRY(),
                                       joint_placement, joint_name('finger12'))
        self.model.appendBodyToJoint(joint_id, inertia(.5, [0, 0, 0]),
                                     pin.SE3.Identity())

        self.viewer.viewer.gui.addCapsule(body_name('finger12'), H, FL - 2 * H,
                                          color)
        pos = pin.SE3(rotate('y', pi / 2), np.matrix([FL / 2 - H, 0, 0]).T)
        self.visuals.append(
            Visual(body_name('finger12'), joint_id, pos, H, FL - 2 * H))

        joint_placement = pin.SE3(eye(3), np.matrix([FL - 2 * H, 0, 0]).T)
        joint_id = self.model.addJoint(joint_id, pin.JointModelRY(),
                                       joint_placement, joint_name('finger13'))
        self.model.appendBodyToJoint(joint_id, inertia(.3, [0, 0, 0]),
                                     pin.SE3.Identity())
        self.viewer.viewer.gui.addSphere(body_name('finger13'), H, color)
        self.visuals.append(
            Visual(body_name('finger13'), joint_id, trans(2 * H, 0, 0), H, 0))

        joint_placement = pin.SE3(eye(3), np.matrix([2 * cm, 0, 0]).T)
        joint_id = self.model.addJoint(palmIdx, pin.JointModelRY(),
                                       joint_placement, joint_name('finger21'))
        self.model.appendBodyToJoint(joint_id, inertia(.5, [0, 0, 0]),
                                     pin.SE3.Identity())
        self.viewer.viewer.gui.addCapsule(body_name('finger21'), H, FL - 2 * H,
                                          color)
        pos = pin.SE3(rotate('y', pi / 2), np.matrix([FL / 2 - H, 0, 0]).T)
        self.visuals.append(
            Visual(body_name('finger21'), joint_id, pos, H, FL - 2 * H))

        joint_placement = pin.SE3(eye(3), np.matrix([FL, 0, 0]).T)
        joint_id = self.model.addJoint(joint_id, pin.JointModelRY(),
                                       joint_placement, joint_name('finger22'))
        self.model.appendBodyToJoint(joint_id, inertia(.5, [0, 0, 0]),
                                     pin.SE3.Identity())
        self.viewer.viewer.gui.addCapsule(body_name('finger22'), H, FL - 2 * H,
                                          color)
        pos = pin.SE3(rotate('y', pi / 2), np.matrix([FL / 2 - H, 0, 0]).T)
        self.visuals.append(
            Visual(body_name('finger22'), joint_id, pos, H, FL - 2 * H))

        joint_placement = pin.SE3(eye(3), np.matrix([FL - H, 0, 0]).T)
        joint_id = self.model.addJoint(joint_id, pin.JointModelRY(),
                                       joint_placement, joint_name('finger23'))
        self.model.appendBodyToJoint(joint_id, inertia(.3, [0, 0, 0]),
                                     pin.SE3.Identity())
        self.viewer.viewer.gui.addSphere(body_name('finger23'), H, color)
        self.visuals.append(
            Visual(body_name('finger23'), joint_id, trans(H, 0, 0), H, 0))

        joint_placement = pin.SE3(eye(3), np.matrix([2 * cm, -W / 2, 0]).T)
        joint_id = self.model.addJoint(palmIdx, pin.JointModelRY(),
                                       joint_placement, joint_name('finger31'))
        self.model.appendBodyToJoint(joint_id, inertia(.5, [0, 0, 0]),
                                     pin.SE3.Identity())
        self.viewer.viewer.gui.addCapsule(body_name('finger31'), H, FL - 2 * H,
                                          color)
        pos = pin.SE3(rotate('y', pi / 2), np.matrix([FL / 2 - H, 0, 0]).T)
        self.visuals.append(
            Visual(body_name('finger31'), joint_id, pos, H, FL - 2 * H))

        joint_placement = pin.SE3(eye(3), np.matrix([FL, 0, 0]).T)
        joint_id = self.model.addJoint(joint_id, pin.JointModelRY(),
                                       joint_placement, joint_name('finger32'))
        self.model.appendBodyToJoint(joint_id, inertia(.5, [0, 0, 0]),
                                     pin.SE3.Identity())
        self.viewer.viewer.gui.addCapsule(body_name('finger32'), H, FL - 2 * H,
                                          color)
        pos = pin.SE3(rotate('y', pi / 2), np.matrix([FL / 2 - H, 0, 0]).T)
        self.visuals.append(
            Visual(body_name('finger32'), joint_id, pos, H, FL - 2 * H))

        joint_placement = pin.SE3(eye(3), np.matrix([FL - 2 * H, 0, 0]).T)
        joint_id = self.model.addJoint(joint_id, pin.JointModelRY(),
                                       joint_placement, joint_name('finger33'))
        self.model.appendBodyToJoint(joint_id, inertia(.3, [0, 0, 0]),
                                     pin.SE3.Identity())
        self.viewer.viewer.gui.addSphere(body_name('finger33'), H, color)
        self.visuals.append(
            Visual(body_name('finger33'), joint_id, trans(2 * H, 0, 0), H, 0))

        joint_placement = pin.SE3(eye(3),
                                  np.matrix([1 * cm, -W / 2 - H * 1.5, 0]).T)
        joint_id = self.model.addJoint(1, pin.JointModelRY(), joint_placement,
                                       joint_name('thumb1'))
        self.model.appendBodyToJoint(joint_id, inertia(.5, [0, 0, 0]),
                                     pin.SE3.Identity())
        self.viewer.viewer.gui.addCapsule(body_name('thumb1'), H, 2 * cm,
                                          color)
        pos = pin.SE3(
            rotate('z', pi / 3) * rotate('x', pi / 2),
            np.matrix([1 * cm, -1 * cm, 0]).T)
        self.visuals.append(Visual(body_name('thumb1'), joint_id, pos, 2 * cm))

        joint_placement = pin.SE3(
            rotate('z', pi / 3) * rotate('x', pi),
            np.matrix([3 * cm, -1.8 * cm, 0]).T)
        joint_id = self.model.addJoint(joint_id, pin.JointModelRZ(),
                                       joint_placement, joint_name('thumb2'))
        self.model.appendBodyToJoint(joint_id, inertia(.4, [0, 0, 0]),
                                     pin.SE3.Identity())
        self.viewer.viewer.gui.addCapsule(body_name('thumb2'), H, FL - 2 * H,
                                          color)
        pos = pin.SE3(rotate('x', pi / 3),
                      np.matrix([-0.7 * cm, .8 * cm, -0.5 * cm]).T)
        self.visuals.append(
            Visual(body_name('thumb2'), joint_id, pos, H, FL - 2 * H))

        # Prepare some patches to represent collision points. Yet unvisible.
        for i in range(10):
            self.viewer.viewer.gui.addCylinder('world/wa%i' % i, .01, .003,
                                               [1.0, 0, 0, 1])
            self.viewer.viewer.gui.addCylinder('world/wb%i' % i, .01, .003,
                                               [1.0, 0, 0, 1])
            self.viewer.viewer.gui.setVisibility('world/wa%i' % i, 'OFF')
            self.viewer.viewer.gui.setVisibility('world/wb%i' % i, 'OFF')
def rotatePlacement(placement, axis, angle):
    T = rotate(axis, angle)
    placement.rotation = placement.rotation * T
    return placement
Exemple #8
0
elif PHASE_BACKUP[PHASE_NAME]:
    np.save(BACKUP_PATH + '%s.xs.npy' % PHASE_NAME, ddp.xs)
    np.save(BACKUP_PATH + '%s.us.npy' % PHASE_NAME, ddp.us)
disp(ddp.xs)

models[fig].differential.costs.costs['xreg'].weight = 0.1
models[fig].differential.costs.costs['xreg'].cost.ref = x0.copy()
models[fig].differential.costs.costs['xreg'].cost.activation.weights[rmodel.nv:] = 10

# ---------------------------------------------------------------------------------------------
# Jump with twist PI/2
PHASE_NAME = "twist"

ddp.setCandidate(xs=xjump0, us=ujump0)

impact.costs['track16'].cost.ref = SE3(rotate('z', 1.5), zero(3)) * impact.costs['track16'].cost.ref
impact.costs['track30'].cost.ref = SE3(rotate('z', 1.5), zero(3)) * impact.costs['track30'].cost.ref
models[-1].differential.costs.costs['xreg'].cost.activation.weights[5] = 0

impact.costs['track30'].weight = 10**6
impact.costs['track16'].weight = 10**6
print("*** SOLVE %s ***" % PHASE_NAME)
ddp.solve(init_xs=ddp.xs, init_us=ddp.us, maxiter=PHASE_ITERATIONS[PHASE_NAME], isFeasible=True)

if PHASE_ITERATIONS[PHASE_NAME] == 0:
    ddp.setCandidate(xs=[x.copy() for x in np.load(BACKUP_PATH + '%s.xs.npy' % PHASE_NAME)],
                     us=[u.copy() for u in np.load(BACKUP_PATH + '%s.us.npy' % PHASE_NAME)])
elif PHASE_BACKUP[PHASE_NAME]:
    np.save(BACKUP_PATH + '%s.xs.npy' % PHASE_NAME, ddp.xs)
    np.save(BACKUP_PATH + '%s.us.npy' % PHASE_NAME, ddp.us)
disp(ddp.xs)