Skip to content

Commit

Permalink
[plotting] add simFlushPersistentMarkers()
Browse files Browse the repository at this point in the history
  • Loading branch information
madratman committed Nov 12, 2019
1 parent 317d4d9 commit 705a55d
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 2 deletions.
1 change: 1 addition & 0 deletions AirLib/include/api/RpcLibClientBase.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ class RpcLibClientBase {
int simGetSegmentationObjectID(const std::string& mesh_name) const;
void simPrintLogMessage(const std::string& message, std::string message_param = "", unsigned char severity = 0);

void simFlushPersistentMarkers();
void simPlotPoints(const vector<Vector3r>& points, const vector<float>& color_rgba, float size, float duration, bool is_persistent);
void simPlotLineStrip(const vector<Vector3r>& points, const vector<float>& color_rgba, float thickness, float duration, bool is_persistent);
void simPlotLineList(const vector<Vector3r>& points, const vector<float>& color_rgba, float thickness, float duration, bool is_persistent);
Expand Down
1 change: 1 addition & 0 deletions AirLib/include/api/WorldSimApiBase.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ class WorldSimApiBase {
const std::string& message_param = "", unsigned char severity = 0) = 0;

//----------- Plotting APIs ----------/
virtual void simFlushPersistentMarkers() = 0;
virtual void simPlotPoints(const vector<Vector3r>& points, const vector<float>& color_rgba, float size, float duration, bool is_persistent) = 0;
virtual void simPlotLineStrip(const vector<Vector3r>& points, const vector<float>& color_rgba, float thickness, float duration, bool is_persistent) = 0;
virtual void simPlotLineList(const vector<Vector3r>& points, const vector<float>& color_rgba, float thickness, float duration, bool is_persistent) = 0;
Expand Down
5 changes: 5 additions & 0 deletions AirLib/src/api/RpcLibClientBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,11 @@ void RpcLibClientBase::simPrintLogMessage(const std::string& message, std::strin
pimpl_->client.call("simPrintLogMessage", message, message_param, severity);
}

void RpcLibClientBase::simFlushPersistentMarkers()
{
pimpl_->client.call("simFlushPersistentMarkers");
}

void RpcLibClientBase::simPlotPoints(const vector<Vector3r>& points, const vector<float>& color_rgba, float size, float duration, bool is_persistent)
{
vector<RpcLibAdapatorsBase::Vector3r> conv_points;
Expand Down
3 changes: 3 additions & 0 deletions AirLib/src/api/RpcLibServerBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,9 @@ RpcLibServerBase::RpcLibServerBase(ApiProvider* api_provider, const std::string&
return getWorldSimApi()->setObjectPose(object_name, pose.to(), teleport);
});

pimpl_->server.bind("simFlushPersistentMarkers", [&]() -> void {
getWorldSimApi()->simFlushPersistentMarkers();
});
pimpl_->server.bind("simPlotPoints", [&](const std::vector<RpcLibAdapatorsBase::Vector3r>& points, const vector<float>& color_rgba, float size, float duration, bool is_persistent) -> void {
vector<Vector3r> conv_points;
RpcLibAdapatorsBase::to(points, conv_points);
Expand Down
6 changes: 6 additions & 0 deletions PythonClient/airsim/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,12 @@ def simGetLidarSegmentation(self, lidar_name = '', vehicle_name = ''):
return self.client.call('simGetLidarSegmentation', lidar_name, vehicle_name)

# Plotting APIs
def simFlushPersistentMarkers(self):
"""
Clear any persistent markers - those plotted with setting is_persistent=True in the APIs below
"""
self.client.call('simFlushPersistentMarkers')

def simPlotPoints(self, points, color_rgba=[1.0, 0.0, 0.0, 1.0], size = 10.0, duration = -1.0, is_persistent = False):
"""
Plot a list of 3D points in World NED frame
Expand Down
11 changes: 9 additions & 2 deletions PythonClient/computer_vision/plot_markers.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,18 @@
client.simPlotLineList(points = [Vector3r(x,y,-7) for x, y in zip(np.linspace(0,-10,10), np.linspace(0,-20,10))], color_rgba=[1.0, 0.0, 0.0, 1.0], thickness = 5, duration = 30.0, is_persistent = False)

# plot transforms
client.simPlotStrings(strings = ["Microsoft AirSim" for i in range(5)], positions = [Vector3r(x,y,-2) for x, y in zip(np.linspace(0,-5,5), np.linspace(0,-5,5))],
scale = 1, color_rgba=[1.0, 1.0, 1.0, 1.0], duration = 10.0)

client.simPlotTransforms(poses = [Pose(position_val=Vector3r(x,y,-7), orientation_val=to_quaternion(pitch=0.0, roll=0.0, yaw=np.pi/2)) for x, y in zip(np.linspace(0,-10,10), np.linspace(0,-20,10))],
scale = 35, thickness = 5, duration = 10.0, is_persistent = False)

client.simPlotTransforms(poses = [Pose(position_val=Vector3r(x,y,-5), orientation_val=to_quaternion(pitch=0.0, roll=0.0, yaw=0.0)) for x, y in zip(np.linspace(0,-10,10), np.linspace(0,-20,10))],
scale = 35, thickness = 5, duration = 10.0, is_persistent = False)

client.simPlotStrings(strings = ["Microsoft AirSim" for i in range(5)], positions = [Vector3r(x,y,-2) for x, y in zip(np.linspace(0,-5,5), np.linspace(0,-5,5))],
scale = 1, color_rgba=[1.0, 1.0, 1.0, 1.0], duration = 10.0)
client.simPlotTransformsWithNames(poses = [Pose(position_val=Vector3r(x,y,-1), orientation_val=to_quaternion(pitch=0.0, roll=0.0, yaw=0.0)) for x, y in zip(np.linspace(0,-10,10), np.linspace(0,-20,10))],
names=["transform_" + str(idx) for idx in range(10)], tf_scale = 45, tf_thickness = 3, text_scale = 2, text_color_rgba = [1.0, 1.0, 1.0, 1.0], duration = 1200.0)

time.sleep(20.0)

client.simFlushPersistentMarkers()
5 changes: 5 additions & 0 deletions Unreal/Plugins/AirSim/Source/WorldSimApi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,11 @@ void WorldSimApi::setWeatherParameter(WeatherParameter param, float val)
}

//----------- Plotting APIs ----------/
void WorldSimApi::simFlushPersistentMarkers()
{
FlushPersistentDebugLines(simmode_->GetWorld());
}

void WorldSimApi::simPlotPoints(const vector<Vector3r>& points, const vector<float>& color_rgba, float size, float duration, bool is_persistent)
{
FLinearColor color {color_rgba[0], color_rgba[1], color_rgba[2], color_rgba[3]};
Expand Down
1 change: 1 addition & 0 deletions Unreal/Plugins/AirSim/Source/WorldSimApi.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class WorldSimApi : public msr::airlib::WorldSimApiBase {
virtual bool setObjectPose(const std::string& object_name, const Pose& pose, bool teleport) override;

//----------- Plotting APIs ----------/
virtual void simFlushPersistentMarkers() override;
virtual void simPlotPoints(const vector<Vector3r>& points, const vector<float>& color_rgba, float size, float duration, bool is_persistent) override;
virtual void simPlotLineStrip(const vector<Vector3r>& points, const vector<float>& color_rgba, float thickness, float duration, bool is_persistent) override;
virtual void simPlotLineList(const vector<Vector3r>& points, const vector<float>& color_rgba, float thickness, float duration, bool is_persistent) override;
Expand Down

0 comments on commit 705a55d

Please sign in to comment.