Skip to content

Commit

Permalink
squashing last 3 commits to get rid of visuallint
Browse files Browse the repository at this point in the history
  • Loading branch information
sytelus committed May 29, 2018
1 parent 536fc3a commit 4beb27b
Show file tree
Hide file tree
Showing 42 changed files with 836 additions and 618 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ DerivedDataCache/
UnrealHeaderTool/
UnrealPak/
obj/
.vs/
.vscode/
.visuallint/
*.VC.opendb
*.VC.db
*.opensdf
Expand Down
2 changes: 1 addition & 1 deletion AirLib/AirLib.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@
<ClInclude Include="include\vehicles\car\api\CarRpcLibClient.hpp" />
<ClInclude Include="include\vehicles\car\api\CarRpcLibServer.hpp" />
<ClInclude Include="include\safety\SafetyEval.hpp" />
<ClInclude Include="include\vehicles\multirotor\api\MultirotorApiBase.h" />
<ClInclude Include="include\vehicles\multirotor\api\MultirotorApiBase.hpp" />
<ClInclude Include="include\common\Settings.hpp" />
<ClInclude Include="include\safety\SphereGeoFence.hpp" />
<ClInclude Include="include\common\Waiter.hpp" />
Expand Down
12 changes: 6 additions & 6 deletions AirLib/AirLib.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -348,9 +348,6 @@
<ClInclude Include="include\vehicles\car\api\CarApiBase.hpp">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="include\api\RpcLibClientBase.hpp">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="include\api\RpcLibServerBase.hpp">
<Filter>Header Files</Filter>
</ClInclude>
Expand Down Expand Up @@ -408,9 +405,6 @@
<ClInclude Include="include\api\VehicleApiBase.hpp">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="include\vehicles\multirotor\api\MultirotorApiBase.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="include\api\VehicleConnectorBase.hpp">
<Filter>Header Files</Filter>
</ClInclude>
Expand All @@ -429,6 +423,12 @@
<ClInclude Include="include\vehicles\multirotor\firmwares\simple_flight\SimpleFlightQuadXParams.hpp">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="include\api\RpcLibClientBase.hpp">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="include\vehicles\multirotor\api\MultirotorApiBase.hpp">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="src\safety\ObstacleMap.cpp">
Expand Down
13 changes: 7 additions & 6 deletions AirLib/include/api/RpcLibClientBase.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,14 @@ class RpcLibClientBase {
Initial = 0, Connected, Disconnected, Reset, Unknown
};
public:
RpcLibClientBase(const string& ip_address = "localhost", uint16_t port = 41451, uint timeout_ms = 60000);
RpcLibClientBase(const string& ip_address = "localhost", uint16_t port = 41451, float timeout_sec = 60);
virtual ~RpcLibClientBase(); //required for pimpl

void confirmConnection();
bool isApiControlEnabled() const;
void enableApiControl(bool is_enabled);
void resetVehicle();
void simResetWorld();
void reset();
bool armDisarm(bool arm);
void cancelPendingTasks();

ConnectionState getConnectionState();
bool ping();
Expand Down Expand Up @@ -55,9 +53,12 @@ class RpcLibClientBase {
int simGetSegmentationObjectID(const std::string& mesh_name) const;
void simPrintLogMessage(const std::string& message, std::string message_param = "", unsigned char severity = 0);

CameraInfo getCameraInfo(int camera_id) const;
void setCameraOrientation(int camera_id, const Quaternionr& orientation);
CameraInfo simGetCameraInfo(int camera_id) const;
void simSetCameraOrientation(int camera_id, const Quaternionr& orientation);

//task management APIs
void cancelLastTask();
virtual bool waitOnLastTask(float timeout_sec = Utils::nan<float>());

protected:
void* getClient();
Expand Down
2 changes: 1 addition & 1 deletion AirLib/include/api/VehicleApiBase.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class VehicleApiBase : public UpdatableObject {
virtual void enableApiControl(bool is_enabled) = 0;
virtual bool isApiControlEnabled() const = 0;
virtual bool armDisarm(bool arm) = 0;
virtual void cancelPendingTasks() = 0;
virtual void cancelLastTask() = 0;
virtual GeoPoint getHomeGeoPoint() const = 0;

virtual bool isReady(std::string& message) const
Expand Down
24 changes: 17 additions & 7 deletions AirLib/include/common/AirSimSettings.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ struct AirSimSettings {
std::string pawn_path;
bool allow_api_always = true;
bool auto_create = true;
Vector3r home_geo_point = Vector3r::Zero();

RCSettings rc;
};
Expand All @@ -100,7 +101,7 @@ struct AirSimSettings {
};

struct CaptureSetting {
//below settinsg are obtained by using Unreal console command (press ~):
//below settings are obtained by using Unreal console command (press ~):
// ShowFlag.VisualizeHDR 1.
//to replicate camera settings to SceneCapture2D
//TODO: should we use UAirBlueprintLib::GetDisplayGamma()?
Expand Down Expand Up @@ -334,7 +335,7 @@ struct AirSimSettings {
{
std::string settings_filename = Settings::getUserDirectoryFullPath("settings.json");
Settings& settings = Settings::loadJSonString("{}");
//write some settings in new file otherwise the string "null" is written if all settigs are empty
//write some settings in new file otherwise the string "null" is written if all settings are empty
settings.setString("SeeDocsAt", "https://github.com/Microsoft/AirSim/blob/master/docs/settings.md");
settings.setDouble("SettingsVersion", 1.0);

Expand Down Expand Up @@ -376,7 +377,7 @@ struct AirSimSettings {
}
}

RCSettings loadRCSetting(const Settings& settings)
RCSettings getRCSetting(const Settings& settings) const
{
RCSettings rc_setting;
rc_setting.remote_control_id = settings.getInt("RemoteControlID", rc_setting.remote_control_id);
Expand Down Expand Up @@ -497,7 +498,7 @@ struct AirSimSettings {
}
}

std::unique_ptr<VehicleSetting> createPX4VehicleSetting(const Settings& settings)
std::unique_ptr<VehicleSetting> createPX4VehicleSetting(const Settings& settings) const
{
//these settings are expected in same section, not in another child
auto vehicle_setting = std::unique_ptr<PX4VehicleSetting>(new PX4VehicleSetting());
Expand Down Expand Up @@ -535,8 +536,12 @@ struct AirSimSettings {
return vehicle_setting;
}

Vector3r getVectorSetting(const Settings& settings) const
{
return Vector3r(settings.getFloat("x", 0), settings.getFloat("y", 0), settings.getFloat("z", 0));
}

std::unique_ptr<VehicleSetting> createVehicleSetting(const Settings& settings, const std::string vehicle_name)
std::unique_ptr<VehicleSetting> createVehicleSetting(const Settings& settings, const std::string vehicle_name) const
{
auto vehicle_type = Utils::toLower(settings.getString("VehicleType", ""));

Expand All @@ -560,7 +565,12 @@ struct AirSimSettings {

Settings rc_json;
if (settings.getChild("RC", rc_json)) {
vehicle_setting->rc = loadRCSetting(rc_json);
vehicle_setting->rc = getRCSetting(rc_json);
}

Settings homepoint_json;
if (settings.getChild("HomePoint", homepoint_json)) {
vehicle_setting->home_geo_point = getVectorSetting(homepoint_json);
}

return vehicle_setting;
Expand Down Expand Up @@ -816,7 +826,7 @@ struct AirSimSettings {
{ //load origin geopoint
Settings origin_geopoint_json;
if (settings.getChild("OriginGeopoint", origin_geopoint_json)) {
GeoPoint origin = origin_geopoint.home_point;
GeoPoint origin = origin_geopoint.home_geo_point;
origin.latitude = origin_geopoint_json.getDouble("Latitude", origin.latitude);
origin.longitude = origin_geopoint_json.getDouble("Longitude", origin.longitude);
origin.altitude = origin_geopoint_json.getFloat("Altitude", origin.altitude);
Expand Down
17 changes: 15 additions & 2 deletions AirLib/include/common/CancelToken.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,14 @@ namespace msr { namespace airlib {
class CancelToken {
public:
CancelToken()
: is_cancelled_(false), recursion_count_(0)
: is_cancelled_(false), is_complete_(false), recursion_count_(0)
{
}

void reset()
{
is_cancelled_ = false;
is_complete_ = false;
recursion_count_ = 0;
}

Expand Down Expand Up @@ -55,6 +56,16 @@ class CancelToken {
return !isCancelled();
}

void complete(bool is_complete = true)
{
is_complete_ = is_complete;
}

bool isComplete() const
{
return is_complete_;
}

int getRecursionCount()
{
return recursion_count_;
Expand Down Expand Up @@ -83,8 +94,10 @@ class CancelToken {

private:
std::atomic<bool> is_cancelled_;
std::recursive_mutex wait_mutex_;
std::atomic<bool> is_complete_;
std::atomic<int> recursion_count_;

std::recursive_mutex wait_mutex_;
};

}} //namespace
Expand Down
14 changes: 7 additions & 7 deletions AirLib/include/common/CommonStructs.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -173,21 +173,21 @@ struct GeoPoint {
};

struct HomeGeoPoint {
GeoPoint home_point;
GeoPoint home_geo_point;
double lat_rad, lon_rad;
double cos_lat, sin_lat;

HomeGeoPoint()
{}
HomeGeoPoint(const GeoPoint& home_point_val)
HomeGeoPoint(const GeoPoint& home_geo_point_val)
{
initialize(home_point_val);
initialize(home_geo_point_val);
}
void initialize(const GeoPoint& home_point_val)
void initialize(const GeoPoint& home_geo_point_val)
{
home_point = home_point_val;
lat_rad = Utils::degreesToRadians(home_point.latitude);
lon_rad = Utils::degreesToRadians(home_point.longitude);
home_geo_point = home_geo_point_val;
lat_rad = Utils::degreesToRadians(home_geo_point.latitude);
lon_rad = Utils::degreesToRadians(home_geo_point.longitude);
cos_lat = cos(lat_rad);
sin_lat = sin(lat_rad);
}
Expand Down
4 changes: 2 additions & 2 deletions AirLib/include/common/EarthUtils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -298,9 +298,9 @@ class EarthUtils {
atan2(y_rad * sin_c, c * home_geo_point.cos_lat * cos_c - x_rad * home_geo_point.sin_lat * sin_c));

return GeoPoint(Utils::radiansToDegrees(lat_rad), Utils::radiansToDegrees(lon_rad),
home_geo_point.home_point.altitude - v.z());
home_geo_point.home_geo_point.altitude - v.z());
} else
return GeoPoint(home_geo_point.home_point.latitude, home_geo_point.home_point.longitude, home_geo_point.home_point.altitude - v.z());
return GeoPoint(home_geo_point.home_geo_point.latitude, home_geo_point.home_geo_point.longitude, home_geo_point.home_geo_point.altitude - v.z());
}

//below are approximate versions and would produce errors of more than 10m for points farther than 1km
Expand Down
48 changes: 31 additions & 17 deletions AirLib/include/common/Waiter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,44 +14,58 @@
namespace msr { namespace airlib {

class Waiter {
private:
TTimePoint proc_start_;
TTimePoint loop_start_;

TTimeDelta sleep_duration_, timeout_duration_;

public:
Waiter(TTimeDelta sleep_duration_seconds, TTimeDelta timeout_duration = std::numeric_limits<TTimeDelta>::max())
: sleep_duration_(sleep_duration_seconds), timeout_duration_(timeout_duration)
Waiter(TTimeDelta sleep_duration_seconds, TTimeDelta timeout_sec, CancelToken& cancelable_action)
: sleep_duration_(sleep_duration_seconds), timeout_sec_(timeout_sec),
cancelable_action_(cancelable_action), is_complete_(false)
{
proc_start_ = loop_start_ = clock()->nowNanos();
}

virtual bool sleep(CancelToken& cancelable_action)
bool sleep()
{
// Sleeps for the time needed to get current running time up to the requested sleep_duration_.
// So this can be used to "throttle" any loop to check something every sleep_duration_ seconds.

if (isComplete())
throw std::domain_error("Process was already complete. This instance of Waiter shouldn't be reused!");
if (isTimeout())
return false;

//measure time spent since last iteration
TTimeDelta running_time = clock()->elapsedSince(loop_start_);
double remaining = sleep_duration_ - running_time;
bool completed = cancelable_action.sleep(remaining);
bool done = cancelable_action_.sleep(remaining);
loop_start_ = clock()->nowNanos();
return completed;
return done;
}

void resetSleep()
//call this mark process as complete
void complete()
{
loop_start_ = clock()->nowNanos();
is_complete_ = true;
}
void resetTimeout()

bool isComplete() const
{
proc_start_ = clock()->nowNanos();
return is_complete_;
}

bool is_timeout() const
bool isTimeout() const
{
return clock()->elapsedSince(proc_start_) >= timeout_duration_;
if (isComplete())
return false;
else
return clock()->elapsedSince(proc_start_) >= timeout_sec_;
}
private:
TTimeDelta sleep_duration_, timeout_sec_;
CancelToken& cancelable_action_;
bool is_complete_; //each waiter should maintain its own complete status

TTimePoint proc_start_;
TTimePoint loop_start_;

static ClockBase* clock()
{
return ClockFactory::get();
Expand Down
Loading

0 comments on commit 4beb27b

Please sign in to comment.