Skip to content

Commit 271c9cb

Browse files
committed
Revert "feat(components): add assignment methods (c++) (#224)"
This reverts commit b8d7f0e.
1 parent 1c1e399 commit 271c9cb

7 files changed

Lines changed: 4 additions & 157 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ Release Versions:
2727

2828
## Upcoming changes
2929

30-
- fix(controllers): remove assignment methods (#240)
30+
- fix: remove assignment methods from C++ components and controllers (#240)
3131

3232
## 5.4.0
3333

source/modulo_components/include/modulo_components/ComponentInterface.hpp

Lines changed: 1 addition & 108 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
#include <modulo_core/exceptions.hpp>
1818
#include <modulo_core/translators/parameter_translators.hpp>
1919

20-
#include <modulo_interfaces/msg/assignment.hpp>
2120
#include <modulo_interfaces/msg/predicate_collection.hpp>
2221
#include <modulo_interfaces/srv/empty_trigger.hpp>
2322
#include <modulo_interfaces/srv/string_trigger.hpp>
@@ -163,34 +162,6 @@ class ComponentInterface {
163162
virtual bool
164163
on_validate_parameter_callback(const std::shared_ptr<state_representation::ParameterInterface>& parameter);
165164

166-
/**
167-
* @brief Add an assignment to the map of assignments.
168-
* @tparam T The type of the assignment
169-
* @param assignment_name the name of the associated assignment
170-
*/
171-
template<typename T>
172-
void add_assignment(const std::string& assignment_name);
173-
174-
/**
175-
* @brief Set the value of an assignment.
176-
* @tparam T The type of the assignment
177-
* @param assignment_name The name of the assignment to set
178-
* @param assignment_value The value of the assignment
179-
*/
180-
template<typename T>
181-
void set_assignment(const std::string& assignment_name, const T& assignment_value);
182-
183-
/**
184-
* @brief Get the value of an assignment.
185-
* @tparam T The type of the assignment
186-
* @param assignment_name The name of the assignment to get
187-
* @throws modulo_core::exceptions::InvalidAssignmentException if the assignment does not exist or the type does not
188-
match
189-
@throws state_representation::exceptions::EmptyStateException if the assignment has not been set yet
190-
*/
191-
template<typename T>
192-
T get_assignment(const std::string& assignment_name) const;
193-
194165
/**
195166
* @brief Add a predicate to the map of predicates.
196167
* @param predicate_name the name of the associated predicate
@@ -500,7 +471,7 @@ class ComponentInterface {
500471
bool validate_parameter(const std::shared_ptr<state_representation::ParameterInterface>& parameter);
501472

502473
/**
503-
* @brief Populate a Predicate message with the name and the value of a predicate.
474+
* @brief Populate a Prediate message with the name and the value of a predicate.
504475
* @param name The name of the predicate
505476
* @param value The value of the predicate
506477
*/
@@ -583,9 +554,6 @@ class ComponentInterface {
583554
modulo_interfaces::msg::PredicateCollection predicate_message_;
584555
std::vector<std::string> triggers_;///< List of triggers
585556

586-
state_representation::ParameterMap assignments_map_; ///< Map of assignments
587-
std::shared_ptr<rclcpp::Publisher<modulo_interfaces::msg::Assignment>> assignment_publisher_;///< Assignment publisher
588-
589557
std::map<std::string, std::shared_ptr<rclcpp::Service<modulo_interfaces::srv::EmptyTrigger>>>
590558
empty_services_;///< Map of EmptyTrigger services
591559
std::map<std::string, std::shared_ptr<rclcpp::Service<modulo_interfaces::srv::StringTrigger>>>
@@ -852,79 +820,4 @@ inline void ComponentInterface::publish_transforms(
852820
"Failed to send " << modifier << "transform: " << ex.what());
853821
}
854822
}
855-
856-
template<typename T>
857-
inline void ComponentInterface::add_assignment(const std::string& assignment_name) {
858-
std::string parsed_name = modulo_utils::parsing::parse_topic_name(assignment_name);
859-
if (parsed_name.empty()) {
860-
RCLCPP_ERROR_STREAM(
861-
this->node_logging_->get_logger(),
862-
"The parsed name for assignment '" + assignment_name
863-
+ "' is empty. Provide a string with valid characters for the assignment name ([a-z0-9_]).");
864-
return;
865-
}
866-
if (assignment_name != parsed_name) {
867-
RCLCPP_WARN_STREAM(
868-
this->node_logging_->get_logger(),
869-
"The parsed name for assignment '" + assignment_name + "' is '" + parsed_name
870-
+ "'. Use the parsed name to refer to this assignment.");
871-
}
872-
try {
873-
this->assignments_map_.get_parameter(parsed_name);
874-
RCLCPP_WARN_STREAM(
875-
this->node_logging_->get_logger(), "Assignment with name '" + parsed_name + "' already exists, overwriting.");
876-
} catch (const state_representation::exceptions::InvalidParameterException& ex) {
877-
RCLCPP_DEBUG_STREAM(this->node_logging_->get_logger(), "Adding assignment '" << parsed_name << "'.");
878-
}
879-
try {
880-
assignments_map_.set_parameter(state_representation::make_shared_parameter<T>(parsed_name));
881-
} catch (const std::exception& ex) {
882-
RCLCPP_ERROR_STREAM_THROTTLE(
883-
this->node_logging_->get_logger(), *this->node_clock_->get_clock(), 1000,
884-
"Failed to add assignment '" << parsed_name << "': " << ex.what());
885-
}
886-
}
887-
888-
template<typename T>
889-
void ComponentInterface::set_assignment(const std::string& assignment_name, const T& assignment_value) {
890-
modulo_interfaces::msg::Assignment message;
891-
std::shared_ptr<state_representation::ParameterInterface> assignment;
892-
try {
893-
assignment = this->assignments_map_.get_parameter(assignment_name);
894-
} catch (const state_representation::exceptions::InvalidParameterException&) {
895-
RCLCPP_ERROR_STREAM_THROTTLE(
896-
this->node_logging_->get_logger(), *this->node_clock_->get_clock(), 1000,
897-
"Failed to set assignment '" << assignment_name << "': Assignment does not exist.");
898-
return;
899-
}
900-
try {
901-
assignment->set_parameter_value<T>(assignment_value);
902-
} catch (const state_representation::exceptions::InvalidParameterCastException&) {
903-
RCLCPP_ERROR_STREAM_THROTTLE(
904-
this->node_logging_->get_logger(), *this->node_clock_->get_clock(), 1000,
905-
"Failed to set assignment '" << assignment_name << "': Incompatible value type.");
906-
return;
907-
}
908-
message.node = this->node_base_->get_fully_qualified_name();
909-
message.assignment = modulo_core::translators::write_parameter(assignment).to_parameter_msg();
910-
this->assignment_publisher_->publish(message);
911-
}
912-
913-
template<typename T>
914-
T ComponentInterface::get_assignment(const std::string& assignment_name) const {
915-
std::shared_ptr<state_representation::ParameterInterface> assignment;
916-
try {
917-
assignment = this->assignments_map_.get_parameter(assignment_name);
918-
} catch (const state_representation::exceptions::InvalidParameterException&) {
919-
throw modulo_core::exceptions::InvalidAssignmentException(
920-
"Failed to get value of assignment '" + assignment_name + "': Assignment does not exist.");
921-
}
922-
try {
923-
return assignment->get_parameter_value<T>();
924-
} catch (const state_representation::exceptions::InvalidParameterCastException&) {
925-
auto expected_type = state_representation::get_parameter_type_name(assignment->get_parameter_type());
926-
throw modulo_core::exceptions::InvalidAssignmentException(
927-
"Incompatible type for assignment '" + assignment_name + "' defined with type '" + expected_type + "'.");
928-
}
929-
}
930823
}// namespace modulo_components

source/modulo_components/src/ComponentInterface.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,6 @@ ComponentInterface::ComponentInterface(
2828
});
2929
this->add_parameter("rate", 10.0, "The rate in Hertz for all periodic callbacks", true);
3030

31-
this->assignment_publisher_ = rclcpp::create_publisher<modulo_interfaces::msg::Assignment>(
32-
this->node_parameters_, this->node_topics_, "/assignments", this->qos_);
33-
3431
this->predicate_publisher_ = rclcpp::create_publisher<modulo_interfaces::msg::PredicateCollection>(
3532
this->node_parameters_, this->node_topics_, "/predicates", this->qos_);
3633
this->predicate_message_.node = this->node_base_->get_fully_qualified_name();

source/modulo_components/test/cpp/include/test_modulo_components/component_public_interfaces.hpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ class ComponentInterfacePublicInterface : public ComponentInterface {
2121
using ComponentInterface::add_input;
2222
using ComponentInterface::add_parameter;
2323
using ComponentInterface::add_predicate;
24-
using ComponentInterface::add_assignment;
2524
using ComponentInterface::add_service;
2625
using ComponentInterface::add_static_tf_broadcaster;
2726
using ComponentInterface::add_tf_broadcaster;
@@ -31,7 +30,6 @@ class ComponentInterfacePublicInterface : public ComponentInterface {
3130
using ComponentInterface::declare_input;
3231
using ComponentInterface::declare_output;
3332
using ComponentInterface::empty_services_;
34-
using ComponentInterface::get_assignment;
3533
using ComponentInterface::get_parameter;
3634
using ComponentInterface::get_parameter_value;
3735
using ComponentInterface::get_predicate;
@@ -46,15 +44,13 @@ class ComponentInterfacePublicInterface : public ComponentInterface {
4644
using ComponentInterface::parameter_map_;
4745
using ComponentInterface::periodic_outputs_;
4846
using ComponentInterface::predicates_;
49-
using ComponentInterface::assignments_map_;
5047
using ComponentInterface::publish_output;
5148
using ComponentInterface::raise_error;
5249
using ComponentInterface::remove_input;
5350
using ComponentInterface::send_static_transform;
5451
using ComponentInterface::send_static_transforms;
5552
using ComponentInterface::send_transform;
5653
using ComponentInterface::send_transforms;
57-
using ComponentInterface::set_assignment;
5854
using ComponentInterface::set_parameter_value;
5955
using ComponentInterface::set_predicate;
6056
using ComponentInterface::set_qos;

source/modulo_components/test/cpp/test_component_interface.cpp

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
#include <modulo_utils/testutils/ServiceClient.hpp>
88

99
#include "test_modulo_components/component_public_interfaces.hpp"
10-
#include "state_representation/exceptions/EmptyStateException.hpp"
1110

1211
#include <sensor_msgs/msg/image.hpp>
1312

@@ -42,35 +41,6 @@ class ComponentInterfaceTest : public ::testing::Test {
4241
using NodeTypes = ::testing::Types<rclcpp::Node, rclcpp_lifecycle::LifecycleNode>;
4342
TYPED_TEST_SUITE(ComponentInterfaceTest, NodeTypes);
4443

45-
TYPED_TEST(ComponentInterfaceTest, AddAssignment) {
46-
this->component_->template add_assignment<int>("an_assignment");
47-
// adding an assignment with empty name should fail
48-
EXPECT_NO_THROW(this->component_->template add_assignment<int>(""));
49-
// adding an assignment with the same name should just overwrite
50-
this->component_->template add_assignment<int>("an_assignment");
51-
EXPECT_EQ(this->component_->assignments_map_.get_parameter_list().size(), 1);
52-
// names should be cleaned up
53-
EXPECT_NO_THROW(this->component_->template add_assignment<int>("7cleEaGn_AaSssiGNgn#ment"));
54-
EXPECT_EQ(this->component_->assignments_map_.get_parameter_list().size(), 2);
55-
// names without valid characters should fail
56-
EXPECT_NO_THROW(this->component_->template add_assignment<int>("@@@@@@"));
57-
EXPECT_EQ(this->component_->assignments_map_.get_parameter_list().size(), 2);
58-
}
59-
60-
TYPED_TEST(ComponentInterfaceTest, GetSetAssignment) {
61-
this->component_->template add_assignment<int>("int_assignment");
62-
63-
EXPECT_THROW(this->component_->template get_assignment<int>("non_existent"), modulo_core::exceptions::InvalidAssignmentException);
64-
EXPECT_NO_THROW(this->component_->set_assignment("non_existent", 5));
65-
66-
EXPECT_THROW(this->component_->template get_assignment<int>("int_assignment"), state_representation::exceptions::EmptyStateException);
67-
EXPECT_NO_THROW(this->component_->set_assignment("int_assignment", 5));
68-
EXPECT_NO_THROW(this->component_->set_assignment("int_assignment", std::string("test")));
69-
70-
EXPECT_EQ(this->component_->template get_assignment<int>("int_assignment"), 5);
71-
EXPECT_THROW(this->component_->template get_assignment<std::string>("int_assignment"), modulo_core::exceptions::InvalidAssignmentException);
72-
}
73-
7444
TYPED_TEST(ComponentInterfaceTest, AddBoolPredicate) {
7545
this->component_->add_predicate("foo", true);
7646
auto predicate_iterator = this->component_->predicates_.find("foo");

source/modulo_core/include/modulo_core/exceptions.hpp

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -42,16 +42,6 @@ class AddSignalException : public CoreException {
4242
explicit AddSignalException(const std::string& msg) : CoreException("AddSignalException", msg) {}
4343
};
4444

45-
/**
46-
* @class InvalidAssignmentException
47-
* @brief An exception class to notify errors when getting the value of an assignment.
48-
* @details This is an exception class to be thrown if there is a problem while getting the value of an assignment in a modulo class.
49-
*/
50-
class InvalidAssignmentException : public CoreException {
51-
public:
52-
explicit InvalidAssignmentException(const std::string& msg) : CoreException("InvalidAssignmentException", msg) {}
53-
};
54-
5545
/**
5646
* @class InvalidPointerCastException
5747
* @brief An exception class to notify if the result of getting an instance of a derived class through dynamic
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
string node
2-
rcl_interfaces/Parameter assignment
2+
string assignment
3+
rcl_interfaces/ParameterValue value

0 commit comments

Comments
 (0)