How to use the airsim.CarClient 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 / car / drive_straight.py View on Github external
import setup_path 
import airsim

#from keras.models import load_model
import sys
import numpy as np

#if (len(sys.argv) != 2):
#    print('usage: python drive.py ')
#    sys.exit()

#print('Loading model...')
#model = load_model(sys.argv[1])

# connect to the AirSim simulator 
client = airsim.CarClient()
client.confirmConnection()
client.enableApiControl(True)
car_controls = airsim.CarControls()

car_controls.steering = 0
car_controls.throttle = 0
car_controls.brake = 0

image_buf = np.zeros((1, 144, 256, 3))
state_buf = np.zeros((1,4))

def get_image():
    image = client.simGetImages([airsim.ImageRequest("0", airsim.ImageType.Scene, False, False)])[0]
    image1d = np.fromstring(image.image_data_uint8, dtype=np.uint8)
    image_rgba = image1d.reshape(image.height, image.width, 4)
    image_rgba = np.flipud(image_rgba)
github microsoft / AirSim / PythonClient / car / multi_agent_car.py View on Github external
"Vehicles": {
		"Car1": {
		  "VehicleType": "PhysXCar",
		  "X": 4, "Y": 0, "Z": -2
		},
		"Car2": {
		  "VehicleType": "PhysXCar",
		  "X": -4, "Y": 0, "Z": -2
		}

    }
}
"""

# connect to the AirSim simulator 
client = airsim.CarClient()
client.confirmConnection()
client.enableApiControl(True, "Car1")
client.enableApiControl(True, "Car2")

car_controls1 = airsim.CarControls()
car_controls2 = airsim.CarControls()


for idx in range(3):
    # get state of the car
    car_state1 = client.getCarState("Car1")
    print("Car1: Speed %d, Gear %d" % (car_state1.speed, car_state1.gear))
    car_state2 = client.getCarState("Car2")
    print("Car1: Speed %d, Gear %d" % (car_state2.speed, car_state2.gear))

    # go forward
github microsoft / AirSim / PythonClient / ros / car_pose.py View on Github external
def airpub():
    pub = rospy.Publisher("airsimPose", PoseStamped, queue_size=1)
    rospy.init_node('airpub', anonymous=True)
    rate = rospy.Rate(10) # 10hz

    # connect to the AirSim simulator 
    client = airsim.CarClient()
    client.confirmConnection()

#    start = time.time()


    while not rospy.is_shutdown():

        # get state of the car
        car_state = client.getCarState()
        pos = car_state.kinematics_estimated.position
        orientation = car_state.kinematics_estimated.orientation
#        milliseconds = (time.time() - start) * 1000


        # populate PoseStamped ros message
        simPose = PoseStamped()
github microsoft / AirSim / PythonClient / imitation_learning / drive_model.py View on Github external
import numpy as np

import airsim

import keras.backend as K
from keras.preprocessing import image
from PIL import Image, ImageDraw
import matplotlib.pyplot as plt

# Trained model path
MODEL_PATH = './models/example_model.h5'

model = load_model(MODEL_PATH)

# Connect to AirSim 
client = airsim.CarClient()
client.confirmConnection()
client.enableApiControl(True)
car_controls = airsim.CarControls()

# Start driving
car_controls.steering = 0
car_controls.throttle = 0
car_controls.brake = 0
client.setCarControls(car_controls)

# Initialize image buffer
image_buf = np.zeros((1, 66, 200, 3))

def get_image():
    """
    Get image from AirSim client
github microsoft / AirSim / PythonClient / car / car_lidar.py View on Github external
def __init__(self):

        # connect to the AirSim simulator
        self.client = airsim.CarClient()
        self.client.confirmConnection()
        self.client.enableApiControl(True)
        self.car_controls = airsim.CarControls()
github microsoft / AirSim / PythonClient / ros / car_image_raw.py View on Github external
def airpub():
    pub = rospy.Publisher("airsim/image_raw", Image, queue_size=1)
    rospy.init_node('image_raw', anonymous=True)
    rate = rospy.Rate(10) # 10hz

    # connect to the AirSim simulator 
    client = airsim.CarClient()
    client.confirmConnection()

    while not rospy.is_shutdown():
         # get camera images from the car
        responses = client.simGetImages([
            airsim.ImageRequest("1", airsim.ImageType.Scene, False, False)])  #scene vision image in uncompressed RGB array

        for response in responses:
            img_rgb_string = response.image_data_uint8

        # Populate image message
        msg=Image() 
        msg.header.stamp = rospy.Time.now()
        msg.header.frame_id = "frameId"
        msg.encoding = "rgb8"
        msg.height = 360  # resolution should match values in settings.json 
github nesl / UnrealAirSimDRL / Util / PointCloud.py View on Github external
############################################

# file will be saved in PythonClient folder (i.e. same folder as script)
# point cloud ASCII format, use viewers like CloudCompare http://www.danielgm.net/cc/ or see http://www.geonext.nl/wp-content/uploads/2014/05/Point-Cloud-Viewers.pdf
outputFile = "cloud.asc" 
color = (0,255,0)
rgb = "%d %d %d" % color
projectionMatrix = np.array([[-0.501202762, 0.000000000, 0.000000000, 0.000000000],
                              [0.000000000, -0.501202762, 0.000000000, 0.000000000],
                              [0.000000000, 0.000000000, 10.00000000, 100.00000000],
                              [0.000000000, 0.000000000, -10.0000000, 0.000000000]])


# Connect to the AirSim simulator and begin:
print('Initializing Car Client')
client = airsim.CarClient()
client.confirmConnection()
client.enableApiControl(False)
print('Initialization DONE!')

print("Setting Camera Views")
orien = Vector3r(0, 0, 0)
client.simSetCameraOrientation("3", orien) #radians
orien = Vector3r(0, 0, -np.pi/2)
client.simSetCameraOrientation("1", orien)
orien = Vector3r(0, 0, np.pi/2)
client.simSetCameraOrientation("2", orien)
orien = Vector3r(0, 0, np.pi/2)
# Reset Collion Flags
print("Setting Camera Views DONE!")