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

Limit thruster system's input thrust cmd #1318

Merged
merged 3 commits into from
Feb 4, 2022
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
31 changes: 27 additions & 4 deletions src/systems/thruster/Thruster.cc
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,12 @@ class ignition::gazebo::systems::ThrusterPrivateData
/// and writes the angular velocity directly to the joint. default: false
public: bool velocityControl = false;

/// \brief Maximum input force [N] for the propellerController, default: 1000N
/// TODO(chapulina) Make it configurable from SDF.
/// \brief Maximum input force [N] for the propellerController,
/// default: 1000N
public: double cmdMax = 1000;

/// \brief Minimum input force [N] for the propellerController, default: 1000N
/// TODO(chapulina) Make it configurable from SDF.
/// \brief Minimum input force [N] for the propellerController,
/// default: -1000N
public: double cmdMin = -1000;

/// \brief Thrust coefficient relating the propeller angular velocity to the
Expand Down Expand Up @@ -206,6 +206,29 @@ void Thruster::Configure(
enableComponent<components::WorldAngularVelocity>(_ecm,
this->dataPtr->linkEntity);

double minThrustCmd = this->dataPtr->cmdMin;
double maxThrustCmd = this->dataPtr->cmdMax;
if (_sdf->HasElement("max_thrust_cmd"))
{
maxThrustCmd = _sdf->Get<double>("max_thrust_cmd");
}
if (_sdf->HasElement("min_thrust_cmd"))
{
minThrustCmd = _sdf->Get<double>("min_thrust_cmd");
}
if (maxThrustCmd < minThrustCmd)
{
ignerr << "<max_thrust_cmd> must be greater than or equal to "
<< "<min_thrust_cmd>. Revert to using default values: "
<< "min: " << this->dataPtr->cmdMin << ", "
<< "max: " << this->dataPtr->cmdMax << std::endl;
}
else
{
this->dataPtr->cmdMax = maxThrustCmd;
this->dataPtr->cmdMin = minThrustCmd;
}

if (_sdf->HasElement("velocity_control"))
{
this->dataPtr->velocityControl = _sdf->Get<bool>("velocity_control");
Expand Down
4 changes: 4 additions & 0 deletions src/systems/thruster/Thruster.hh
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ namespace systems
/// no units, defaults to 0.0]
/// - <d_gain> - Derivative gain for joint PID controller. [Optional,
/// no units, defaults to 0.0]
/// - <max_thrust_cmd> - Maximum thrust command. [Optional,
/// defaults to 1000N]
/// - <min_thrust_cmd> - Minimum thrust command. [Optional,
/// defaults to -1000N]
///
/// ## Example
/// An example configuration is installed with Gazebo. The example
Expand Down
22 changes: 20 additions & 2 deletions test/integration/thruster.cc
Original file line number Diff line number Diff line change
Expand Up @@ -134,9 +134,24 @@ void ThrusterTest::TestWorld(const std::string &_world,
EXPECT_LT(sleep, maxSleep);
EXPECT_TRUE(pub.HasConnections());

double force{300.0};
// input force cmd - this should be capped to 0
double forceCmd{-1000.0};
msgs::Double msg;
msg.set_data(force);
msg.set_data(forceCmd);
pub.Publish(msg);

// Check no movement
fixture.Server()->Run(true, 100, false);
std::this_thread::sleep_for(std::chrono::milliseconds(100));
EXPECT_DOUBLE_EQ(0.0, modelPoses.back().Pos().X());
EXPECT_EQ(100u, modelPoses.size());
EXPECT_EQ(100u, propellerAngVels.size());
modelPoses.clear();
propellerAngVels.clear();

// input force cmd this should be capped to 300
forceCmd = 1000.0;
msg.set_data(forceCmd);
pub.Publish(msg);

// Check movement
Expand All @@ -152,6 +167,9 @@ void ThrusterTest::TestWorld(const std::string &_world,
EXPECT_EQ(100u * sleep, modelPoses.size());
EXPECT_EQ(100u * sleep, propellerAngVels.size());

// max allowed force
double force{300.0};

// F = m * a
// s = a * t^2 / 2
// F = m * 2 * s / t^2
Expand Down
2 changes: 2 additions & 0 deletions test/worlds/thruster_pid.sdf
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@
<thrust_coefficient>0.004</thrust_coefficient>
<fluid_density>1000</fluid_density>
<propeller_diameter>0.2</propeller_diameter>
<max_thrust_cmd>300</max_thrust_cmd>
<min_thrust_cmd>0</min_thrust_cmd>
</plugin>
</model>

Expand Down
2 changes: 2 additions & 0 deletions test/worlds/thruster_vel_cmd.sdf
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@
<fluid_density>950</fluid_density>
<propeller_diameter>0.25</propeller_diameter>
<velocity_control>true</velocity_control>
<max_thrust_cmd>300</max_thrust_cmd>
<min_thrust_cmd>0</min_thrust_cmd>
</plugin>
</model>

Expand Down