bitsim
Model, simulate, estimate and control robots in C++
Loading...
Searching...
No Matches
cart_pole_swing_up.h
Go to the documentation of this file.
1#ifndef BITRL_CLASSIC_CONTROL_CART_POLE_SWING_UP_H
2#define BITRL_CLASSIC_CONTROL_CART_POLE_SWING_UP_H
3
9
10#include <any>
11#include <string>
12#include <unordered_map>
13#include <vector>
14
15namespace bitrl
16{
18{
19
41class CartPoleSwingUp final
42 : public EnvBase<TimeStep<std::vector<real_t>>,
43 ContinuousVectorStateContinuousVectorActionEnv<5, 1, real_t, real_t>>
44{
45 public:
52
56 static constexpr real_t UPRIGHT = 12.0 * 3.14159265358979323846 / 180.0;
57
59
60 void make(const std::string &version,
61 const std::unordered_map<std::string, std::any> &make_options,
62 const std::unordered_map<std::string, std::any> &reset_options) override;
63
64 void close() override;
65
70
75
79 time_step_type step(const action_type &action) override;
80
81 uint_t n_steps() const noexcept { return n_steps_; }
82
83 uint_t max_steps() const noexcept { return max_steps_; }
84
85 real_t dt() const noexcept { return dt_; }
86
90 real_t angle() const;
91
92 const bitsim::dynamics::CartPoleDynamics &dynamics() const noexcept { return dynamics_; }
93
94 private:
95 state_type observe_() const;
96
98 real_t dt_{0.02};
99 real_t off_track_penalty_{100.0};
100 uint_t max_steps_{500};
101 uint_t n_steps_{0};
102};
103
104} // namespace envs::classic_control
105} // namespace bitrl
106
107#endif // BITRL_CLASSIC_CONTROL_CART_POLE_SWING_UP_H
ContinuousVectorStateContinuousVectorActionEnv< 5, 1, real_t, 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
ContinuousVectorStateContinuousVectorActionEnv< 5, 1, real_t, 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.
uint_t n_steps() const noexcept
Definition cart_pole_swing_up.h:81
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.
base_type::state_type state_type
Definition cart_pole_swing_up.h:50
real_t angle() const
The angle of the pole from upright, in (-pi, pi].
time_step_type reset() override
Start an episode with the next seed.
base_type::time_step_type time_step_type
Definition cart_pole_swing_up.h:49
base_type::action_type action_type
Definition cart_pole_swing_up.h:51
time_step_type step(const action_type &action) override
Push the cart with action[0] newtons, positive towards +x.
static constexpr real_t UPRIGHT
Within this of upright [rad] the pole counts as up.
Definition cart_pole_swing_up.h:56
const bitsim::dynamics::CartPoleDynamics & dynamics() const noexcept
Definition cart_pole_swing_up.h:92
void close() override
Close and release any acquired environment resources.
uint_t max_steps() const noexcept
Definition cart_pole_swing_up.h:83
real_t dt() const noexcept
Definition cart_pole_swing_up.h:85
EnvBase< TimeStep< std::vector< real_t > >, ContinuousVectorStateContinuousVectorActionEnv< 5, 1, real_t, real_t > > base_type
Definition cart_pole_swing_up.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