-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathobjective.py
More file actions
34 lines (24 loc) · 1008 Bytes
/
Copy pathobjective.py
File metadata and controls
34 lines (24 loc) · 1008 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
"""Objective function factory module."""
from typing import Callable, Tuple
import numpy as np
import jax.numpy as jnp
from optim.grippers.kinematics.parallel_jaw import kin_pj_right, kin_pj_left
def create_cube_objective(xinit: Tuple[np.ndarray, jnp.ndarray], com: np.ndarray) -> Callable:
"""Create an objective function for the cube optimization.
Args:
xinit: Optimization variable on initialization.
com: Cube center of mass.
Returns:
The objective function callable.
"""
def objective(x: jnp.ndarray) -> float:
"""Calculate the value of the objective function at the current configuration.
Args:
x: The current configuration.
Returns:
The value of the objective.
"""
regularizer = jnp.sum((x - xinit)**2)
diff_r, diff_l = kin_pj_right(x)[:3, 3] - com, kin_pj_left(x)[:3, 3] - com
return regularizer * 1e-4 + jnp.sum(diff_r**2) + jnp.sum(diff_l**2)
return objective