Camera Control

AirGen provides methods for controlling camera settings within the simulation environment, including camera pose and field of view (FOV). Below are the key methods for camera manipulation.

simSetCameraPose

This function sets the pose (position and orientation) of a specified camera. You can control both internal and external cameras.

def simSetCameraPose(self, camera_name, pose, vehicle_name="", external=False):
    """
    Set the pose of a camera.

    Args:
        camera_name (str): Name of the camera
        pose (Pose): Desired position and orientation
        vehicle_name (str, optional): Associated vehicle name
        external (bool, optional): Controls an external camera
    """
    self.client.call("simSetCameraPose", str(camera_name), pose, vehicle_name, external)

Example:

To set the pose of the "front_center" camera using AirGenCar:

import airgen
import time
import math
from grid.robot.airgen_car import AirGenCar

airgen_car_0 = AirGenCar()
client = airgen_car_0.client

def euler_to_quaternion(pitch, roll, yaw):
    # Convert Euler angles to quaternion
    pitch, roll, yaw = map(math.radians, [pitch, roll, yaw])
    cy, sy = math.cos(yaw * 0.5), math.sin(yaw * 0.5)
    cr, sr = math.cos(roll * 0.5), math.sin(roll * 0.5)
    cp, sp = math.cos(pitch * 0.5), math.sin(pitch * 0.5)
    return airgen.Quaternionr(cy * cr * cp + sy * sr * sp, cy * sr * cp - sy * cr * sp, cy * cr * sp + sy * sr * cp, sy * cr * cp - cy * sr * sp)

initial_pose = client.simGetCameraInfo("front_center").pose

test_poses = [
    airgen.Pose(airgen.Vector3r(0, 0, -10), euler_to_quaternion(0, 0, 0)),
    airgen.Pose(airgen.Vector3r(0, 0, -10), euler_to_quaternion(0, 0, 90)),
]

for pose in test_poses:
    client.simSetCameraPose("front_center", pose)
    time.sleep(2)
    client.simSetCameraPose("front_center", initial_pose)

Arguments:

  • camera_name: Name of the camera

  • pose: Pose object representing position and orientation

  • vehicle_name: (Optional) Vehicle to which the camera is attached

  • external: (Optional) Controls external cameras

Notes:

  • The Pose object follows the North-East-Down (NED) coordinate system.

  • This method supports external camera control using the external flag.

simSetCameraFov

Modifies the field of view (FOV) of a selected camera.

def simSetCameraFov(self, camera_name, fov_degrees, vehicle_name="", external=False):
    """
    Set the FOV of a camera.

    Args:
        camera_name (str): Name of the camera
        fov_degrees (float): FOV in degrees
        vehicle_name (str, optional): Associated vehicle name
        external (bool, optional): Controls an external camera
    """
    self.client.call("simSetCameraFov", str(camera_name), fov_degrees, vehicle_name, external)

Example:

Set the FOV for the "front_center" camera to 90 degrees:

client.simSetCameraFov("front_center", 90.0)

Arguments:

  • camera_name: Name of the camera

  • fov_degrees: FOV in degrees

  • vehicle_name: (Optional) Associated vehicle name

  • external: (Optional) Controls external cameras

Coordinate System and Frame of Reference

Camera position and orientation follow the North-East-Down (NED) frame:

  • X: Points forward (north)

  • Y: Points right (east)

  • Z: Points downward

Please ensure your poses are aligned with this frame.