Skip to content

Commit

Permalink
separate functionality of maxCmd into max/minCmd
Browse files Browse the repository at this point in the history
use a separate minCmd variable to scale negative input commands
  • Loading branch information
acxz committed Jul 18, 2022
1 parent cd7185b commit 0c7f85f
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,12 @@ namespace gazebo
/// \param[in] _msg The thrust angle message to process.
public: void OnThrustAngle(const std_msgs::Float32::ConstPtr &_msg);

/// \brief Maximum abs val of incoming command.
/// \brief Maximum val of incoming command.
public: double maxCmd;

/// \brief Minimum val of incoming command.
public: double minCmd;

/// \brief Max forward force in Newtons.
public: double maxForceFwd;

Expand Down Expand Up @@ -134,8 +137,10 @@ namespace gazebo
/// Optional elements:
/// <mappingType>: Thruster mapping (0=linear; 1=GLF, nonlinear),
/// default is 0
/// <maxCmd>:Maximum (abs val) of thrust commands,
/// <maxCmd>:Maximum of thrust commands,
/// defualt is 1.0
/// <minCmd>:Minimum of thrust commands,
/// defualt is -1.0
/// <maxForceFwd>: Maximum forward force [N].
/// default is 250.0 N
/// <maxForceRev>: Maximum reverse force [N].
Expand All @@ -159,6 +164,7 @@ namespace gazebo
/// <enableAngle>false</enableAngle>
/// <mappingType>1</mappingType>
/// <maxCmd>1.0</maxCmd>
/// <minCmd>-1.0</minCmd>
/// <maxForceFwd>250.0</maxForceFwd>
/// <maxForceRev>-100.0</maxForceRev>
/// <maxAngle>1.57</maxAngle>
Expand All @@ -172,6 +178,7 @@ namespace gazebo
/// <enableAngle>false</enableAngle>
/// <mappingType>1</mappingType>
/// <maxCmd>1.0</maxCmd>
/// <minCmd>-1.0</minCmd>
/// <maxForceFwd>250.0</maxForceFwd>
/// <maxForceRev>-100.0</maxForceRev>
/// <maxAngle>1.57</maxAngle>
Expand Down Expand Up @@ -208,6 +215,7 @@ namespace gazebo
/// \return Value scaled and saturated.
private: double ScaleThrustCmd(const double _cmd,
const double _max_cmd,
const double _min_cmd,
const double _max_pos,
const double _max_neg) const;

Expand Down
7 changes: 5 additions & 2 deletions usv_gazebo_plugins/src/usv_gazebo_thrust_plugin.cc
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,7 @@ void UsvThrust::Load(physics::ModelPtr _parent, sdf::ElementPtr _sdf)
}

thruster.maxCmd = this->SdfParamDouble(thrusterSDF, "maxCmd", 1.0);
thruster.minCmd = this->SdfParamDouble(thrusterSDF, "minCmd", -1.0);
thruster.maxForceFwd =
this->SdfParamDouble(thrusterSDF, "maxForceFwd", 250.0);
thruster.maxForceRev =
Expand Down Expand Up @@ -297,7 +298,7 @@ void UsvThrust::Load(physics::ModelPtr _parent, sdf::ElementPtr _sdf)

//////////////////////////////////////////////////
double UsvThrust::ScaleThrustCmd(const double _cmd, const double _maxCmd,
const double _maxPos, const double _maxNeg) const
const double _minCmd, const double _maxPos, const double _maxNeg) const
{
double val = 0.0;
if (_cmd >= 0.0)
Expand All @@ -308,7 +309,8 @@ double UsvThrust::ScaleThrustCmd(const double _cmd, const double _maxCmd,
else
{
double absMaxNeg = std::abs(_maxNeg);
val = _cmd / _maxCmd * absMaxNeg;
double absMinCmd = std::abs(_minCmd);
val = _cmd / absMinCmd * absMaxNeg;
val = std::max(val, -1.0 * absMaxNeg);
}
return val;
Expand Down Expand Up @@ -372,6 +374,7 @@ void UsvThrust::Update()
tforcev.X() = this->ScaleThrustCmd(this->thrusters[i].currCmd/
this->thrusters[i].maxCmd,
this->thrusters[i].maxCmd,
this->thrusters[i].minCmd,
this->thrusters[i].maxForceFwd,
this->thrusters[i].maxForceRev);
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
<!-- Optional Parameters -->
<mappingType>1</mappingType>
<maxCmd>1.0</maxCmd>
<minCmd>-1.0</minCmd>
<maxForceFwd>250.0</maxForceFwd>
<maxForceRev>-100.0</maxForceRev>
<maxAngle>${pi/2}</maxAngle>
Expand Down

0 comments on commit 0c7f85f

Please sign in to comment.