Directory: | ./ |
---|---|
File: | include/hpp/core/configuration-shooter/gaussian.hh |
Date: | 2024-12-13 16:14:03 |
Exec | Total | Coverage | |
---|---|---|---|
Lines: | 16 | 20 | 80.0% |
Branches: | 6 | 14 | 42.9% |
Line | Branch | Exec | Source |
---|---|---|---|
1 | // | ||
2 | // Copyright (c) 2018 CNRS | ||
3 | // Authors: Joseph Mirabel | ||
4 | // | ||
5 | |||
6 | // Redistribution and use in source and binary forms, with or without | ||
7 | // modification, are permitted provided that the following conditions are | ||
8 | // met: | ||
9 | // | ||
10 | // 1. Redistributions of source code must retain the above copyright | ||
11 | // notice, this list of conditions and the following disclaimer. | ||
12 | // | ||
13 | // 2. Redistributions in binary form must reproduce the above copyright | ||
14 | // notice, this list of conditions and the following disclaimer in the | ||
15 | // documentation and/or other materials provided with the distribution. | ||
16 | // | ||
17 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
18 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
19 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | ||
20 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | ||
21 | // HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
22 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | ||
23 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
24 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | ||
25 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
26 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
27 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH | ||
28 | // DAMAGE. | ||
29 | |||
30 | #ifndef HPP_CORE_CONFIGURATION_SHOOTER_GAUSSIAN_HH | ||
31 | #define HPP_CORE_CONFIGURATION_SHOOTER_GAUSSIAN_HH | ||
32 | |||
33 | #include <hpp/core/configuration-shooter.hh> | ||
34 | #include <hpp/pinocchio/device.hh> | ||
35 | #include <sstream> | ||
36 | |||
37 | namespace hpp { | ||
38 | namespace core { | ||
39 | namespace configurationShooter { | ||
40 | /// \addtogroup configuration_sampling | ||
41 | /// \{ | ||
42 | |||
43 | /// Sample configuration using a gaussian distribution around a | ||
44 | /// configuration. | ||
45 | class HPP_CORE_DLLAPI Gaussian : public ConfigurationShooter { | ||
46 | public: | ||
47 | 1 | static GaussianPtr_t create(const DevicePtr_t& robot) { | |
48 |
1/2✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
|
1 | Gaussian* ptr = new Gaussian(robot); |
49 | 1 | GaussianPtr_t shPtr(ptr); | |
50 | 1 | ptr->init(shPtr); | |
51 | 1 | return shPtr; | |
52 | } | ||
53 | |||
54 | ✗ | void center(ConfigurationIn_t c) { center_ = c; } | |
55 | 1 | const Configuration_t& center() const { return center_; } | |
56 | |||
57 | /// Set the standard deviation proportional to a default value | ||
58 | /// | ||
59 | /// The default value is: | ||
60 | /// \li for vector spaces, the difference between the upper and the | ||
61 | /// lower bounds, | ||
62 | /// \li for SO(n), \f$\frac{2\pi}{\sqrt{2n-3}}\f$ on each of the | ||
63 | /// \f$ 2n-3 \f$ dimensions, | ||
64 | /// \li SE(n) is treated as \f$ R^n \times SO(n) \f$. | ||
65 | void sigma(const value_type& factor); | ||
66 | |||
67 | ✗ | void sigmas(vectorIn_t s) { | |
68 | ✗ | assert(s.size() == robot_->numberDof()); | |
69 | ✗ | sigmas_ = s; | |
70 | } | ||
71 | const vector_t& sigmas() const { return sigmas_; } | ||
72 | |||
73 | protected: | ||
74 | /// Create a gaussian distribution centered in the robot current | ||
75 | /// configuration. The standard deviation is computed as \c sigma(0.25) | ||
76 | /// \sa Gaussian::sigma | ||
77 | 1 | Gaussian(const DevicePtr_t& robot) | |
78 | 2 | : robot_(robot), | |
79 |
2/4✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
|
1 | center_(robot->currentConfiguration()), |
80 |
2/4✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 1 times.
✗ Branch 8 not taken.
|
2 | sigmas_(robot->numberDof()) { |
81 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | sigma(1. / 4.); |
82 | 1 | } | |
83 | 1 | void init(const GaussianPtr_t& self) { | |
84 | 1 | ConfigurationShooter::init(self); | |
85 | 1 | weak_ = self; | |
86 | 1 | } | |
87 | |||
88 | virtual void impl_shoot(Configuration_t& q) const; | ||
89 | |||
90 | private: | ||
91 | const DevicePtr_t& robot_; | ||
92 | /// The mean value | ||
93 | Configuration_t center_; | ||
94 | /// The standard deviation | ||
95 | vector_t sigmas_; | ||
96 | |||
97 | GaussianWkPtr_t weak_; | ||
98 | }; // class Gaussian | ||
99 | /// \} | ||
100 | } // namespace configurationShooter | ||
101 | } // namespace core | ||
102 | } // namespace hpp | ||
103 | |||
104 | #endif // HPP_CORE_CONFIGURATION_SHOOTER_GAUSSIAN_HH | ||
105 |