| Directory: | ./ |
|---|---|
| File: | bindings/python/crocoddyl/multibody/residuals/pair-collision.cpp |
| Date: | 2025-03-13 15:22:42 |
| Exec | Total | Coverage | |
|---|---|---|---|
| Lines: | 35 | 37 | 94.6% |
| Branches: | 25 | 50 | 50.0% |
| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | /////////////////////////////////////////////////////////////////////////////// | ||
| 2 | // BSD 3-Clause License | ||
| 3 | // | ||
| 4 | // Copyright (C) 2021-2023, University of Edinburgh, LAAS-CNRS, INRIA, | ||
| 5 | // Heriot-Watt University | ||
| 6 | // Copyright note valid unless otherwise stated in individual files. | ||
| 7 | // All rights reserved. | ||
| 8 | /////////////////////////////////////////////////////////////////////////////// | ||
| 9 | |||
| 10 | #ifdef PINOCCHIO_WITH_HPP_FCL | ||
| 11 | |||
| 12 | #include "crocoddyl/multibody/residuals/pair-collision.hpp" | ||
| 13 | |||
| 14 | #include "python/crocoddyl/multibody/multibody.hpp" | ||
| 15 | #include "python/crocoddyl/utils/copyable.hpp" | ||
| 16 | |||
| 17 | namespace crocoddyl { | ||
| 18 | namespace python { | ||
| 19 | |||
| 20 | 10 | void exposeResidualPairCollision() { | |
| 21 | 10 | bp::register_ptr_to_python<std::shared_ptr<ResidualModelPairCollision> >(); | |
| 22 | |||
| 23 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | bp::class_<ResidualModelPairCollision, bp::bases<ResidualModelAbstract> >( |
| 24 | "ResidualModelPairCollision", | ||
| 25 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | bp::init<std::shared_ptr<StateMultibody>, std::size_t, |
| 26 | std::shared_ptr<pinocchio::GeometryModel>, pinocchio::PairIndex, | ||
| 27 | pinocchio::JointIndex>( | ||
| 28 | 20 | bp::args("self", "state", "nu", "geom_model", "pair_id", "joint_id"), | |
| 29 | "Initialize the pair collision residual model.\n\n" | ||
| 30 | ":param state: state of the multibody system\n" | ||
| 31 | ":param nu: dimension of control vector\n" | ||
| 32 | ":param geom_model: geometric model of the multibody system\n" | ||
| 33 | ":param pair_id: id of the pair of colliding objects\n" | ||
| 34 | ":param joint_id: used to calculate the Jacobian at the joint")) | ||
| 35 | .def<void (ResidualModelPairCollision::*)( | ||
| 36 | const std::shared_ptr<ResidualDataAbstract>&, | ||
| 37 | const Eigen::Ref<const Eigen::VectorXd>&, | ||
| 38 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | const Eigen::Ref<const Eigen::VectorXd>&)>( |
| 39 | "calc", &ResidualModelPairCollision::calc, | ||
| 40 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
20 | bp::args("self", "data", "x", "u"), |
| 41 | "Compute the pair collision residual.\n\n" | ||
| 42 | ":param data: residual data\n" | ||
| 43 | ":param x: state point (dim. state.nx)\n" | ||
| 44 | ":param u: control input (dim. nu)") | ||
| 45 | .def<void (ResidualModelPairCollision::*)( | ||
| 46 | const std::shared_ptr<ResidualDataAbstract>&, | ||
| 47 | 20 | const Eigen::Ref<const Eigen::VectorXd>&)>( | |
| 48 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
20 | "calc", &ResidualModelAbstract::calc, bp::args("self", "data", "x")) |
| 49 | .def<void (ResidualModelPairCollision::*)( | ||
| 50 | const std::shared_ptr<ResidualDataAbstract>&, | ||
| 51 | const Eigen::Ref<const Eigen::VectorXd>&, | ||
| 52 |
2/4✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 10 times.
✗ Branch 5 not taken.
|
20 | const Eigen::Ref<const Eigen::VectorXd>&)>( |
| 53 | "calcDiff", &ResidualModelPairCollision::calcDiff, | ||
| 54 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
20 | bp::args("self", "data", "x", "u"), |
| 55 | "Compute the Jacobians of the pair collision residual.\n\n" | ||
| 56 | "It assumes that calc has been run first.\n" | ||
| 57 | ":param data: action data\n" | ||
| 58 | ":param x: state point (dim. state.nx)\n" | ||
| 59 | ":param u: control input (dim. nu)") | ||
| 60 | .def<void (ResidualModelPairCollision::*)( | ||
| 61 | const std::shared_ptr<ResidualDataAbstract>&, | ||
| 62 | 20 | const Eigen::Ref<const Eigen::VectorXd>&)>( | |
| 63 | "calcDiff", &ResidualModelAbstract::calcDiff, | ||
| 64 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
20 | bp::args("self", "data", "x")) |
| 65 |
2/4✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 10 times.
✗ Branch 5 not taken.
|
20 | .def("createData", &ResidualModelPairCollision::createData, |
| 66 | ✗ | bp::with_custodian_and_ward_postcall<0, 2>(), | |
| 67 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
20 | bp::args("self", "data"), |
| 68 | "Create the pair collision residual data.\n\n" | ||
| 69 | ":param data: shared data\n" | ||
| 70 | ":return residual data.") | ||
| 71 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | .def(CopyableVisitor<ResidualModelPairCollision>()); |
| 72 | |||
| 73 | 10 | bp::register_ptr_to_python<std::shared_ptr<ResidualDataPairCollision> >(); | |
| 74 | |||
| 75 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | bp::class_<ResidualDataPairCollision, bp::bases<ResidualDataAbstract> >( |
| 76 | "ResidualDataPairCollision", "Data for pair collision residual.\n\n", | ||
| 77 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | bp::init<ResidualModelPairCollision*, DataCollectorAbstract*>( |
| 78 | 10 | bp::args("self", "model", "data"), | |
| 79 | "Create pair collision residual data.\n\n" | ||
| 80 | ":param model: pair collision residual model\n" | ||
| 81 | ✗ | ":param data: shared data")[bp::with_custodian_and_ward< | |
| 82 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
20 | 1, 2, bp::with_custodian_and_ward<1, 3> >()]) |
| 83 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | .add_property("pinocchio", |
| 84 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | bp::make_getter(&ResidualDataPairCollision::pinocchio, |
| 85 | 10 | bp::return_internal_reference<>()), | |
| 86 | "pinocchio data") | ||
| 87 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | .add_property("geometry", |
| 88 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | bp::make_getter(&ResidualDataPairCollision::geometry, |
| 89 | 10 | bp::return_internal_reference<>()), | |
| 90 | "pinocchio geometry data") | ||
| 91 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | .add_property("J", |
| 92 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | bp::make_getter(&ResidualDataPairCollision::J, |
| 93 | 10 | bp::return_internal_reference<>()), | |
| 94 | "Jacobian of the collision joint") | ||
| 95 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | .add_property("d", |
| 96 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | bp::make_getter(&ResidualDataPairCollision::d, |
| 97 | 10 | bp::return_internal_reference<>()), | |
| 98 | "vector from joint to collision point in world frame") | ||
| 99 |
1/2✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
|
10 | .def(CopyableVisitor<ResidualDataPairCollision>()); |
| 100 | 10 | } | |
| 101 | |||
| 102 | } // namespace python | ||
| 103 | } // namespace crocoddyl | ||
| 104 | |||
| 105 | #endif // PINOCCHIO_WITH_HPP_FCL | ||
| 106 |