@@ -18,8 +18,8 @@ namespace msr { namespace airlib {
1818
1919class FastPhysicsEngine : public PhysicsEngineBase {
2020public:
21- FastPhysicsEngine (bool enable_ground_lock = true )
22- : enable_ground_lock_(enable_ground_lock)
21+ FastPhysicsEngine (bool enable_ground_lock = true , Vector3r wind = Vector3r::Zero() )
22+ : enable_ground_lock_(enable_ground_lock), wind_(wind)
2323 {
2424 }
2525
@@ -59,6 +59,12 @@ class FastPhysicsEngine : public PhysicsEngineBase {
5959 }
6060 // *** End: UpdatableState implementation ***//
6161
62+ // Set Wind, for API and Settings implementation
63+ void setWind (const Vector3r& wind) override
64+ {
65+ wind_ = wind;
66+ }
67+
6268private:
6369 void initPhysicsBody (PhysicsBody* body_ptr)
6470 {
@@ -76,7 +82,7 @@ class FastPhysicsEngine : public PhysicsEngineBase {
7682
7783 // first compute the response as if there was no collision
7884 // this is necessary to take in to account forces and torques generated by body
79- getNextKinematicsNoCollision (dt, body, current, next, next_wrench);
85+ getNextKinematicsNoCollision (dt, body, current, next, next_wrench, wind_ );
8086
8187 // if there is collision, see if we need collision response
8288 const CollisionInfo collision_info = body.getCollisionInfo ();
@@ -255,9 +261,9 @@ class FastPhysicsEngine : public PhysicsEngineBase {
255261 }
256262
257263 static Wrench getDragWrench (const PhysicsBody& body, const Quaternionr& orientation,
258- const Vector3r& linear_vel, const Vector3r& angular_vel_body)
264+ const Vector3r& linear_vel, const Vector3r& angular_vel_body, const Vector3r& wind_world )
259265 {
260- // add linear drag due to velocity we had since last dt seconds
266+ // add linear drag due to velocity we had since last dt seconds + wind
261267 // drag vector magnitude is proportional to v^2, direction opposite of velocity
262268 // total drag is b*v + c*v*v but we ignore the first term as b << c (pg 44, Classical Mechanics, John Taylor)
263269 // To find the drag force, we find the magnitude in the body frame and unit vector direction in world frame
@@ -268,9 +274,13 @@ class FastPhysicsEngine : public PhysicsEngineBase {
268274 Wrench wrench = Wrench::zero ();
269275 const real_T air_density = body.getEnvironment ().getState ().air_density ;
270276
277+ // Use relative velocity of the body wrt wind
278+ const Vector3r relative_vel = linear_vel - wind_world;
279+ const Vector3r linear_vel_body = VectorMath::transformToBodyFrame (relative_vel, orientation);
280+
271281 for (uint vi = 0 ; vi < body.dragVertexCount (); ++vi) {
272282 const auto & vertex = body.getDragVertex (vi);
273- const Vector3r vel_vertex = VectorMath::transformToBodyFrame (linear_vel, orientation) + angular_vel_body.cross (vertex.getPosition ());
283+ const Vector3r vel_vertex = linear_vel_body + angular_vel_body.cross (vertex.getPosition ());
274284 const real_T vel_comp = vertex.getNormal ().dot (vel_vertex);
275285 // if vel_comp is -ve then we cull the face. If velocity too low then drag is not generated
276286 if (vel_comp > kDragMinVelocity ) {
@@ -312,7 +322,7 @@ class FastPhysicsEngine : public PhysicsEngineBase {
312322 }
313323
314324 static void getNextKinematicsNoCollision (TTimeDelta dt, PhysicsBody& body, const Kinematics::State& current,
315- Kinematics::State& next, Wrench& next_wrench)
325+ Kinematics::State& next, Wrench& next_wrench, const Vector3r& wind )
316326 {
317327 const real_T dt_real = static_cast <real_T>(dt);
318328
@@ -338,13 +348,13 @@ class FastPhysicsEngine : public PhysicsEngineBase {
338348 next.accelerations .linear = Vector3r::Zero ();
339349 }
340350 else {
341- // add linear drag due to velocity we had since last dt seconds
351+ // add linear drag due to velocity we had since last dt seconds + wind
342352 // drag vector magnitude is proportional to v^2, direction opposite of velocity
343353 // total drag is b*v + c*v*v but we ignore the first term as b << c (pg 44, Classical Mechanics, John Taylor)
344354 // To find the drag force, we find the magnitude in the body frame and unit vector direction in world frame
345355 avg_linear = current.twist .linear + current.accelerations .linear * (0 .5f * dt_real);
346356 avg_angular = current.twist .angular + current.accelerations .angular * (0 .5f * dt_real);
347- const Wrench drag_wrench = getDragWrench (body, current.pose .orientation , avg_linear, avg_angular);
357+ const Wrench drag_wrench = getDragWrench (body, current.pose .orientation , avg_linear, avg_angular, wind );
348358
349359 next_wrench = body_wrench + drag_wrench;
350360
@@ -449,6 +459,7 @@ class FastPhysicsEngine : public PhysicsEngineBase {
449459 std::stringstream debug_string_;
450460 bool enable_ground_lock_;
451461 TTimePoint last_message_time;
462+ Vector3r wind_;
452463};
453464
454465}} // namespace
0 commit comments