Skip to content

Commit

Permalink
Merge pull request #61 from nasa-jpl/bowkett-prof-vel-init-tweak
Browse files Browse the repository at this point in the history
Add minimum dt to trap_update_vel
  • Loading branch information
JosephBowkett authored Nov 22, 2022
2 parents a7e2a53 + 22dc6b4 commit fcae4ce
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/trap.c
Original file line number Diff line number Diff line change
Expand Up @@ -488,7 +488,7 @@ int trap_update_vel(trap_t* self, double t, double* pos, double* vel)
double dt;

if (t < self->t_acc) {
dt = t - self->t_init;
dt = fmax(t - self->t_init, 0.001);
*vel = self->vel_init + self->acc * dt;
*pos = self->pos_init + self->vel_init * dt + 0.5 * self->acc * dt * dt;
} else {
Expand Down
2 changes: 2 additions & 0 deletions test/test_unit/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ set(TEST_SOURCES
test_linear_interpolation.cc

test_jsd_device_base.cc

test_trap.cc
)

foreach(TEST_SOURCE ${TEST_SOURCES})
Expand Down
63 changes: 63 additions & 0 deletions test/test_unit/test_trap.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
#include <gtest/gtest.h>

#include "fastcat/trap.h"

namespace
{
class TrapTest : public ::testing::Test
{
protected:
void SetUp() override {
}

trap_t trap_1_;
};

TEST_F(TrapTest, TrapVelocityReInit){

double time_initial = 0.0;
double position_initial = 0.0;
double velocity_initial = 0.0;
double velocity_final = 1.0;
double acceleration = 1.0;
double max_time = 10.0;

// Generate the first version of the trap
trap_generate_vel(&trap_1_,
time_initial,
position_initial,
velocity_initial,
velocity_final,
acceleration,
max_time);

double dt = 0.01;

double tracking_time = time_initial;
double tracking_position = position_initial;
double tracking_velocity = velocity_initial;

for (int i=0; i<1000; i++) {
// Update trap before any change in time has occurred
trap_update_vel(&trap_1_, tracking_time,
&tracking_position,
&tracking_velocity);

// Increment time
tracking_time += dt;

// Regenerate trap to simulate incoming updated setpoint
trap_generate_vel(&trap_1_, tracking_time,
tracking_position,
tracking_velocity,
velocity_final,
acceleration,
max_time);
}

// The minimum dt used in track vel should guarantee that
// motion occurs despite regeneration happening every cycle
EXPECT_TRUE(tracking_position > position_initial);
}

}

0 comments on commit fcae4ce

Please sign in to comment.