Public Types | Public Member Functions | Private Member Functions | Private Attributes | List of all members
hebi::robot_model::CustomObjective< N > Class Template Referencefinal

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

#include <robot_model.hpp>

Inheritance diagram for hebi::robot_model::CustomObjective< N >:
Inheritance graph
[legend]

Public Types

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

Public Member Functions

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

Private Member Functions

HebiStatusCode addObjective (HebiIKPtr ik) const override
 

Private Attributes

ObjectiveCallback _callback
 
double _weight
 

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;
}
)
);

Definition at line 135 of file robot_model.hpp.

Member Typedef Documentation

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

Definition at line 140 of file robot_model.hpp.

Constructor & Destructor Documentation

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

Definition at line 142 of file robot_model.hpp.

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

Definition at line 143 of file robot_model.hpp.

Member Function Documentation

template<size_t N>
HebiStatusCode hebi::robot_model::CustomObjective< N >::addObjective ( HebiIKPtr  ik) const
inlineoverrideprivatevirtual

Implements hebi::robot_model::Objective.

Definition at line 171 of file robot_model.hpp.

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

Definition at line 147 of file robot_model.hpp.

Member Data Documentation

template<size_t N>
ObjectiveCallback hebi::robot_model::CustomObjective< N >::_callback
private

Definition at line 176 of file robot_model.hpp.

template<size_t N>
double hebi::robot_model::CustomObjective< N >::_weight
private

Definition at line 175 of file robot_model.hpp.


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


hebi_cpp_api_ros
Author(s): Chris Bollinger , Matthew Tesch
autogenerated on Thu May 28 2020 03:14:45