Skip to content

Commit b15af94

Browse files
committed
Add simSetWind API
1 parent c4f6c8f commit b15af94

File tree

11 files changed

+42
-2
lines changed

11 files changed

+42
-2
lines changed

AirLib/include/api/RpcLibClientBase.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,8 @@ class RpcLibClientBase {
114114
void stopRecording();
115115
bool isRecording();
116116

117+
void simSetWind(const Vector3r& wind) const;
118+
117119
protected:
118120
void* getClient();
119121
const void* getClient() const;

AirLib/include/api/WorldSimApiBase.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@ class WorldSimApiBase {
7070
virtual void startRecording() = 0;
7171
virtual void stopRecording() = 0;
7272
virtual bool isRecording() const = 0;
73+
74+
virtual void setWind(const Vector3r& wind) const = 0;
7375
};
7476

7577

AirLib/src/api/RpcLibClientBase.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -432,6 +432,12 @@ bool RpcLibClientBase::isRecording()
432432
return pimpl_->client.call("isRecording").as<bool>();
433433
}
434434

435+
void RpcLibClientBase::simSetWind(const Vector3r& wind) const
436+
{
437+
RpcLibAdapatorsBase::Vector3r conv_wind(wind);
438+
pimpl_->client.call("simSetWind", conv_wind);
439+
}
440+
435441
void* RpcLibClientBase::getClient()
436442
{
437443
return &pimpl_->client;

AirLib/src/api/RpcLibServerBase.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -366,6 +366,10 @@ RpcLibServerBase::RpcLibServerBase(ApiProvider* api_provider, const std::string&
366366
return getWorldSimApi()->isRecording();
367367
});
368368

369+
pimpl_->server.bind("simSetWind", [&](const RpcLibAdapatorsBase::Vector3r& wind) -> void {
370+
getWorldSimApi()->setWind(wind.to());
371+
});
372+
369373
//if we don't suppress then server will bomb out for exceptions raised by any method
370374
pimpl_->server.suppress_exceptions(true);
371375
}

PythonClient/airsim/client.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -699,6 +699,15 @@ def isRecording(self):
699699
"""
700700
return self.client.call('isRecording')
701701

702+
def simSetWind(self, wind):
703+
"""
704+
Set simulated wind, in World frame, NED direction, m/s
705+
706+
Args:
707+
wind (Vector3r): Wind, in World frame, NED direction, in m/s
708+
"""
709+
self.client.call('simSetWind', wind)
710+
702711
# ----------------------------------- Multirotor APIs ---------------------------------------------
703712
class MultirotorClient(VehicleClient, object):
704713
def __init__(self, ip = "", port = 41451, timeout_value = 3600):

Unreal/Plugins/AirSim/Source/SimMode/SimModeBase.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,13 @@ void ASimModeBase::continueForTime(double seconds)
263263
throw std::domain_error("continueForTime is not implemented by SimMode");
264264
}
265265

266+
void ASimModeBase::setWind(const msr::airlib::Vector3r& wind) const
267+
{
268+
// should be overridden by derived class
269+
unused(wind);
270+
throw std::domain_error("setWind not implemented by SimMode");
271+
}
272+
266273
std::unique_ptr<msr::airlib::ApiServerBase> ASimModeBase::createApiServer() const
267274
{
268275
//this will be the case when compilation with RPCLIB is disabled or simmode doesn't support APIs

Unreal/Plugins/AirSim/Source/SimMode/SimModeBase.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ class AIRSIM_API ASimModeBase : public AActor
6262
virtual void pause(bool is_paused);
6363
virtual void continueForTime(double seconds);
6464

65+
virtual void setWind(const msr::airlib::Vector3r& wind) const;
66+
6567
virtual void setTimeOfDay(bool is_enabled, const std::string& start_datetime, bool is_start_datetime_dst,
6668
float celestial_clock_speed, float update_interval_secs, bool move_sun);
6769

Unreal/Plugins/AirSim/Source/SimMode/SimModeWorldBase.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ void ASimModeWorldBase::continueForTime(double seconds)
100100
UGameplayStatics::SetGamePaused(this->GetWorld(), true);
101101
}
102102

103-
void ASimModeWorldBase::setWind(const msr::airlib::Vector3r& wind)
103+
void ASimModeWorldBase::setWind(const msr::airlib::Vector3r& wind) const
104104
{
105105
physics_engine_->setWind(wind);
106106
}

Unreal/Plugins/AirSim/Source/SimMode/SimModeWorldBase.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class AIRSIM_API ASimModeWorldBase : public ASimModeBase
3131
virtual void pause(bool is_paused) override;
3232
virtual void continueForTime(double seconds) override;
3333

34-
void setWind(const msr::airlib::Vector3r& wind);
34+
virtual void setWind(const msr::airlib::Vector3r& wind) const override;
3535

3636
protected:
3737
void startAsyncUpdator();

Unreal/Plugins/AirSim/Source/WorldSimApi.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -406,3 +406,9 @@ bool WorldSimApi::isRecording() const
406406
{
407407
return simmode_->isRecording();
408408
}
409+
410+
411+
void WorldSimApi::setWind(const Vector3r& wind) const
412+
{
413+
simmode_->setWind(wind);
414+
}

0 commit comments

Comments
 (0)