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

wind addition to advanced_lift_drag plugin #2226

Merged
merged 2 commits into from
Nov 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
14 changes: 13 additions & 1 deletion src/systems/advanced_lift_drag/AdvancedLiftDrag.cc
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
#include "gz/sim/components/Name.hh"
#include "gz/sim/components/ExternalWorldWrenchCmd.hh"
#include "gz/sim/components/Pose.hh"
#include "gz/sim/components/Wind.hh"

using namespace gz;
using namespace sim;
Expand Down Expand Up @@ -481,6 +482,13 @@ void AdvancedLiftDragPrivate::Update(EntityComponentManager &_ecm)
const auto worldPose =
_ecm.Component<components::WorldPose>(this->linkEntity);

// get wind as a component from the _ecm
components::WorldLinearVelocity *windLinearVel = nullptr;
if(_ecm.EntityByComponents(components::Wind()) != kNullEntity){
Entity windEntity = _ecm.EntityByComponents(components::Wind());
windLinearVel =
_ecm.Component<components::WorldLinearVelocity>(windEntity);
}

std::vector<components::JointPosition*> controlJointPosition_vec(
this->num_ctrl_surfaces);
Expand All @@ -499,8 +507,12 @@ void AdvancedLiftDragPrivate::Update(EntityComponentManager &_ecm)

const auto &pose = worldPose->Data();
const auto cpWorld = pose.Rot().RotateVector(this->cp);
const auto air_velocity = worldLinVel->Data() + worldAngVel->Data().Cross(
auto air_velocity = worldLinVel->Data() + worldAngVel->Data().Cross(
cpWorld);
if (windLinearVel != nullptr){
air_velocity = worldLinVel->Data() + worldAngVel->Data().Cross(
cpWorld) - windLinearVel->Data();
}

// Define body frame: X forward, Z downward, Y out the right wing
gz::math::Vector3d body_x_axis = pose.Rot().RotateVector(this->forward);
Expand Down
2 changes: 2 additions & 0 deletions src/systems/advanced_lift_drag/AdvancedLiftDrag.hh
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ namespace systems
/// https:/PX4/PX4-Autopilot/blob/main/Tools/simulation/
/// gz/tools/avl_automation/
///
/// Note: Wind calculations can be enabled by setting the wind parameter
/// in the world file.
///
/// ## System Parameters
///
Expand Down