pinocchio  3.7.0
A fast and flexible implementation of Rigid Body Dynamics algorithms and their analytical derivatives
 
Loading...
Searching...
No Matches
model-checker.hpp
1//
2// Copyright (c) 2025 INRIA
3//
4
5#ifndef __pinocchio_python_utils_model_checker_hpp__
6#define __pinocchio_python_utils_model_checker_hpp__
7
8#include <Python.h>
9#include <string>
10
11#include "pinocchio/algorithm/check-model.hpp"
12#include "pinocchio/bindings/python/fwd.hpp"
13
14namespace pinocchio
15{
16 namespace python
17 {
18
19 // Checker Policy to make a safe version of python function, concerning joint mimic.
20 // This will throw a runtime error in case algorithm does not allow joint mimic in the model.
21 template<class Policy = boost::python::default_call_policies>
23 {
25 : Policy()
26 , model_idx(model_idx_)
27 {
28 }
29
30 template<class ArgumentPackage>
31 bool precall(ArgumentPackage const & args) const
32 {
33 // Convert the object to a tuple
34 boost::python::tuple py_args = boost::python::extract<boost::python::tuple>(args);
35
36 context::Model m = boost::python::extract<context::Model>(py_args[model_idx]);
37 if (!m.check(MimicChecker()))
38 {
39 PyErr_SetString(PyExc_RuntimeError, m_error_message.c_str());
40 return false;
41 }
42 else
43 return static_cast<const Policy *>(this)->precall(args);
44 }
45
46 protected:
47 static const std::string m_error_message;
48 // index of the pinocchio in the function arguments. Need it to avoid a loop
49 const size_t model_idx;
50 };
51
52 template<class Policy>
54 "This algorithm does not support Joint Mimic type in the model.";
55 } // namespace python
56} // namespace pinocchio
57#endif // model_checker
Main pinocchio namespace.
Definition treeview.dox:11
Simple model checker, that assert that there is a mimic joint in the tree.