@@ -203,12 +203,13 @@ TEST_F(JointTest, TestReadEncodersOnce)
203203{
204204 ros::Duration elapsed_time (0.2 );
205205 double velocity = 0.5 ;
206- double absolute_noise = - 2 * this ->imc ->getAbsoluteRadPerBit ();
206+ double velocity_with_noise = velocity - 2 * this ->imc ->getAbsoluteRadPerBit () / elapsed_time. toSec ();
207207
208208 double initial_incremental_position = 5 ;
209209 double initial_absolute_position = 3 ;
210+
210211 double new_incremental_position = initial_incremental_position + velocity * elapsed_time.toSec ();
211- double new_absolute_position = initial_absolute_position + velocity * elapsed_time.toSec () + absolute_noise ;
212+ double new_absolute_position = initial_absolute_position + velocity_with_noise * elapsed_time.toSec ();
212213
213214 EXPECT_CALL (*this ->imc , getIMCVoltage ()).WillOnce (Return (48 ));
214215 EXPECT_CALL (*this ->imc , getMotorCurrent ()).WillOnce (Return (5 ));
@@ -221,14 +222,17 @@ TEST_F(JointTest, TestReadEncodersOnce)
221222 .WillOnce (Return (new_absolute_position))
222223 .WillOnce (Return (new_absolute_position));
223224
225+ EXPECT_CALL (*this ->imc , getVelocityRadIncremental ()).WillOnce (Return (velocity)).WillOnce (Return (velocity));
226+ EXPECT_CALL (*this ->imc , getVelocityRadAbsolute ()).WillOnce (Return (velocity_with_noise));
227+
224228 march::Joint joint (" actuate_true" , 0 , true , std::move (this ->imc ));
225229 joint.prepareActuation ();
226230
227231 joint.readEncoders (elapsed_time);
228232
229233 ASSERT_DOUBLE_EQ (joint.getPosition (), initial_absolute_position + velocity * elapsed_time.toSec ());
230- ASSERT_DOUBLE_EQ (joint.getVelocity (),
231- (new_incremental_position - initial_incremental_position) / elapsed_time. toSec () );
234+ ASSERT_NEAR (joint.getVelocity (), (new_incremental_position - initial_incremental_position) / elapsed_time. toSec (),
235+ 0.0000001 );
232236}
233237
234238TEST_F (JointTest, TestReadEncodersTwice)
@@ -238,13 +242,15 @@ TEST_F(JointTest, TestReadEncodersTwice)
238242 double second_velocity = 0.8 ;
239243
240244 double absolute_noise = -this ->imc ->getAbsoluteRadPerBit ();
245+ double first_velocity_with_noise = first_velocity + absolute_noise / elapsed_time.toSec ();
246+ double second_velocity_with_noise = second_velocity + absolute_noise / elapsed_time.toSec ();
241247
242248 double initial_incremental_position = 5 ;
243249 double initial_absolute_position = 3 ;
244250 double second_incremental_position = initial_incremental_position + first_velocity * elapsed_time.toSec ();
245- double second_absolute_position = initial_absolute_position + first_velocity * elapsed_time.toSec () + absolute_noise ;
251+ double second_absolute_position = initial_absolute_position + first_velocity * elapsed_time.toSec ();
246252 double third_incremental_position = second_incremental_position + second_velocity * elapsed_time.toSec ();
247- double third_absolute_position = second_absolute_position + second_velocity * elapsed_time.toSec () + absolute_noise ;
253+ double third_absolute_position = second_absolute_position + second_velocity_with_noise * elapsed_time.toSec ();
248254
249255 EXPECT_CALL (*this ->imc , getIMCVoltage ()).WillOnce (Return (48 )).WillOnce (Return (48.01 ));
250256 EXPECT_CALL (*this ->imc , getAngleRadIncremental ())
@@ -259,6 +265,14 @@ TEST_F(JointTest, TestReadEncodersTwice)
259265 .WillOnce (Return (second_absolute_position))
260266 .WillOnce (Return (third_absolute_position))
261267 .WillOnce (Return (third_absolute_position));
268+ EXPECT_CALL (*this ->imc , getVelocityRadIncremental ())
269+ .WillOnce (Return (first_velocity))
270+ .WillOnce (Return (first_velocity))
271+ .WillOnce (Return (second_velocity))
272+ .WillOnce (Return (second_velocity));
273+ EXPECT_CALL (*this ->imc , getVelocityRadAbsolute ())
274+ .WillOnce (Return (first_velocity_with_noise))
275+ .WillOnce (Return (second_velocity_with_noise));
262276
263277 march::Joint joint (" actuate_true" , 0 , true , std::move (this ->imc ));
264278 joint.prepareActuation ();
@@ -268,21 +282,22 @@ TEST_F(JointTest, TestReadEncodersTwice)
268282
269283 ASSERT_DOUBLE_EQ (joint.getPosition (),
270284 initial_absolute_position + (first_velocity + second_velocity) * elapsed_time.toSec ());
271- ASSERT_DOUBLE_EQ (joint.getVelocity (),
272- (third_incremental_position - second_incremental_position) / elapsed_time. toSec () );
285+ ASSERT_NEAR (joint.getVelocity (), (third_incremental_position - second_incremental_position) / elapsed_time. toSec (),
286+ 0.0000001 );
273287}
274288
275289TEST_F (JointTest, TestReadEncodersNoUpdate)
276290{
277291 ros::Duration elapsed_time (0.2 );
278- double first_velocity = 0.5 ;
292+
293+ double velocity = 0.5 ;
279294
280295 double absolute_noise = -this ->imc ->getAbsoluteRadPerBit ();
281296
282297 double initial_incremental_position = 5 ;
283298 double initial_absolute_position = 3 ;
284- double second_incremental_position = initial_incremental_position + first_velocity * elapsed_time.toSec ();
285- double second_absolute_position = initial_absolute_position + first_velocity * elapsed_time.toSec () + absolute_noise;
299+ double second_incremental_position = initial_incremental_position + velocity * elapsed_time.toSec ();
300+ double second_absolute_position = initial_absolute_position + velocity * elapsed_time.toSec () + absolute_noise;
286301
287302 EXPECT_CALL (*this ->imc , getIMCVoltage ()).WillRepeatedly (Return (48 ));
288303 EXPECT_CALL (*this ->imc , getAngleRadIncremental ())
@@ -291,14 +306,15 @@ TEST_F(JointTest, TestReadEncodersNoUpdate)
291306 EXPECT_CALL (*this ->imc , getAngleRadAbsolute ())
292307 .WillOnce (Return (initial_absolute_position))
293308 .WillRepeatedly (Return (second_absolute_position));
309+ EXPECT_CALL (*this ->imc , getVelocityRadIncremental ()).WillRepeatedly (Return (velocity));
310+ EXPECT_CALL (*this ->imc , getVelocityRadAbsolute ()).WillRepeatedly (Return (velocity));
294311
295312 march::Joint joint (" actuate_true" , 0 , true , std::move (this ->imc ));
296313 joint.prepareActuation ();
297314
298315 joint.readEncoders (elapsed_time);
299316 joint.readEncoders (elapsed_time);
300317
301- ASSERT_DOUBLE_EQ (joint.getPosition (), initial_absolute_position + 2 * first_velocity * elapsed_time.toSec ());
302- ASSERT_DOUBLE_EQ (joint.getVelocity (),
303- (second_incremental_position - initial_incremental_position) / elapsed_time.toSec ());
318+ ASSERT_DOUBLE_EQ (joint.getPosition (), initial_absolute_position + 2 * velocity * elapsed_time.toSec ());
319+ ASSERT_DOUBLE_EQ (joint.getVelocity (), velocity);
304320}
0 commit comments