Directory: | ./ |
---|---|
File: | src/configuration-shooter/gaussian.cc |
Date: | 2024-12-13 16:14:03 |
Exec | Total | Coverage | |
---|---|---|---|
Lines: | 36 | 38 | 94.7% |
Branches: | 64 | 122 | 52.5% |
Line | Branch | Exec | Source |
---|---|---|---|
1 | // Copyright (c) 2018, Joseph Mirabel | ||
2 | // Authors: Joseph Mirabel (joseph.mirabel@laas.fr) | ||
3 | // | ||
4 | |||
5 | // Redistribution and use in source and binary forms, with or without | ||
6 | // modification, are permitted provided that the following conditions are | ||
7 | // met: | ||
8 | // | ||
9 | // 1. Redistributions of source code must retain the above copyright | ||
10 | // notice, this list of conditions and the following disclaimer. | ||
11 | // | ||
12 | // 2. Redistributions in binary form must reproduce the above copyright | ||
13 | // notice, this list of conditions and the following disclaimer in the | ||
14 | // documentation and/or other materials provided with the distribution. | ||
15 | // | ||
16 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
17 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
18 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | ||
19 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | ||
20 | // HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
21 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | ||
22 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
23 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | ||
24 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
25 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
26 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH | ||
27 | // DAMAGE. | ||
28 | |||
29 | #include <math.h> | ||
30 | |||
31 | #include <boost/random/mersenne_twister.hpp> | ||
32 | #include <boost/random/normal_distribution.hpp> | ||
33 | #include <hpp/core/configuration-shooter/gaussian.hh> | ||
34 | #include <hpp/pinocchio/configuration.hh> | ||
35 | #include <hpp/pinocchio/joint-collection.hh> | ||
36 | #include <hpp/pinocchio/liegroup.hh> | ||
37 | #include <pinocchio/algorithm/joint-configuration.hpp> | ||
38 | #include <pinocchio/multibody/model.hpp> | ||
39 | |||
40 | namespace hpp { | ||
41 | namespace core { | ||
42 | namespace configurationShooter { | ||
43 | namespace liegroup = pinocchio::liegroup; | ||
44 | |||
45 | template <typename LG1, typename LG2> | ||
46 | void computeSigmasAlgo(liegroup::CartesianProductOperation<LG1, LG2> lg, | ||
47 | vectorOut_t sigmas, vectorIn_t upper, vectorIn_t lower); | ||
48 | |||
49 | template <int N> | ||
50 | 4 | void computeSigmasAlgo(liegroup::SpecialOrthogonalOperation<N>, | |
51 | vectorOut_t sigmas, vectorIn_t, vectorIn_t) { | ||
52 |
1/2✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
|
4 | sigmas.setConstant(2 * M_PI / std::sqrt((value_type)N)); |
53 | } | ||
54 | |||
55 | template <int N> | ||
56 | 4 | void computeSigmasAlgo(liegroup::SpecialEuclideanOperation<N>, | |
57 | vectorOut_t sigmas, vectorIn_t upper, vectorIn_t lower) { | ||
58 | typedef liegroup::CartesianProductOperation< | ||
59 | liegroup::VectorSpaceOperation<N, true>, | ||
60 | liegroup::SpecialOrthogonalOperation<N> > | ||
61 | LG_t; | ||
62 |
4/8✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 2 times.
✗ Branch 6 not taken.
✓ Branch 8 taken 2 times.
✗ Branch 9 not taken.
✓ Branch 11 taken 2 times.
✗ Branch 12 not taken.
|
4 | computeSigmasAlgo(LG_t(), sigmas, upper, lower); |
63 | } | ||
64 | |||
65 | template <int N, bool rot> | ||
66 | 108 | void computeSigmasAlgo(liegroup::VectorSpaceOperation<N, rot>, | |
67 | vectorOut_t sigmas, vectorIn_t upper, vectorIn_t lower) { | ||
68 | // TODO isFinite was added after 3.2.4 | ||
69 | // sigmas.array() = | ||
70 | // (upper.array().isFinite() && lower.array().isFinite()) | ||
71 | // .select (upper - lower, 1); | ||
72 |
2/2✓ Branch 1 taken 58 times.
✓ Branch 2 taken 54 times.
|
224 | for (size_type i = 0; i < sigmas.size(); ++i) { |
73 |
7/14✓ Branch 1 taken 58 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 58 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 58 times.
✗ Branch 7 not taken.
✓ Branch 9 taken 58 times.
✗ Branch 10 not taken.
✓ Branch 12 taken 58 times.
✗ Branch 13 not taken.
✓ Branch 14 taken 58 times.
✗ Branch 15 not taken.
✓ Branch 16 taken 58 times.
✗ Branch 17 not taken.
|
116 | if (Eigen::numext::isfinite(upper(i)) && Eigen::numext::isfinite(lower(i))) |
74 | 116 | sigmas(i) = upper(i) - lower(i); | |
75 | else | ||
76 | ✗ | sigmas(i) = 1.; | |
77 | } | ||
78 | } | ||
79 | |||
80 | template <typename LG1, typename LG2> | ||
81 | 4 | void computeSigmasAlgo(liegroup::CartesianProductOperation<LG1, LG2>, | |
82 | vectorOut_t sigmas, vectorIn_t upper, vectorIn_t lower) { | ||
83 |
7/14✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 2 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 2 times.
✗ Branch 11 not taken.
✓ Branch 13 taken 2 times.
✗ Branch 14 not taken.
✓ Branch 17 taken 2 times.
✗ Branch 18 not taken.
✓ Branch 20 taken 2 times.
✗ Branch 21 not taken.
|
4 | computeSigmasAlgo(LG1(), sigmas.head(LG1::NV), upper.head(LG1::NQ), |
84 | 4 | lower.head(LG1::NQ)); | |
85 |
7/14✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 2 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 2 times.
✗ Branch 11 not taken.
✓ Branch 13 taken 2 times.
✗ Branch 14 not taken.
✓ Branch 16 taken 2 times.
✗ Branch 17 not taken.
✓ Branch 19 taken 2 times.
✗ Branch 20 not taken.
|
4 | computeSigmasAlgo(LG2(), sigmas.tail(LG2::NV), upper.tail(LG2::NQ), |
86 | 4 | lower.tail(LG2::NQ)); | |
87 | } | ||
88 | |||
89 | struct ComputeSigmasStep | ||
90 | : public ::pinocchio::fusion::JointUnaryVisitorBase<ComputeSigmasStep> { | ||
91 | typedef boost::fusion::vector<const pinocchio::Model&, vector_t&> ArgsType; | ||
92 | |||
93 | template <typename JointModel> | ||
94 | 108 | static void algo(const ::pinocchio::JointModelBase<JointModel>& jmodel, | |
95 | const pinocchio::Model& model, vector_t& sigmas) { | ||
96 | typedef typename pinocchio::DefaultLieGroupMap::operation<JointModel>::type | ||
97 | LG_t; | ||
98 |
8/14✓ Branch 1 taken 54 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 54 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 54 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 54 times.
✗ Branch 11 not taken.
✓ Branch 13 taken 2 times.
✓ Branch 14 taken 52 times.
✗ Branch 15 not taken.
✓ Branch 16 taken 2 times.
✓ Branch 17 taken 52 times.
✗ Branch 18 not taken.
|
216 | computeSigmasAlgo(LG_t(), jmodel.jointVelocitySelector(sigmas), |
99 |
1/2✓ Branch 1 taken 54 times.
✗ Branch 2 not taken.
|
216 | jmodel.jointConfigSelector(model.upperPositionLimit), |
100 | 108 | jmodel.jointConfigSelector(model.lowerPositionLimit)); | |
101 | } | ||
102 | }; | ||
103 | |||
104 | 11 | void Gaussian::impl_shoot(Configuration_t& config) const { | |
105 |
4/8✓ Branch 0 taken 1 times.
✓ Branch 1 taken 10 times.
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
✓ Branch 6 taken 1 times.
✗ Branch 7 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
|
11 | static boost::random::mt19937 eng; |
106 |
2/4✓ Branch 2 taken 11 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 11 times.
✗ Branch 6 not taken.
|
11 | vector_t velocity(robot_->numberDof()); |
107 |
2/2✓ Branch 1 taken 352 times.
✓ Branch 2 taken 11 times.
|
363 | for (size_type i = 0; i < velocity.size(); ++i) { |
108 |
1/2✓ Branch 1 taken 352 times.
✗ Branch 2 not taken.
|
352 | boost::random::normal_distribution<value_type> distrib(0, sigmas_[i]); |
109 |
2/4✓ Branch 1 taken 352 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 352 times.
✗ Branch 5 not taken.
|
352 | velocity[i] = distrib(eng); |
110 | } | ||
111 | |||
112 |
2/4✓ Branch 2 taken 11 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 11 times.
✗ Branch 6 not taken.
|
11 | config.resize(robot_->configSize()); |
113 |
1/2✓ Branch 1 taken 11 times.
✗ Branch 2 not taken.
|
11 | vector_t center(center_); |
114 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 11 times.
|
11 | if (center.size() == 0) { |
115 | // center has not been initialized, use robot neutral configuration | ||
116 | ✗ | center = robot_->neutralConfiguration(); | |
117 | } | ||
118 |
4/8✓ Branch 1 taken 11 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 11 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 11 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 11 times.
✗ Branch 11 not taken.
|
11 | ::hpp::pinocchio::integrate(robot_, center_, velocity, config); |
119 |
2/4✓ Branch 1 taken 11 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 11 times.
✗ Branch 5 not taken.
|
11 | ::hpp::pinocchio::saturate(robot_, config); |
120 | 11 | } | |
121 | |||
122 | 2 | void Gaussian::sigma(const value_type& factor) { | |
123 | 2 | const pinocchio::Model& model = robot_->model(); | |
124 |
1/2✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
|
2 | ComputeSigmasStep::ArgsType args(model, sigmas_); |
125 |
2/2✓ Branch 1 taken 54 times.
✓ Branch 2 taken 2 times.
|
56 | for (std::size_t i = 1; i < model.joints.size(); ++i) |
126 |
2/4✓ Branch 1 taken 54 times.
✗ Branch 2 not taken.
✓ Branch 5 taken 54 times.
✗ Branch 6 not taken.
|
54 | ComputeSigmasStep::run(model.joints[i], args); |
127 | |||
128 |
1/2✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
|
2 | sigmas_ *= factor; |
129 | 2 | } | |
130 | } // namespace configurationShooter | ||
131 | } // namespace core | ||
132 | } // namespace hpp | ||
133 |