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

default value initialization to avoid redundant variable assignment #678

Merged
merged 14 commits into from
Jun 26, 2023
Merged
Show file tree
Hide file tree
Changes from 11 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
76 changes: 52 additions & 24 deletions vrx_gz/src/Wavefield.cc
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
#include <gz/math/Vector2.hh>
#include <gz/math/Vector3.hh>

#include <iostream>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need this #include?

Copy link
Collaborator Author

@tejalbarnwal tejalbarnwal Jun 26, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sorry, I forgot to remove that
I used it to debug initially, will remove it


#include "Wavefield.hh"

using namespace gz;
Expand All @@ -48,21 +50,21 @@ class vrx::WavefieldPrivate
{
/// \brief Constructor.
public: WavefieldPrivate():
size({1000, 1000}),
cellCount({50, 50}),
size({6000, 6000}),
cellCount({300, 300}),
model("PMS"),
number(1),
scale(2),
angle(2.0*M_PI/10.0),
steepness(1.0),
number(3),
scale(1.1),
angle(0.4),
steepness(0.0),
amplitude(0.0),
period(1.0),
period(5.0),
phase(0.0),
direction(1, 0),
angularFrequency(2.0*M_PI),
wavelength(2 * M_PI / this->DeepWaterDispersionToWavenumber(2.0 * M_PI)),
wavenumber(this->DeepWaterDispersionToWavenumber(2.0 * M_PI)),
tau(1.0),
tau(2.0),
gain(1.0)
{
}
Expand Down Expand Up @@ -469,22 +471,48 @@ void Wavefield::Load(const msgs::Param &_msg)
{
auto params = _msg.params();

this->data->size = {params["size"].vector3d_value().x(),
params["size"].vector3d_value().y()};
this->data->cellCount = {params["cell_count"].vector3d_value().x(),
params["cell_count"].vector3d_value().y()};
this->data->number = params["number"].int_value();
this->data->scale = params["scale"].double_value();
this->data->angle = params["angle"].double_value();
this->data->steepness = params["steepness"].double_value();
this->data->amplitude = params["amplitude"].double_value();
this->data->period = params["period"].double_value();
this->data->phase = params["phase"].double_value();
this->data->direction = {params["direction"].vector3d_value().x(),
params["direction"].vector3d_value().y()};
this->data->model = params["model"].string_value();
this->data->gain = params["gain"].double_value();
this->data->tau = params["tau"].double_value();
if (params.count("size") > 0){
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nitpick: Could you move the open bracket to the next line to be consistent with the Gazebo style?

if (params.count("size") > 0)
{
  this->data->size = {params["size"].vector3d_value().x(),
    params["size"].vector3d_value().y()};
}

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure, i will update them

this->data->size = {params["size"].vector3d_value().x(),
params["size"].vector3d_value().y()};
}
if (params.count("cell_count") > 0){
this->data->cellCount = {params["cell_count"].vector3d_value().x(),
params["cell_count"].vector3d_value().y()};
}
if (params.count("number") > 0){
this->data->number = params["number"].int_value();
}
if (params.count("scale") > 0){
this->data->scale = params["scale"].double_value();
}
if (params.count("angle") > 0){
this->data->angle = params["angle"].double_value();
}
if (params.count("steepness") > 0){
this->data->steepness = params["steepness"].double_value();
}
if (params.count("amplitude") > 0){
this->data->amplitude = params["amplitude"].double_value();
}
if (params.count("period") > 0){
this->data->period = params["period"].double_value();
}
if (params.count("phase") > 0){
this->data->phase = params["phase"].double_value();
}
if (params.count("direction") > 0){
this->data->direction = {params["direction"].vector3d_value().x(),
params["direction"].vector3d_value().y()};
}
if (params.count("model") > 0){
this->data->model = params["model"].string_value();
}
if (params.count("gain") > 0){
this->data->gain = params["gain"].double_value();
}
if (params.count("tau") > 0){
this->data->tau = params["tau"].double_value();
}

this->data->FillParameters();
this->data->Recalculate();
Expand Down
16 changes: 8 additions & 8 deletions vrx_gz/src/Wavefield.hh
Original file line number Diff line number Diff line change
Expand Up @@ -77,31 +77,31 @@ namespace vrx
/// * `<topic>` (string, default: "/wavefield/parameters")
/// The topic for publishing wave field updates.
///
/// * `<size>` (Vector2D, default: (1000 1000))
/// * `<size>` (Vector2D, default: (6000 6000))
/// A two component vector for the size of the wave field in each direction.
///
/// * `<cell_count>` (int, default: (50 50))
/// * `<cell_count>` (int, default: (300 300))
/// A two component vector for the number of grid cells in each direction.
///
/// * `<number>` (int, default: 1)
/// * `<number>` (int, default: 3)
/// The number of component waves.
///
/// * `<scale>` (double, default: 2.0)
/// * `<scale>` (double, default: 1.1)
/// The scale between the mean and largest / smallest component waves.
///
/// * `<angle>` (double, default: 2*pi/10)
/// * `<angle>` (double, default: 0.4)
/// The angle between the mean wave direction and the
/// largest / smallest component waves.
///
/// * `<steepness>` (double, default: 1.0)
/// * `<steepness>` (double, default: 0.0)
/// A parameter in [0, 1] controlling the wave steepness with
/// 1 being steepest.
///
/// * `<amplitude>` (double, default: 0.0)
/// The amplitude of the mean wave in [m]. This parameter is only used when
/// model is CWR.
///
/// * `<period>` (double, default: 1.0)
/// * `<period>` (double, default: 5.0)
/// The period of the mean wave in [s].
///
/// * `<phase>` (double, default: 0.0)
Expand All @@ -117,7 +117,7 @@ namespace vrx
/// * `<gain>` (double, default: 1.0)
/// For PMS, the multiplier applied to component amplitudes.
///
/// * `<tau>` (double, default: 1.0)
/// * `<tau>` (double, default: 2.0)
/// Time constant used to gradually increase wavefield at startup.
///
/// ## SDF parameters in secondary mode:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -479,30 +479,6 @@
<plugin filename="libPublisherPlugin.so" name="vrx::PublisherPlugin">
<message type="gz.msgs.Param" topic="/vrx/wavefield/parameters"
every="2.0">
params {
key: "amplitude"
value {
type: DOUBLE
double_value: 0
}
}
params {
key: "angle"
value {
type: DOUBLE
double_value: 0.4
}
}
params {
key: "cell_count"
value {
type: VECTOR3D
vector3d_value {
x: 300
y: 300
}
}
}
params {
key: "direction"
value {
Expand All @@ -519,65 +495,20 @@
double_value: 0.3
}
}
params {
key: "model"
value {
type: STRING
string_value: "PMS"
}
}
params {
key: "number"
value {
type: INT32
int_value: 3
}
}
params {
key: "period"
value {
type: DOUBLE
double_value: 5
}
}
params {
key: "phase"
value {
type: DOUBLE
double_value: 0
}
}
params {
key: "scale"
value {
type: DOUBLE
double_value: 1.1
}
}
params {
key: "size"
value {
type: VECTOR3D
vector3d_value {
x: 6000
y: 6000
}
}
}
params {
key: "steepness"
value {
type: DOUBLE
double_value: 0
}
}
params {
key: "tau"
value {
type: DOUBLE
double_value: 2
}
}
</message>
</plugin>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -479,30 +479,6 @@
<plugin filename="libPublisherPlugin.so" name="vrx::PublisherPlugin">
<message type="gz.msgs.Param" topic="/vrx/wavefield/parameters"
every="2.0">
params {
key: "amplitude"
value {
type: DOUBLE
double_value: 0
}
}
params {
key: "angle"
value {
type: DOUBLE
double_value: 0.4
}
}
params {
key: "cell_count"
value {
type: VECTOR3D
vector3d_value {
x: 300
y: 300
}
}
}
params {
key: "direction"
value {
Expand All @@ -519,65 +495,20 @@
double_value: 0.5
}
}
params {
key: "model"
value {
type: STRING
string_value: "PMS"
}
}
params {
key: "number"
value {
type: INT32
int_value: 3
}
}
params {
key: "period"
value {
type: DOUBLE
double_value: 5
}
}
params {
key: "phase"
value {
type: DOUBLE
double_value: 0
}
}
params {
key: "scale"
value {
type: DOUBLE
double_value: 1.1
}
}
params {
key: "size"
value {
type: VECTOR3D
vector3d_value {
x: 6000
y: 6000
}
}
}
params {
key: "steepness"
value {
type: DOUBLE
double_value: 0
}
}
params {
key: "tau"
value {
type: DOUBLE
double_value: 2
}
}
</message>
</plugin>

Expand Down
Loading