HEBI C++ API  3.4.0
hebi::robot_model::CustomObjective< N > Class Template Referencefinal

Allows you to add a custom objective function. More...

#include <robot_model.hpp>

Public Types

using ObjectiveCallback = std::function< void(const std::vector< double > &, std::array< double, N > &)>
 

Public Member Functions

 CustomObjective (ObjectiveCallback error_function)
 
 CustomObjective (double weight, ObjectiveCallback error_function)
 
void callCallback (void *, size_t num_positions, const double *positions, double *errors) const
 
- Public Member Functions inherited from hebi::robot_model::Objective
virtual ~Objective ()
 

Additional Inherited Members

Detailed Description

template<size_t N>
class hebi::robot_model::CustomObjective< N >

Allows you to add a custom objective function.

To use, you must implement and pass in a std::function object that takes a vector of positions and an array of error values that you should fill in:

std::function<void(const std::vector<double>&, std::array<double, N>&)>;

This function is called at each step of the optimization.

Note that the template parameter N is the number of independent errors that your objective function sets.

Example usage, using a lambda function for the callback. Note that this toy example optimizes for joint angles that sum to 2:

Eigen::VectorXd initial_joint_angles(group->size());
Eigen::VectorXd ik_result_joint_angles(group->size());
model->solveIK(
initial_joint_angles,
ik_result_joint_angles,
robot_model::CustomObjective<1>(
[](const std::vector<double> positions, std::array<double, 1>& errors)
{
// Add up all the joint angles
double sum = 0;
for (auto p : positions)
sum += p;
// This objective prefers joint angles that sum to '2'
errors[0] = 2 - sum;
}
)
);

Member Typedef Documentation

◆ ObjectiveCallback

template<size_t N>
using hebi::robot_model::CustomObjective< N >::ObjectiveCallback = std::function<void(const std::vector<double>&, std::array<double, N>&)>

Constructor & Destructor Documentation

◆ CustomObjective() [1/2]

template<size_t N>
hebi::robot_model::CustomObjective< N >::CustomObjective ( ObjectiveCallback  error_function)
inline

◆ CustomObjective() [2/2]

template<size_t N>
hebi::robot_model::CustomObjective< N >::CustomObjective ( double  weight,
ObjectiveCallback  error_function 
)
inline

Member Function Documentation

◆ callCallback()

template<size_t N>
void hebi::robot_model::CustomObjective< N >::callCallback ( void *  ,
size_t  num_positions,
const double *  positions,
double *  errors 
) const
inline

The documentation for this class was generated from the following file: