forked from uzh-rpg/flightmare
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
created trajectory tracking reward based environment, added assertion…
…s for nan cases in reward function, unsure of cause still
- Loading branch information
1 parent
f760a4d
commit 1de85dd
Showing
15 changed files
with
28,041 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
98 changes: 98 additions & 0 deletions
98
flightlib/include/flightlib/envs/quadrotor_env/quadrotor_env_bydata_traj.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
#pragma once | ||
|
||
// std lib | ||
#include <stdlib.h> | ||
#include <cmath> | ||
#include <iostream> | ||
|
||
// yaml cpp | ||
#include <yaml-cpp/yaml.h> | ||
|
||
// flightlib | ||
|
||
#include "quadenv_ctl.hpp" | ||
|
||
|
||
namespace flightlib { | ||
|
||
// namespace quadenv { | ||
|
||
// enum Ctl : int { | ||
// // observations | ||
// kObs = 0, | ||
// // | ||
// kPos = 0, | ||
// kNPos = 3, | ||
// kOri = 3, | ||
// kNOri = 3, | ||
// kLinVel = 6, | ||
// kNLinVel = 3, | ||
// kAngVel = 9, | ||
// kNAngVel = 3, | ||
// kNObs = 12, | ||
// // control actions | ||
// kAct = 0, | ||
// kNAct = 4, | ||
// }; | ||
// }; | ||
|
||
class QuadrotorEnvByDataTraj final : public EnvBase { | ||
public: | ||
EIGEN_MAKE_ALIGNED_OPERATOR_NEW | ||
|
||
QuadrotorEnvByDataTraj(); | ||
QuadrotorEnvByDataTraj(const std::string &cfg_path); | ||
~QuadrotorEnvByDataTraj(); | ||
|
||
// - public OpenAI-gym-style functions | ||
bool reset(Ref<Vector<>> obs, const bool random = true) override; | ||
bool resetRange(Ref<Vector<>> obs, int lower_zbound, int upper_zbound, int lower_xybound, int upper_xybound, const bool random = true) override; | ||
Scalar step(const Ref<Vector<>> act, Ref<Vector<>> obs) override; | ||
|
||
// - public set functions | ||
bool loadParam(const YAML::Node &cfg); | ||
|
||
// - public get functions | ||
bool getObs(Ref<Vector<>> obs) override; | ||
bool getAct(Ref<Vector<>> act) const; | ||
bool getAct(Command *const cmd) const; | ||
|
||
// - auxiliar functions | ||
bool isTerminalState(Scalar &reward) override; | ||
void addObjectsToUnity(std::shared_ptr<UnityBridge> bridge); | ||
|
||
friend std::ostream &operator<<(std::ostream &os, | ||
const QuadrotorEnvByDataTraj &quad_env); | ||
|
||
private: | ||
// quadrotor | ||
std::shared_ptr<Quadrotor> quadrotor_ptr_; | ||
QuadState quad_state_; | ||
Command cmd_; | ||
Logger logger_{"QuadrotorEnvByDataTraj"}; | ||
|
||
// Define reward for training | ||
Scalar pos_coeff_, ori_coeff_, lin_vel_coeff_, ang_vel_coeff_, act_coeff_; | ||
|
||
// observations and actions (for RL) | ||
Vector<quadenv::kNObs> quad_obs_; | ||
Vector<quadenv::kNAct> quad_act_; | ||
// Store a trajectory as a list of states (pos, ori, lin_vel -> 10 elements) | ||
std::vector<Vector<10>> traj_; | ||
int mid_train_step_; | ||
|
||
|
||
// reward function design (for model-free reinforcement learning) | ||
Vector<quadenv::kNObs> goal_state_; | ||
|
||
// action and observation normalization (for learning) | ||
Vector<quadenv::kNAct> act_mean_; | ||
Vector<quadenv::kNAct> act_std_; | ||
Vector<quadenv::kNObs> obs_mean_ = Vector<quadenv::kNObs>::Zero(); | ||
Vector<quadenv::kNObs> obs_std_ = Vector<quadenv::kNObs>::Ones(); | ||
|
||
YAML::Node cfg_; | ||
Matrix<3, 2> world_box_; | ||
}; | ||
|
||
} // namespace flightlib |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.