I use the following code to save a trajectory to csv when running UnrealCV:
import argparse
import atexit
import time
import numpy as np
import pandas as pd
from unrealcv import client
trajectory = []
_TORAD = np.pi / 180
def unreal_euler2quat(roll, pitch, yaw):
"""
Convert Unreal Euler angles to a quaternion.
Based on FRotator::Quaternion in
Engine/Source/Runtime/Core/Private/Math/UnrealMath.cpp ln 373
:param roll: Roll angle
:param pitch: Pitch angle
:param yaw: Yaw angle
:return: A tuple quaternion in unreal space, w first
"""
angles = np.array([roll, pitch, yaw])
angles = angles * _TORAD / 2
sr, sp, sy = np.sin(angles)
cr, cp, cy = np.cos(angles)
x = cr * sp * sy - sr * cp * cy
y = -cr * sp * cy - sr * cp * sy
z = cr * cp * sy - sr * sp * cy
w = cr * cp * cy + sr * sp * sy
return w, x, y, z
def callback(ts):
x, y, z, pitch, yaw, roll = [float(v) for v in client.request("vget /camera/0/pose").split(" ")]
qw, qx, qy, qz = unreal_euler2quat(roll, pitch, yaw)
entry = {"ts": ts, "x": x / 100, "y": y / 100, "z": z / 100, "qx": qx, "qy": qy, "qz": qz, "qw": qw}
trajectory.append(entry)
def save_to_file(filename):
if len(trajectory) != 0:
df = pd.DataFrame(trajectory)
df["ts"] -= df["ts"][0]
df["ts"] *= 1e9
df["ts"] = df["ts"].astype(int)
with open(filename, "w") as f:
f.write("# timestamp, x, y, z, qx, qy, qz, qw\n")
df.to_csv(filename, index=False, header=False, mode="a")
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument("--filename", default="camera-trajectory.csv")
args = parser.parse_args()
atexit.register(save_to_file, args.filename)
client.connect()
try:
if not client.isconnected():
print("Please connect")
else:
last_time = time.time()
while True:
current_time = time.time()
if current_time - last_time >= 0.1:
callback(current_time)
last_time = current_time
except KeyboardInterrupt:
print("\nDone")
I want to have the same trajectory when running esim in combination with UnrealCV, and so I convert the Euler angles I get from UnrealCV to quaternions using unreal_euler2quat(). I save these in a csv which is then loaded in esim with the following .conf:
Any idea what could be the cause of this? I saw the other issues regarding trajectories, but these seemed to be largely about --trajectory_lambda=0. I saw something here about a rotation to the right, but that code seems commented out.
I use the following code to save a trajectory to csv when running UnrealCV:
I want to have the same trajectory when running esim in combination with UnrealCV, and so I convert the Euler angles I get from UnrealCV to quaternions using
unreal_euler2quat()
. I save these in a csv which is then loaded in esim with the following.conf
:However, the resulting trajectory seems to
Any idea what could be the cause of this? I saw the other issues regarding trajectories, but these seemed to be largely about
--trajectory_lambda=0
. I saw something here about a rotation to the right, but that code seems commented out.