40 #include <pybind11/stl.h> 44 #include <Rcs_resourcePath.h> 45 #include <Rcs_macros.h> 46 #include <Rcs_MatNd.h> 47 #include <Rcs_Vec3d.h> 48 #include <PhysicsFactory.h> 50 #include <SegFaultHandler.h> 51 #include <Rcs_typedef.h> 53 RCS_INSTALL_ERRORHANDLERS
62 py::register_exception<Rcs::JointLimitException>(m,
"JointLimitException");
65 py::class_<Rcs::BoxSpace>(m,
"BoxSpace")
68 .def_property_readonly(
"names", [](
74 return py::cast(names);
78 py::class_<Rcs::RcsSimEnv>(m,
"RcsSimEnv")
79 .def(py::init([](py::kwargs kwargs) {
82 std::string configFileName;
83 if (
try_get(kwargs,
"experimentConfigFile", configFileName)) {
94 py::call_guard<py::gil_scoped_release>())
95 .def(
"reset", [](
Rcs::RcsSimEnv&
self, py::object domainParam,
const MatNd* initState) {
97 if (!domainParam.is_none()) {
100 MatNd* result =
self.reset(domainParamSource, initState);
101 if (!domainParam.is_none()) {
102 delete domainParamSource;
106 py::arg(
"domainParam").none(
true) = py::none(), py::arg(
"initState").none(
true) = py::none()
111 .def(
"saveConfigXML", [](
Rcs::RcsSimEnv&
self,
const char* fileName) {
112 self.getConfig()->properties->saveXML(fileName,
"Experiment");
114 .def(
"getBodyPosition",
115 [](
Rcs::RcsSimEnv&
self,
const char* bodyName,
const char* refBodyName,
const char* refFrameName) {
116 const RcsBody* body = RcsGraph_getBodyByName(
self.getConfig()->graph, bodyName);
118 const RcsBody* refBody = RcsGraph_getBodyByName(
self.getConfig()->graph, refBodyName);
119 const RcsBody* refFrame = RcsGraph_getBodyByName(
self.getConfig()->graph, refFrameName);
123 Vec3d_copy(I_r, body->A_BI->org);
126 if (refBody != NULL) {
127 Vec3d_subSelf(I_r, refBody->A_BI->org);
130 if ((refFrame != NULL) && (refFrame != refBody)) {
131 Vec3d_rotateSelf(I_r, refFrame->A_BI->rot);
135 Vec3d_rotateSelf(I_r, refBody->A_BI->rot);
141 if (refFrame != NULL) {
142 Vec3d_rotateSelf(I_r, refFrame->A_BI->rot);
147 pos = MatNd_create(3, 1);
148 for (
unsigned int i = 0; i < 3; i++) {
149 MatNd_set(pos, i, 0, I_r[i]);
153 py::arg(
"bodyName"), py::arg(
"refFrameName"), py::arg(
"refBodyName")
155 .def(
"getBodyExtents", [](
Rcs::RcsSimEnv&
self,
const char* bodyName,
const int shapeIdx) {
156 const RcsBody* body = RcsGraph_getBodyByName(
self.getConfig()->graph, bodyName);
159 MatNd* extents = NULL;
160 extents = MatNd_create(3, 1);
161 for (
unsigned int i = 0; i < 3; i++) {
162 MatNd_set(extents, i, 0, body->shape[shapeIdx]->extents[i]);
166 py::arg(
"bodyName"), py::arg(
"shapeIdx")
177 self.getPhysicsManager()->getValues(&psink);
182 return self.getConfig()->dt;
186 py::return_value_policy::copy);
189 py::class_<Rcs::ControlPolicy> controlPolicy(m,
"ControlPolicy");
191 controlPolicy.def(
"__call__", [](
Rcs::ControlPolicy&
self,
const MatNd* input,
unsigned int output_size) {
192 MatNd* output = MatNd_create(output_size, 1);
193 self.computeAction(output, input);
197 controlPolicy.def_property_readonly_static(
"types", [](py::handle ) {
212 m.def(
"saveExperimentParams", [](py::dict& config,
const char* filename){
214 ps->saveXML(filename,
"Experiment");
215 }, py::arg(
"config"), py::arg(
"filename"));
218 m.def(
"setLogLevel", [](
int level) { RcsLogLevel = level; });
221 m.def(
"addResourcePath", [](
const char* path) {
return Rcs_addResourcePath(path); });
224 m.def(
"supportsPhysicsEngine", &Rcs::PhysicsFactory::hasEngine);
void setTransitionNoiseBuffer(const MatNd *tnb)
void setVortexLogLevel(const char *level)
static std::vector< std::string > getTypeNames()
List available policy names.
unsigned int getInternalStateDim()
RCS_INSTALL_ERRORHANDLERS PYBIND11_MODULE(_rcsenv, m)
virtual void render(std::string mode="human", bool close=false)
const BoxSpace * actionSpace()
const MatNd * getMin() const
const BoxSpace * observationSpace()
MatNd * getCurrentAction() const
void toggleVideoRecording()
const MatNd * getMax() const
static PropertySource * empty()
MatNd * getCurrentObservation() const
bool try_get(const py::dict &dict, const char *key, T &var)
static ControlPolicy * create(const char *name, const char *dataFile)
virtual MatNd * step(const MatNd *action, const MatNd *disturbance=NULL)
const std::vector< std::string > & getNames() const
const BoxSpace * initStateSpace()