Skip to content

Commit

Permalink
Merge pull request #2 from RBinsonB/feat/improvement
Browse files Browse the repository at this point in the history
Feat/improvement
  • Loading branch information
stevedanomodolor authored Sep 4, 2024
2 parents 03bf4ad + 06020fd commit 8e1a11e
Show file tree
Hide file tree
Showing 14 changed files with 1,229 additions and 715 deletions.
30 changes: 23 additions & 7 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ set(IGNITION_PLUGIN_VER ${ignition-plugin1_VERSION_MAJOR})
set(IGNITION_SIM_VER ${ignition-gazebo6_VERSION_MAJOR})
set(IGNITION_COMMON_VER ${ignition-common4_VERSION_MAJOR})
set(IGNITION_RENDERING_VER ${ignition-rendering6_VERSION_MAJOR})
set(IGNITION_SENSORS_VER ${ignition-sensors6_VERSION_MAJOR})

# Add the plugins directory to the include path
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/Plugins)
Expand All @@ -32,13 +33,13 @@ target_link_libraries(SolarPanelPlugin
PRIVATE ignition-gazebo${IGNITION_SIM_VER}::core
)

# Add the RtgPlugin library
add_library(RtgPlugin SHARED
plugins/RtgPlugin.cc
# Add the RadioisotopeThermalGeneratorPlugin library
add_library(RadioisotopeThermalGeneratorPlugin SHARED
plugins/RadioisotopeThermalGeneratorPlugin.cc
)

# Link the RtgPlugin library with required dependencies
target_link_libraries(RtgPlugin
# Link the RadioisotopeThermalGeneratorPlugin library with required dependencies
target_link_libraries(RadioisotopeThermalGeneratorPlugin
PRIVATE ignition-plugin${IGNITION_PLUGIN_VER}::ignition-plugin${IGNITION_PLUGIN_VER}
PRIVATE ignition-gazebo${IGNITION_SIM_VER}::core
)
Expand All @@ -48,13 +49,28 @@ add_library(RechargeableBatteryPlugin SHARED
plugins/RechargeableBatteryPlugin.cc
)

# Link the SolarPanelPlugin library with required dependencies
# Link the RechargeableBatteryPlugin library with required dependencies
target_link_libraries(RechargeableBatteryPlugin
PRIVATE ignition-plugin${IGNITION_PLUGIN_VER}::ignition-plugin${IGNITION_PLUGIN_VER}
PRIVATE ignition-gazebo${IGNITION_SIM_VER}::core
# PRIVATE ignition-common${IGN_COMMON_VER}::ignition-common${IGNITION_COMMON_VER}
)


# add the SensorPowerSystemPlugin library
add_library(SensorPowerSystemPlugin SHARED
plugins/SensorPowerSystemPlugin.cc
)

# Link the SensorPowerSystemPlugin library with required dependencies
target_link_libraries(SensorPowerSystemPlugin
PRIVATE ignition-plugin${IGNITION_PLUGIN_VER}::ignition-plugin${IGNITION_PLUGIN_VER}
PRIVATE ignition-gazebo${IGNITION_SIM_VER}::core
PRIVATE ignition-gazebo${IGNITION_SIM_VER}::ignition-gazebo${IGNITION_SIM_VER}
PRIVATE ignition-sensors${IGNITION_SENSORS_VER}::ignition-sensors${IGNITION_SENSORS_VER}
)


# Create the models directory
file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/models/curiosity_path)

Expand All @@ -66,7 +82,7 @@ install(DIRECTORY
)

# Install the plugin library
install(TARGETS SolarPanelPlugin RtgPlugin RechargeableBatteryPlugin
install(TARGETS SolarPanelPlugin RadioisotopeThermalGeneratorPlugin RechargeableBatteryPlugin SensorPowerSystemPlugin
ARCHIVE DESTINATION lib
LIBRARY DESTINATION lib
RUNTIME DESTINATION bin
Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,11 @@ The plugin needs to be attached to a model. The link specified by **<link_name>*
- **LOS (Line-Of-Sight)**: If the sun is occulted, no power is supplied by the solar panel plugin. To know if the panel is occulted, the plugin checks the line of sight between the `sun` (by using the `<pose>` element) and the link visual children. The panel solar link needs to have at least one visual element for the plugin to work.
- **Power computation**: The plugin computes the power generated by the panel by checking the angle between the Z-axis of the solar panel link and the `direction` vector of the sun.

### RtgPlugin
### RadioisotopeThermalGeneratorPlugin
The radioisotope thermal generator plugin allows to simulate an RTG power output. It provides a constant power supply.

* Required elements
* **link_name** (`str`) -- The solar panel link in the model
* **link_name** (`str`) -- The RTG link in the model
* **nominal_power** (`float`) -- The constant power in watt generated by the RTG.

* Publications
Expand All @@ -71,7 +71,7 @@ The radioisotope thermal generator plugin allows to simulate an RTG power output
The plugin needs to be attached to a model. Example below:

```XML
<plugin filename="libRtgPlugin.so" name="simulation::RtgPlugin">
<plugin filename="libRadioisotopeThermalGeneratorPlugin.so" name="simulation::RadioisotopeThermalGeneratorPlugin">
<link_name>chassis</link_name>
<nominal_power>100.0</nominal_power>
</plugin>
Expand Down Expand Up @@ -121,7 +121,7 @@ The plugin needs to be attached to a model. Example below:

* The power source topic needs to be on the format `<link_name>/<plugin_power_output_name>`. As of now, the following plugins can provide power to charge the battery:
* **SolarPanelPlugin**: with topic `<link_name>/solar_panel_output`
* **RtgPlugin**: with topic `<link_name>/radioisotope_thermal_generator_output`
* **RadioisotopeThermalGeneratorPlugin**: with topic `<link_name>/radioisotope_thermal_generator_output`

## Models

Expand Down
2 changes: 1 addition & 1 deletion models/curiosity_path/urdf/curiosity_mars_rover.gazebo
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@
<link_name>arm_tools</link_name>
<nominal_power>100.0</nominal_power>
</plugin>
<plugin filename="libRtgPlugin.so" name="simulation::RtgPlugin">
<plugin filename="libRadioisotopeThermalGeneratorPlugin.so" name="simulation::RadioisotopeThermalGeneratorPlugin">
<link_name>chassis</link_name>
<nominal_power>100.0</nominal_power>
</plugin>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,9 @@
<link_name>rear_solar_panel</link_name>
<nominal_power>150.0</nominal_power>
</plugin>
</gazebo>

<plugin filename="libSensorPowerSystemPlugin.so" name="simulation::SensorPowerSystemPlugin">
</plugin>

<plugin filename="libRechargeableBatteryPlugin.so" name="simulation::RechargeableBatteryPlugin">
<battery_name>rechargeable_battery</battery_name>
Expand All @@ -127,6 +129,9 @@
<power_load>11.0</power_load>
<power_draining_topic>/battery/discharge</power_draining_topic>
</plugin>
</gazebo>




<!-- Sensor suit as detailed for NASA VIPER Rover -->
Expand All @@ -135,6 +140,8 @@
<sensor type="camera" name="NavCam_left">
<visualize>1</visualize>
<update_rate>10.0</update_rate>
<power_load>11.0</power_load>
<battery_name>rechargeable_battery</battery_name>
<camera>
<pose>1.0 0 0 0 0 0</pose>
<horizontal_fov>1.22173</horizontal_fov>
Expand All @@ -161,6 +168,8 @@
<sensor type="camera" name="NavCam_right">
<visualize>1</visualize>
<update_rate>10.0</update_rate>
<power_load>12.0</power_load>
<battery_name>rechargeable_battery</battery_name>
<camera>
<pose>1.0 0 0 0 0 0</pose>
<horizontal_fov>1.22173</horizontal_fov>
Expand All @@ -187,6 +196,8 @@
<sensor type="camera" name="AftCam_left">
<visualize>1</visualize>
<update_rate>10.0</update_rate>
<power_load>13.0</power_load>
<battery_name>rechargeable_battery</battery_name>
<camera>
<pose>1.0 0 0 0 0 0</pose>
<horizontal_fov>1.91986</horizontal_fov>
Expand All @@ -213,6 +224,8 @@
<sensor type="camera" name="AftCam_right">
<visualize>1</visualize>
<update_rate>10.0</update_rate>
<power_load>15.0</power_load>
<battery_name>rechargeable_battery</battery_name>
<camera>
<pose>1.0 0 0 0 0 0</pose>
<horizontal_fov>1.91986</horizontal_fov>
Expand Down Expand Up @@ -240,6 +253,8 @@
<always_on>1</always_on>
<update_rate>100</update_rate>
<visualize>true</visualize>
<power_load>16.0</power_load>
<battery_name>rechargeable_battery</battery_name>
<topic>imu</topic>
</sensor>
</gazebo>
Expand Down
121 changes: 121 additions & 0 deletions plugins/RadioisotopeThermalGeneratorPlugin.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
#include "RadioisotopeThermalGeneratorPlugin.hh"

#include <ignition/transport/Node.hh>
#include "ignition/gazebo/Model.hh"

#include <ignition/msgs/double.pb.h>

#include <gz/common/Profiler.hh>

#include <gz/plugin/Register.hh>

using namespace simulation;

/// \brief Private data class for RadioisotopeThermalGeneratorPlugin
class simulation::RadioisotopeThermalGeneratorPluginPrivate
{
/// \brief Name of the link
public:
std::string linkName;

/// \brief Name of the model
public:
std::string modelName;

/// \brief Name of the topic where the data will be published
public:
std::string topicName;

/// \brief Power output of the radioisotope thermal generator
public:
double nominalPower;

/// \brief Ignition communication node
public:
ignition::transport::Node node;

/// \brief Publisher for the radioisotope thermal generator output
public:
ignition::transport::Node::Publisher nominalPowerPub;
};

//////////////////////////////////////////////////
RadioisotopeThermalGeneratorPlugin::RadioisotopeThermalGeneratorPlugin()
: dataPtr(std::make_unique<RadioisotopeThermalGeneratorPluginPrivate>())
{
}

//////////////////////////////////////////////////
RadioisotopeThermalGeneratorPlugin::~RadioisotopeThermalGeneratorPlugin() = default;

//////////////////////////////////////////////////
void RadioisotopeThermalGeneratorPlugin::Configure(const ignition::gazebo::Entity &_entity,
const std::shared_ptr<const sdf::Element> &_sdf,
ignition::gazebo::EntityComponentManager &_ecm,
ignition::gazebo::EventManager &_eventMgr)
{
// Store the pointer to the model the RTG is under
auto model = ignition::gazebo::Model(_entity);
if (!model.Valid(_ecm))
{
ignerr << "Radioisotope Thermal Generator plugin should be attached to a model entity. "
<< "Failed to initialize." << std::endl;
return;
}

this->dataPtr->modelName = model.Name(_ecm);

// Load params
if (_sdf->HasElement("link_name"))
{
this->dataPtr->linkName = _sdf->Get<std::string>("link_name");
this->dataPtr->topicName = "/model/" + this->dataPtr->modelName + "/" + this->dataPtr->linkName + "/radioisotope_thermal_generator_output";
auto validTopic = ignition::transport::TopicUtils::AsValidTopic(this->dataPtr->topicName);
if (validTopic.empty())
{
ignerr << "Failed to create valid topic [" << this->dataPtr->topicName << "]" << std::endl;
return;
}
// Advertise topic where data will be published
this->dataPtr->nominalPowerPub = this->dataPtr->node.Advertise<ignition::msgs::Float>(validTopic);
}
else
{
ignerr << "Radioisotope Thermal Generator plugin should have a <link_name> element. "
<< "Failed to initialize." << std::endl;
return;
}

if (_sdf->HasElement("nominal_power"))
{
this->dataPtr->nominalPower = _sdf->Get<double>("nominal_power");
}
else
{
ignerr << "Radioisotope Thermal Generator plugin should have a <nominal_power> element. "
<< "Failed to initialize." << std::endl;
return;
}
}

//////////////////////////////////////////////////
void RadioisotopeThermalGeneratorPlugin::PostUpdate(const ignition::gazebo::UpdateInfo &_info,
const ignition::gazebo::EntityComponentManager &_ecm)
{
IGN_PROFILE("RadioisotopeThermalGeneratorPlugin::PostUpdate");
if (_info.paused)
{
return;
}
// Publish result
ignition::msgs::Float msg;
msg.set_data(this->dataPtr->nominalPower);
this->dataPtr->nominalPowerPub.Publish(msg);
igndbg << "Published RTG output: " << this->dataPtr->nominalPower << std::endl;
}

IGNITION_ADD_PLUGIN(RadioisotopeThermalGeneratorPlugin, ignition::gazebo::System,
RadioisotopeThermalGeneratorPlugin::ISystemConfigure,
RadioisotopeThermalGeneratorPlugin::ISystemPostUpdate)

IGNITION_ADD_PLUGIN_ALIAS(RadioisotopeThermalGeneratorPlugin, "simulation::RadioisotopeThermalGeneratorPlugin")
50 changes: 50 additions & 0 deletions plugins/RadioisotopeThermalGeneratorPlugin.hh
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#ifndef Radioisotope_Thermal_Generator_Plugin_HH_
#define Radioisotope_Thermal_Generator_Plugin_HH_

#include <memory>
#include <ignition/gazebo/System.hh>

namespace simulation
{

// Forward declaration
class RadioisotopeThermalGeneratorPluginPrivate;

/// \class RadioisotopeThermalGenerator RadioisotopeThermalGenerator.hh
/// \brief Radioisotope Thermal Generator plugin. plugin allows to simulate an radioisotope thermal generator power output. It provides a constant power supply.

/// ## System Parameters
///
/// - `link_name`: The name of the link where the radioisotope thermal generator is attached.
/// - `nominal_power`: The nominal power output of the radioisotope thermal generator.
class RadioisotopeThermalGeneratorPlugin : public ignition::gazebo::System,
public ignition::gazebo::ISystemConfigure,
public ignition::gazebo::ISystemPostUpdate
{

/// \brief Constructor
public:
RadioisotopeThermalGeneratorPlugin();

/// \brief Destructor
public:
~RadioisotopeThermalGeneratorPlugin() override;

/// Documentation inherited
public:
void Configure(const ignition::gazebo::Entity &_entity,
const std::shared_ptr<const sdf::Element> &_sdf,
ignition::gazebo::EntityComponentManager &_ecm,
ignition::gazebo::EventManager &_eventMgr) override;

/// Documentation inherited
public:
void PostUpdate(const ignition::gazebo::UpdateInfo &_info,
const ignition::gazebo::EntityComponentManager &_ecm) final;

/// \brief Private data pointer
private:
std::unique_ptr<RadioisotopeThermalGeneratorPluginPrivate> dataPtr;
};
}
#endif // Radioisotope_Thermal_Generator_Plugin_HH_
Loading

0 comments on commit 8e1a11e

Please sign in to comment.