Skip to content

Commit

Permalink
Added and registered node
Browse files Browse the repository at this point in the history
  • Loading branch information
maierdev committed Oct 25, 2024
1 parent 41a64e4 commit c36d985
Show file tree
Hide file tree
Showing 3 changed files with 181 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/NodeRegistry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ std::vector<std::string> NAV::NodeRegistry::GetParentNodeDataTypes(const std::st
#include "Nodes/DataProcessor/KalmanFilter/LooselyCoupledKF.hpp"
#include "Nodes/DataProcessor/KalmanFilter/TightlyCoupledKF.hpp"
#include "Nodes/DataProcessor/SensorCombiner/ImuFusion.hpp"
#include "Nodes/DataProcessor/DetectAndAvoid/DetectAndAvoid.hpp"
// Data Provider
#include "Nodes/DataProvider/CSV/CsvFile.hpp"
#include "Nodes/DataProvider/GNSS/FileReader/RinexNavFile.hpp"
Expand Down Expand Up @@ -263,6 +264,7 @@ void NAV::NodeRegistry::RegisterNodeTypes()
registerNodeType<SinglePointPositioning>();
registerNodeType<ImuIntegrator>();
registerNodeType<LooselyCoupledKF>();
registerNodeType<DetectAndAvoid>();
// registerNodeType<TightlyCoupledKF>();
registerNodeType<ImuFusion>();
// Data Provider
Expand Down
102 changes: 102 additions & 0 deletions src/Nodes/DataProcessor/DetectAndAvoid/DetectAndAvoid.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
// This file is part of INSTINCT, the INS Toolkit for Integrated
// Navigation Concepts and Training by the Institute of Navigation of
// the University of Stuttgart, Germany.
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at https://mozilla.org/MPL/2.0/.

#include "DetectAndAvoid.hpp"

#include <imgui.h>
#include <imgui_internal.h>

#include "NodeData/State/PosVelAtt.hpp"
#include "internal/FlowManager.hpp"
#include "internal/Node/Pin.hpp"
#include "internal/NodeManager.hpp"
namespace nm = NAV::NodeManager;
#include "internal/gui/widgets/HelpMarker.hpp"
#include "internal/gui/widgets/imgui_ex.hpp"
#include "internal/gui/widgets/InputWithUnit.hpp"
#include "internal/gui/NodeEditorApplication.hpp"
#include "NodeRegistry.hpp"
#include "util/Logger.hpp"

NAV::DetectAndAvoid::DetectAndAvoid()
: Node(typeStatic())
{
LOG_TRACE("{}: called", name);

_hasConfig = true;
_guiConfigDefaultWindowSize = { 822, 936 }; // TODO: Adapt this, once the node is finished

nm::CreateInputPin(this, "PosVelAttIn", Pin::Type::Flow, { NAV::PosVelAtt::type() }, &DetectAndAvoid::recvPosVelAtt);
nm::CreateOutputPin(this, "PosVelAttOut", Pin::Type::Flow, { PosVelAtt::type() });
}

NAV::DetectAndAvoid::~DetectAndAvoid()
{
LOG_TRACE("{}: called", nameId());
}

std::string NAV::DetectAndAvoid::typeStatic()
{
return "DetectAndAvoid";
}

std::string NAV::DetectAndAvoid::type() const

Check warning on line 48 in src/Nodes/DataProcessor/DetectAndAvoid/DetectAndAvoid.cpp

View check run for this annotation

Codecov / codecov/patch

src/Nodes/DataProcessor/DetectAndAvoid/DetectAndAvoid.cpp#L48

Added line #L48 was not covered by tests
{
return typeStatic();

Check warning on line 50 in src/Nodes/DataProcessor/DetectAndAvoid/DetectAndAvoid.cpp

View check run for this annotation

Codecov / codecov/patch

src/Nodes/DataProcessor/DetectAndAvoid/DetectAndAvoid.cpp#L50

Added line #L50 was not covered by tests
}

std::string NAV::DetectAndAvoid::category()
{
return "Data Processor";
}

void NAV::DetectAndAvoid::guiConfig()

Check warning on line 58 in src/Nodes/DataProcessor/DetectAndAvoid/DetectAndAvoid.cpp

View check run for this annotation

Codecov / codecov/patch

src/Nodes/DataProcessor/DetectAndAvoid/DetectAndAvoid.cpp#L58

Added line #L58 was not covered by tests
{
[[maybe_unused]] float itemWidth = 470 * gui::NodeEditorApplication::windowFontRatio(); // TODO: Adapt this, once the node is finished
[[maybe_unused]] float unitWidth = 180 * gui::NodeEditorApplication::windowFontRatio(); // TODO: Adapt this, once the node is finished
}

Check warning on line 62 in src/Nodes/DataProcessor/DetectAndAvoid/DetectAndAvoid.cpp

View check run for this annotation

Codecov / codecov/patch

src/Nodes/DataProcessor/DetectAndAvoid/DetectAndAvoid.cpp#L60-L62

Added lines #L60 - L62 were not covered by tests

json NAV::DetectAndAvoid::save() const

Check warning on line 64 in src/Nodes/DataProcessor/DetectAndAvoid/DetectAndAvoid.cpp

View check run for this annotation

Codecov / codecov/patch

src/Nodes/DataProcessor/DetectAndAvoid/DetectAndAvoid.cpp#L64

Added line #L64 was not covered by tests
{
LOG_TRACE("{}: called", nameId());

json j;

Check warning on line 68 in src/Nodes/DataProcessor/DetectAndAvoid/DetectAndAvoid.cpp

View check run for this annotation

Codecov / codecov/patch

src/Nodes/DataProcessor/DetectAndAvoid/DetectAndAvoid.cpp#L68

Added line #L68 was not covered by tests

return j;

Check warning on line 70 in src/Nodes/DataProcessor/DetectAndAvoid/DetectAndAvoid.cpp

View check run for this annotation

Codecov / codecov/patch

src/Nodes/DataProcessor/DetectAndAvoid/DetectAndAvoid.cpp#L70

Added line #L70 was not covered by tests
}

void NAV::DetectAndAvoid::restore(json const& /* j */) // TODO: Adapt this, once the node is finished

Check warning on line 73 in src/Nodes/DataProcessor/DetectAndAvoid/DetectAndAvoid.cpp

View check run for this annotation

Codecov / codecov/patch

src/Nodes/DataProcessor/DetectAndAvoid/DetectAndAvoid.cpp#L73

Added line #L73 was not covered by tests
{
LOG_TRACE("{}: called", nameId());
}

Check warning on line 76 in src/Nodes/DataProcessor/DetectAndAvoid/DetectAndAvoid.cpp

View check run for this annotation

Codecov / codecov/patch

src/Nodes/DataProcessor/DetectAndAvoid/DetectAndAvoid.cpp#L76

Added line #L76 was not covered by tests

bool NAV::DetectAndAvoid::initialize()

Check warning on line 78 in src/Nodes/DataProcessor/DetectAndAvoid/DetectAndAvoid.cpp

View check run for this annotation

Codecov / codecov/patch

src/Nodes/DataProcessor/DetectAndAvoid/DetectAndAvoid.cpp#L78

Added line #L78 was not covered by tests
{
LOG_TRACE("{}: called", nameId());

return true;

Check warning on line 82 in src/Nodes/DataProcessor/DetectAndAvoid/DetectAndAvoid.cpp

View check run for this annotation

Codecov / codecov/patch

src/Nodes/DataProcessor/DetectAndAvoid/DetectAndAvoid.cpp#L82

Added line #L82 was not covered by tests
}

void NAV::DetectAndAvoid::deinitialize()

Check warning on line 85 in src/Nodes/DataProcessor/DetectAndAvoid/DetectAndAvoid.cpp

View check run for this annotation

Codecov / codecov/patch

src/Nodes/DataProcessor/DetectAndAvoid/DetectAndAvoid.cpp#L85

Added line #L85 was not covered by tests
{
LOG_TRACE("{}: called", nameId());
}

Check warning on line 88 in src/Nodes/DataProcessor/DetectAndAvoid/DetectAndAvoid.cpp

View check run for this annotation

Codecov / codecov/patch

src/Nodes/DataProcessor/DetectAndAvoid/DetectAndAvoid.cpp#L88

Added line #L88 was not covered by tests

void NAV::DetectAndAvoid::recvPosVelAtt(InputPin::NodeDataQueue& queue, size_t /* pinIdx */)

Check warning on line 90 in src/Nodes/DataProcessor/DetectAndAvoid/DetectAndAvoid.cpp

View check run for this annotation

Codecov / codecov/patch

src/Nodes/DataProcessor/DetectAndAvoid/DetectAndAvoid.cpp#L90

Added line #L90 was not covered by tests
{
auto posVelAtt = std::static_pointer_cast<const PosVelAtt>(queue.extract_front());

invokeCallbackWithPosVelAtt(*posVelAtt);
}

Check warning on line 95 in src/Nodes/DataProcessor/DetectAndAvoid/DetectAndAvoid.cpp

View check run for this annotation

Codecov / codecov/patch

src/Nodes/DataProcessor/DetectAndAvoid/DetectAndAvoid.cpp#L95

Added line #L95 was not covered by tests

void NAV::DetectAndAvoid::invokeCallbackWithPosVelAtt(const PosVelAtt& posVelAtt)

Check warning on line 97 in src/Nodes/DataProcessor/DetectAndAvoid/DetectAndAvoid.cpp

View check run for this annotation

Codecov / codecov/patch

src/Nodes/DataProcessor/DetectAndAvoid/DetectAndAvoid.cpp#L97

Added line #L97 was not covered by tests
{
auto posVelAtt_solution = std::make_shared<PosVelAtt>();
posVelAtt_solution->insTime = posVelAtt.insTime;

Check warning on line 100 in src/Nodes/DataProcessor/DetectAndAvoid/DetectAndAvoid.cpp

View check run for this annotation

Codecov / codecov/patch

src/Nodes/DataProcessor/DetectAndAvoid/DetectAndAvoid.cpp#L100

Added line #L100 was not covered by tests
invokeCallbacks(OUTPUT_PORT_INDEX_SOLUTION, posVelAtt_solution);
}

Check warning on line 102 in src/Nodes/DataProcessor/DetectAndAvoid/DetectAndAvoid.cpp

View check run for this annotation

Codecov / codecov/patch

src/Nodes/DataProcessor/DetectAndAvoid/DetectAndAvoid.cpp#L102

Added line #L102 was not covered by tests
77 changes: 77 additions & 0 deletions src/Nodes/DataProcessor/DetectAndAvoid/DetectAndAvoid.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
// This file is part of INSTINCT, the INS Toolkit for Integrated
// Navigation Concepts and Training by the Institute of Navigation of
// the University of Stuttgart, Germany.
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at https://mozilla.org/MPL/2.0/.

/// @file DetectAndAvoid.hpp
/// @brief Detect-And-Avoid class
/// @author M. Maier ([email protected])
/// @date 2024-10-25

#pragma once

#include <cstddef>
#include "internal/Node/Node.hpp"
#include "NodeData/State/PosVelAtt.hpp"

namespace NAV
{
/// @brief Detect-And-Avoid class
class DetectAndAvoid : public Node
{
public:
/// @brief Default constructor
DetectAndAvoid();
/// @brief Destructor
~DetectAndAvoid() override;
/// @brief Copy constructor
DetectAndAvoid(const DetectAndAvoid&) = delete;
/// @brief Move constructor
DetectAndAvoid(DetectAndAvoid&&) = delete;
/// @brief Copy assignment operator
DetectAndAvoid& operator=(const DetectAndAvoid&) = delete;
/// @brief Move assignment operator
DetectAndAvoid& operator=(DetectAndAvoid&&) = delete;
/// @brief String representation of the class type
[[nodiscard]] static std::string typeStatic();

/// @brief String representation of the class type
[[nodiscard]] std::string type() const override;

/// @brief String representation of the class category
[[nodiscard]] static std::string category();

/// @brief ImGui config window which is shown on double click
/// @attention Don't forget to set _hasConfig to true in the constructor of the node
void guiConfig() override;

/// @brief Saves the node into a json object
[[nodiscard]] json save() const override;

/// @brief Restores the node from a json object
/// @param[in] j Json object with the node state
void restore(const json& j) override;

private:
constexpr static size_t INPUT_PORT_INDEX_POS_VEL_ATT = 0; ///< @brief Flow (PosVelAtt)
constexpr static size_t OUTPUT_PORT_INDEX_SOLUTION = 0; ///< @brief Flow (DaaSolution)

/// @brief Initialize the node
bool initialize() override;

/// @brief Deinitialize the node
void deinitialize() override;

/// @brief Invoke the callback with a PosVelAtt solution
/// @param[in] posVelAtt PosVelAtt solution
void invokeCallbackWithPosVelAtt(const PosVelAtt& posVelAtt);

/// @brief Receive Function for the PosVelAtt observation
/// @param[in] queue Queue with all the received data messages
/// @param[in] pinIdx Index of the pin the data is received on
void recvPosVelAtt(InputPin::NodeDataQueue& queue, size_t pinIdx);
};
} // namespace NAV

0 comments on commit c36d985

Please sign in to comment.