Closed ajof closed 4 years ago
You can control the camera state with the simSetCameraPose
function
https://microsoft.github.io/AirSim/image_apis/#camera-apis
def set_camera_state(xyz, orientation, name='0'):
# airsim quat is in the order xyzw
quat = [float(orientation[1]), float(orientation[2]), float(orientation[3]), float(orientation[0])]
pose = Pose(
position_val=Vector3r(
x_val=xyz[0], y_val=xyz[1], z_val=xyz[2]
),
orientation_val=Quaternionr(
x_val=quat[0], y_val=quat[1], z_val=quat[2], w_val=quat[3]
)
)
client.simSetCameraPose(name, pose)
Just a few things to keep in mind with the code above, you need to convert your position into an airsim Vector3r
and your quaternion into a Quaternionr
object. Then pass both into the Pose
class. You also have to make sure you convert your orientation correctly. If you have your orientation in euler angles, you need to convert it into a quaternion. I won't go into the details because that is convered much better an extensively online. As long as you know the order of your euler rotations and if they're static or rotating frame, you can use the function here
https://github.com/abr/abr_control/blob/master/abr_control/utils/transformations.py#L1087
The last "gotcha" here is that you need to change the order of your quaternion. They are typically in the order wxyz
, but Airsim takes it as xyzw
. The function I linked above will return them in the order wxyz
, so make sure you flip that order as is done in the code above.
I want to use AirSim to record a video where the camera moves along a pre-defined path within an Unreal environment.
I know that the MultirotorClient has MoveAlongPath features, but that would include the dynamics of the vehicle. I want to be able to define the position (XYZ) and attitude (All 3 angles) for each step of the path. For example, I would like to input a path (X,Y,Z as functions of t (time)), and have the camera follow that exact path.
Maybe if I could control the location of the camera in "ComputerVision" mode via an API, that might work for me.
I am looking for suggestions for how to do this.
Thanks!