1D Search Improvements

December 24, 2024 · View on GitHub

Improving the 1D search algorithm in IK-Geo to achieve high precision and success rate. Testing is performed on the Motoman SIA50D 7-DOF robot arm parameterized by conventional SEW angle with shoulder placed on joint 2.

Problem formulation

The goal was to achieve 100% empirical success rate over 10,000 random test cases (random joint angles) while minimizing execution time based on the following milestones:

  • 20 Hz, 50 ms – GUI display
  • 100 Hz, 10 ms – Mid-range control loop
  • 500 Hz, 2 ms – Real-time control loop (stretch goal)

Testing was performed using MATLAB MEX on a computer running Windows 10 on an Intel Core i7-3770K CPU at 3.50 GHz and 16 GB memory.

Results

With just a few improvements, 1D search performance was significantly improved. Success rate went from 89% to 100%, and computation time was better than the fastest milestone.

imageSIA50_500
RevisionNote% CorrectTime (us)
0891235.55
1Search over 2/4 branches89800.56
2LS solns, increase cross thresh, decrease search tol99.81158.93
3Cut initial samples from 1e3 to 50099.8656.318
3** Increase test cases from 1,000 to 10,00099.78735.829
4Simplify zero cross detection code, fix NaN branches99.78715.402
5Find local min / max for each triangle pointing to 0100754.681
5** Increase test cases from 10,000 to 100,00099.999791.278
6Decrease samples from 500 to 250 (10,000 test cases)100497.381

The following improvements were made:

  • Search over only 2 of 4 error function branches. Due to robot symmetry, the four error function branches come in two identical pairs.
  • Use least-squares solutions. This guarantees the error function is always defined, meaning the bracketing method does not fail near endpoints.
  • Search not just for zeros but also for minima / maxima. This improves performance near robot singularities where the error function touches but only barely passes zero.

Future work

There are still a number of strategies that may improve 1D search performance even further:

  • Use multiple unique error functions
  • Hard-code kinematic parameters into code
    • Or hard code error function with tan⁡(𝜃/2)
  • Use intelligent global optimization algorithms (not uniform sampling)
  • Search for endpoints
    • Or find endpoints analytically

C++ Results

Similar changes were made to the C++ code in the main IK-Geo repository.

Timing is much slower for C++ (but still faster than the stretch goal). It's possible that the testing method is what's slowing down the code.

RevisionNote% CorrectTime (us)
065?
1Increased samples to 1e3 to match MATLAB rev0891718.24
2Only use 2 of 4 branches to finds zeros89979.174
3LS solns, don't use cross thresh892007.35
4Cut initial samples from 1e3 to 500961263.59
5Fix broken false position method99.321227.1
6Fix broken wrap_to_pi function99.921264.86
7Min / max for root finding99.871315.02
8Fix min/max logic, reduce initial samples 500->250100907.286