3#include <google/protobuf/util/json_util.h>
4#include <google/protobuf/util/type_resolver_util.h>
6#include "clproto/encoders.h"
7#include "clproto/decoders.h"
9#include <state_representation/State.hpp>
10#include <state_representation/parameters/Parameter.hpp>
11#include <state_representation/space/SpatialState.hpp>
12#include <state_representation/space/cartesian/CartesianState.hpp>
13#include <state_representation/space/cartesian/CartesianPose.hpp>
14#include <state_representation/space/cartesian/CartesianTwist.hpp>
15#include <state_representation/space/cartesian/CartesianAcceleration.hpp>
16#include <state_representation/space/cartesian/CartesianWrench.hpp>
17#include <state_representation/space/Jacobian.hpp>
18#include <state_representation/space/joint/JointState.hpp>
19#include <state_representation/space/joint/JointPositions.hpp>
20#include <state_representation/space/joint/JointVelocities.hpp>
21#include <state_representation/space/joint/JointAccelerations.hpp>
22#include <state_representation/space/joint/JointTorques.hpp>
24#include "state_representation/state_message.pb.h"
30DecodingException::DecodingException(
const std::string& msg) : std::runtime_error(msg) {}
32JsonParsingException::JsonParsingException(
const std::string& msg) : std::runtime_error(msg) {}
39 if (proto::StateMessage message; message.ParseFromString(msg)) {
40 return static_cast<MessageType>(message.message_type_case());
58 return MessageType::UNKNOWN_MESSAGE;
62 if (proto::StateMessage message; message.ParseFromString(msg) && message.has_parameter()) {
63 return static_cast<ParameterMessageType>(message.parameter().parameter_value().value_type_case());
65 return ParameterMessageType::UNKNOWN_PARAMETER;
70void pack_fields(
const std::vector<std::string>& fields,
char* data) {
71 std::size_t index = 0;
81 for (std::size_t field = 0; field < nfields; ++field) {
82 sizes[field] =
static_cast<field_length_t>(fields.at(field).size());
88 for (std::size_t field = 0; field < nfields; ++field) {
89 memcpy(&data[index], fields.at(field).c_str(), sizes[field]);
90 index += sizes[field];
95 std::size_t index = 0;
98 char field_buffer[CLPROTO_PACKING_MAX_FIELD_LENGTH];
99 std::vector<std::string> fields;
110 for (std::size_t field = 0; field < nfields; ++field) {
111 memcpy(field_buffer, &data[index], sizes[field]);
112 fields.emplace_back(std::string(field_buffer, sizes[field]));
113 index += sizes[field];
123 auto resolver = std::unique_ptr<google::protobuf::util::TypeResolver>{
124 google::protobuf::util::NewTypeResolverForDescriptorPool(
125 "", google::protobuf::DescriptorPool::generated_pool())
128 auto status = google::protobuf::util::BinaryToJsonString(
129 resolver.get(),
"/state_representation.proto.StateMessage", msg, std::addressof(json));
131 if (!status.ok() || json.size() <= 2) {
132 throw JsonParsingException(
"Could not parse the binary data into a JSON formatted state message");
140 auto resolver = std::unique_ptr<google::protobuf::util::TypeResolver>{
141 google::protobuf::util::NewTypeResolverForDescriptorPool(
142 "", google::protobuf::DescriptorPool::generated_pool())
145 auto status = google::protobuf::util::JsonToBinaryString(
146 resolver.get(),
"/state_representation.proto.StateMessage", json, std::addressof(msg));
159std::string encode<State>(
const State& obj);
161State decode(
const std::string& msg);
163bool decode(
const std::string& msg,
State& obj);
165std::string encode<State>(
const State& obj) {
166 proto::StateMessage message;
167 *message.mutable_state() = encoder(obj);
168 return message.SerializeAsString();
174 throw DecodingException(
"Could not decode the message into a State");
181 proto::StateMessage message;
182 if (!(message.ParseFromString(msg)
183 && message.message_type_case() == proto::StateMessage::MessageTypeCase::kState)) {
187 auto state = message.state();
188 obj =
State(
decoder(state.type()), state.name(), state.empty());
189 std::chrono::time_point<std::chrono::steady_clock> timepoint(
timestamp_duration_t(state.timestamp()));
202std::string encode<SpatialState>(
const SpatialState& obj);
208std::string encode<SpatialState>(
const SpatialState& obj) {
209 proto::StateMessage message;
210 *message.mutable_spatial_state() =
encoder(obj);
211 return message.SerializeAsString();
217 throw DecodingException(
"Could not decode the message into a SpatialState");
224 proto::StateMessage message;
225 if (!(message.ParseFromString(msg)
226 && message.message_type_case() == proto::StateMessage::MessageTypeCase::kSpatialState)) {
230 auto spatial_state = message.spatial_state();
232 decoder(spatial_state.state().type()), spatial_state.state().name(), spatial_state.reference_frame(),
233 spatial_state.state().empty());
252 proto::StateMessage message;
253 *message.mutable_cartesian_state() =
encoder(obj);
254 return message.SerializeAsString();
260 throw DecodingException(
"Could not decode the message into a CartesianState");
267 proto::StateMessage message;
268 if (!(message.ParseFromString(msg)
269 && message.message_type_case() == proto::StateMessage::MessageTypeCase::kCartesianState)) {
273 auto state = message.cartesian_state();
274 obj.
set_name(state.spatial_state().state().name());
284 obj.
set_empty(state.spatial_state().state().empty());
302 proto::StateMessage message;
304 *message.mutable_cartesian_pose()->mutable_spatial_state() = cartesian_state.spatial_state();
305 *message.mutable_cartesian_pose()->mutable_position() = cartesian_state.position();
306 *message.mutable_cartesian_pose()->mutable_orientation() = cartesian_state.orientation();
307 return message.SerializeAsString();
313 throw DecodingException(
"Could not decode the message into a CartesianPose");
320 proto::StateMessage message;
321 if (!(message.ParseFromString(msg)
322 && message.message_type_case() == proto::StateMessage::MessageTypeCase::kCartesianPose)) {
325 auto pose = message.cartesian_pose();
326 obj.
set_name(pose.spatial_state().state().name());
330 obj.
set_empty(pose.spatial_state().state().empty());
348 proto::StateMessage message;
350 *message.mutable_cartesian_twist()->mutable_spatial_state() = cartesian_state.spatial_state();
351 *message.mutable_cartesian_twist()->mutable_linear_velocity() = cartesian_state.linear_velocity();
352 *message.mutable_cartesian_twist()->mutable_angular_velocity() = cartesian_state.angular_velocity();
353 return message.SerializeAsString();
359 throw DecodingException(
"Could not decode the message into a CartesianTwist");
366 proto::StateMessage message;
367 if (!(message.ParseFromString(msg)
368 && message.message_type_case() == proto::StateMessage::MessageTypeCase::kCartesianTwist)) {
371 auto twist = message.cartesian_twist();
372 obj.
set_name(twist.spatial_state().state().name());
376 obj.
set_empty(twist.spatial_state().state().empty());
394 proto::StateMessage message;
396 *message.mutable_cartesian_acceleration()->mutable_spatial_state() = cartesian_state.spatial_state();
397 *message.mutable_cartesian_acceleration()->mutable_linear_acceleration() = cartesian_state.linear_acceleration();
398 *message.mutable_cartesian_acceleration()->mutable_angular_acceleration() = cartesian_state.angular_acceleration();
399 return message.SerializeAsString();
405 throw DecodingException(
"Could not decode the message into a CartesianAcceleration");
412 proto::StateMessage message;
413 if (!(message.ParseFromString(msg)
414 && message.message_type_case() == proto::StateMessage::MessageTypeCase::kCartesianAcceleration)) {
417 auto acceleration = message.cartesian_acceleration();
418 obj.
set_name(acceleration.spatial_state().state().name());
422 obj.
set_empty(acceleration.spatial_state().state().empty());
440 proto::StateMessage message;
442 *message.mutable_cartesian_wrench()->mutable_spatial_state() = cartesian_state.spatial_state();
443 *message.mutable_cartesian_wrench()->mutable_force() = cartesian_state.force();
444 *message.mutable_cartesian_wrench()->mutable_torque() = cartesian_state.torque();
445 return message.SerializeAsString();
451 throw DecodingException(
"Could not decode the message into a CartesianWrench");
458 proto::StateMessage message;
459 if (!(message.ParseFromString(msg)
460 && message.message_type_case() == proto::StateMessage::MessageTypeCase::kCartesianWrench)) {
463 auto wrench = message.cartesian_wrench();
464 obj.
set_name(wrench.spatial_state().state().name());
468 obj.
set_empty(wrench.spatial_state().state().empty());
479std::string encode<Jacobian>(
const Jacobian& obj);
485std::string encode<Jacobian>(
const Jacobian& obj) {
486 proto::StateMessage message;
487 *message.mutable_jacobian() =
encoder(obj);
488 return message.SerializeAsString();
494 throw DecodingException(
"Could not decode the message into a Jacobian");
501 proto::StateMessage message;
502 if (!(message.ParseFromString(msg)
503 && message.message_type_case() == proto::StateMessage::MessageTypeCase::kJacobian)) {
507 auto jacobian = message.jacobian();
509 jacobian.state().name(),
decoder(jacobian.joint_names()), jacobian.frame(), jacobian.reference_frame());
510 if (!jacobian.state().empty() && !jacobian.data().empty()) {
511 auto raw_data =
const_cast<double*
>(jacobian.data().data());
512 auto data = Eigen::Map<Eigen::MatrixXd>(raw_data, jacobian.rows(), jacobian.cols());
527std::string encode<JointState>(
const JointState& obj);
533std::string encode<JointState>(
const JointState& obj) {
534 proto::StateMessage message;
535 *message.mutable_joint_state() =
encoder(obj);
536 return message.SerializeAsString();
542 throw DecodingException(
"Could not decode the message into a JointState");
549 proto::StateMessage message;
550 if (!(message.ParseFromString(msg)
551 && message.message_type_case() == proto::StateMessage::MessageTypeCase::kJointState)) {
555 auto state = message.joint_state();
579 proto::StateMessage message;
581 *message.mutable_joint_positions()->mutable_state() = joint_state.state();
582 *message.mutable_joint_positions()->mutable_joint_names() = joint_state.joint_names();
583 *message.mutable_joint_positions()->mutable_positions() = joint_state.positions();
584 return message.SerializeAsString();
590 throw DecodingException(
"Could not decode the message into a JointPositions");
597 proto::StateMessage message;
598 if (!(message.ParseFromString(msg)
599 && message.message_type_case() == proto::StateMessage::MessageTypeCase::kJointPositions)) {
603 auto state = message.joint_positions();
624 proto::StateMessage message;
626 *message.mutable_joint_velocities()->mutable_state() = joint_state.state();
627 *message.mutable_joint_velocities()->mutable_joint_names() = joint_state.joint_names();
628 *message.mutable_joint_velocities()->mutable_velocities() = joint_state.velocities();
629 return message.SerializeAsString();
635 throw DecodingException(
"Could not decode the message into a JointVelocities");
642 proto::StateMessage message;
643 if (!(message.ParseFromString(msg)
644 && message.message_type_case() == proto::StateMessage::MessageTypeCase::kJointVelocities)) {
648 auto state = message.joint_velocities();
669 proto::StateMessage message;
671 *message.mutable_joint_accelerations()->mutable_state() = joint_state.state();
672 *message.mutable_joint_accelerations()->mutable_joint_names() = joint_state.joint_names();
673 *message.mutable_joint_accelerations()->mutable_accelerations() = joint_state.accelerations();
674 return message.SerializeAsString();
680 throw DecodingException(
"Could not decode the message into a JointAccelerations");
687 proto::StateMessage message;
688 if (!(message.ParseFromString(msg)
689 && message.message_type_case() == proto::StateMessage::MessageTypeCase::kJointAccelerations)) {
693 auto state = message.joint_accelerations();
707std::string encode<JointTorques>(
const JointTorques& obj);
713std::string encode<JointTorques>(
const JointTorques& obj) {
714 proto::StateMessage message;
716 *message.mutable_joint_torques()->mutable_state() = joint_state.state();
717 *message.mutable_joint_torques()->mutable_joint_names() = joint_state.joint_names();
718 *message.mutable_joint_torques()->mutable_torques() = joint_state.torques();
719 return message.SerializeAsString();
725 throw DecodingException(
"Could not decode the message into a JointTorques");
732 proto::StateMessage message;
733 if (!(message.ParseFromString(msg)
734 && message.message_type_case() == proto::StateMessage::MessageTypeCase::kJointTorques)) {
738 auto state = message.joint_torques();
752static std::string encode_parameter(
const Parameter<T>& obj);
754static Parameter<T> decode_parameter(
const std::string& msg);
756static bool decode_parameter(
const std::string& msg,
Parameter<T>& obj);
759static std::string encode_parameter(
const Parameter<T>& obj) {
760 proto::StateMessage message;
761 *message.mutable_parameter() = encoder<T>(obj);
763 message.mutable_parameter()->mutable_state()->set_empty(
true);
765 return message.SerializeAsString();
768static Parameter<T> decode_parameter(
const std::string& msg) {
771 throw DecodingException(
"Could not decode the message into a Parameter");
776static bool decode_parameter(
const std::string& msg,
Parameter<T>& obj) {
778 proto::StateMessage message;
779 if (!(message.ParseFromString(msg)
780 && message.message_type_case() == proto::StateMessage::MessageTypeCase::kParameter)) {
783 obj = decoder<T>(message.parameter());
784 if (message.parameter().state().empty()) {
804 return encode_parameter(obj);
808 return decode_parameter<int>(msg);
812 return decode_parameter(msg, obj);
826 return encode_parameter(obj);
830 return decode_parameter<std::vector<int>>(msg);
834 return decode_parameter(msg, obj);
848 return encode_parameter(obj);
852 return decode_parameter<double>(msg);
856 return decode_parameter(msg, obj);
867bool decode(
const std::string& msg,
Parameter<std::vector<double>>& obj);
870 return encode_parameter(obj);
874 return decode_parameter<std::vector<double>>(msg);
877bool decode(
const std::string& msg,
Parameter<std::vector<double>>& obj) {
878 return decode_parameter(msg, obj);
892 return encode_parameter(obj);
896 return decode_parameter<bool>(msg);
900 return decode_parameter(msg, obj);
914 return encode_parameter(obj);
918 return decode_parameter<std::vector<bool>>(msg);
921bool decode(
const std::string& msg,
Parameter<std::vector<bool>>& obj) {
922 return decode_parameter(msg, obj);
936 return encode_parameter(obj);
940 return decode_parameter<std::string>(msg);
944 return decode_parameter(msg, obj);
955bool decode(
const std::string& msg,
Parameter<std::vector<std::string>>& obj);
958 return encode_parameter(obj);
962 return decode_parameter<std::vector<std::string>>(msg);
965bool decode(
const std::string& msg,
Parameter<std::vector<std::string>>& obj) {
966 return decode_parameter(msg, obj);
980 return encode_parameter(obj);
984 return decode_parameter<Eigen::VectorXd>(msg);
988 return decode_parameter(msg, obj);
1002 return encode_parameter(obj);
1006 return decode_parameter<Eigen::MatrixXd>(msg);
1010 return decode_parameter(msg, obj);
1017std::shared_ptr<T> safe_dynamic_pointer_cast(
const std::shared_ptr<State>& state) {
1018 auto new_state = std::dynamic_pointer_cast<T>(state);
1019 if (new_state ==
nullptr) {
1020 throw std::invalid_argument(
"Dynamic pointer casting of state failed.");
1025template<> std::string encode<std::shared_ptr<State>>(
const std::shared_ptr<State>& obj);
1026template<> std::shared_ptr<State>
decode(
const std::string& msg);
1027template<>
bool decode(
const std::string& msg, std::shared_ptr<State>& obj);
1028template<> std::string encode<std::shared_ptr<State>>(
const std::shared_ptr<State>& obj) {
1029 std::string message;
1031 case StateType::STATE:
1032 message = encode<State>(*obj);
1034 case StateType::SPATIAL_STATE:
1035 message = encode<SpatialState>(*safe_dynamic_pointer_cast<SpatialState>(obj));
1037 case StateType::CARTESIAN_STATE:
1038 message = encode<CartesianState>(*safe_dynamic_pointer_cast<CartesianState>(obj));
1040 case StateType::CARTESIAN_POSE:
1041 message = encode<CartesianPose>(*safe_dynamic_pointer_cast<CartesianPose>(obj));
1043 case StateType::CARTESIAN_TWIST:
1044 message = encode<CartesianTwist>(*safe_dynamic_pointer_cast<CartesianTwist>(obj));
1046 case StateType::CARTESIAN_ACCELERATION:
1047 message = encode<CartesianAcceleration>(*safe_dynamic_pointer_cast<CartesianAcceleration>(obj));
1049 case StateType::CARTESIAN_WRENCH:
1050 message = encode<CartesianWrench>(*safe_dynamic_pointer_cast<CartesianWrench>(obj));
1052 case StateType::JOINT_STATE:
1053 message = encode<JointState>(*safe_dynamic_pointer_cast<JointState>(obj));
1055 case StateType::JOINT_POSITIONS:
1056 message = encode<JointPositions>(*safe_dynamic_pointer_cast<JointPositions>(obj));
1058 case StateType::JOINT_VELOCITIES:
1059 message = encode<JointVelocities>(*safe_dynamic_pointer_cast<JointVelocities>(obj));
1061 case StateType::JOINT_ACCELERATIONS:
1062 message = encode<JointAccelerations>(*safe_dynamic_pointer_cast<JointAccelerations>(obj));
1064 case StateType::JOINT_TORQUES:
1065 message = encode<JointTorques>(*safe_dynamic_pointer_cast<JointTorques>(obj));
1067 case StateType::JACOBIAN:
1068 message = encode<Jacobian>(*safe_dynamic_pointer_cast<Jacobian>(obj));
1070 case StateType::PARAMETER: {
1071 auto param_ptr = safe_dynamic_pointer_cast<ParameterInterface>(obj);
1072 switch (param_ptr->get_parameter_type()) {
1073 case ParameterType::BOOL:
1074 message = encode<Parameter<bool>>(*safe_dynamic_pointer_cast<Parameter<bool>>(param_ptr));
1076 case ParameterType::BOOL_ARRAY:
1077 message = encode<Parameter<std::vector<bool>>>(*safe_dynamic_pointer_cast<Parameter<std::vector<bool>>>(param_ptr));
1079 case ParameterType::INT:
1080 message = encode<Parameter<int>>(*safe_dynamic_pointer_cast<Parameter<int>>(param_ptr));
1082 case ParameterType::INT_ARRAY:
1083 message = encode<Parameter<std::vector<int>>>(*safe_dynamic_pointer_cast<Parameter<std::vector<int>>>(param_ptr));
1085 case ParameterType::DOUBLE:
1086 message = encode<Parameter<double>>(*safe_dynamic_pointer_cast<Parameter<double>>(param_ptr));
1088 case ParameterType::DOUBLE_ARRAY:
1089 message = encode<Parameter<std::vector<double>>>(*safe_dynamic_pointer_cast<Parameter<std::vector<double>>>(param_ptr));
1091 case ParameterType::STRING:
1092 message = encode<Parameter<std::string>>(*safe_dynamic_pointer_cast<Parameter<std::string>>(param_ptr));
1094 case ParameterType::STRING_ARRAY:
1095 message = encode<Parameter<std::vector<std::string>>>(*safe_dynamic_pointer_cast<Parameter<std::vector<std::string>>>(param_ptr));
1097 case ParameterType::VECTOR:
1098 message = encode<Parameter<Eigen::VectorXd>>(*safe_dynamic_pointer_cast<Parameter<Eigen::VectorXd>>(param_ptr));
1100 case ParameterType::MATRIX:
1101 message = encode<Parameter<Eigen::MatrixXd>>(*safe_dynamic_pointer_cast<Parameter<Eigen::MatrixXd>>(param_ptr));
1104 throw std::invalid_argument(
"The ParameterType contained by parameter " + param_ptr->get_name() +
" is unsupported.");
1110 throw std::invalid_argument(
"The StateType contained by state " + obj->
get_name() +
" is unsupported.");
1115template<> std::shared_ptr<State>
decode(
const std::string& msg) {
1116 std::shared_ptr<State> obj;
1118 case MessageType::STATE_MESSAGE:
1119 obj = make_shared_state(
State());
1121 case MessageType::SPATIAL_STATE_MESSAGE:
1124 case MessageType::CARTESIAN_STATE_MESSAGE:
1127 case MessageType::CARTESIAN_POSE_MESSAGE:
1130 case MessageType::CARTESIAN_TWIST_MESSAGE:
1133 case MessageType::CARTESIAN_ACCELERATION_MESSAGE:
1136 case MessageType::CARTESIAN_WRENCH_MESSAGE:
1139 case MessageType::JOINT_STATE_MESSAGE:
1142 case MessageType::JOINT_POSITIONS_MESSAGE:
1145 case MessageType::JOINT_VELOCITIES_MESSAGE:
1148 case MessageType::JOINT_ACCELERATIONS_MESSAGE:
1151 case MessageType::JOINT_TORQUES_MESSAGE:
1154 case MessageType::JACOBIAN_MESSAGE:
1155 obj = make_shared_state(
Jacobian());
1157 case MessageType::PARAMETER_MESSAGE: {
1159 case ParameterMessageType::BOOL:
1162 case ParameterMessageType::BOOL_ARRAY:
1163 obj = make_shared_state(
Parameter<std::vector<bool>>(
""));
1165 case ParameterMessageType::INT:
1168 case ParameterMessageType::INT_ARRAY:
1169 obj = make_shared_state(
Parameter<std::vector<int>>(
""));
1171 case ParameterMessageType::DOUBLE:
1174 case ParameterMessageType::DOUBLE_ARRAY:
1175 obj = make_shared_state(
Parameter<std::vector<double>>(
""));
1177 case ParameterMessageType::STRING:
1180 case ParameterMessageType::STRING_ARRAY:
1181 obj = make_shared_state(
Parameter<std::vector<std::string>>(
""));
1183 case ParameterMessageType::VECTOR:
1186 case ParameterMessageType::MATRIX:
1190 throw std::invalid_argument(
"The ParameterMessageType contained by this message is unsupported.");
1196 throw std::invalid_argument(
"The MessageType contained by this message is unsupported.");
1200 throw DecodingException(
"Could not decode the message into a std::shared_ptr<State>");
1204template<>
bool decode(
const std::string& msg, std::shared_ptr<State>& obj) {
1206 switch (obj->get_type()) {
1207 case StateType::STATE:
1208 obj = make_shared_state(decode<State>(msg));
1210 case StateType::SPATIAL_STATE:
1211 obj = make_shared_state(decode<SpatialState>(msg));
1213 case StateType::CARTESIAN_STATE:
1214 obj = make_shared_state(decode<CartesianState>(msg));
1216 case StateType::CARTESIAN_POSE:
1217 obj = make_shared_state(decode<CartesianPose>(msg));
1219 case StateType::CARTESIAN_TWIST:
1220 obj = make_shared_state(decode<CartesianTwist>(msg));
1222 case StateType::CARTESIAN_ACCELERATION:
1223 obj = make_shared_state(decode<CartesianAcceleration>(msg));
1225 case StateType::CARTESIAN_WRENCH:
1226 obj = make_shared_state(decode<CartesianWrench>(msg));
1228 case StateType::JOINT_STATE:
1229 obj = make_shared_state(decode<JointState>(msg));
1231 case StateType::JOINT_POSITIONS:
1232 obj = make_shared_state(decode<JointPositions>(msg));
1234 case StateType::JOINT_VELOCITIES:
1235 obj = make_shared_state(decode<JointVelocities>(msg));
1237 case StateType::JOINT_ACCELERATIONS:
1238 obj = make_shared_state(decode<JointAccelerations>(msg));
1240 case StateType::JOINT_TORQUES:
1241 obj = make_shared_state(decode<JointTorques>(msg));
1243 case StateType::JACOBIAN:
1244 obj = make_shared_state(decode<Jacobian>(msg));
1246 case StateType::PARAMETER: {
1247 auto param_ptr = safe_dynamic_pointer_cast<ParameterInterface>(obj);
1248 switch (param_ptr->get_parameter_type()) {
1249 case ParameterType::BOOL:
1252 case ParameterType::BOOL_ARRAY:
1253 obj = make_shared_state(decode<
Parameter<std::vector<bool>>>(msg));
1255 case ParameterType::INT:
1258 case ParameterType::INT_ARRAY:
1259 obj = make_shared_state(decode<
Parameter<std::vector<int>>>(msg));
1261 case ParameterType::DOUBLE:
1264 case ParameterType::DOUBLE_ARRAY:
1265 obj = make_shared_state(decode<
Parameter<std::vector<double>>>(msg));
1267 case ParameterType::STRING:
1270 case ParameterType::STRING_ARRAY:
1271 obj = make_shared_state(decode<
Parameter<std::vector<std::string>>>(msg));
1273 case ParameterType::VECTOR:
1276 case ParameterType::MATRIX:
1280 throw std::invalid_argument(
"The ParameterType contained by parameter " + param_ptr->get_name() +
" is unsupported.");
1286 throw std::invalid_argument(
"The StateType contained by state " + obj->get_name() +
" is unsupported.");
A JsonParsingException is raised whenever a JSON conversion operation fails due to invalid encoding.
Class to define acceleration in cartesian space as 3D linear and angular acceleration vectors.
Class to define CartesianPose in cartesian space as 3D position and quaternion based orientation.
Class to represent a state in Cartesian space.
void set_orientation(const Eigen::Quaterniond &orientation)
Setter of the orientation.
void set_angular_acceleration(const Eigen::Vector3d &angular_acceleration)
Setter of the angular velocity attribute.
void set_force(const Eigen::Vector3d &force)
Setter of the force attribute.
void set_linear_acceleration(const Eigen::Vector3d &linear_acceleration)
Setter of the linear acceleration attribute.
void set_position(const Eigen::Vector3d &position)
Setter of the position.
void set_torque(const Eigen::Vector3d &torque)
Setter of the torque attribute.
void set_linear_velocity(const Eigen::Vector3d &linear_velocity)
Setter of the linear velocity attribute.
void set_angular_velocity(const Eigen::Vector3d &angular_velocity)
Setter of the angular velocity attribute.
Class to define twist in cartesian space as 3D linear and angular velocity vectors.
Class to define wrench in cartesian space as 3D force and torque vectors.
Class to define a robot Jacobian matrix.
void set_data(const Eigen::MatrixXd &data) override
Setter of the data attribute.
Class to define accelerations of the joints.
Class to define a positions of the joints.
Class to define a state in joint space.
void set_accelerations(const Eigen::VectorXd &accelerations)
Setter of the accelerations attribute.
void set_positions(const Eigen::VectorXd &positions)
Setter of the positions attribute.
void set_torques(const Eigen::VectorXd &torques)
Setter of the torques attribute.
void set_velocities(const Eigen::VectorXd &velocities)
Setter of the velocities attribute.
Class to define torques of the joints.
Class to define velocities of the joints.
virtual void set_reference_frame(const std::string &reference_frame)
Setter of the reference frame.
Abstract class to represent a state.
const std::string & get_name() const
Getter of the name as const reference.
virtual void set_name(const std::string &name)
Setter of the name.
void set_timestamp(const std::chrono::time_point< std::chrono::steady_clock > &timepoint)
Setter of the timestamp attribute.
const StateType & get_type() const
Getter of the type attribute.
bool is_empty() const
Getter of the empty attribute.
void set_empty(bool empty=true)
Setter of the empty attribute.
Bindings to encode and decode state objects into serialised binary message.
std::chrono::nanoseconds timestamp_duration_t
Duration type to use when representing chrono timestamps as integer count since epoch.
ParameterMessageType check_parameter_message_type(const std::string &msg)
Check which control libraries parameter type a serialized binary string can be decoded as,...
uint32_t field_length_t
Size type used to indicate number of fields and field data length in pack_fields() and unpack_fields(...
state_representation::proto::Parameter encoder(const state_representation::Parameter< ParamT > ¶meter)
Encoding helper method for the Parameter type.
std::string from_json(const std::string &json)
Convert a JSON formatted state message description into a serialized binary string representation (wi...
MessageType check_message_type(const std::string &msg)
Check which control libraries message type a serialized binary string can be decoded as,...
T decode(const std::string &msg)
Decode a serialized binary string from wire format into a control libraries object instance.
MessageType
The MessageType enumeration contains the possible message types in the clproto.
std::vector< FieldT > decoder(const google::protobuf::RepeatedField< FieldT > &message)
Decoding helper method for a RepeatedField message into vector data.
std::string to_json(const std::string &msg)
Convert a serialized binary string from wire format into a JSON formatted state message description.
ParameterMessageType
The ParameterMessageType enumeration contains the possible value types contained in a parameter messa...
void pack_fields(const std::vector< std::string > &fields, char *data)
Pack an ordered vector of encoded field messages into a single data array.
std::vector< std::string > unpack_fields(const char *data)
Unpack a data array into an ordered vector of encoded field messages.
bool is_valid(const std::string &msg)
Check if a serialized binary string can be decoded into a support control libraries message type.
Core state variables and objects.