How to use the airsim.to_quaternion function in airsim

To help you get started, we’ve selected a few airsim examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github microsoft / AirSim / PythonClient / computer_vision / character_control.py View on Github external
airsim.wait_key('Press any key to set preset')
client.reset()
for x in range(0, 10, 3):
    client.simCharSetFacePreset("FACS_0" + str(x), 5);
    time.sleep(1)

airsim.wait_key('Press any key to set multiple presets')
presets = {"Phoneme_l":0.5, "Phoneme_ae": 1, "Phoneme_ooo":0.0}
client.simCharSetFacePresets(presets)

airsim.wait_key('Press any key to turn head around')
client.reset()
for pitch in range(-5, 5, 5):
    for yaw in range(-10, 10, 2):
        q = airsim.to_quaternion(pitch/10.0, 0, yaw/10.0)
        client.simCharSetHeadRotation(q)
        time.sleep(0.1)

airsim.wait_key('Press any key to get images')
for x in range(3): # do few times
    responses = client.simGetImages([
        airsim.ImageRequest("0", airsim.ImageType.DepthVis),
        airsim.ImageRequest("0", airsim.ImageType.Segmentation),
        airsim.ImageRequest("0", airsim.ImageType.Scene),
        airsim.ImageRequest("0", airsim.ImageType.SurfaceNormals)])

    for i, response in enumerate(responses):
        if response.pixels_as_float:
            print("Type %d, size %d, pos %s" % (response.image_type, len(response.image_data_float), pprint.pformat(response.camera_position)))
            airsim.write_pfm(os.path.normpath('/temp/cv_mode_' + str(x) + "_" + str(i) + '.pfm'), airsim.get_pfm_array(response))
        else:
github microsoft / DroneRescue / resources / search_sample.py View on Github external
def OrbitAnimal(cx, cy, radius, speed, altitude, camera_angle, animal):
    """
    @param cx: The x position of our orbit starting location
    @param cy: The x position of our orbit starting location
    @param radius: The radius of the orbit circle
    @param speed: The speed the drone should more, it's hard to take photos when flying fast
    @param altitude: The altidude we want to fly at, dont fly too high!
    @param camera_angle: The angle of the camera
    @param animal: The name of the animal, used to prefix the photos
    """

    x = cx - radius
    y = cy

    # set camera angle
    client.simSetCameraOrientation(0, airsim.to_quaternion(
        camera_angle * math.pi / 180, 0, 0))  # radians

    # move the drone to the requested location
    print("moving to position...")
    client.moveToPositionAsync(
        x, y, z, 1, 60, drivetrain=airsim.DrivetrainType.MaxDegreeOfFreedom, yaw_mode=airsim.YawMode(False, 0)).join()
    pos = client.getMultirotorState().kinematics_estimated.position

    dx = x - pos.x_val
    dy = y - pos.y_val
    yaw = airsim.to_eularian_angles(
        client.getMultirotorState().kinematics_estimated.orientation)[2]

    # keep the drone on target, it's windy out there!
    print("correcting position and yaw...")
    while abs(dx) > 1 or abs(dy) > 1 or abs(yaw) > 0.1:
github danmcduff / AvatarSim / AvatarControl / avatar_head_movement.py View on Github external
import setup_path 
import airsim
import pprint
import os
import time
import math
import argparse
import random

client = airsim.VehicleClient()
client.confirmConnection()

client.reset()

# reset head to neutral position
resets = airsim.to_quaternion(0, 0, 0)


length = 10000 # sets duration of the head movement

start_time = time.time()
elapsed_time = 0

while True:
    delay = random.uniform(1, 4)
    elapsed_time = time.time() - start_time
    number_of_steps = 20

    client.simCharSetHeadRotation(resets)

    current_pitch = client.simCharGetHeadRotation()['y_val'] # the y_val is definitely the pitch, which is what needs to be moved the most. Although I'm not sure what exactly z, w and x are, it doesn't matter since they need to be set to equally small values...
    current_roll = client.simCharGetHeadRotation()['x_val']
github microsoft / AirSim / PythonClient / computer_vision / cv_mode.py View on Github external
# https://github.com/Microsoft/AirSim/blob/master/docs/image_apis.md#computer-vision-mode

import setup_path 
import airsim

import pprint
import os
import time

pp = pprint.PrettyPrinter(indent=4)

client = airsim.VehicleClient()
client.confirmConnection()

airsim.wait_key('Press any key to set camera-0 gimble to 15-degree pitch')
client.simSetCameraOrientation("0", airsim.to_quaternion(0.261799, 0, 0)); #radians

airsim.wait_key('Press any key to get camera parameters')
for camera_name in range(5):
    camera_info = client.simGetCameraInfo(str(camera_name))
    print("CameraInfo %d: %s" % (camera_name, pp.pprint(camera_info)))

airsim.wait_key('Press any key to get images')
for x in range(3): # do few times
    z = x * -20 - 5 # some random number
    client.simSetVehiclePose(airsim.Pose(airsim.Vector3r(z, z, z), airsim.to_quaternion(x / 3.0, 0, x / 3.0)), True)

    responses = client.simGetImages([
        airsim.ImageRequest("0", airsim.ImageType.DepthVis),
        airsim.ImageRequest("1", airsim.ImageType.DepthPerspective, True),
        airsim.ImageRequest("2", airsim.ImageType.Segmentation),
        airsim.ImageRequest("3", airsim.ImageType.Scene),
github microsoft / AirSim / PythonClient / computer_vision / cv_navigate.py View on Github external
moveUAV(client,pos,yaw)

    if (target_dist < 1):
        print('Target reached.')
        airsim.wait_key('Press any key to continue')
        break

    # write to png 
    #imsave(os.path.normpath(os.path.join(tmp_dir, "depth_" + str(z) + '.png')), generate_depth_viz(img2d,5))

    #pose = client.simGetPose()
    #pp.pprint(pose)
    #time.sleep(5)

# currently reset() doesn't work in CV mode. Below is the workaround
client.simSetVehiclePose(airsim.Pose(airsim.Vector3r(0, 0, 0), airsim.to_quaternion(0, 0, 0)), True)