test_wrist_transmission.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2008, Willow Garage, Inc.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  *
8  * * Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  * * Redistributions in binary form must reproduce the above copyright
11  * notice, this list of conditions and the following disclaimer in the
12  * documentation and/or other materials provided with the distribution.
13  * * Neither the name of the Willow Garage, Inc. nor the names of its
14  * contributors may be used to endorse or promote products derived from
15  * this software without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
21  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27  * POSSIBILITY OF SUCH DAMAGE.
28  */
29 
30 #include <gtest/gtest.h>
31 #include <vector>
34 
35 using namespace pr2_mechanism_model;
36 using namespace pr2_hardware_interface;
37 using namespace std;
38 
39 static const double eps = 1e-6;
40 
41 class BaseFixture : public testing::Test
42 {
43 public:
45  std::vector<Actuator*> actuators_;
46  std::vector<JointState*> joint_states_;
47 
48 protected:
49  //virtual void SetUp()
51  {
52  actuators_.resize(2);
53  actuators_[0] = new Actuator();
54  actuators_[1] = new Actuator();
55 
56  joint_states_.resize(2);
57  joint_states_[0] = new JointState();
58  joint_states_[1] = new JointState();
59 
60 #if URDFDOM_1_0_0_API
61  urdf::JointConstSharedPtr joint(new urdf::Joint());
62 #else
63  boost::shared_ptr<const urdf::Joint> joint(new urdf::Joint());
64 #endif
65  joint_states_[0]->joint_ = joint;
66  joint_states_[1]->joint_ = joint;
67 
68  }
69 
70  virtual void TearDown()
71  {
72  delete actuators_[0];
73  delete actuators_[1];
74  delete joint_states_[0];
75  delete joint_states_[1];
76  }
77 };
78 
79 // ******* Sets all the gearings to 1. This is a very basic test *******
81 {
82  virtual void SetUp()
83  {
84  vector<double> ar(2);
85  ar[0] = 1.0;
86  ar[1] = 1.0;
87 
88  vector<double> jr(2);
89  jr[0] = 1.0;
90  jr[1] = 1.0;
91 
92  wrist_.setReductions(ar, jr);
93  }
94 };
95 
96 TEST_F(EasyNoGearingTest, ForwardPositionTest1)
97 {
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);
103 }
104 
105 TEST_F(EasyNoGearingTest, ForwardVelocityTest1)
106 {
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);
112 }
113 
114 TEST_F(EasyNoGearingTest, ForwardMeasuredEffortTest1)
115 {
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);
121 }
122 
123 // ******* Check joint gearing *******
125 {
126  virtual void SetUp()
127  {
128  vector<double> ar(2);
129  ar[0] = 1.0;
130  ar[1] = 1.0;
131 
132  vector<double> jr(2);
133  jr[0] = 10.0;
134  jr[1] = 100.0;
135 
136  wrist_.setReductions(ar, jr);
137  }
138 };
139 
140 TEST_F(EasyJointGearingTest, ForwardPositionTest1)
141 {
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);
147 }
148 
149 // ******* Check motor gearing *******
151 {
152  virtual void SetUp()
153  {
154  vector<double> ar(2);
155  ar[0] = 10.0;
156  ar[1] = 100.0;
157 
158  vector<double> jr(2);
159  jr[0] = 1.0;
160  jr[1] = 1.0;
161 
162  wrist_.setReductions(ar, jr);
163  }
164 };
165 
166 TEST_F(EasyMotorGearingTest, ForwardPositionTest1)
167 {
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);
173 }
174 
175 TEST_F(EasyMotorGearingTest, ForwardPositionTest2)
176 {
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);
182 }
183 
184 // ******* Check both directions *******
186 {
187 public:
188  std::vector<Actuator*> actuators2_;
189 
191  {
192  actuators2_.resize(2);
193  actuators2_[0] = new Actuator();
194  actuators2_[1] = new Actuator();
195  }
196 
198  {
199  delete actuators2_[0];
200  delete actuators2_[1];
201  }
202 
203  virtual void SetUp()
204  {
205  vector<double> ar(2);
206  ar[0] = 10.0;
207  ar[1] = 100.0;
208 
209  vector<double> jr(2);
210  jr[0] = 20.0;
211  jr[1] = 40.0;
212 
213  wrist_.setReductions(ar, jr);
214 
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;
219  }
220 };
221 
223 {
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);
230 }
231 
233 {
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);
240 }
241 
242 TEST_F(PropagateSanityCheck, MeasuredEffort)
243 {
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);
250 }
251 
253 {
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);
260 }
261 
262 
263 int main(int argc, char **argv)
264 {
265  ros::Time::init();
266  testing::InitGoogleTest(&argc, argv);
267  return RUN_ALL_TESTS();
268 }
TEST_F(EasyNoGearingTest, ForwardPositionTest1)
static const double eps
WristTransmission wrist_
int main(int argc, char **argv)
std::vector< Actuator * > actuators2_
std::vector< JointState * > joint_states_
static void init()
std::vector< Actuator * > actuators_
virtual void TearDown()


pr2_mechanism_model
Author(s): Eric Berger berger@willowgarage.com, Stuart Glaser, Wim Meeussen
autogenerated on Tue Mar 7 2023 03:54:53