AvidEslami / flightmare

An Open Flexible Quadrotor Simulator
https://uzh-rpg.github.io/flightmare/
Other
4 stars 3 forks source link

Instantiating Gates Visible via Python #3

Open MistyGH opened 6 months ago

MistyGH commented 6 months ago
MistyGH commented 6 months ago

To spawn a gate:

Initialize Gate:

// add includes for gate implementation
#include "flightlib/eigen-3.4.0/Eigen/Eigen"

#include "flightlib/bridges/unity_bridge.hpp"
#include "flightlib/bridges/unity_message_types.hpp"
#include "flightlib/common/types.hpp"
#include "flightlib/objects/static_gate.hpp"

Following code can be global:

// Initialize gates (with positions)
std::string object_id = "UNIQUE_GATE_NAME"; // Unique name

std::string prefab_id = "rpg_gate"; // Name of the prefab in the Assets/Resources folder
std::shared_ptr<StaticGate> GATE_NAME =
  std::make_shared<StaticGate>(object_id, prefab_id);

At the start of the "reset" function, initialize positions by adding the following lines:

GATE_NAME->setPosition(Eigen::Vector3f(0, 10, 2.5));
GATE_NAME->setQuaternion(
  Quaternion(std::cos(0.5 * M_PI_2), 0.0, 0.0, std::sin(0.5 * M_PI_2)));

Add Gate Object:

Within the "addObjectsToUnity" function, add the following line:

bridge->addStaticObject(GATE_NAME);