bitsim
Model, simulate, estimate and control robots in C++
Loading...
Searching...
No Matches
cart_pole.h
Go to the documentation of this file.
1#ifndef BITRL_CLASSIC_CONTROL_CART_POLE_H
2#define BITRL_CLASSIC_CONTROL_CART_POLE_H
3
9
10#include <any>
11#include <string>
12#include <unordered_map>
13#include <vector>
14
15namespace bitrl
16{
18{
19
39class CartPole final : public EnvBase<TimeStep<std::vector<real_t>>,
40 ContinuousVectorStateDiscreteActionEnv<4, 2, 0, real_t>>
41{
42 public:
49
50 static constexpr real_t THETA_LIMIT = 12.0 * 3.14159265358979323846 / 180.0;
51
53
54 void make(const std::string &version,
55 const std::unordered_map<std::string, std::any> &make_options,
56 const std::unordered_map<std::string, std::any> &reset_options) override;
57
58 void close() override;
59
64
69
73 time_step_type step(const action_type &action) override;
74
75 uint_t n_steps() const noexcept { return n_steps_; }
76
77 uint_t max_steps() const noexcept { return max_steps_; }
78
79 const bitsim::dynamics::CartPoleDynamics &dynamics() const noexcept { return dynamics_; }
80
81 private:
82 state_type observe_() const;
83
85 real_t dt_{0.02};
86 uint_t max_steps_{500};
87 uint_t n_steps_{0};
88};
89
90} // namespace envs::classic_control
91} // namespace bitrl
92
93#endif // BITRL_CLASSIC_CONTROL_CART_POLE_H
ContinuousVectorStateDiscreteActionEnv< 4, 2, 0, real_t >::state_type state_type
Definition env_base.h:48
const std::unordered_map< std::string, std::any > & reset_options() const noexcept
Definition env_base.h:105
EnvBase(const std::string &idx=bitsim::consts::INVALID_STR, const std::string &name=bitsim::consts::INVALID_STR)
const std::unordered_map< std::string, std::any > & make_options() const noexcept
Definition env_base.h:96
ContinuousVectorStateDiscreteActionEnv< 4, 2, 0, real_t >::action_type action_type
Definition env_base.h:54
time_step_type reset(uint_t seed)
Start an episode with the given seed.
base_type::time_step_type time_step_type
Definition cart_pole.h:46
const bitsim::dynamics::CartPoleDynamics & dynamics() const noexcept
Definition cart_pole.h:79
void make(const std::string &version, const std::unordered_map< std::string, std::any > &make_options, const std::unordered_map< std::string, std::any > &reset_options) override
Construct the environment instance.
void close() override
Close and release any acquired environment resources.
time_step_type reset() override
Start an episode with the next seed.
time_step_type step(const action_type &action) override
Push the cart: 0 to the left, 1 to the right.
EnvBase< TimeStep< std::vector< real_t > >, ContinuousVectorStateDiscreteActionEnv< 4, 2, 0, real_t > > base_type
Definition cart_pole.h:45
uint_t max_steps() const noexcept
Definition cart_pole.h:77
uint_t n_steps() const noexcept
Definition cart_pole.h:75
static constexpr real_t THETA_LIMIT
Definition cart_pole.h:50
base_type::state_type state_type
Definition cart_pole.h:47
base_type::action_type action_type
Definition cart_pole.h:48
A cart on a straight track, pushed by a horizontal force F, with a pole hinged on it.
Definition cart_pole_dynamics.h:70
Definition cart_pole.h:18
Various utilities used when working with RL problems.
Definition bitrl_log.h:25
std::size_t uint_t
uint_t
Definition bitsim_types.h:40
double real_t
real_t
Definition bitsim_types.h:20