Skip to content

Commit 1aefdf3

Browse files
committed
Add support for configurable optimization methods
1 parent a242fce commit 1aefdf3

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

src/ikpy/chain.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ def inverse_kinematics(self, target_position=None, target_orientation=None, orie
119119
* "Y": Target the Y axis
120120
* "Z": Target the Z axis
121121
* "all": Target the entire frame (e.g. the three axes) (not currently supported)
122-
kwargs
122+
kwargs: See ikpy.inverse_kinematics.inverse_kinematic_optimization
123123
124124
Returns
125125
-------
@@ -159,6 +159,7 @@ def inverse_kinematics_frame(self, target, initial_position=None, **kwargs):
159159
The frame target of the inverse kinematic, in meters. It must be 4x4 transformation matrix
160160
initial_position: numpy.array
161161
Optional : the initial position of each joint of the chain. Defaults to 0 for each joint
162+
kwargs: See ikpy.inverse_kinematics.inverse_kinematic_optimization
162163
163164
Returns
164165
-------

src/ikpy/inverse_kinematics.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
ORIENTATION_COEFF = 1.
88

99

10-
def inverse_kinematic_optimization(chain, target_frame, starting_nodes_angles, regularization_parameter=None, max_iter=None, orientation_mode=None, no_position=False):
10+
def inverse_kinematic_optimization(chain, target_frame, starting_nodes_angles, regularization_parameter=None, max_iter=None, orientation_mode=None, no_position=False, optimization_method='L-BFGS-B'):
1111
"""
1212
Computes the inverse kinematic on the specified target with an optimization method
1313
@@ -32,6 +32,8 @@ def inverse_kinematic_optimization(chain, target_frame, starting_nodes_angles, r
3232
* "all": Target the three axes
3333
no_position: bool
3434
Do not optimize against position
35+
optimization_method: str
36+
Optimization method to use. Defaults to 'L-BFGS-B'
3537
"""
3638
# Begin with the position
3739
target = target_frame[:3, -1]
@@ -131,7 +133,7 @@ def optimize_total(x):
131133
options["maxiter"] = max_iter
132134

133135
# Utilisation d'une optimisation L-BFGS-B
134-
res = scipy.optimize.minimize(optimize_total, chain.active_from_full(starting_nodes_angles), method='L-BFGS-B', bounds=real_bounds, options=options)
136+
res = scipy.optimize.minimize(optimize_total, chain.active_from_full(starting_nodes_angles), method=optimization_method, bounds=real_bounds, options=options)
135137

136138
logs.logger.info("Inverse kinematic optimisation OK, done in {} iterations".format(res.nit))
137139

0 commit comments

Comments
 (0)