pinocchio 4.1.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-2026 INRIA
3//
4
5#pragma once
6
7#include <Python.h>
8#include <string>
9
10#include "pinocchio/algorithm/check-model.hpp"
11#include "pinocchio/bindings/python/fwd.hpp"
12
13namespace pinocchio
14{
15 namespace python
16 {
17
18 // Checker Policy to make a safe version of python function, concerning joint mimic.
19 // This will throw a runtime error in case algorithm does not allow joint mimic in the model.
20 template<class Policy = boost::python::default_call_policies>
21 struct mimic_not_supported_function : Policy
22 {
23 mimic_not_supported_function(size_t model_arg_list_idx_)
24 : Policy()
25 , model_arg_list_idx(model_arg_list_idx_)
26 {
27 }
28
29 template<class ArgumentPackage>
30 bool precall(ArgumentPackage const & args) const
31 {
32 // Convert the object to a tuple
33 boost::python::tuple py_args = boost::python::extract<boost::python::tuple>(args);
34
35 boost::python::extract<const context::Model &> get_model(py_args[model_arg_list_idx]);
36 if (!get_model().check(MimicChecker()))
37 {
38 PyErr_SetString(PyExc_RuntimeError, m_error_message.c_str());
39 return false;
40 }
41 else
42 return static_cast<const Policy *>(this)->precall(args);
43 }
44
45 protected:
46 static const std::string m_error_message;
47 // index of the pinocchio in the function arguments. Need it to avoid a loop
48 const size_t model_arg_list_idx;
49 };
50
51 template<class Policy>
52 const std::string mimic_not_supported_function<Policy>::m_error_message =
53 "This algorithm does not support Joint Mimic type in the model.";
54 } // namespace python
55} // namespace pinocchio
Main pinocchio namespace.
Definition treeview.dox:11
Simple model checker, that assert that there is a mimic joint in the tree.