sess.run(init_op)

    # Once the brakes come on, we need to keep them on for a while before exiting; otherwise,
    # the vehicle will resume moving.
    brakingCount = 0

    # Loop until we detect a collision
    while True:

        # Get RGBA camera images from the car
        responses = client.simGetImages(
            [ImageRequest(1, AirSimImageType.Scene)])

        # Save it to a temporary file
        image = responses[0].image_data_uint8
        AirSimClientBase.write_file(os.path.normpath(TMPFILE), image)

        # Read-load the image as a grayscale array
        image = loadgray(TMPFILE)

        # Run the image through our inference engine.
        # Engine returns a softmax output inside a list, so we grab the first
        # element of the list (the actual softmax vector), whose second element
        # is the absence of an obstacle.
        safety = sess.run(output, feed_dict={x: [image]})[0][1]

        # Slam on the brakes if it ain't safe!
        if safety < 0.5:

            if brakingCount > BRAKING_DURATION:
                print('BRAKING TO AVOID COLLISSION')
示例#2
0
z = client.moveToZ(initialZ, 5)
if z == True:
    x1 = client.moveByVelocityZ(vx, vy, initialZ, 100)
        


while True:
    
    #Get uncompressed RGBA array bytes
    responses = client.simGetImages([ImageRequest(3, AirSimImageType.Scene)])  
    
    #Add image to queue
    imagequeue.append(responses[0].image_data_uint8)

    #Dump queue when it gets full
    if len(imagequeue) == maximages:
        for i in range(maximages):
            AirSimClientBase.write_file(os.path.normpath(IMAGEDIR + '/image%03d.png'  % i ), imagequeue[i])
        imagequeue.pop(0)    
    
    #Receive info when drone has collided
    collision = client.getCollisionInfo()
    
    if collision.has_collided:
        print("Drone has collided")
        client.reset()
        break

client.enableApiControl(False)

示例#3
0
imagequeue = []

while True:
    client.moveByVelocityAsync(vx, vy, 0, 1, airsim.DrivetrainType.ForwardOnly,
                               airsim.YawMode(False, 0)).join()
    # get RGBA camera images from the car
    responses = client.simGetImages([ImageRequest(1, AirSimImageType.Scene)])

    # add image to queue
    imagequeue.append(responses[0].image_data_uint8)

    # dump queue when it gets full
    if len(imagequeue) == QUEUESIZE:
        for i in range(QUEUESIZE):
            AirSimClientBase.write_file(
                os.path.normpath(IMAGEDIR + '/image%03d.png' % i),
                imagequeue[i])
        imagequeue.pop(0)

    collision_info = client.simGetCollisionInfo()

    if collision_info.has_collided:
        print(
            "Collision at pos %s, normal %s, impact pt %s, penetration %f, name %s, obj id %d"
            % (pprint.pformat(collision_info.position),
               pprint.pformat(collision_info.normal),
               pprint.pformat(collision_info.impact_point),
               collision_info.penetration_depth, collision_info.object_name,
               collision_info.object_id))
        break
示例#4
0
client = CarClient()
client.confirmConnection()
print('Connected')
#client.enableApiControl(True)
car_controls = CarControls()

#client.reset()

## go forward
#car_controls.throttle = 1.0
#car_controls.steering = 0
#client.setCarControls(car_controls)

cnt = 0

while True:

    # get RGBA camera images from the car
    responses = client.simGetImages(
        [ImageRequest(1, AirSimImageType.Segmentation)])

    image = responses[0].image_data_uint8

    AirSimClientBase.write_file(
        os.path.normpath(IMAGEDIR + '/image%03d.png' % cnt), image)
    print('save image%03d' % cnt)

    cnt += 1

    time.sleep(0.1)