35 #include <gtest/gtest.h> 42 static const double eps = 1e-10;
44 TEST(JointStatesDeflator, easy1)
48 vector<string> joint_names;
49 joint_names.resize(2);
54 JointStatePtr joint_states;
60 joint_states.reset(
new JointState);
61 joint_states->name.resize(3);
62 joint_states->position.resize(3);
63 joint_states->velocity.resize(3);
64 joint_states->effort.resize(3);
65 joint_states->name[0] =
"A";
66 joint_states->name[1] =
"B";
67 joint_states->name[2] =
"C";
68 joint_states->position[0] = 1.0;
69 joint_states->position[1] = 2.0;
70 joint_states->position[2] = 3.0;
72 deflater.
deflate(joint_states, deflated_msg);
73 deflater.
prune(*joint_states, pruned);
75 ASSERT_EQ(deflated_msg.
channels_.size(), (
unsigned int) 2);
79 ASSERT_EQ(pruned.name.size(), (
unsigned int) 2);
80 ASSERT_EQ(pruned.position.size(), (
unsigned int) 2);
81 EXPECT_EQ(pruned.name[0],
"A");
82 EXPECT_EQ(pruned.name[1],
"C");
83 EXPECT_NEAR(pruned.position[0], 1.0,
eps);
84 EXPECT_NEAR(pruned.position[1], 3.0,
eps);
88 joint_states.reset(
new JointState);
89 joint_states->name.resize(3);
90 joint_states->position.resize(3);
91 joint_states->velocity.resize(3);
92 joint_states->effort.resize(3);
93 joint_states->name[0] =
"C";
94 joint_states->name[1] =
"A";
95 joint_states->name[2] =
"B";
96 joint_states->position[0] = 4.0;
97 joint_states->position[1] = 5.0;
98 joint_states->position[2] = 6.0;
100 deflater.
deflate(joint_states, deflated_msg);
101 deflater.
prune(*joint_states, pruned);
103 EXPECT_EQ(deflated_msg.
channels_.size(), (
unsigned int) 2);
107 ASSERT_EQ(pruned.name.size(), (
unsigned int) 2);
108 ASSERT_EQ(pruned.position.size(), (
unsigned int) 2);
109 EXPECT_EQ(pruned.name[0],
"A");
110 EXPECT_EQ(pruned.name[1],
"C");
111 EXPECT_NEAR(pruned.position[0], 5.0,
eps);
112 EXPECT_NEAR(pruned.position[1], 4.0,
eps);
116 joint_states.reset(
new JointState);
117 joint_states->name.resize(4);
118 joint_states->position.resize(4);
119 joint_states->velocity.resize(4);
120 joint_states->effort.resize(4);
121 joint_states->name[0] =
"D";
122 joint_states->name[1] =
"C";
123 joint_states->name[2] =
"B";
124 joint_states->name[3] =
"A";
125 joint_states->position[0] = 7.0;
126 joint_states->position[1] = 8.0;
127 joint_states->position[2] = 9.0;
128 joint_states->position[3] = 10.0;
130 deflater.
deflate(joint_states, deflated_msg);
131 deflater.
prune(*joint_states, pruned);
133 EXPECT_EQ(deflated_msg.
channels_.size(), (
unsigned int) 2);
137 ASSERT_EQ(pruned.name.size(), (
unsigned int) 2);
138 ASSERT_EQ(pruned.position.size(), (
unsigned int) 2);
139 EXPECT_EQ(pruned.name[0],
"A");
140 EXPECT_EQ(pruned.name[1],
"C");
141 EXPECT_NEAR(pruned.position[0], 10.0,
eps);
142 EXPECT_NEAR(pruned.position[1], 8.0,
eps);
146 int main(
int argc,
char **argv){
147 testing::InitGoogleTest(&argc, argv);
148 return RUN_ALL_TESTS();
void prune(const sensor_msgs::JointState &joint_states, sensor_msgs::JointState &pruned_joint_states)
Remove all the joints that we don't care about.
TEST(JointStatesDeflator, easy1)
int main(int argc, char **argv)
std::vector< double > channels_
void deflate(const sensor_msgs::JointStateConstPtr &joint_states, DeflatedJointStates &deflated_elem)
Perform the deflation on a joint_states message.
void setDeflationJointNames(std::vector< std::string > joint_names)
Specify which joints to extract.
Given a set a joint names, efficiently extracts a subset of joint positions.