Skip to content

Commit

Permalink
added constructor for Quaternionr for PythonClient, cv_mode.py exampl…
Browse files Browse the repository at this point in the history
…e, docs update
  • Loading branch information
sytelus committed Sep 19, 2017
1 parent 384e755 commit 1fe5e40
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 2 deletions.
7 changes: 7 additions & 0 deletions PythonClient/PythonClient.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,13 @@ class Quaternionr(MsgpackMixin):
y_val = np.float32(0)
z_val = np.float32(0)

def __init__(self, x_val = np.float32(0), y_val = np.float32(0), z_val = np.float32(0), w_val = np.float32(0)):
self.x_val = x_val
self.y_val = y_val
self.z_val = z_val
self.w_val = w_val


class CollisionInfo(MsgpackMixin):
has_collided = False
normal = Vector3r()
Expand Down
5 changes: 4 additions & 1 deletion PythonClient/PythonClient.pyproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>e2049e20-b6dd-474e-8bca-1c8dc54725aa</ProjectGuid>
<ProjectHome>.</ProjectHome>
<StartupFile>hello_drone.py</StartupFile>
<StartupFile>cv_mode.py</StartupFile>
<SearchPath>
</SearchPath>
<WorkingDirectory>.</WorkingDirectory>
Expand All @@ -28,6 +28,9 @@
<Compile Include="camera.py">
<SubType>Code</SubType>
</Compile>
<Compile Include="cv_mode.py">
<SubType>Code</SubType>
</Compile>
<Compile Include="hello_drone.py">
<SubType>Code</SubType>
</Compile>
Expand Down
28 changes: 28 additions & 0 deletions PythonClient/cv_mode.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# In settings.json first activate computer vision mode:
# https://github.com/Microsoft/AirSim/blob/master/docs/image_apis.md#computer-vision-mode

from PythonClient import *

client = AirSimClient()
client.confirmConnection()

for x in range(3): # do 5 times
z = x * -20 - 5
# you can also use AirSimClient.toQuaternion(0, 0, x) to generate quaternion
client.simSetPose(Vector3r(1, 1, z), Quaternionr(0, 0, 0, 1))

responses = client.simGetImages([
ImageRequest(0, AirSimImageType.DepthVis),
ImageRequest(1, AirSimImageType.DepthMeters, True),
ImageRequest(0, AirSimImageType.Segmentation),
ImageRequest(0, AirSimImageType.Scene),
ImageRequest(0, AirSimImageType.DisparityNormalized),
ImageRequest(0, AirSimImageType.SurfaceNormals)])

for i, response in enumerate(responses):
if response.pixels_as_float:
print("Type %d, size %d" % (response.image_type, len(response.image_data_float)))
AirSimClient.write_pfm(os.path.normpath('/temp/cv_mode_' + str(x) + "_" + str(i) + '.pfm'), AirSimClient.getPfmArray(response))
else:
print("Type %d, size %d" % (response.image_type, len(response.image_data_uint8)))
AirSimClient.write_file(os.path.normpath('/temp/cv_mode_' + str(x) + "_" + str(i) + '.png'), response.image_data_uint8)
2 changes: 2 additions & 0 deletions docs/build_linux.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ It's super simple 1-2-3!
# go to folder where you clone GitHub projects
git clone -b 4.17 https://github.com/EpicGames/UnrealEngine.git
cd UnrealEngine
# few times Epic folks broke the build so we will get commit that works
git checkout af96417313a908b20621a443175ba91683c238c8
./Setup.sh
./GenerateProjectFiles.sh
make
Expand Down
2 changes: 2 additions & 0 deletions docs/image_apis.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ To active this mode, edit [settings.json](settings.json) that you can find in yo
}
```

[Here's the Python code example](https://github.com/Microsoft/AirSim/blob/master/PythonClient/cv_mode.py) to move camera around and capture images.

If you are only interested in this mode, you might also want to take a look at [UnrealCV project](http://unrealcv.org/).

## How to Set Position and Orientation (Pose)?
Expand Down
2 changes: 1 addition & 1 deletion docs/unreal_blocks.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Here are quick steps to get Blocks environment up and running:
2. Navigate to folder `AirSim\Unreal\Environments\Blocks` and run `update_from_git.bat`.
3. Double click on generated .sln file to open in Visual Studio 2015 Update 3 or newer.
4. Make sure `Blocks` project is the startup project, build configuration is set to `DebugGame` and `Win64`. Hit F5 to run.
5. Press the Play button in Unreal Editor and you will see something like in below video. Also see [how to use AirSim](../#how-to-use-it).
5. Press the Play button in Unreal Editor and you will see something like in below video. Also see [how to use AirSim](https://github.com/Microsoft/AirSim/#how-to-use-it).

### Changing Code and Rebuilding
For Windows, you can just change the code in Visual Studio, press F5 and re-run. There are few batch files available in folder `AirSim\Unreal\Environments\Blocks` that lets you sync code, clean etc.
Expand Down

0 comments on commit 1fe5e40

Please sign in to comment.