bitsim
Model, simulate, estimate and control robots in C++
Loading...
Searching...
No Matches
Using Gymnasium environments (Part 3)

This example follows Using Gymnasium environments (Part 1) and Using Gymnasium environments (Part 2) and shows how to use bitrl::envs::gymnasium::LunarLanderDiscreteEnv and bitrl::envs::gymnasium::LunarLanderContinuousEnv.

#include <iostream>
#include <unordered_map>
#include <vector>
namespace box2d_example
{
using namespace bitsim;
const std::string SERVER_URL = "http://0.0.0.0:8001/api";
} // namespace box2d_example
int main()
{
using namespace box2d_example;
std::unordered_map<std::string, std::any> options;
options["wind_power"] = std::any(static_cast<bitsim::real_t>(10.0));
options["enable_wind"] = std::any(static_cast<bool>(true));
options["gravity"] = std::any(static_cast<bitsim::real_t>(-9.86));
options["turbulence_power"] = std::any(static_cast<bitsim::real_t>(1.5));
std::unordered_map<std::string, std::any> reset_ops;
reset_ops.insert({"seed", static_cast<uint_t>(42)});
{
std::cout << "Working with LunarLanderDiscreteEnv..." << std::endl;
std::cout << "Is environment registered: "
<< server.is_env_registered(LunarLanderDiscreteEnv::name) << std::endl;
env.make("v3", options, reset_ops);
std::cout << "Is environment created? " << env.is_created() << std::endl;
std::cout << "Is environment alive? " << env.is_alive() << std::endl;
std::cout << "Number of valid actions? " << env.n_actions() << std::endl;
auto time_step = env.reset();
std::cout << "Time step: " << time_step << std::endl;
time_step = env.step(1);
std::cout << "Time step: " << time_step << std::endl;
env.close();
}
{
std::cout << "Working with LunarLanderContinuousEnv..." << std::endl;
env.make("v3", options, reset_ops);
std::cout << "Is environment created? " << env.is_created() << std::endl;
std::cout << "Is environment alive? " << env.is_alive() << std::endl;
std::cout << "Action space size " << env.n_actions() << std::endl;
std::cout << "Environment URI: " << server.get_uri(env.env_name()) << std::endl;
auto time_step = env.reset();
std::cout << "Time step: " << time_step << std::endl;
std::vector<real_t> action = {0.8, 0.9};
time_step = env.step(action);
std::cout << "Time step: " << time_step << std::endl;
env.close();
}
return 0;
}
Definition lunar_lander_env.h:271
LunarLanderDiscreteEnv environment with discrete action space.
Definition lunar_lander_env.h:202
Utility class to facilitate HTTP requests between the environments REST API and C++ drivers.
Definition rest_rl_env_client.h:28
static const std::string name
name
Definition lunar_lander_env.h:207
int main()
Definition discounted_returns.cpp:19
Definition dc_motor_backend_base.h:9
std::size_t uint_t
uint_t
Definition bitsim_types.h:40
double real_t
real_t
Definition bitsim_types.h:20
Definition gymnasium_part_3.cpp:11
const std::string SERVER_URL
Definition gymnasium_part_3.cpp:13
dict action
Definition play.py:46
env
Definition play.py:33