def execute(self):
     #self.client.reset()
     print('Scanning Has Started\n')
     print('Use Keyboard Interrupt \'CTRL + C\' to Stop Scanning\n')
     f = open('data.asc', "w")
     try:
         while True:
             lidarData = self.client.getLidarData();
             flag = 0
             for item in lidarData.point_cloud:
                 if (flag == 0):
                     X = item
                 elif (flag == 1):
                     Y = item
                 else:
                     Z = item
                 flag = flag + 1
                 if (flag == 3):
                     f.write("%f %f %f %d %d %d \n" % (X,Y,Z,255,255,0))
                     flag=0
                 else:
                     pass
     except KeyboardInterrupt:
         f.close()
         pass
         #time.sleep(5)
         airsim.wait_key('Press any key to reset to original state')
         self.client.reset()
         print("Done!\n")
Exemple #2
0
 def stop(self):
     """ Safely reset and release AirSim control """
     airsim.wait_key('Press any key to reset to original state')
     self.client.armDisarm(False)
     self.client.reset()
     self.client.enableApiControl(False)
     print("Done!\n")
Exemple #3
0
    def execute(self):

        for i in range(3):

            state = self.client.getCarState()
            s = pprint.pformat(state)
            #print("state: %s" % s)

            # go forward
            self.car_controls.throttle = 0.5
            self.car_controls.steering = 0
            self.client.setCarControls(self.car_controls)
            print("Go Forward")
            time.sleep(3)  # let car drive a bit

            # Go forward + steer right
            self.car_controls.throttle = 0.5
            self.car_controls.steering = 1
            self.client.setCarControls(self.car_controls)
            print("Go Forward, steer right")
            time.sleep(3)  # let car drive a bit

            airsim.wait_key('Press any key to get Lidar readings')

            for i in range(1, 3):
                lidarData = self.client.getLidarData()
                if (len(lidarData.point_cloud) < 3):
                    print("\tNo points received from Lidar data")
                else:
                    points = self.parse_lidarData(lidarData)
                    print("\tReading %d: time_stamp: %d number_of_points: %d" %
                          (i, lidarData.time_stamp, len(points)))
                time.sleep(5)
 def setTimeOfDay(self, enabled, time_of_day):
         if (enabled):
             airsim.wait_key('Press any key to change time of day to [{}]'.format(time_of_day))
             self.client.simSetTimeOfDay(enabled, time_of_day)
         else:
             airsim.wait_key('Press any key to change time of day to default time')
             self.client.simSetTimeOfDay(enabled)
    def execute(self, vehicle_name, lidar_names):
        print('Scanning Has Started\n')
        print('Use Keyboard Interrupt \'CTRL + C\' to Stop Scanning\n')
        existing_data_cleared = False  #change to true to superimpose new scans onto existing .asc files
        try:
            while True:
                for lidar_name in lidar_names:
                    filename = f"{vehicle_name}_{lidar_name}_pointcloud.asc"
                    if not existing_data_cleared:
                        f = open(filename, 'w')
                    else:
                        f = open(filename, 'a')
                    lidar_data = self.client.getLidarData(
                        lidar_name=lidar_name, vehicle_name=vehicle_name)

                    for i in range(0, len(lidar_data.point_cloud), 3):
                        xyz = lidar_data.point_cloud[i:i + 3]

                        f.write("%f %f %f %d %d %d \n" %
                                (xyz[0], xyz[1], xyz[2], 255, 255, 0))
                    f.close()
                existing_data_cleared = True
        except KeyboardInterrupt:
            airsim.wait_key('Press any key to stop running this script')
            print("Done!\n")
    def run(self):
        while True:
            command = input()
            args = command.split(" ")
            print("Args given", args)
            command_type = args[0]
            if command_type.lower() == ARM:
                self.arm()
            elif command_type.lower() == DISARM:
                self.disarm()
            elif command_type.lower() == MOVE:
                self.move_to_position(args)
            elif command_type.lower() == MOVE_PATH:
                self.move_on_path(args)
            elif command_type.lower() == HOME:
                self.home()
            elif command_type.lower() == TAKEOFF:
                self.takeoff()
            elif command_type.lower() == STATE:
                self.print_stats()
            elif command_type.lower() == KEYBOARD_CONTROL:
                self.enter_keyboard_control()
            elif command_type.lower() == STOP:
                self.stop()
                break
            else:
                print("The command given is not a valid command.")

        # that's enough fun for now. let's quit cleanly
        airsim.wait_key("When ready to kill")
        self.client.enableApiControl(False)
Exemple #7
0
    def execute(self):

        for i in range(3):
           
            state = self.client.getCarState()
            s = pprint.pformat(state)
            #print("state: %s" % s)
            
            # go forward
            self.car_controls.throttle = 0.5
            self.car_controls.steering = 0
            self.client.setCarControls(self.car_controls)
            print("Go Forward")
            time.sleep(3)   # let car drive a bit

            # Go forward + steer right
            self.car_controls.throttle = 0.5
            self.car_controls.steering = 1
            self.client.setCarControls(self.car_controls)
            print("Go Forward, steer right")
            time.sleep(3)   # let car drive a bit
            
            airsim.wait_key('Press any key to get Lidar readings')
        
            for i in range(1,3):
                lidarData = self.client.getLidarData();
                if (len(lidarData.point_cloud) < 3):
                    print("\tNo points received from Lidar data")
                else:
                    points = self.parse_lidarData(lidarData)
                    print("\tReading %d: time_stamp: %d number_of_points: %d" % (i, lidarData.time_stamp, len(points)))
                    print("\t\tlidar position: %s" % (pprint.pformat(lidarData.pose.position)))
                    print("\t\tlidar orientation: %s" % (pprint.pformat(lidarData.pose.orientation)))
                time.sleep(5)
    def initializeAirSimClient(client):
        client.confirmConnection()
        client.enableApiControl(True)
        client.armDisarm(True)

        state = client.getMultirotorState()
        s = pprint.pformat(state)
        print("state: %s" % s)

        imu_data = client.getImuData()
        s = pprint.pformat(imu_data)
        print("imu_data: %s" % s)

        barometer_data = client.getBarometerData()
        s = pprint.pformat(barometer_data)
        print("barometer_data: %s" % s)

        magnetometer_data = client.getMagnetometerData()
        s = pprint.pformat(magnetometer_data)
        print("magnetometer_data: %s" % s)

        gps_data = client.getGpsData()
        s = pprint.pformat(gps_data)
        print("gps_data: %s" % s)

        airsim.wait_key('Press any key to takeoff')
        client.takeoffAsync().join()

        state = client.getMultirotorState()
        print("state: %s" % pprint.pformat(state))

        airsim.wait_key(
            'Press any key to move vehicle to (-10, 10, -10) at 5 m/s')
    def stop(self):

        airsim.wait_key('Press any key to reset to original state')

        self.client.reset()

        self.client.enableApiControl(False)
        print("Done!\n")
Exemple #10
0
    def stop(self):

        airsim.wait_key('Press any key to reset to original state')

        self.client.reset()

        self.client.enableApiControl(False)
        print("Done!\n")
 def setTimeOfDay(self, enabled, time_of_day):
     if (enabled):
         airsim.wait_key(
             'Press any key to change time of day to [{}]'.format(
                 time_of_day))
         self.client.simSetTimeOfDay(enabled, time_of_day)
     else:
         airsim.wait_key(
             'Press any key to change time of day to default time')
         self.client.simSetTimeOfDay(enabled)
Exemple #12
0
def enter_edit_mode(client: airsim.MultirotorClient,
                    points: List[Vector3r]) -> None:
    mode = EditMode.TRANSLATING
    step = 1.0
    total = {
        EditMode.TRANSLATING:
        Vector3r(0, 0, 0),
        # EditMode.ROTATING: Vector3r(0, 0, 0),
        EditMode.SCALING:
        Vector3r(1, 1, 1),
    }
    try:
        while True:
            key = ord(airsim.wait_key())
            if key == 224:  # arrow keys
                arrow_key = ArrowKey(ord(airsim.wait_key()))
                client.simFlushPersistentMarkers()
                if mode == EditMode.TRANSLATING:
                    delta = {
                        ArrowKey.Up: Vector3r(step, 0, 0),
                        ArrowKey.Down: Vector3r(-step, 0, 0),
                        ArrowKey.Left: Vector3r(0, -step, 0),
                        ArrowKey.Right: Vector3r(0, step, 0),
                    }[arrow_key]
                    points = [point + delta for point in points]
                    total[EditMode.TRANSLATING] += delta
                elif mode == EditMode.SCALING:
                    factor = {
                        ArrowKey.Up: 1 + step * 0.1,
                        ArrowKey.Down: 1 - step * 0.1,
                        ArrowKey.Left: 1 - step * 0.1,
                        ArrowKey.Right: 1 + step * 0.1,
                    }[arrow_key]
                    points = [point * factor for point in points]
                    total[EditMode.SCALING] *= factor
                else:
                    assert False  # TODO handle other edit modes for rotating and scaling
                client.simPlotPoints(points,
                                     Rgba.Blue,
                                     POINT_CLOUD_POINT_SIZE,
                                     is_persistent=True)
            elif key == 27:  # esc
                ff.log("TRANSLATING:", total[EditMode.TRANSLATING])
                ff.log("SCALING:", total[EditMode.SCALING])
                return
            else:
                if key == ord(b"["):
                    step /= 2.0
                elif key == ord(b"]"):
                    step *= 2.0
                elif key == ord(b"\t"):
                    mode = EditMode.next(mode)
                ff.log(f"{mode=} {step=}")
    except KeyboardInterrupt:
        return
Exemple #13
0
    def prepare(self):
        # connect to the AirSim simulator
        self.client = airsim.MultirotorClient()
        self.client.confirmConnection()
        self.client.enableApiControl(True)
        self.client.armDisarm(True)
    
        state = self.client.getMultirotorState()
        s = pprint.pformat(state)
        print("state: %s" % s)

        airsim.wait_key('Press any key to takeoff')
    def execute(self):
        #self.client.reset()
        print('Scanning Has Started\n')
        print('Use Keyboard Interrupt \'CTRL + C\' to Stop Scanning\n')
        f = open('data.asc', "w")
        try:
            while True:
                lidarData = self.client.getLidarData()
                [q0, q1, q2, q3] = [
                    lidarData.pose.orientation.w_val,
                    lidarData.pose.orientation.x_val,
                    lidarData.pose.orientation.y_val,
                    lidarData.pose.orientation.z_val
                ]
                rotationMatrix = np.array(([
                    1 - 2 * (q2 * q2 + q3 * q3), 2 * (q1 * q2 - q3 * q0),
                    2 * (q1 * q3 + q2 * q0)
                ], [
                    2 * (q1 * q2 + q3 * q0), 1 - 2 * (q1 * q1 + q3 * q3),
                    2 * (q2 * q3 - q1 * q0)
                ], [
                    2 * (q1 * q3 - q2 * q0), 2 * (q2 * q3 + q1 * q0),
                    1 - 2 * (q1 * q1 + q2 * q2)
                ]))

                flag = 0
                XYZ = np.zeros((3, 1))
                for item in lidarData.point_cloud:
                    if (flag == 0):
                        XYZ[0, 0] = item
                    elif (flag == 1):
                        XYZ[1, 0] = item
                    else:
                        XYZ[2, 0] = item
                    flag = flag + 1
                    if (flag == 3):
                        [correctedX, correctedY,
                         correctedZ] = np.matmul(rotationMatrix, XYZ)
                        finalX = correctedX + lidarData.pose.position.x_val
                        finalY = correctedY + lidarData.pose.position.y_val
                        finalZ = correctedZ + lidarData.pose.position.z_val
                        f.write("%f %f %f %d %d %d \n" %
                                (finalX, finalY, finalZ, 255, 255, 0))
                        flag = 0
                    else:
                        pass
        except KeyboardInterrupt:
            f.close()
            pass
            #time.sleep(5)
            airsim.wait_key('Press any key to reset to original state')
            self.client.reset()
            print("Done!\n")
def start(client, navigators, iterations=1, snapshots=3):
    for nav in navigators:
        print(f"arming the drone ({nav.name})...")
        client.armDisarm(True, nav.name)
    
    # AirSim uses NED coordinates so negative axis is up
    # for simplicity we'll consider no drone has already tookoff
    async_call_list = []
    for nav in navigators:
        async_call_list.append(client.takeoffAsync(timeout_sec=10, vehicle_name=nav.name))
    for task in async_call_list:
        task.join() # waits for the task to complete

    airsim.wait_key('Press any key to move the drones')
    async_call_list = []
    z_list = []
    state_list = [client.getMultirotorState(nav.name) for nav in navigators]
    start_list = []
    for idx, nav in enumerate(navigators):
        z = -nav.altitude + nav.home.z_val
        z_list.append(z)
        start = state_list[idx].kinematics_estimated.position
        start_list.append(start)
        print("{} climbing to position: {},{},{}".format(nav.name, start.x_val, start.y_val, z))
        async_call_list.append(client.moveToPositionAsync(start.x_val, start.y_val, z, nav.speed, 
                                                          vehicle_name=nav.name))
    for idx, task in enumerate(async_call_list):
        task.join() # waits for the task to complete
        navigators[idx].z = z_list[idx] # FIXME
    
    # TODO orbit and take images
    
    airsim.wait_key('Press any key to reset to original state')    
    async_call_list = []
    land_list = []
    for idx, nav in enumerate(navigators):
        if nav.z < nav.home.z_val:
            print(f"{nav.name} descending")
            async_call_list.append(
                client.moveToPositionAsync(start_list[idx].x_val, start_list[idx].y_val, nav.home.z_val - 5, 
                                           velocity=2, vehicle_name=nav.name))
            land_list.append(nav)
    for task in async_call_list:
        task.join() # waits for the task to complete
    async_call_list = []
    for nav in land_list:
        async_call_list.append(client.landAsync(timeout_sec=40, vehicle_name=nav.name))
    for task in async_call_list:
        task.join() # waits for the task to complete
    for nav in navigators:
        client.armDisarm(False, nav.name)
    def execute(self, vehicle_name, lidar_names):
        print('Scanning Has Started\n')
        print('Use Keyboard Interrupt \'CTRL + C\' to Stop Scanning\n')
        existing_data_cleared = False  #change to true to superimpose new scans onto existing .asc files
        try:
            while True:
                for lidar_name in lidar_names:
                    filename = f"{vehicle_name}_{lidar_name}_pointcloud.asc"
                    if not existing_data_cleared:
                        f = open(filename, 'w')
                    else:
                        f = open(filename, 'a')
                    lidar_data = self.client.getLidarData(
                        lidar_name=lidar_name, vehicle_name=vehicle_name)

                    orientation = lidar_data.pose.orientation
                    q0, q1, q2, q3 = orientation.w_val, orientation.x_val, orientation.y_val, orientation.z_val
                    rotation_matrix = np.array(([
                        1 - 2 * (q2 * q2 + q3 * q3), 2 * (q1 * q2 - q3 * q0),
                        2 * (q1 * q3 + q2 * q0)
                    ], [
                        2 * (q1 * q2 + q3 * q0), 1 - 2 * (q1 * q1 + q3 * q3),
                        2 * (q2 * q3 - q1 * q0)
                    ], [
                        2 * (q1 * q3 - q2 * q0), 2 * (q2 * q3 + q1 * q0),
                        1 - 2 * (q1 * q1 + q2 * q2)
                    ]))

                    position = lidar_data.pose.position
                    for i in range(0, len(lidar_data.point_cloud), 3):
                        xyz = lidar_data.point_cloud[i:i + 3]

                        corrected_x, corrected_y, corrected_z = np.matmul(
                            rotation_matrix, np.asarray(xyz))
                        final_x = corrected_x + position.x_val
                        final_y = corrected_y + position.y_val
                        final_z = corrected_z + position.z_val

                        f.write("%f %f %f %d %d %d \n" %
                                (final_x, final_y, final_z, 255, 255, 0))
                    f.close()
                existing_data_cleared = True
        except KeyboardInterrupt:
            airsim.wait_key('Press any key to stop running this script')
            print("Done!\n")
Exemple #17
0
    def execute(self):

        print("arming the drone...")
        self.client.armDisarm(True)

        state = self.client.getMultirotorState()
        s = pprint.pformat(state)
        #print("state: %s" % s)

        airsim.wait_key('Press any key to takeoff')
        self.client.takeoffAsync().join()

        state = self.client.getMultirotorState()
        #print("state: %s" % pprint.pformat(state))

        airsim.wait_key('Press any key to move vehicle to (-10, 10, -10) at 5 m/s')
        self.client.moveToPositionAsync(-10, 10, -10, 5).join()

        self.client.hoverAsync().join()

        airsim.wait_key('Press any key to get Lidar readings')
        
        for i in range(1,5):
            lidarData = self.client.getLidarData();
            if (len(lidarData.point_cloud) < 3):
                print("\tNo points received from Lidar data")
            else:
                points = self.parse_lidarData(lidarData)
                print("\tReading %d: time_stamp: %d number_of_points: %d" % (i, lidarData.time_stamp, len(points)))
                print("\t\tlidar position: %s" % (pprint.pformat(lidarData.pose.position)))
                print("\t\tlidar orientation: %s" % (pprint.pformat(lidarData.pose.orientation)))
            time.sleep(5)
Exemple #18
0
    def execute(self):

        print("arming the drone...")
        self.client.armDisarm(True)

        state = self.client.getMultirotorState()
        s = pprint.pformat(state)
        #print("state: %s" % s)

        airsim.wait_key('Press any key to takeoff')
        self.client.takeoffAsync().join()

        state = self.client.getMultirotorState()
        #print("state: %s" % pprint.pformat(state))

        airsim.wait_key(
            'Press any key to move vehicle to (-10, 10, -10) at 5 m/s')
        self.client.moveToPositionAsync(-10, 10, -10, 5).join()

        self.client.hoverAsync().join()

        airsim.wait_key('Press any key to get Lidar readings')

        for i in range(1, 5):
            lidarData = self.client.getLidarData()
            if (len(lidarData.point_cloud) < 3):
                print("\tNo points received from Lidar data")
            else:
                points = self.parse_lidarData(lidarData)
                print("\tReading %d: time_stamp: %d number_of_points: %d" %
                      (i, lidarData.time_stamp, len(points)))
            time.sleep(5)
Exemple #19
0
    def _start_keyboard_controller(cls, client, drone_name, cur_yaw, scale,
                                   speed, is_mininet_enabled):
        # create helpers
        screenshot_helper = screenshotHelper(drone_name, client)
        mininet_helper = mininetHelper() if is_mininet_enabled else None

        display_info = (
            'Press AWSD,R(up)F(down)QE(turn left/right) key to move the drone.\n'
            'Press P to take images.\n'
            'Press B key to reset to original state.\n'
            'Press O key to release API control.\n'
            'drone will be moved {}m with speed {}m/s.\n').format(
                scale, speed)

        while True:
            pressed_key = airsim.wait_key(display_info).decode('utf-8').upper()
            log.info("pressed_key={}".format(pressed_key))
            if pressed_key == 'P':
                image_file_list = screenshot_helper.do_screenshot(
                    is_display=True)
                if mininet_helper is not None:
                    mininet_helper.send_image(image_file_list[0])
            elif pressed_key == 'O':
                client.enableApiControl(False, drone_name)
                break
            elif pressed_key == 'B':
                client.reset()
            else:
                move_xyz_yaw = cls._DIRECTION_DICT.get(pressed_key, None)
                if move_xyz_yaw is None:
                    log.error('invalid key')
                    continue
                # connect to the AirSim simulator
                dx, dy, dz, cur_yaw = cls._compute_abs_direction(
                    cur_yaw, scale, move_xyz_yaw)
                result = cls._move_drone(client,
                                         drone_name,
                                         dx,
                                         dy,
                                         dz,
                                         cur_yaw,
                                         speed,
                                         mininet_helper=mininet_helper)
                assert result == True
Exemple #20
0
    def execute(self):

        print("arming the drone...")
        self.client.armDisarm(True)

        state = self.client.getMultirotorState()
        s = pprint.pformat(state)
        #print("state: %s" % s)

        airsim.wait_key('Press any key to takeoff')
        self.client.takeoffAsync().join()

        state = self.client.getMultirotorState()
        #print("state: %s" % pprint.pformat(state))

        self.client.hoverAsync().join()

        airsim.wait_key('Press any key to get Boundary readings')
        boundary = self.client.simGetBoundary()
        print(boundary)

        airsim.wait_key('Press any key to set Boundary')
        self.client.simEnableCustomBoundaryData(True)

        for i in range(1, 5):
            boundary = Boundary()
            boundary.pos = state.kinematics_estimated.position
            scale = 10 / i
            z = boundary.pos.z_val
            boundary.boundary = [
                Vector3r(scale, -scale, z),
                Vector3r(-scale, scale, z),
                Vector3r(scale, scale, z),
                Vector3r(-scale, -scale, z)
            ]
            self.client.simSetBoundary(boundary)
            boundary = self.client.simGetBoundary()
            print(boundary)
            time.sleep(1)
Exemple #21
0
# In settings.json first activate computer vision mode: 
# https://github.com/Microsoft/AirSim/blob/master/docs/image_apis.md#computer-vision-mode

import setup_path 
import airsim

import pprint
import tempfile
import os
import time

pp = pprint.PrettyPrinter(indent=4)

client = airsim.VehicleClient()

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

airsim.wait_key('Press any key to get images')
tmp_dir = os.path.join(tempfile.gettempdir(), "airsim_drone")
print ("Saving images to %s" % tmp_dir)
try:
    for n in range(3):
        os.makedirs(os.path.join(tmp_dir, str(n)))
except OSError:
    if not os.path.isdir(tmp_dir):
        raise

for x in range(50): # do few times
Exemple #22
0
client.enableApiControl(True, "Drone6")
client.enableApiControl(True, "Drone7")
client.enableApiControl(True, "Drone8")
client.enableApiControl(True, "Drone9")
client.armDisarm(True, "Drone1")
client.armDisarm(True, "Drone2")
client.armDisarm(True, "Drone3")
client.armDisarm(True, "Drone4")
client.armDisarm(True, "Drone5")
client.armDisarm(True, "Drone6")
client.armDisarm(True, "Drone7")
client.armDisarm(True, "Drone8")
client.armDisarm(True, "Drone9")
# airsim.wait_key('Press any key to takeoff')
# client.takeoffAsync().join()
airsim.wait_key('Press any key to takeoff')
f1 = client.takeoffAsync(vehicle_name="Drone1")
f2 = client.takeoffAsync(vehicle_name="Drone2")
f3 = client.takeoffAsync(vehicle_name="Drone3")
f4 = client.takeoffAsync(vehicle_name="Drone4")
f5 = client.takeoffAsync(vehicle_name="Drone5")
f6 = client.takeoffAsync(vehicle_name="Drone6")
f7 = client.takeoffAsync(vehicle_name="Drone7")
f8 = client.takeoffAsync(vehicle_name="Drone8")
f9 = client.takeoffAsync(vehicle_name="Drone9")
f1.join()
f2.join()
f3.join()
f4.join()
f5.join()
f6.join()
for i in range(0, 6):

    vehicle_name = "Drone{}".format(i)
    pose_obj = client.simGetObjectPose(vehicle_name)
    # pose_obj = client.simGetVehiclePose(vehicle_name=vehicle_name)
    print('{} is at {}'.format(vehicle_name, pose_obj.position))

    pose_obj.position.x_val = pos_init[i][0]
    pose_obj.position.y_val = pos_init[i][1]
    pose_obj.position.z_val = pos_init[i][2]
    success = client.simSetObjectPose(vehicle_name, pose_obj, True)
    # time.sleep(1)
    pose_obj = client.simGetObjectPose(vehicle_name)
    print('{} is at {}'.format(vehicle_name, pose_obj.position))

airsim.wait_key("Success: {}")



airsim.wait_key("Success: {}")

for i in range(0, 6):
    vehicle_name = "Drone{}".format(i)
    multirotor_state = client.getMultirotorState(vehicle_name=vehicle_name)
    landed = multirotor_state.landed_state
    if landed == airsim.LandedState.Landed:
        print("taking off...")
        client.takeoffAsync(vehicle_name=vehicle_name).join()
    else:
        print("already flying...")
        client.hoverAsync(vehicle_name=vehicle_name).join()
Exemple #24
0
# In settings.json first activate computer vision mode: 
# 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),
Exemple #25
0
s = pprint.pformat(imu_data)
print("imu_data: %s" % s)

barometer_data = client.getBarometerData()
s = pprint.pformat(barometer_data)
print("barometer_data: %s" % s)

magnetometer_data = client.getMagnetometerData()
s = pprint.pformat(magnetometer_data)
print("magnetometer_data: %s" % s)

gps_data = client.getGpsData()
s = pprint.pformat(gps_data)
print("gps_data: %s" % s)

airsim.wait_key('Press any key to takeoff')
print("Taking off...")
client.armDisarm(True)
client.takeoffAsync().join()

state = client.getMultirotorState()
print("state: %s" % pprint.pformat(state))

airsim.wait_key('Press any key to move vehicle to (-10, 10, -10) at 5 m/s')
client.moveToPositionAsync(-10, 10, -10, 5).join()

client.hoverAsync().join()

state = client.getMultirotorState()
print("state: %s" % pprint.pformat(state))
# In settings.json first activate computer vision mode: 
# https://github.com/Microsoft/AirSim/blob/master/docs/image_apis.md#computer-vision-mode

import airsim
import cv2
import numpy as np
import setup_path 

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

airsim.wait_key('Press any key to set all object IDs to 0')
found = client.simSetSegmentationObjectID("[\w]*", 0, True);
print("Done: %r" % (found))

#for block environment

# airsim.wait_key('Press any key to change one ground object ID')
# found = client.simSetSegmentationObjectID("Ground", 20);
# print("Done: %r" % (found))

# #regex are case insensitive
# airsim.wait_key('Press any key to change all ground object ID')
# found = client.simSetSegmentationObjectID("ground[\w]*", 22, True);
# print("Done: %r" % (found))

##for neighborhood environment

#set object ID for sky
# found = client.simSetSegmentationObjectID("SkySphere", 42, True);
# print("Done: %r" % (found))
Exemple #27
0
        top = np.vsplit(gray, 2)[0]

        # now look at 4 horizontal bands (far left, left, right, far right) and see which is most open.
        # the depth map uses black for far away (0) and white for very close (255), so we invert that
        # to get an estimate of distance.
        bands = np.hsplit(top, [50, 100, 150, 200])
        maxes = [np.max(x) for x in bands]
        min = np.argmin(maxes)
        distance = 255 - maxes[min]

        # sanity check on what is directly in front of us (slot 2 in our hsplit)
        current = 255 - maxes[2]

        if (current < 20):
            client.hoverAsync().join()
            airsim.wait_key("whoops - we are about to crash, so stopping!")

        pitch, roll, yaw = airsim.to_eularian_angles(
            client.simGetVehiclePose().orientation)

        if (distance > current + 30):

            # we have a 90 degree field of view (pi/2), we've sliced that into 5 chunks, each chunk then represents
            # an angular delta of the following pi/10.
            change = 0
            driving = min
            if (min == 0):
                change = -2 * pi / 10
            elif (min == 1):
                change = -pi / 10
            elif (min == 2):
Exemple #28
0
import pprint
import setup_path
import tempfile

# connect to the AirSim simulator
num_agents = 10

client = airsim.MultirotorClient()
client.confirmConnection()

for i in range(0, num_agents):
    client.enableApiControl(True, "Drone" + str(i))
    client.armDisarm(True, "Drone" + str(i))
    client.takeoffAsync(1, "Drone" + str(i))

airsim.wait_key('Press any key to continue')

for i in range(0, num_agents):
    print(i)
    print(client.simGetPositionWRTOrigin("Drone" + str(i)).x_val / 100.0)
    print(client.simGetPositionWRTOrigin("Drone" + str(i)).y_val / 100.0)
    print(client.simGetPositionWRTOrigin("Drone" + str(i)).z_val / 100.0)

airsim.wait_key('Press any key to reset to original state')

client.armDisarm(False, "Drone1")
client.armDisarm(False, "Drone2")
client.reset()

# that's enough fun for now. let's quit cleanly
client.enableApiControl(False, "Drone1")
Exemple #29
0
import pprint

import setup_path
import airsim

# connect to the AirSim simulator
client = airsim.MultirotorClient()
client.confirmConnection()
client.enableApiControl(True)
client.armDisarm(True)

state = client.getMultirotorState()
s = pprint.pformat(state)
print("state: %s" % s)

airsim.wait_key('Press any key to takeoff')
client.takeoff()

state = client.getMultirotorState()
print("state: %s" % pprint.pformat(state))

airsim.wait_key('Press any key to move vehicle to (-10, 10, -10) at 5 m/s')
client.moveToPosition(-10, 10, -10, 5)

client.hover()

state = client.getMultirotorState()
print("state: %s" % pprint.pformat(state))

airsim.wait_key('Press any key to take images')
# get camera images from the car
Exemple #30
0
client = airsim.MultirotorClient()  # connect to the simulator
client.confirmConnection()
client.enableApiControl(True,
                        vehicle_name="Drone0")  # enable API control on Drone0
client.armDisarm(True, vehicle_name="Drone0")  # arm Drone0

client.takeoffAsync(vehicle_name="Drone0").join()  # let Drone0 take-off
client.moveToPositionAsync(15, -3, -4, 5, vehicle_name="Drone0").join(
)  # Drone0 moves to (15, -3, 4) at 5m/s and hovers (note the inverted Z axis)
client.hoverAsync(vehicle_name="Drone0").join(
)  # .join() let the script wait for asynchronous (i.e. non-blocking) methods

raw = client.simGetImage(
    "bottom_center", airsim.ImageType.Scene, vehicle_name="Drone0"
)  # take an image of type "Scene" from the "bottom_center" of "Drone0"
f = open("Drone0a.png", "wb")
f.write(raw)  # save the image as a PNG file
f.close()

raw = client.simGetImage(
    "bottom_center", airsim.ImageType.Segmentation, vehicle_name="Drone0"
)  # take an image of type "Segmentation" from the "bottom_center" of "Drone0"
f = open("Drone0b.png", "wb")
f.write(raw)  # save the image as a PNG file
f.close()

airsim.wait_key('Press any key to reset')  # press any key
client.armDisarm(False, vehicle_name="Drone0")  # disarm Drone0
client.reset()  # reset the simulation
client.enableApiControl(False,
                        vehicle_name="Drone0")  # disable API control of Drone0
Exemple #31
0
import numpy as np
import os
import tempfile
import pprint

# connect to the AirSim simulator
client = airsim.MultirotorClient()
client.confirmConnection()
client.enableApiControl(True)
client.armDisarm(True)

state = client.getMultirotorState()
s = pprint.pformat(state)
print("state: %s" % s)

airsim.wait_key('Press any key to takeoff')
client.takeoffAsync().join()

state = client.getMultirotorState()
print("state: %s" % pprint.pformat(state))

airsim.wait_key('Press any key to move vehicle to (-10, 10, -10) at 5 m/s')
client.moveToPositionAsync(-10, 10, -10, 5).join()

client.hoverAsync().join()

state = client.getMultirotorState()
print("state: %s" % pprint.pformat(state))

airsim.wait_key('Press any key to take images')
# get camera images from the car
		  "X": 8, "Y": 0, "Z": -2
		}

    }
}
"""

# connect to the AirSim simulator
client = airsim.MultirotorClient()
client.confirmConnection()
client.enableApiControl(True, "Drone1")
client.enableApiControl(True, "Drone2")
client.armDisarm(True, "Drone1")
client.armDisarm(True, "Drone2")

airsim.wait_key('Press any key to takeoff')
f1 = client.takeoffAsync(vehicle_name="Drone1")
f2 = client.takeoffAsync(vehicle_name="Drone2")
f1.join()
f2.join()

state1 = client.getMultirotorState(vehicle_name="Drone1")
s = pprint.pformat(state1)
print("state: %s" % s)
state2 = client.getMultirotorState(vehicle_name="Drone2")
s = pprint.pformat(state2)
print("state: %s" % s)

airsim.wait_key('Press any key to move vehicles')
f1 = client.moveToPositionAsync(-5, 5, -10, 5, vehicle_name="Drone1")
f2 = client.moveToPositionAsync(5, -5, -10, 5, vehicle_name="Drone2")
"""
For connecting to the AirSim drone environment and testing API functionality
"""
import setup_path 
import airsim

import os
import tempfile
import pprint

# connect to the AirSim simulator
client = airsim.MultirotorClient()
client.confirmConnection()
client.enableApiControl(True)
client.armDisarm(True)

state = client.getMultirotorState()
s = pprint.pformat(state)
print("state: %s" % s)

client.moveByManualAsync(vx_max = 1E6, vy_max = 1E6, z_min = -1E6, duration = 1E10)
airsim.wait_key('Manual mode is setup. Press any key to send RC data to takeoff')

client.moveByRC(rcdata = airsim.RCData(pitch = 0.0, throttle = 1.0, is_initialized = True, is_valid = True))

airsim.wait_key('Set Yaw and pitch to 0.5')

client.moveByRC(rcdata = airsim.RCData(roll = 0.5, throttle = 1.0, yaw = 0.5, is_initialized = True, is_valid = True))
Exemple #34
0
pose2 = client.simGetObjectPose("PulsingCone");
print("PulsingCone - Position: %s, Orientation: %s" % (pprint.pformat(pose2.position),
    pprint.pformat(pose2.orientation)))

# search non-existent object
pose3 = client.simGetObjectPose("Non-Existent"); # should return nan pose
print("Non-Existent - Position: %s, Orientation: %s" % (pprint.pformat(pose3.position),
    pprint.pformat(pose3.orientation)))


#------------------------------------ Set new pose ------------------------------------------------

# here we move with teleport enabled so collisions are ignored
pose1.position = pose1.position + airsim.Vector3r(-2, -2, -2)
success = client.simSetObjectPose("OrangeBall", pose1, True);
airsim.wait_key("OrangeBall moved. Success: %i" % (success))

# here we move with teleport enabled so collisions are not ignored
pose2.position = pose2.position + airsim.Vector3r(3, 3, -2)
success = client.simSetObjectPose("PulsingCone", pose2, False);
airsim.wait_key("PulsingCone moved. Success: %i" % (success))

# move non-existent object
success = client.simSetObjectPose("Non-Existent", pose2); # should return nan pose
airsim.wait_key("Non-Existent moved. Success: %i" % (success))

#------------------------------------ Get new pose ------------------------------------------------


pose1 = client.simGetObjectPose("OrangeBall");
print("OrangeBall - Position: %s, Orientation: %s" % (pprint.pformat(pose1.position),
Exemple #35
0
# In settings.json first activate computer vision mode: 
# https://github.com/Microsoft/AirSim/blob/master/docs/image_apis.md#computer-vision-mode

import setup_path 
import airsim

import numpy as np

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

airsim.wait_key('Press any key to set all object IDs to 0')
found = client.simSetSegmentationObjectID("[\w]*", 0, True);
print("Done: %r" % (found))

#for block environment

airsim.wait_key('Press any key to change one ground object ID')
found = client.simSetSegmentationObjectID("Ground", 20);
print("Done: %r" % (found))

#regex are case insensitive
airsim.wait_key('Press any key to change all ground object ID')
found = client.simSetSegmentationObjectID("ground[\w]*", 22, True);
print("Done: %r" % (found))

##for neighborhood environment

#set object ID for sky
found = client.simSetSegmentationObjectID("SkySphere", 42, True);
print("Done: %r" % (found))
For connecting to the AirSim drone environment and testing API functionality
"""
import setup_path
import airsim

import os
import tempfile
import pprint

# connect to the AirSim simulator
client = airsim.MultirotorClient()
client.confirmConnection()
client.enableApiControl(True)
client.armDisarm(True)

state = client.getMultirotorState()
s = pprint.pformat(state)
print("state: %s" % s)

client.moveByManualAsync(vx_max=1E6, vy_max=1E6, z_min=-1E6, duration=1E10)
airsim.wait_key(
    'Manual mode is setup. Press any key to send RC data to takeoff')

client.moveByRC(rcdata=airsim.RCData(
    pitch=0.0, throttle=1.0, is_initialized=True, is_valid=True))

airsim.wait_key('Set Yaw and pitch to 0.5')

client.moveByRC(rcdata=airsim.RCData(
    roll=1100, throttle=2000, yaw=0.0, is_initialized=True, is_valid=True))
import setup_path 
import airsim


import pprint
import os
import time

pp = pprint.PrettyPrinter(indent=4)

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

airsim.wait_key('Press any key to set skin age to 1')
client.simCharSetSkinAgeing(1)

airsim.wait_key('Press any key to set skin color to 0.9')
client.simCharSetSkinDarkness(0.9)

#airsim.wait_key('Press any key to set face expression')
#client.simCharSetFaceExpression("BlendShapeNode_Smile", 1);

airsim.wait_key('Press any key to set bone pose')
client.reset()
jaw_pose = airsim.Pose()
jaw_pose.position = airsim.Vector3r(0.002, 0.001, -0.003)
jaw_pose.orientation = airsim.to_quaternion(0, 0, -.15)
client.simCharSetBonePose( "Jaw", jaw_pose);
Exemple #38
0
import os
import pprint

import cv2
import numpy as np

client = airsim.MultirotorClient()
client.confirmConnection()
client.enableApiControl(True)
client.armDisarm(True)

state = client.getMultirotorState()
s = pprint.pformat(state)
print("state: %s" % s)

airsim.wait_key('type something to move')
client.takeoffAsync().join()

client.moveToPositionAsync(-40, 40, -40, 10).join()

client.hoverAsync().join()

state = client.getMultirotorState()
s = pprint.pformat(state)
print("state: %s" % s)

airsim.wait_key('press again to reset')

# exit protocol
client.armDisarm(False)
client.reset()
Exemple #39
0
    responses = client.simGetImages([
        airsim.ImageRequest("1", airsim.ImageType.DepthPlanner, True)])
    response = responses[0]

    # get numpy array
    img1d = response.image_data_float

    # reshape array to 2D array H X W
    img2d = np.reshape(img1d,(response.height, response.width)) 
    
    [pos,yaw,target_dist] = predictControl.get_next_vec(img2d, uav_size, goal, pos)
    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)



import setup_path
import airsim

import pprint
import os
import time
import math
import tempfile

pp = pprint.PrettyPrinter(indent=4)

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

airsim.wait_key('Press any key to set camera-0 gimbal to 15-degree pitch')
camera_pose = airsim.Pose(airsim.Vector3r(0, 0, 0),
                          airsim.to_quaternion(math.radians(15), 0,
                                               0))  #radians
client.simSetCameraPose("0", camera_pose)

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:" % camera_name)
    pp.pprint(camera_info)

tmp_dir = os.path.join(tempfile.gettempdir(), "airsim_cv_mode")
print("Saving images to %s" % tmp_dir)
try:
    os.makedirs(tmp_dir)
Exemple #41
0
import setup_path 
import airsim


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

client.simEnableWeather(True)

airsim.wait_key('Press any key to enable rain at 25%')
client.simSetWeatherParameter(airsim.WeatherParameter.Rain, 0.25);

airsim.wait_key('Press any key to enable rain at 75%')
client.simSetWeatherParameter(airsim.WeatherParameter.Rain, 0.75);

airsim.wait_key('Press any key to enable snow at 50%')
client.simSetWeatherParameter(airsim.WeatherParameter.Snow, 0.50);

airsim.wait_key('Press any key to enable maple leaves at 50%')
client.simSetWeatherParameter(airsim.WeatherParameter.MapleLeaf, 0.50);

airsim.wait_key('Press any key to set all effects to 0%')
client.simSetWeatherParameter(airsim.WeatherParameter.Rain, 0.0);
client.simSetWeatherParameter(airsim.WeatherParameter.Snow, 0.0);
client.simSetWeatherParameter(airsim.WeatherParameter.MapleLeaf, 0.0);

airsim.wait_key('Press any key to enable dust at 50%')
client.simSetWeatherParameter(airsim.WeatherParameter.Dust, 0.50);

airsim.wait_key('Press any key to enable fog at 50%')
client.simSetWeatherParameter(airsim.WeatherParameter.Fog, 0.50);
import airsim
import numpy as np
import os
import tempfile
import pprint
import cv2

# connect to the AirSim simulator
client = airsim.MultirotorClient()
client.confirmConnection()
client.enableApiControl(True)
client.armDisarm(True)
import pdb
pdb.set_trace()
state = client.getMultirotorState()
airsim.wait_key('Press any key to takeoff')
client.takeoffAsync().join()
name = 0
x_val, y_val, z_val = 0, 0, -30
#while True:
# pitch = float(input("Pitch"))
# roll = float(input("Roll"))
# z = float(input("Z"))
# yaw = float(input("Yaw"))
# dur = float(input("Duration"))
# client.moveByRollPitchYawZAsync(roll,pitch,yaw,z,dur).join()
client.moveToPositionAsync(x_val,
                           y_val,
                           z_val,
                           5,
                           yaw_mode=airsim.YawMode(is_rate=False)).join()

# Establish connection with the car
client = airsim.CarClient()
client.confirmConnection()
client.enableApiControl(True)
car_controls = airsim.CarControls()

# Grab the current state of the car and print it out
state = client.getCarState()
s = pprint.pformat(state)

# File writing test: Wait for the user's key press, then write the coordinates to a file

# Wait for the user input to continue
airsim.wait_key('Press any key to continue')

# Grab the raw lidar data
lidarData = client.getLidarData()

# Make sure it is valid
if (len(lidarData.point_cloud) < 3):
    print("\tNo points received from Lidar data")
else:
    points = parse_lidarData(lidarData)
    print("\tReading data with time_stamp: %d number_of_points: %d" %
          (lidarData.time_stamp, len(points)))
    points_size = len(points)

    # Write the points to a file
    with open("out.txt", "w") as file:
Exemple #44
0
        for image_type in image_type_list
    ]


###############################################################################

# connect to the AirSim simulator
client = airsim.MultirotorClient()
client.confirmConnection()
client.enableApiControl(True)
client.armDisarm(True)

# state = client.getMultirotorState()
# s = pprint.pformat(state)
# print("state: %s" % s)
airsim.wait_key('Press any key to takeoff')
client.takeoffAsync(timeout_sec=10).join()
# airsim.wait_key('Press any key to move vehicle to (-10, 10, -10) at 5 m/s')
# client.moveToPositionAsync(-10, 10, -10, 5).join()
client.hoverAsync().join()

airsim.wait_key('Press any key to take images')
# get camera images
responses = client.simGetImages(generateImageRequestList(camera_name='0'))
print('Retrieved images: %d' % len(responses))

tmp_dir = os.path.join('.', "airsim_drone")
try:
    os.makedirs(tmp_dir)
except OSError:
    if not os.path.isdir(tmp_dir):
import setup_path 
import airsim


# connect to the AirSim simulator
client = airsim.MultirotorClient()
client.confirmConnection()
client.enableApiControl(True)
client.armDisarm(True)

state = client.getMultirotorState()
s = pprint.pformat(state)
print("state: %s" % s)

airsim.wait_key('Press any key to takeoff')
client.takeoff()

state = client.getMultirotorState()
print("state: %s" % pprint.pformat(state))

airsim.wait_key('Press any key to move vehicle to (-10, 10, -10) at 5 m/s')
client.moveToPosition(-10, 10, -10, 5)

client.hover()

state = client.getMultirotorState()
print("state: %s" % pprint.pformat(state))

airsim.wait_key('Press any key to take images')
# get camera images from the car