Integrate Raptor policy with a custom simulator
masterTo use the Raptor foundation policy with your own simulator, install the foundation-policy package. The policy expects observations in the FLU (Forward, Left, Up) axis convention.
Observation Vector Requirements: Construct a numpy array containing the following elements in order:
- Position: Absolute position in meters (or relative offset to target trajectory).
- Orientation: Flattened (row-major) $3\times3$ rotation matrix.
- Linear Velocity: Linear velocity in m/s (or relative offset to target trajectory).
- Angular Velocity: Angular velocity in the body frame in rad/s.
- Previous Action: The action from the previous timestep (using the same normalization).
Action Output Requirements:
- The policy returns actions in batches by default. Use
policy.evaluate_step(observation)[0]to get a single action. - Motor conventions:
[front-right, back-right, back-left, front-left]. - Motor commands are normalized in the range
[-1, 1]. - To convert to RPM:
rpm(action) = (max_rpm - min_rpm) * (action + 1)/2 + min_rpm.
Timing: The policy is trained for 100 Hz control. While it can handle other frequencies, 100 Hz (10 ms dt) is the nominal value for best results.
pip install foundation-policy==1.0.1from foundation_policy import Raptor
import numpy as np
policy = Raptor()
policy.reset()
for simulation_step in range(1000):
# Construct observation: [pos, rot, lin_vel, ang_vel, prev_action]
observation = np.array([[*sim.position, *R(sim.orientation).flatten(), *sim.linear_velocity, *sim.angular_velocity, *sim.action]])
# Policy works on batches; take the first element
action = policy.evaluate_step(observation)[0]
simulation.step(action) # simulation dt=10 ms