30 #include <gtest/gtest.h>
39 static const double eps = 1e-6;
56 joint_states_.resize(2);
61 urdf::JointConstSharedPtr joint(
new urdf::Joint());
65 joint_states_[0]->joint_ = joint;
66 joint_states_[1]->joint_ = joint;
74 delete joint_states_[0];
75 delete joint_states_[1];
92 wrist_.setReductions(ar, jr);
98 actuators_[0]->state_.position_ = 1.0;
99 actuators_[1]->state_.position_ = 1.0;
100 wrist_.propagatePosition(actuators_, joint_states_);
101 EXPECT_NEAR(joint_states_[0]->position_, 0.0,
eps);
102 EXPECT_NEAR(joint_states_[1]->position_, -1.0,
eps);
107 actuators_[0]->state_.velocity_ = 1.0;
108 actuators_[1]->state_.velocity_ =-1.0;
109 wrist_.propagatePosition(actuators_, joint_states_);
110 EXPECT_NEAR(joint_states_[0]->velocity_, 1.0,
eps);
111 EXPECT_NEAR(joint_states_[1]->velocity_, 0.0,
eps);
116 actuators_[0]->state_.last_measured_effort_ = 1.0;
117 actuators_[1]->state_.last_measured_effort_ = -1.0;
118 wrist_.propagatePosition(actuators_, joint_states_);
119 EXPECT_NEAR(joint_states_[0]->measured_effort_, 2.0,
eps);
120 EXPECT_NEAR(joint_states_[1]->measured_effort_, 0.0,
eps);
128 vector<double> ar(2);
132 vector<double> jr(2);
136 wrist_.setReductions(ar, jr);
142 actuators_[0]->state_.position_ = 3.0;
143 actuators_[1]->state_.position_ = 1.0;
144 wrist_.propagatePosition(actuators_, joint_states_);
145 EXPECT_NEAR(joint_states_[0]->position_, 0.10,
eps);
146 EXPECT_NEAR(joint_states_[1]->position_, -0.02,
eps);
154 vector<double> ar(2);
158 vector<double> jr(2);
162 wrist_.setReductions(ar, jr);
168 actuators_[0]->state_.position_ = 100.0;
169 actuators_[1]->state_.position_ = 0.0;
170 wrist_.propagatePosition(actuators_, joint_states_);
171 EXPECT_NEAR(joint_states_[0]->position_, 5,
eps);
172 EXPECT_NEAR(joint_states_[1]->position_, -5,
eps);
177 actuators_[0]->state_.position_ = 0.0;
178 actuators_[1]->state_.position_ = 100.0;
179 wrist_.propagatePosition(actuators_, joint_states_);
180 EXPECT_NEAR(joint_states_[0]->position_, -0.5,
eps);
181 EXPECT_NEAR(joint_states_[1]->position_, -0.5,
eps);
192 actuators2_.resize(2);
199 delete actuators2_[0];
200 delete actuators2_[1];
205 vector<double> ar(2);
209 vector<double> jr(2);
213 wrist_.setReductions(ar, jr);
215 actuators_[0]->state_.velocity_ = 3.0;
216 actuators_[1]->state_.velocity_ = 4.0;
217 actuators_[0]->state_.last_measured_effort_ = 5.0;
218 actuators_[1]->state_.last_measured_effort_ = 6.0;
224 actuators_[0]->state_.position_ = 1.0;
225 actuators_[1]->state_.position_ = 2.0;
226 wrist_.propagatePosition(actuators_, joint_states_);
227 wrist_.propagatePositionBackwards(joint_states_, actuators2_);
228 EXPECT_NEAR(actuators2_[0]->state_.position_, actuators_[0]->state_.position_,
eps);
229 EXPECT_NEAR(actuators2_[1]->state_.position_, actuators_[1]->state_.position_,
eps);
234 actuators_[0]->state_.velocity_ = 1.0;
235 actuators_[1]->state_.velocity_ = 2.0;
236 wrist_.propagatePosition(actuators_, joint_states_);
237 wrist_.propagatePositionBackwards(joint_states_, actuators2_);
238 EXPECT_NEAR(actuators2_[0]->state_.velocity_, actuators_[0]->state_.velocity_,
eps);
239 EXPECT_NEAR(actuators2_[1]->state_.velocity_, actuators_[1]->state_.velocity_,
eps);
244 actuators_[0]->state_.last_measured_effort_ = 1.0;
245 actuators_[1]->state_.last_measured_effort_ = 2.0;
246 wrist_.propagatePosition(actuators_, joint_states_);
247 wrist_.propagatePositionBackwards(joint_states_, actuators2_);
248 EXPECT_NEAR(actuators2_[0]->state_.last_measured_effort_, actuators_[0]->state_.last_measured_effort_,
eps);
249 EXPECT_NEAR(actuators2_[1]->state_.last_measured_effort_, actuators_[1]->state_.last_measured_effort_,
eps);
254 actuators_[0]->command_.effort_ = 1.0;
255 actuators_[1]->command_.effort_ = 2.0;
256 wrist_.propagateEffortBackwards(actuators_, joint_states_);
257 wrist_.propagateEffort(joint_states_, actuators2_);
258 EXPECT_NEAR(actuators2_[0]->command_.effort_, actuators_[0]->command_.effort_,
eps);
259 EXPECT_NEAR(actuators2_[1]->command_.effort_, actuators_[1]->command_.effort_,
eps);
263 int main(
int argc,
char **argv)
266 testing::InitGoogleTest(&argc, argv);
267 return RUN_ALL_TESTS();