cartesian_state_test.cpp
Go to the documentation of this file.
1 // -- BEGIN LICENSE BLOCK ----------------------------------------------
2 // Copyright 2021 FZI Forschungszentrum Informatik
3 // Created on behalf of Universal Robots A/S
4 //
5 // Licensed under the Apache License, Version 2.0 (the "License");
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
8 //
9 // http://www.apache.org/licenses/LICENSE-2.0
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16 // -- END LICENSE BLOCK ------------------------------------------------
17 
18 //-----------------------------------------------------------------------------
25 //-----------------------------------------------------------------------------
26 
27 #include <gtest/gtest.h>
28 
30 #include <Eigen/Dense>
31 #include <Eigen/src/Geometry/Quaternion.h>
32 #include <cartesian_control_msgs/CartesianTrajectoryPoint.h>
33 
34 using namespace ros_controllers_cartesian;
35 
36 TEST(TestCartesianState, EmptyStateIsZeroInitialized) // except for quaternion w
37 {
38  CartesianState state;
39  for (size_t i = 0; i < 3; ++i)
40  {
41  EXPECT_EQ(state.p[i], 0);
42  EXPECT_EQ(state.v[i], 0);
43  EXPECT_EQ(state.v_dot[i], 0);
44  EXPECT_EQ(state.w[i], 0);
45  EXPECT_EQ(state.w_dot[i], 0);
46  }
47 }
48 
49 TEST(TestCartesianState, EmptyStateHasNormalizedQuaternion)
50 {
51  CartesianState state;
52  Eigen::Quaterniond q;
53  q.w() = 1;
54  q.normalize();
55  EXPECT_DOUBLE_EQ(q.norm(), state.q.norm());
56 }
57 
58 TEST(TestCartesianState, EmptyStateYieldsZeroRotationVector)
59 {
60  CartesianState state;
61  EXPECT_EQ(Eigen::Vector3d::Zero(), state.rot());
62 }
63 
64 TEST(TestCartesianState, EmptyStateYieldsNormalizedTrajectoryPoint)
65 {
66  CartesianState state;
67  cartesian_control_msgs::CartesianTrajectoryPoint point;
68  point.pose.orientation.w = 1;
69 
70  // Compact check if both `read` the same.
71  std::stringstream state_str;
72  std::stringstream point_str;
73  state_str << state.toMsg();
74  point_str << point;
75 
76  EXPECT_EQ(point_str.str(), state_str.str());
77 }
78 
79 TEST(TestCartesianState, RosMessageInitializationYieldsNormalizedQuaternions)
80 {
81  cartesian_control_msgs::CartesianTrajectoryPoint init;
82  auto c = CartesianState(init);
83  EXPECT_DOUBLE_EQ(1.0, c.q.norm());
84 }
85 
86 TEST(TestCartesianState, ConversionReturnsInitializingArgument)
87 {
88  // Fill some fields with arbitrary values.
89  // Note that jerk, posture and time_from_start do not have a representation
90  // in CartesianState and are therefore initialized to 0 (by default) in order to make their string representations to
91  // be expected the same..
92 
93  cartesian_control_msgs::CartesianTrajectoryPoint init;
94  init.acceleration.angular.x = 1.2345;
95  init.acceleration.linear.y = -173.47;
96  init.pose.orientation.w = 1;
97  init.pose.position.z = 0.003;
98  init.twist.linear.x = 67.594;
99 
100  CartesianState state(init);
101  std::stringstream init_str;
102  std::stringstream state_str;
103  init_str << init;
104  state_str << state.toMsg();
105 
106  EXPECT_EQ(init_str.str(), state_str.str());
107 }
108 
109 TEST(CartesianState, RotationDifferenceIsPlausible)
110 {
111  CartesianState a;
112  CartesianState b;
113  b.p[0] = 1;
114  b.v[0] = 1;
115  b.w[0] = 1;
116  b.v_dot[0] = 1;
117  b.w_dot[0] = 1;
118 
119  // Subtraction from zero yields the negative argument
120  auto diff = a - b;
121  EXPECT_DOUBLE_EQ(-b.p[0], diff.p[0]);
122  EXPECT_DOUBLE_EQ(-b.v[0], diff.v[0]);
123  EXPECT_DOUBLE_EQ(-b.w[0], diff.w[0]);
124  EXPECT_DOUBLE_EQ(-b.v_dot[0], diff.v_dot[0]);
125  EXPECT_DOUBLE_EQ(-b.w_dot[0], diff.w_dot[0]);
126 
127  // Rotations of 180 deg around single axis will have vanishing
128  // difference (singularity).
129  a.q.x() = 1;
130  EXPECT_DOUBLE_EQ(0.0, diff.rot().norm());
131  b.q.x() = 1;
132  EXPECT_DOUBLE_EQ(0.0, diff.rot().norm());
133 }
134 
135 int main(int argc, char** argv)
136 {
137  testing::InitGoogleTest(&argc, argv);
138  return RUN_ALL_TESTS();
139 }
Eigen::Vector3d w
angular velocity,
void init(const M_string &remappings)
cartesian_control_msgs::CartesianTrajectoryPoint toMsg(int time_from_start=0) const
Convenience method for conversion.
Eigen::Vector3d v
linear velocity,
Eigen::Vector3d v_dot
linear acceleration,
Cartesian state with pose, velocity and acceleration.
TEST(TestCartesianState, EmptyStateIsZeroInitialized)
Eigen::Vector3d rot() const
Get Euler-Rodrigues vector from orientation.
Eigen::Vector3d w_dot
angular acceleration,
int main(int argc, char **argv)


cartesian_trajectory_interpolation
Author(s):
autogenerated on Thu Feb 23 2023 03:10:46