Skip to content

Commit

Permalink
fix problem with multirotor sim on PX4 drones.
Browse files Browse the repository at this point in the history
  • Loading branch information
lovettchris committed Nov 29, 2018
1 parent 8bfbf35 commit 046356b
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 8 deletions.
2 changes: 1 addition & 1 deletion PythonClient/multirotor/land.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
print("already landed...")
else:
print("landing...")
client.land()
client.landAsync()

client.armDisarm(False)
client.enableApiControl(False)
2 changes: 1 addition & 1 deletion PythonClient/multirotor/path.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,6 @@
12, 120,
airsim.DrivetrainType.ForwardOnly, airsim.YawMode(False,0), 20, 1).join()
client.moveToPositionAsync(0,0,z,1).join()
client.land()
client.landAsync()
client.armDisarm(False)
client.enableApiControl(False)
4 changes: 2 additions & 2 deletions PythonClient/multirotor/setup_path.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# Else we look up grand-parent folder to see if it has airsim folder
# and if it does then we add that in sys.path

import os,sys,inspect,logging
import os,sys,logging

#this class simply tries to see if airsim
class SetupPath:
Expand All @@ -15,7 +15,7 @@ def getDirLevels(path):

@staticmethod
def getCurrentPath():
cur_filepath = os.path.abspath(inspect.getfile(inspect.currentframe()))
cur_filepath = __file__
return os.path.dirname(cur_filepath)

@staticmethod
Expand Down
22 changes: 18 additions & 4 deletions PythonClient/multirotor/survey.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,19 @@ def __init__(self, args):
self.client.confirmConnection()
self.client.enableApiControl(True)

def move_to_position(self, x, y, z, threshold=2):
self.client.moveToPositionAsync(0, 0, z, self.velocity).join()
# bufbuf: seems moveToPositionAsync isn't working right...
while True:
k = self.client.simGetGroundTruthKinematics()
pos = self.client.getPosition()
dx = abs(pos.x_val - x)
dy = abs(pos.y_val - y)
dz = abs(pos.z_val - z)
if dx+dy+dz < threshold:
return
time.sleep(0.1) # 100ms should be fine

def start(self):
print("arming the drone...")
self.client.armDisarm(True)
Expand All @@ -29,10 +42,10 @@ def start(self):
z = -self.altitude

print("climbing to altitude: " + str(self.altitude))
self.client.moveToPositionAsync(0, 0, z, self.velocity).join()
self.move_to_position(0, 0, z)

print("flying to first corner of survey box")
self.client.moveToPositionAsync(x, -self.boxsize, z, self.velocity).join()
self.move_to_position(x, -self.boxsize, z)

# let it settle there a bit.
self.client.hoverAsync().join()
Expand Down Expand Up @@ -66,11 +79,12 @@ def start(self):
pass

print("flying back home")
self.client.moveToPositionAsync(0, 0, z, self.velocity).join()
self.move_to_position(0, 0, z)

if z < -5:
print("descending")
self.client.moveToPositionAsync(0, 0, -5, 2).join()
self.velocity = 2
self.move_to_position(0, 0, -5)

print("landing...")
self.client.landAsync().join()
Expand Down
7 changes: 7 additions & 0 deletions Unreal/Plugins/AirSim/Source/PawnSimApi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,12 @@ void PawnSimApi::update()
environment_->update();
//kinematics_->update();

// and in the case of subclasses that are overriding getGroundTruthEnvironment, make sure those
// are also updated.
msr::airlib::Environment* vehicleEnvironment = const_cast<msr::airlib::Environment*>(getGroundTruthEnvironment());
vehicleEnvironment->setPosition(kinematics_.pose.position);
vehicleEnvironment->update();

VehicleSimApiBase::update();
}

Expand Down Expand Up @@ -418,6 +424,7 @@ void PawnSimApi::setPoseInternal(const Pose& pose, bool ignore_collision)
//translate to new PawnSimApi position & orientation from NED to NEU
FVector position = ned_transform_.fromLocalNed(pose.position);
state_.current_position = position;
kinematics_.pose = pose;

//quaternion formula comes from http://stackoverflow.com/a/40334755/207661
FQuat orientation = ned_transform_.fromNed(pose.orientation);
Expand Down

0 comments on commit 046356b

Please sign in to comment.