Directory: | ./ |
---|---|
File: | include/hpp/core/configuration-shooter/uniform-tpl.hh |
Date: | 2024-08-10 11:29:48 |
Exec | Total | Coverage | |
---|---|---|---|
Lines: | 11 | 11 | 100.0% |
Branches: | 2 | 6 | 33.3% |
Line | Branch | Exec | Source |
---|---|---|---|
1 | // Copyright (c) 2023 Eureka Robotics | ||
2 | // Authors: Joseph Mirabel | ||
3 | |||
4 | #ifndef HPP_CORE_CONFIGURATION_SHOOTER_UNIFORM_TPL_HH | ||
5 | #define HPP_CORE_CONFIGURATION_SHOOTER_UNIFORM_TPL_HH | ||
6 | |||
7 | #include <hpp/core/configuration-shooter.hh> | ||
8 | #include <hpp/pinocchio/device.hh> | ||
9 | #include <random> | ||
10 | |||
11 | namespace hpp { | ||
12 | namespace core { | ||
13 | namespace configurationShooter { | ||
14 | |||
15 | /// \addtogroup configuration_sampling | ||
16 | /// \{ | ||
17 | |||
18 | /// Uniformly sample with bounds of degrees of freedom using a custom generator. | ||
19 | template <class generator_t> | ||
20 | class HPP_CORE_DLLAPI UniformTpl : public ConfigurationShooter { | ||
21 | public: | ||
22 | typedef shared_ptr<UniformTpl<generator_t>> Ptr_t; | ||
23 | typedef weak_ptr<UniformTpl<generator_t>> WkPtr_t; | ||
24 | |||
25 | 1 | static Ptr_t create(const DevicePtr_t& robot) { | |
26 |
1/2✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
|
1 | UniformTpl* ptr = new UniformTpl(robot); |
27 | 1 | Ptr_t shPtr(ptr); | |
28 |
0/2✗ Branch 1 not taken.
✗ Branch 2 not taken.
|
1 | ptr->init(shPtr); |
29 | 1 | return shPtr; | |
30 | } | ||
31 | |||
32 | /// Set the generator seed. | ||
33 | 2 | void seed(typename generator_t::result_type seed) { generator_.seed(seed); } | |
34 | |||
35 | protected: | ||
36 | /// Uniformly sample configuration space | ||
37 | /// | ||
38 | /// Note that translation joints have to be bounded. | ||
39 |
1/2✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
|
1 | UniformTpl(const DevicePtr_t& robot) : robot_(robot) {} |
40 | 1 | void init(const Ptr_t& self) { | |
41 | 1 | ConfigurationShooter::init(self); | |
42 | 1 | weak_ = self; | |
43 | 1 | } | |
44 | |||
45 | virtual void impl_shoot(Configuration_t& q) const; | ||
46 | |||
47 | private: | ||
48 | DevicePtr_t robot_; | ||
49 | WkPtr_t weak_; | ||
50 | |||
51 | // The generator must be mutable because impl_shoot is const and | ||
52 | // generator_t::operator() is not. | ||
53 | mutable generator_t generator_; | ||
54 | }; // class UniformTpl | ||
55 | /// \} | ||
56 | |||
57 | typedef UniformTpl<std::default_random_engine> UniformSeedable; | ||
58 | |||
59 | } // namespace configurationShooter | ||
60 | } // namespace core | ||
61 | } // namespace hpp | ||
62 | |||
63 | #endif // HPP_CORE_CONFIGURATION_SHOOTER_UNIFORM_TPL_HH | ||
64 |