From 8219117a17c175a405d4ba08950f60e087482dc0 Mon Sep 17 00:00:00 2001 From: Martin Bokeloh Date: Tue, 24 Jul 2018 14:32:38 +0200 Subject: [PATCH] [GenericPoseGraph] Add serialization tests for constraints. (#1318) * [GenericPoseGraph] Add rotation 3d constraint. * [GenericPoseGraph] Add serialization tests for constraints. * Remove files from other branch * Updated include paths. --- .../relative_pose_constraint_2d_test.cc | 58 +++++++++++++++++++ .../relative_pose_constraint_3d_test.cc | 58 +++++++++++++++++++ 2 files changed, 116 insertions(+) create mode 100644 cartographer/pose_graph/constraint/relative_pose_constraint_2d_test.cc create mode 100644 cartographer/pose_graph/constraint/relative_pose_constraint_3d_test.cc diff --git a/cartographer/pose_graph/constraint/relative_pose_constraint_2d_test.cc b/cartographer/pose_graph/constraint/relative_pose_constraint_2d_test.cc new file mode 100644 index 0000000..85c396e --- /dev/null +++ b/cartographer/pose_graph/constraint/relative_pose_constraint_2d_test.cc @@ -0,0 +1,58 @@ +/* + * Copyright 2018 The Cartographer Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "cartographer/pose_graph/constraint/relative_pose_constraint_2d.h" + +#include "cartographer/testing/test_helpers.h" + +namespace cartographer { +namespace pose_graph { +namespace { + +using testing::EqualsProto; +using testing::ParseProto; + +constexpr char kConstraint[] = R"PROTO( + id: "narf" + cost_function { + relative_pose_2d { + first { object_id: "node0" } + second { object_id: "node1" } + parameters { + first_t_second { + translation: { x: 1 y: 1 } + rotation: -2.214297 + } + translation_weight: 1 + rotation_weight: 10 + } + } + } + + loss_function { quadratic_loss {} } +)PROTO"; + +TEST(RelativePoseConstraint2DTest, SerializesCorrectly) { + const auto proto = ParseProto(kConstraint); + RelativePoseConstraint2D constraint(proto.id(), proto.loss_function(), + proto.cost_function().relative_pose_2d()); + const auto actual_proto = constraint.ToProto(); + EXPECT_THAT(actual_proto, EqualsProto(kConstraint)); +} + +} // namespace +} // namespace pose_graph +} // namespace cartographer diff --git a/cartographer/pose_graph/constraint/relative_pose_constraint_3d_test.cc b/cartographer/pose_graph/constraint/relative_pose_constraint_3d_test.cc new file mode 100644 index 0000000..6af981b --- /dev/null +++ b/cartographer/pose_graph/constraint/relative_pose_constraint_3d_test.cc @@ -0,0 +1,58 @@ +/* + * Copyright 2018 The Cartographer Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "cartographer/pose_graph/constraint/relative_pose_constraint_3d.h" + +#include "cartographer/testing/test_helpers.h" + +namespace cartographer { +namespace pose_graph { +namespace { + +using testing::EqualsProto; +using testing::ParseProto; + +constexpr char kConstraint[] = R"PROTO( + id: "narf" + cost_function { + relative_pose_3d { + first { object_id: "node0" } + second { object_id: "node1" } + parameters { + first_t_second { + translation: { x: 1 y: 2 z: 3 } + rotation: { x: 0 y: 0.3 z: 0.1 w: 0.2 } + } + translation_weight: 1 + rotation_weight: 10 + } + } + } + + loss_function { quadratic_loss {} } +)PROTO"; + +TEST(RelativePoseConstraint2DTest, SerializesCorrectly) { + const auto proto = ParseProto(kConstraint); + RelativePoseConstraint3D constraint(proto.id(), proto.loss_function(), + proto.cost_function().relative_pose_3d()); + const auto actual_proto = constraint.ToProto(); + EXPECT_THAT(actual_proto, EqualsProto(kConstraint)); +} + +} // namespace +} // namespace pose_graph +} // namespace cartographer