35void read_message(state_representation::CartesianState& state,
const geometry_msgs::msg::Accel& message);
42void read_message(state_representation::CartesianState& state,
const geometry_msgs::msg::AccelStamped& message);
49void read_message(state_representation::CartesianState& state,
const geometry_msgs::msg::Pose& message);
56void read_message(state_representation::CartesianState& state,
const geometry_msgs::msg::PoseStamped& message);
63void read_message(state_representation::CartesianState& state,
const geometry_msgs::msg::Transform& message);
70void read_message(state_representation::CartesianState& state,
const geometry_msgs::msg::TransformStamped& message);
77void read_message(state_representation::CartesianState& state,
const geometry_msgs::msg::Twist& message);
84void read_message(state_representation::CartesianState& state,
const geometry_msgs::msg::TwistStamped& message);
91void read_message(state_representation::CartesianState& state,
const geometry_msgs::msg::Wrench& message);
98void read_message(state_representation::CartesianState& state,
const geometry_msgs::msg::WrenchStamped& message);
105void read_message(state_representation::JointState& state,
const sensor_msgs::msg::JointState& message);
114template<
typename T,
typename U>
115void read_message(state_representation::Parameter<T>& state,
const U& message) {
116 state.set_value(message.data);
124void read_message(
bool& state,
const std_msgs::msg::Bool& message);
131void read_message(
double& state,
const std_msgs::msg::Float64& message);
138void read_message(std::vector<double>& state,
const std_msgs::msg::Float64MultiArray& message);
145void read_message(
int& state,
const std_msgs::msg::Int32& message);
152void read_message(std::string& state,
const std_msgs::msg::String& message);
164 std::string tmp(message.data.begin(), message.data.end());
165 state = clproto::decode<T>(tmp);
166 }
catch (
const std::exception& ex) {
183 auto derived_state_ptr = std::dynamic_pointer_cast<T>(state);
184 if (derived_state_ptr ==
nullptr) {
186 "Dynamic casting of state " + state->get_name() +
" failed.");
188 return derived_state_ptr;
203 std::shared_ptr<state_representation::State>& state, std::shared_ptr<state_representation::State>& new_state) {
206 *derived_state_ptr = *received_state_ptr;
225template<
typename StateT,
typename NewStateT>
227 std::shared_ptr<state_representation::State>& state, std::shared_ptr<state_representation::State>& new_state,
228 std::function<
void(StateT&,
const NewStateT&)> conversion_callback = {}) {
231 StateT tmp_new_state;
232 tmp_new_state.set_name(derived_new_state_ptr->get_name());
233 tmp_new_state.set_reference_frame(derived_new_state_ptr->get_reference_frame());
234 if (!derived_new_state_ptr->is_empty()) {
235 if (conversion_callback) {
236 conversion_callback(tmp_new_state, *derived_new_state_ptr);
239 *derived_state_ptr = tmp_new_state;
259template<
typename StateT,
typename NewStateT>
261 std::shared_ptr<state_representation::State>& state, std::shared_ptr<state_representation::State>& new_state,
262 std::function<
void(StateT&,
const NewStateT&)> conversion_callback = {}) {
265 StateT tmp_new_state(derived_new_state_ptr->get_name(), derived_new_state_ptr->get_names());
266 if (!derived_new_state_ptr->is_empty()) {
267 if (conversion_callback) {
268 conversion_callback(tmp_new_state, *derived_new_state_ptr);
271 *derived_state_ptr = tmp_new_state;
275inline void read_message(std::shared_ptr<state_representation::State>& state,
const EncodedState& message) {
276 using namespace state_representation;
277 std::string tmp(message.data.begin(), message.data.end());
278 std::shared_ptr<State> new_state;
280 new_state = clproto::decode<std::shared_ptr<State>>(tmp);
281 }
catch (
const std::exception& ex) {
282 throw exceptions::MessageTranslationException(ex.what());
285 switch (state->get_type()) {
286 case StateType::STATE: {
287 if (new_state->get_type() == StateType::STATE) {
290 *state = State(new_state->get_name());
294 case StateType::DIGITAL_IO_STATE: {
295 if (new_state->get_type() == StateType::DIGITAL_IO_STATE) {
297 state, new_state, [](DigitalIOState& a,
const DigitalIOState& b) { a.set_data(b.data()); });
303 case StateType::ANALOG_IO_STATE: {
304 if (new_state->get_type() == StateType::ANALOG_IO_STATE) {
306 state, new_state, [](AnalogIOState& a,
const AnalogIOState& b) { a.set_data(b.data()); });
312 case StateType::SPATIAL_STATE: {
313 std::set<StateType> spatial_state_types = {StateType::SPATIAL_STATE, StateType::CARTESIAN_STATE,
314 StateType::CARTESIAN_POSE, StateType::CARTESIAN_TWIST,
315 StateType::CARTESIAN_ACCELERATION, StateType::CARTESIAN_WRENCH};
316 if (spatial_state_types.find(new_state->get_type()) != spatial_state_types.cend()) {
323 case StateType::CARTESIAN_STATE: {
324 if (new_state->get_type() == StateType::CARTESIAN_POSE) {
326 state, new_state, [](CartesianState& a,
const CartesianPose& b) { a.set_pose(b.get_pose()); });
327 }
else if (new_state->get_type() == StateType::CARTESIAN_TWIST) {
329 state, new_state, [](CartesianState& a,
const CartesianTwist& b) { a.set_twist(b.get_twist()); });
330 }
else if (new_state->get_type() == StateType::CARTESIAN_ACCELERATION) {
333 [](CartesianState& a,
const CartesianAcceleration& b) { a.set_acceleration(b.get_acceleration()); });
334 }
else if (new_state->get_type() == StateType::CARTESIAN_WRENCH) {
336 state, new_state, [](CartesianState& a,
const CartesianWrench& b) { a.set_wrench(b.get_wrench()); });
342 case StateType::CARTESIAN_POSE: {
343 if (new_state->get_type() == StateType::CARTESIAN_STATE) {
345 state, new_state, [](CartesianPose& a,
const CartesianState& b) { a.set_pose(b.get_pose()); });
351 case StateType::CARTESIAN_TWIST: {
352 if (new_state->get_type() == StateType::CARTESIAN_STATE) {
354 state, new_state, [](CartesianTwist& a,
const CartesianState& b) { a.set_twist(b.get_twist()); });
360 case StateType::CARTESIAN_ACCELERATION: {
361 if (new_state->get_type() == StateType::CARTESIAN_STATE) {
364 [](CartesianAcceleration& a,
const CartesianState& b) { a.set_acceleration(b.get_acceleration()); });
370 case StateType::CARTESIAN_WRENCH: {
371 if (new_state->get_type() == StateType::CARTESIAN_STATE) {
373 state, new_state, [](CartesianWrench& a,
const CartesianState& b) { a.set_wrench(b.get_wrench()); });
379 case StateType::JOINT_STATE: {
381 if (new_state->get_type() == StateType::JOINT_POSITIONS) {
383 state, new_state, [](JointState& a,
const JointPositions& b) { a.set_positions(b.get_positions()); });
384 }
else if (new_state->get_type() == StateType::JOINT_VELOCITIES) {
386 state, new_state, [](JointState& a,
const JointVelocities& b) { a.set_velocities(b.get_velocities()); });
387 }
else if (new_state->get_type() == StateType::JOINT_ACCELERATIONS) {
390 [](JointState& a,
const JointAccelerations& b) { a.set_accelerations(b.get_accelerations()); });
391 }
else if (new_state->get_type() == StateType::JOINT_TORQUES) {
393 state, new_state, [](JointState& a,
const JointTorques& b) { a.set_torques(b.get_torques()); });
399 case StateType::JOINT_POSITIONS: {
400 if (new_state->get_type() == StateType::JOINT_STATE) {
402 state, new_state, [](JointPositions& a,
const JointState& b) { a.set_positions(b.get_positions()); });
408 case StateType::JOINT_VELOCITIES: {
409 if (new_state->get_type() == StateType::JOINT_STATE) {
411 state, new_state, [](JointVelocities& a,
const JointState& b) { a.set_velocities(b.get_velocities()); });
417 case StateType::JOINT_ACCELERATIONS: {
418 if (new_state->get_type() == StateType::JOINT_STATE) {
421 [](JointAccelerations& a,
const JointState& b) { a.set_accelerations(b.get_accelerations()); });
427 case StateType::JOINT_TORQUES: {
428 if (new_state->get_type() == StateType::JOINT_STATE) {
430 state, new_state, [](JointTorques& a,
const JointState& b) { a.set_torques(b.get_torques()); });
436 case StateType::JACOBIAN:
439 case StateType::PARAMETER: {
440 auto param_ptr = std::dynamic_pointer_cast<ParameterInterface>(state);
441 switch (param_ptr->get_parameter_type()) {
442 case ParameterType::BOOL:
445 case ParameterType::BOOL_ARRAY:
448 case ParameterType::INT:
451 case ParameterType::INT_ARRAY:
454 case ParameterType::DOUBLE:
457 case ParameterType::DOUBLE_ARRAY:
460 case ParameterType::STRING:
463 case ParameterType::STRING_ARRAY:
466 case ParameterType::VECTOR:
469 case ParameterType::MATRIX:
473 throw exceptions::MessageTranslationException(
474 "The ParameterType contained by parameter " + param_ptr->get_name() +
" is unsupported.");
479 throw exceptions::MessageTranslationException(
480 "The StateType contained by state " + new_state->get_name() +
" is unsupported.");
482 }
catch (
const exceptions::MessageTranslationException& ex) {