Skip to content

Commit fcae4ce

Browse files
Merge pull request #61 from nasa-jpl/bowkett-prof-vel-init-tweak
Add minimum dt to trap_update_vel
2 parents a7e2a53 + 22dc6b4 commit fcae4ce

File tree

3 files changed

+66
-1
lines changed

3 files changed

+66
-1
lines changed

src/trap.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -488,7 +488,7 @@ int trap_update_vel(trap_t* self, double t, double* pos, double* vel)
488488
double dt;
489489

490490
if (t < self->t_acc) {
491-
dt = t - self->t_init;
491+
dt = fmax(t - self->t_init, 0.001);
492492
*vel = self->vel_init + self->acc * dt;
493493
*pos = self->pos_init + self->vel_init * dt + 0.5 * self->acc * dt * dt;
494494
} else {

test/test_unit/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ set(TEST_SOURCES
1010
test_linear_interpolation.cc
1111

1212
test_jsd_device_base.cc
13+
14+
test_trap.cc
1315
)
1416

1517
foreach(TEST_SOURCE ${TEST_SOURCES})

test/test_unit/test_trap.cc

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
#include <gtest/gtest.h>
2+
3+
#include "fastcat/trap.h"
4+
5+
namespace
6+
{
7+
class TrapTest : public ::testing::Test
8+
{
9+
protected:
10+
void SetUp() override {
11+
}
12+
13+
trap_t trap_1_;
14+
};
15+
16+
TEST_F(TrapTest, TrapVelocityReInit){
17+
18+
double time_initial = 0.0;
19+
double position_initial = 0.0;
20+
double velocity_initial = 0.0;
21+
double velocity_final = 1.0;
22+
double acceleration = 1.0;
23+
double max_time = 10.0;
24+
25+
// Generate the first version of the trap
26+
trap_generate_vel(&trap_1_,
27+
time_initial,
28+
position_initial,
29+
velocity_initial,
30+
velocity_final,
31+
acceleration,
32+
max_time);
33+
34+
double dt = 0.01;
35+
36+
double tracking_time = time_initial;
37+
double tracking_position = position_initial;
38+
double tracking_velocity = velocity_initial;
39+
40+
for (int i=0; i<1000; i++) {
41+
// Update trap before any change in time has occurred
42+
trap_update_vel(&trap_1_, tracking_time,
43+
&tracking_position,
44+
&tracking_velocity);
45+
46+
// Increment time
47+
tracking_time += dt;
48+
49+
// Regenerate trap to simulate incoming updated setpoint
50+
trap_generate_vel(&trap_1_, tracking_time,
51+
tracking_position,
52+
tracking_velocity,
53+
velocity_final,
54+
acceleration,
55+
max_time);
56+
}
57+
58+
// The minimum dt used in track vel should guarantee that
59+
// motion occurs despite regeneration happening every cycle
60+
EXPECT_TRUE(tracking_position > position_initial);
61+
}
62+
63+
}

0 commit comments

Comments
 (0)