Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for fixed external cameras #3320

Merged
merged 29 commits into from
Jul 26, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
0021bfe
PawnSimApi: Change member init to initializer list
rajat2004 Jan 11, 2021
7cb9b74
Move some Camera API implementations to APIPCamera
rajat2004 Jan 11, 2021
0b18b7d
Add initial External Cameras implementation
rajat2004 Jan 12, 2021
603712e
Add getCameraInfo API for external cameras
rajat2004 Jan 15, 2021
cf4a1cc
Move getCameraInfo implementation to WorldSimApi
rajat2004 Jan 21, 2021
710379e
Move most Camera APIs to WorldSimApi
rajat2004 Jan 21, 2021
22a9dee
Update APIs for getting external images
rajat2004 Jan 22, 2021
77421a5
Windows fixes and small cleanups
rajat2004 Jan 31, 2021
fbf84bf
Add external field to simGetImage/s APIs
rajat2004 Feb 10, 2021
1bc9ef8
Remove unused PawnSimApi getImages APIs
rajat2004 Feb 10, 2021
32d22e0
Add External field to Subwindow settings
rajat2004 Feb 11, 2021
dd24b1e
Update Python API docstrings
rajat2004 Feb 11, 2021
21a7a39
Docs: Add info about external cameras
rajat2004 Feb 11, 2021
4276935
Unity: Update to new Image APIs
rajat2004 Feb 12, 2021
2ae8ffd
Fix some warnings, cleanup
rajat2004 Feb 12, 2021
61e15c9
Fix missing vehicle_name parameter
rajat2004 Jun 9, 2021
f39db30
Pythonclient: example script for testing external cameras
rajat2004 Feb 10, 2021
8812b08
Apply clang-format
rajat2004 Jun 9, 2021
c1025af
Remove deprecated simSetCameraOrientation API
rajat2004 Jun 9, 2021
7c368b2
Move Detection APIs to WorldSimApi, add external field
rajat2004 Jun 23, 2021
0c24753
Update detection Python APIs
rajat2004 Jun 23, 2021
3a1052a
Unity: Move detection APIs
rajat2004 Jun 24, 2021
2e84c97
Add CameraDetails struct
rajat2004 Jun 24, 2021
49bfda3
Fix missing call to parse External Camera settings
rajat2004 Jul 1, 2021
991d35c
Update C++ Image APIs to include external field
rajat2004 Jul 1, 2021
ba3bc1c
Update getImage API to use CameraDetails
rajat2004 Jul 1, 2021
5b310e1
Add CameraDetails::to_string helper method
rajat2004 Jul 1, 2021
d6becac
Update external_camera.py script
rajat2004 Jul 1, 2021
79ee342
Update docs after review
rajat2004 Jul 24, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 13 additions & 13 deletions AirLib/include/api/RpcLibClientBase.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,10 @@ namespace airlib
int simGetSegmentationObjectID(const std::string& mesh_name) const;
void simPrintLogMessage(const std::string& message, std::string message_param = "", unsigned char severity = 0);

void simAddDetectionFilterMeshName(const std::string& camera_name, const std::string& mesh_name, const std::string& vehicle_name = "");
void simSetDetectionFilterRadius(const std::string& camera_name, const float radius_cm, const std::string& vehicle_name = "");
void simClearDetectionMeshNames(const std::string& camera_name, const std::string& vehicle_name = "");
vector<DetectionInfo> simGetDetections(const std::string& camera_name, ImageCaptureBase::ImageType image_type, const std::string& vehicle_name = "");
void simAddDetectionFilterMeshName(const std::string& camera_name, const std::string& mesh_name, const std::string& vehicle_name = "", bool external = false);
void simSetDetectionFilterRadius(const std::string& camera_name, const float radius_cm, const std::string& vehicle_name = "", bool external = false);
void simClearDetectionMeshNames(const std::string& camera_name, const std::string& vehicle_name = "", bool external = false);
vector<DetectionInfo> simGetDetections(const std::string& camera_name, ImageCaptureBase::ImageType image_type, const std::string& vehicle_name = "", bool external = false);

void simFlushPersistentMarkers();
void simPlotPoints(const vector<Vector3r>& points, const vector<float>& color_rgba, float size, float duration, bool is_persistent);
Expand Down Expand Up @@ -108,8 +108,8 @@ namespace airlib
void simSetVehiclePose(const Pose& pose, bool ignore_collision, const std::string& vehicle_name = "");
void simSetTraceLine(const std::vector<float>& color_rgba, float thickness = 3.0f, const std::string& vehicle_name = "");

vector<ImageCaptureBase::ImageResponse> simGetImages(vector<ImageCaptureBase::ImageRequest> request, const std::string& vehicle_name = "");
vector<uint8_t> simGetImage(const std::string& camera_name, ImageCaptureBase::ImageType type, const std::string& vehicle_name = "");
vector<ImageCaptureBase::ImageResponse> simGetImages(vector<ImageCaptureBase::ImageRequest> request, const std::string& vehicle_name = "", bool external = false);
vector<uint8_t> simGetImage(const std::string& camera_name, ImageCaptureBase::ImageType type, const std::string& vehicle_name = "", bool external = false);

bool simTestLineOfSightToPoint(const msr::airlib::GeoPoint& point, const std::string& vehicle_name = "");
bool simTestLineOfSightBetweenPoints(const msr::airlib::GeoPoint& point1, const msr::airlib::GeoPoint& point2);
Expand All @@ -120,13 +120,12 @@ namespace airlib

CollisionInfo simGetCollisionInfo(const std::string& vehicle_name = "") const;

CameraInfo simGetCameraInfo(const std::string& camera_name, const std::string& vehicle_name = "") const;
void simSetDistortionParam(const std::string& camera_name, const std::string& param_name, float value, const std::string& vehicle_name = "");
std::vector<float> simGetDistortionParams(const std::string& camera_name, const std::string& vehicle_name = "");
void simSetCameraPose(const std::string& camera_name, const Pose& pose, const std::string& vehicle_name = "");
void simSetCameraFov(const std::string& camera_name, float fov_degrees, const std::string& vehicle_name = "");
// This is a backwards-compatibility wrapper over simSetCameraPose, and can be removed in future major releases
void simSetCameraOrientation(const std::string& camera_name, const Quaternionr& orientation, const std::string& vehicle_name = "");
CameraInfo simGetCameraInfo(const std::string& camera_name, const std::string& vehicle_name = "", bool external = false) const;
void simSetDistortionParam(const std::string& camera_name, const std::string& param_name, float value, const std::string& vehicle_name = "", bool external = false);
std::vector<float> simGetDistortionParams(const std::string& camera_name, const std::string& vehicle_name = "", bool external = false);
void simSetCameraPose(const std::string& camera_name, const Pose& pose, const std::string& vehicle_name = "", bool external = false);
void simSetCameraFov(const std::string& camera_name, float fov_degrees, const std::string& vehicle_name = "", bool external = false);

bool simCreateVoxelGrid(const Vector3r& position, const int& x_size, const int& y_size, const int& z_size, const float& res, const std::string& output_file);
msr::airlib::Kinematics::State simGetGroundTruthKinematics(const std::string& vehicle_name = "") const;
msr::airlib::Environment::State simGetGroundTruthEnvironment(const std::string& vehicle_name = "") const;
Expand All @@ -152,4 +151,5 @@ namespace airlib
};
}
} //namespace

#endif
14 changes: 0 additions & 14 deletions AirLib/include/api/VehicleSimApiBase.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,22 +49,13 @@ namespace airlib

virtual void initialize() = 0;

virtual std::vector<ImageCaptureBase::ImageResponse> getImages(const std::vector<ImageCaptureBase::ImageRequest>& request) const = 0;
virtual std::vector<uint8_t> getImage(const std::string& camera_name, ImageCaptureBase::ImageType image_type) const = 0;

virtual bool testLineOfSightToPoint(const GeoPoint& point) const = 0;

virtual Pose getPose() const = 0;
virtual void setPose(const Pose& pose, bool ignore_collision) = 0;
virtual const Kinematics::State* getGroundTruthKinematics() const = 0;
virtual const msr::airlib::Environment* getGroundTruthEnvironment() const = 0;

virtual CameraInfo getCameraInfo(const std::string& camera_name) const = 0;
virtual void setCameraPose(const std::string& camera_name, const Pose& pose) = 0;
virtual void setCameraFoV(const std::string& camera_name, float fov_degrees) = 0;
virtual void setDistortionParam(const std::string& camera_name, const std::string& param_name, float value) = 0;
virtual std::vector<float> getDistortionParams(const std::string& camera_name) = 0;

virtual CollisionInfo getCollisionInfo() const = 0;
virtual int getRemoteControlID() const = 0; //which RC to use, 0 is first one, -1 means disable RC (use keyborad)
virtual RCData getRCData() const = 0; //get reading from RC from simulator's host OS
Expand All @@ -73,11 +64,6 @@ namespace airlib
virtual void toggleTrace() = 0;
virtual void setTraceLine(const std::vector<float>& color_rgba, float thickness) = 0;

virtual void addDetectionFilterMeshName(const std::string& camera_name, ImageCaptureBase::ImageType image_type, const std::string& mesh_name) = 0;
virtual void setDetectionFilterRadius(const std::string& camera_name, ImageCaptureBase::ImageType image_type, const float radius_cm) = 0;
virtual void clearDetectionMeshNames(const std::string& camera_name, ImageCaptureBase::ImageType image_type) = 0;
virtual std::vector<DetectionInfo> getDetections(const std::string& camera_name, ImageCaptureBase::ImageType image_type) const = 0;

//use pointer here because of derived classes for VehicleSetting
const AirSimSettings::VehicleSetting* getVehicleSetting() const
{
Expand Down
19 changes: 18 additions & 1 deletion AirLib/include/api/WorldSimApiBase.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#define air_WorldSimApiBase_hpp

#include "common/CommonStructs.hpp"
#include "common/AirSimSettings.hpp"
#include "common/ImageCaptureBase.hpp"

namespace msr
{
Expand Down Expand Up @@ -88,7 +88,24 @@ namespace airlib

virtual bool testLineOfSightBetweenPoints(const msr::airlib::GeoPoint& point1, const msr::airlib::GeoPoint& point2) const = 0;
virtual vector<msr::airlib::GeoPoint> getWorldExtents() const = 0;

// Camera APIs
virtual CameraInfo getCameraInfo(const CameraDetails& camera_details) const = 0;
virtual void setCameraPose(const msr::airlib::Pose& pose, const CameraDetails& camera_details) = 0;
virtual void setCameraFoV(float fov_degrees, const CameraDetails& camera_details) = 0;
virtual void setDistortionParam(const std::string& param_name, float value, const CameraDetails& camera_details) = 0;
virtual std::vector<float> getDistortionParams(const CameraDetails& camera_details) const = 0;

virtual std::vector<ImageCaptureBase::ImageResponse> getImages(const std::vector<ImageCaptureBase::ImageRequest>& requests,
const std::string& vehicle_name, bool external) const = 0;
virtual std::vector<uint8_t> getImage(ImageCaptureBase::ImageType image_type, const CameraDetails& camera_details) const = 0;

virtual void addDetectionFilterMeshName(ImageCaptureBase::ImageType image_type, const std::string& mesh_name, const CameraDetails& camera_details) = 0;
virtual void setDetectionFilterRadius(ImageCaptureBase::ImageType image_type, float radius_cm, const CameraDetails& camera_details) = 0;
virtual void clearDetectionMeshNames(ImageCaptureBase::ImageType image_type, const CameraDetails& camera_details) = 0;
virtual std::vector<DetectionInfo> getDetections(ImageCaptureBase::ImageType image_type, const CameraDetails& camera_details) = 0;
};
}
} //namespace

#endif
41 changes: 34 additions & 7 deletions AirLib/include/common/AirSimSettings.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,16 @@ namespace airlib
bool visible;
std::string camera_name;
std::string vehicle_name;

SubwindowSetting(int window_index_val = 0, ImageType image_type_val = ImageType::Scene,
bool visible_val = false, const std::string& camera_name_val = "", const std::string& vehicle_name_val = "")
: window_index(window_index_val), image_type(image_type_val), visible(visible_val), camera_name(camera_name_val), vehicle_name(vehicle_name_val)
bool external;

SubwindowSetting(int window_index_val = 0, ImageType image_type_val = ImageType::Scene, bool visible_val = false,
const std::string& camera_name_val = "", const std::string& vehicle_name_val = "", bool external_val = false)
: window_index(window_index_val)
, image_type(image_type_val)
, visible(visible_val)
, camera_name(camera_name_val)
, vehicle_name(vehicle_name_val)
, external(external_val)
{
}
};
Expand Down Expand Up @@ -393,6 +399,7 @@ namespace airlib
std::string speed_unit_label = "m\\s";
std::map<std::string, std::shared_ptr<SensorSetting>> sensor_defaults;
Vector3r wind = Vector3r::Zero();
std::map<std::string, CameraSetting> external_cameras;

std::string settings_text_ = "";

Expand Down Expand Up @@ -428,6 +435,7 @@ namespace airlib
loadOtherSettings(settings_json);
loadDefaultSensorSettings(simmode_name, settings_json, sensor_defaults);
loadVehicleSettings(simmode_name, settings_json, vehicles, sensor_defaults);
loadExternalCameraSettings(settings_json, external_cameras);

//this should be done last because it depends on vehicles (and/or their type) we have
loadRecordingSetting(settings_json);
Expand Down Expand Up @@ -1088,6 +1096,7 @@ namespace airlib
subwindow_setting.visible = json_settings_child.getBool("Visible", false);
subwindow_setting.camera_name = getCameraName(json_settings_child);
subwindow_setting.vehicle_name = json_settings_child.getString("VehicleName", "");
subwindow_setting.external = json_settings_child.getBool("External", false);
}
}
}
Expand All @@ -1096,9 +1105,9 @@ namespace airlib
static void initializeSubwindowSettings(std::vector<SubwindowSetting>& subwindow_settings)
{
subwindow_settings.clear();
subwindow_settings.push_back(SubwindowSetting(0, ImageType::DepthVis, false, "", "")); //depth
subwindow_settings.push_back(SubwindowSetting(1, ImageType::Segmentation, false, "", "")); //seg
subwindow_settings.push_back(SubwindowSetting(2, ImageType::Scene, false, "", "")); //vis
subwindow_settings.push_back(SubwindowSetting(0, ImageType::DepthVis, false, "", "", false)); //depth
subwindow_settings.push_back(SubwindowSetting(1, ImageType::Segmentation, false, "", "", false)); //seg
subwindow_settings.push_back(SubwindowSetting(2, ImageType::Scene, false, "", "", false)); //vis
}

void loadOtherSettings(const Settings& settings_json)
Expand Down Expand Up @@ -1327,7 +1336,25 @@ namespace airlib
else
createDefaultSensorSettings(simmode_name, sensors);
}

static void loadExternalCameraSettings(const Settings& settings_json, std::map<std::string, CameraSetting>& external_cameras)
{
external_cameras.clear();

Settings json_parent;
if (settings_json.getChild("ExternalCameras", json_parent)) {
std::vector<std::string> keys;
json_parent.getChildNames(keys);

for (const auto& key : keys) {
Settings child;
json_parent.getChild(key, child);
external_cameras[key] = createCameraSetting(child);
}
}
}
};
}
} //namespace

#endif
22 changes: 22 additions & 0 deletions AirLib/include/common/CommonStructs.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,28 @@ namespace airlib
std::vector<uint32_t> indices;
std::string name;
};

// This is a small helper struct to keep camera details together
// Not currently exposed to the client, just for cleaner codebase internally
struct CameraDetails
{
std::string camera_name;
std::string vehicle_name;
bool external;

CameraDetails(const std::string& camera_name_val, const std::string& vehicle_name_val, bool external_val)
: camera_name(camera_name_val), vehicle_name(vehicle_name_val), external(external_val)
{
}

std::string to_string() const
{
return Utils::stringf("CameraDetails: camera_name=%s, vehicle_name=%s, external=%d",
camera_name.c_str(),
vehicle_name.c_str(),
external);
}
};
}
} //namespace
#endif
Loading