GCC Code Coverage Report


Directory: ./
File: include/crocoddyl/core/actions/unicycle.hpp
Date: 2025-03-26 19:23:43
Exec Total Coverage
Lines: 5 6 83.3%
Branches: 3 8 37.5%

Line Branch Exec Source
1 ///////////////////////////////////////////////////////////////////////////////
2 // BSD 3-Clause License
3 //
4 // Copyright (C) 2019-2025, LAAS-CNRS, University of Edinburgh,
5 // Heriot-Watt University
6 // Copyright note valid unless otherwise stated in individual files.
7 // All rights reserved.
8 ///////////////////////////////////////////////////////////////////////////////
9
10 #ifndef CROCODDYL_CORE_ACTIONS_UNICYCLE_HPP_
11 #define CROCODDYL_CORE_ACTIONS_UNICYCLE_HPP_
12
13 #include <stdexcept>
14
15 #include "crocoddyl/core/action-base.hpp"
16 #include "crocoddyl/core/fwd.hpp"
17 #include "crocoddyl/core/states/euclidean.hpp"
18
19 namespace crocoddyl {
20 template <typename _Scalar>
21 class ActionModelUnicycleTpl : public ActionModelAbstractTpl<_Scalar> {
22 public:
23 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
24 CROCODDYL_DERIVED_CAST(ActionModelBase, ActionModelUnicycleTpl)
25
26 typedef _Scalar Scalar;
27 typedef ActionDataAbstractTpl<Scalar> ActionDataAbstract;
28 typedef ActionModelAbstractTpl<Scalar> Base;
29 typedef ActionDataUnicycleTpl<Scalar> Data;
30 typedef MathBaseTpl<Scalar> MathBase;
31 typedef typename MathBase::VectorXs VectorXs;
32 typedef typename MathBase::Vector2s Vector2s;
33
34 ActionModelUnicycleTpl();
35 70 virtual ~ActionModelUnicycleTpl() = default;
36
37 virtual void calc(const std::shared_ptr<ActionDataAbstract>& data,
38 const Eigen::Ref<const VectorXs>& x,
39 const Eigen::Ref<const VectorXs>& u) override;
40 virtual void calc(const std::shared_ptr<ActionDataAbstract>& data,
41 const Eigen::Ref<const VectorXs>& x) override;
42 virtual void calcDiff(const std::shared_ptr<ActionDataAbstract>& data,
43 const Eigen::Ref<const VectorXs>& x,
44 const Eigen::Ref<const VectorXs>& u) override;
45 virtual void calcDiff(const std::shared_ptr<ActionDataAbstract>& data,
46 const Eigen::Ref<const VectorXs>& x) override;
47 virtual std::shared_ptr<ActionDataAbstract> createData() override;
48
49 /**
50 * @brief Cast the unicycle model to a different scalar type.
51 *
52 * It is useful for operations requiring different precision or scalar types.
53 *
54 * @tparam NewScalar The new scalar type to cast to.
55 * @return ActionModelUnicycleTpl<NewScalar> A unicycle model with the
56 * new scalar type.
57 */
58 template <typename NewScalar>
59 ActionModelUnicycleTpl<NewScalar> cast() const;
60
61 virtual bool checkData(
62 const std::shared_ptr<ActionDataAbstract>& data) override;
63
64 const Vector2s& get_cost_weights() const;
65 void set_cost_weights(const Vector2s& weights);
66
67 Scalar get_dt() const;
68 void set_dt(const Scalar dt);
69
70 /**
71 * @brief Print relevant information of the unicycle model
72 *
73 * @param[out] os Output stream object
74 */
75 virtual void print(std::ostream& os) const override;
76
77 protected:
78 using Base::nu_; //!< Control dimension
79 using Base::state_; //!< Model of the state
80
81 private:
82 Vector2s cost_weights_;
83 Scalar dt_;
84 };
85
86 template <typename _Scalar>
87 struct ActionDataUnicycleTpl : public ActionDataAbstractTpl<_Scalar> {
88 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
89
90 typedef _Scalar Scalar;
91 typedef MathBaseTpl<Scalar> MathBase;
92 typedef ActionDataAbstractTpl<Scalar> Base;
93 using Base::cost;
94 using Base::Fu;
95 using Base::Fx;
96 using Base::Lu;
97 using Base::Luu;
98 using Base::Lx;
99 using Base::Lxu;
100 using Base::Lxx;
101 using Base::r;
102 using Base::xnext;
103
104 template <template <typename Scalar> class Model>
105 1342 explicit ActionDataUnicycleTpl(Model<Scalar>* const model) : Base(model) {
106
3/6
✓ Branch 1 taken 866 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 866 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 866 times.
✗ Branch 8 not taken.
1342 Fx.diagonal().array() = Scalar(1.);
107 1342 }
108 1258 virtual ~ActionDataUnicycleTpl() = default;
109 };
110
111 } // namespace crocoddyl
112
113 /* --- Details -------------------------------------------------------------- */
114 /* --- Details -------------------------------------------------------------- */
115 /* --- Details -------------------------------------------------------------- */
116 #include "crocoddyl/core/actions/unicycle.hxx"
117
118 CROCODDYL_DECLARE_EXTERN_TEMPLATE_CLASS(crocoddyl::ActionModelUnicycleTpl)
119 CROCODDYL_DECLARE_EXTERN_TEMPLATE_STRUCT(crocoddyl::ActionDataUnicycleTpl)
120
121 #endif // CROCODDYL_CORE_ACTIONS_UNICYCLE_HPP_
122