Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 23 additions & 23 deletions include/trackjoint/error_codes.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,32 +22,32 @@ namespace trackjoint
*/
enum ErrorCodeEnum
{
kNoError = 0,
kDesiredDurationTooShort = 1,
kMaxDurationExceeded = 2,
kVelocityExceedsLimit = 3,
kAccelExceedsLimit = 4,
kMaxDurationLessThanDesiredDuration = 5,
kLimitNotPositive = 6,
kGoalPositionMismatch = 7,
kFailureToGenerateSingleWaypoint = 8,
kLessThanTenTimestepsForStreamingMode = 9
NO_ERROR = 0,
DESIRED_DURATION_TOO_SHORT = 1,
MAX_DURATION_EXCEEDED = 2,
VELOCITY_EXCEEDS_LIMIT = 3,
ACCEL_EXCEEDS_LIMIT = 4,
MAX_DURATION_LESS_THAN_DESIRED_DURATION = 5,
LIMIT_NOT_POSITIVE = 6,
GOAL_POSITION_MISMATCH = 7,
FAILURE_TO_GENERATE_SINGLE_WAYPOINT = 8,
LESS_THAN_TEN_TIMESTEPS_FOR_STREAMING_MODE = 9
};

/**
* \brief Use this map to look up human-readable strings for each error code
*/
const std::unordered_map<uint, std::string> kErrorCodeMap(
{ { kNoError, "No error, trajectory generation was successful" },
{ kDesiredDurationTooShort, "Desired duration is too short, cannot have less than one timestep in a "
"trajectory" },
{ kMaxDurationExceeded, "Max duration was exceeded" },
{ kVelocityExceedsLimit, "A velocity input exceeds the velocity limit" },
{ kAccelExceedsLimit, "An acceleration input exceeds the acceleration limit" },
{ kMaxDurationLessThanDesiredDuration, "max_duration should not be less than desired_duration" },
{ kLimitNotPositive, "Vel/accel/jerk limits should be greater than zero" },
{ kGoalPositionMismatch, "Mismatch between the final position and the goal position" },
{ kFailureToGenerateSingleWaypoint, "Failed to generate even a single new waypoint" },
{ kLessThanTenTimestepsForStreamingMode, "In streaming mode, desired duration should be at least 10 "
"timesteps" } });
const std::unordered_map<uint, std::string> ERROR_CODE_MAP(
{ { NO_ERROR, "No error, trajectory generation was successful" },
{ DESIRED_DURATION_TOO_SHORT, "Desired duration is too short, cannot have less than one timestep in a "
"trajectory" },
{ MAX_DURATION_EXCEEDED, "Max duration was exceeded" },
{ VELOCITY_EXCEEDS_LIMIT, "A velocity input exceeds the velocity limit" },
{ ACCEL_EXCEEDS_LIMIT, "An acceleration input exceeds the acceleration limit" },
{ MAX_DURATION_LESS_THAN_DESIRED_DURATION, "max_duration should not be less than desired_duration" },
{ LIMIT_NOT_POSITIVE, "Vel/accel/jerk limits should be greater than zero" },
{ GOAL_POSITION_MISMATCH, "Mismatch between the final position and the goal position" },
{ FAILURE_TO_GENERATE_SINGLE_WAYPOINT, "Failed to generate even a single new waypoint" },
{ LESS_THAN_TEN_TIMESTEPS_FOR_STREAMING_MODE, "In streaming mode, desired duration should be at least 10 "
"timesteps" } });
} // end namespace trackjoint
10 changes: 5 additions & 5 deletions src/simple_example.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,9 @@ int main(int argc, char** argv)
traj_gen.inputChecking(current_joint_states, goal_joint_states, limits, timestep);

// Input error handling - if an error is found, the trajectory is not generated.
if (error_code != trackjoint::ErrorCodeEnum::kNoError)
if (error_code != trackjoint::ErrorCodeEnum::NO_ERROR)
{
std::cout << "Error code: " << trackjoint::kErrorCodeMap.at(error_code) << std::endl;
std::cout << "Error code: " << trackjoint::ERROR_CODE_MAP.at(error_code) << std::endl;
return -1;
}

Expand All @@ -81,17 +81,17 @@ int main(int argc, char** argv)
auto end = std::chrono::system_clock::now();

// Trajectory generation error handling
if (error_code != trackjoint::ErrorCodeEnum::kNoError)
if (error_code != trackjoint::ErrorCodeEnum::NO_ERROR)
{
std::cout << "Error code: " << trackjoint::kErrorCodeMap.at(error_code) << std::endl;
std::cout << "Error code: " << trackjoint::ERROR_CODE_MAP.at(error_code) << std::endl;
return -1;
}

std::chrono::duration<double> elapsed_seconds = end - start;

std::cout << "Runtime: " << elapsed_seconds.count() << std::endl;
std::cout << "Num waypoints: " << output_trajectories.at(0).positions.size() << std::endl;
std::cout << "Error code: " << trackjoint::kErrorCodeMap.at(error_code) << std::endl;
std::cout << "Error code: " << trackjoint::ERROR_CODE_MAP.at(error_code) << std::endl;

// Save the synchronized trajectories to .csv files
traj_gen.saveTrajectoriesToFile(output_trajectories, output_path_base);
Expand Down
8 changes: 4 additions & 4 deletions src/single_joint_generator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ inline ErrorCodeEnum SingleJointGenerator::forwardLimitCompensation(size_t* inde
}
}

return ErrorCodeEnum::kNoError;
return ErrorCodeEnum::NO_ERROR;
}

inline void SingleJointGenerator::recordFailureTime(size_t current_index, size_t* index_last_successful)
Expand Down Expand Up @@ -397,7 +397,7 @@ inline ErrorCodeEnum SingleJointGenerator::predictTimeToReach()
// limits.
// This gives a new duration estimate.

ErrorCodeEnum error_code = ErrorCodeEnum::kNoError;
ErrorCodeEnum error_code = ErrorCodeEnum::NO_ERROR;

// If in normal mode, we can extend trajectories
if (!use_streaming_mode_)
Expand Down Expand Up @@ -474,12 +474,12 @@ inline ErrorCodeEnum SingleJointGenerator::predictTimeToReach()
// Normal mode: Error if we extended the duration to the maximum and it still wasn't successful
if (!use_streaming_mode_ && index_last_successful_ < static_cast<size_t>(waypoints_.elapsed_times.size() - 1))
{
error_code = ErrorCodeEnum::kMaxDurationExceeded;
error_code = ErrorCodeEnum::MAX_DURATION_EXCEEDED;
}
// Error if not even a single waypoint could be generated
if (waypoints_.positions.size() < 2)
{
error_code = ErrorCodeEnum::kFailureToGenerateSingleWaypoint;
error_code = ErrorCodeEnum::FAILURE_TO_GENERATE_SINGLE_WAYPOINT;
}

return error_code;
Expand Down
10 changes: 5 additions & 5 deletions src/streaming_example.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,15 +70,15 @@ int main(int argc, char** argv)
trackjoint::ErrorCodeEnum error_code = traj_gen.inputChecking(start_state, goal_joint_states, limits, timestep);
if (error_code)
{
std::cout << "Error code: " << trackjoint::kErrorCodeMap.at(error_code) << std::endl;
std::cout << "Error code: " << trackjoint::ERROR_CODE_MAP.at(error_code) << std::endl;
return -1;
}

// Generate the initial trajectory
error_code = traj_gen.generateTrajectories(&output_trajectories);
if (error_code != trackjoint::ErrorCodeEnum::kNoError)
if (error_code != trackjoint::ErrorCodeEnum::NO_ERROR)
{
std::cout << "Error code: " << trackjoint::kErrorCodeMap.at(error_code) << std::endl;
std::cout << "Error code: " << trackjoint::ERROR_CODE_MAP.at(error_code) << std::endl;
return -1;
}
std::cout << "Initial trajectory calculation:" << std::endl;
Expand Down Expand Up @@ -110,9 +110,9 @@ int main(int argc, char** argv)
std::cout << "Run time (microseconds): "
<< std::chrono::duration_cast<std::chrono::microseconds>(end_time - start_time).count() << std::endl;

if (error_code != trackjoint::ErrorCodeEnum::kNoError)
if (error_code != trackjoint::ErrorCodeEnum::NO_ERROR)
{
std::cout << "Error code: " << trackjoint::kErrorCodeMap.at(error_code) << std::endl;
std::cout << "Error code: " << trackjoint::ERROR_CODE_MAP.at(error_code) << std::endl;
return -1;
}

Expand Down
20 changes: 10 additions & 10 deletions src/three_dof_examples.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,9 @@ int main(int argc, char** argv)

// Input error handling - if an error is found, the trajectory is not
// generated.
if (error_code != trackjoint::ErrorCodeEnum::kNoError)
if (error_code != trackjoint::ErrorCodeEnum::NO_ERROR)
{
std::cout << "Error code: " << trackjoint::kErrorCodeMap.at(error_code) << std::endl;
std::cout << "Error code: " << trackjoint::ERROR_CODE_MAP.at(error_code) << std::endl;
return -1;
}

Expand All @@ -86,17 +86,17 @@ int main(int argc, char** argv)
auto end = std::chrono::system_clock::now();

// Trajectory generation error handling
if (error_code != trackjoint::ErrorCodeEnum::kNoError)
if (error_code != trackjoint::ErrorCodeEnum::NO_ERROR)
{
std::cout << "Error code: " << trackjoint::kErrorCodeMap.at(error_code) << std::endl;
std::cout << "Error code: " << trackjoint::ERROR_CODE_MAP.at(error_code) << std::endl;
return -1;
}

std::chrono::duration<double> elapsed_seconds = end - start;

std::cout << "Runtime: " << elapsed_seconds.count() << std::endl;
std::cout << "Num waypoints: " << output_trajectories.at(0).positions.size() << std::endl;
std::cout << "Error code: " << trackjoint::kErrorCodeMap.at(error_code) << std::endl;
std::cout << "Error code: " << trackjoint::ERROR_CODE_MAP.at(error_code) << std::endl;

// Save the synchronized trajectories to .csv files
traj_gen.saveTrajectoriesToFile(output_trajectories, output_path_base);
Expand Down Expand Up @@ -167,9 +167,9 @@ int main(int argc, char** argv)

// Input error handling - if an error is found, the trajectory is not
// generated.
if (error_code != trackjoint::ErrorCodeEnum::kNoError)
if (error_code != trackjoint::ErrorCodeEnum::NO_ERROR)
{
std::cout << "Error code: " << trackjoint::kErrorCodeMap.at(error_code) << std::endl;
std::cout << "Error code: " << trackjoint::ERROR_CODE_MAP.at(error_code) << std::endl;
return -1;
}

Expand All @@ -179,17 +179,17 @@ int main(int argc, char** argv)
end = std::chrono::system_clock::now();

// Trajectory generation error handling
if (error_code != trackjoint::ErrorCodeEnum::kNoError)
if (error_code != trackjoint::ErrorCodeEnum::NO_ERROR)
{
std::cout << "Error code: " << trackjoint::kErrorCodeMap.at(error_code) << std::endl;
std::cout << "Error code: " << trackjoint::ERROR_CODE_MAP.at(error_code) << std::endl;
return -1;
}

elapsed_seconds = end - start;

std::cout << "Runtime: " << elapsed_seconds.count() << std::endl;
std::cout << "Num waypoints: " << output_trajectories.at(0).positions.size() << std::endl;
std::cout << "Error code: " << trackjoint::kErrorCodeMap.at(error_code) << std::endl;
std::cout << "Error code: " << trackjoint::ERROR_CODE_MAP.at(error_code) << std::endl;

// Save the synchronized trajectories to .csv files
traj_gen.saveTrajectoriesToFile(output_trajectories, output_path_base);
Expand Down
24 changes: 12 additions & 12 deletions src/trajectory_generator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -194,56 +194,56 @@ ErrorCodeEnum TrajectoryGenerator::inputChecking(const std::vector<KinematicStat
// Need at least 1 timestep
if (rounded_duration < nominal_timestep)
{
return ErrorCodeEnum::kDesiredDurationTooShort;
return ErrorCodeEnum::DESIRED_DURATION_TOO_SHORT;
}

// Maximum duration must be equal to or longer than the nominal, goal duration
if (max_duration_ < rounded_duration)
{
return ErrorCodeEnum::kMaxDurationLessThanDesiredDuration;
return ErrorCodeEnum::MAX_DURATION_LESS_THAN_DESIRED_DURATION;
}

// Check that current vels. are less than the limits.
for (size_t joint = 0; joint < kNumDof; ++joint)
{
if (abs(current_joint_states[joint].velocity) > limits[joint].velocity_limit)
{
return ErrorCodeEnum::kVelocityExceedsLimit;
return ErrorCodeEnum::VELOCITY_EXCEEDS_LIMIT;
}

// Check that goal vels. are less than the limits.
if (abs(goal_joint_states[joint].velocity) > limits[joint].velocity_limit)
{
return ErrorCodeEnum::kVelocityExceedsLimit;
return ErrorCodeEnum::VELOCITY_EXCEEDS_LIMIT;
}

// Check that current accels. are less than the limits.
if (abs(current_joint_states[joint].acceleration) > limits[joint].acceleration_limit)
{
return ErrorCodeEnum::kAccelExceedsLimit;
return ErrorCodeEnum::ACCEL_EXCEEDS_LIMIT;
}

// Check that goal accels. are less than the limits.
if (abs(goal_joint_states[joint].acceleration) > limits[joint].acceleration_limit)
{
return ErrorCodeEnum::kAccelExceedsLimit;
return ErrorCodeEnum::ACCEL_EXCEEDS_LIMIT;
}

// Check for positive limits.
if (limits[joint].velocity_limit <= 0 || limits[joint].acceleration_limit <= 0 || limits[joint].jerk_limit <= 0)
{
return ErrorCodeEnum::kLimitNotPositive;
return ErrorCodeEnum::LIMIT_NOT_POSITIVE;
}

// In streaming mode, the user-requested duration should be >= kNumWaypointsThreshold * timestep.
// upsample and downSample aren't used in streaming mode.
if (rounded_duration < kNumWaypointsThreshold * nominal_timestep && use_streaming_mode_)
{
return ErrorCodeEnum::kLessThanTenTimestepsForStreamingMode;
return ErrorCodeEnum::LESS_THAN_TEN_TIMESTEPS_FOR_STREAMING_MODE;
}
}

return ErrorCodeEnum::kNoError;
return ErrorCodeEnum::NO_ERROR;
}

void TrajectoryGenerator::saveTrajectoriesToFile(const std::vector<JointTrajectory>& output_trajectories,
Expand Down Expand Up @@ -309,7 +309,7 @@ ErrorCodeEnum TrajectoryGenerator::synchronizeTrajComponents(std::vector<JointTr
// This indicates that a successful trajectory wasn't found, even when the trajectory was extended to max_duration
if ((longest_num_waypoints - 1) < std::floor(desired_duration_ / upsampled_timestep_) && !use_streaming_mode_)
{
return ErrorCodeEnum::kMaxDurationExceeded;
return ErrorCodeEnum::MAX_DURATION_EXCEEDED;
}

// Subtract one from longest_num_waypoints because the first index doesn't count toward duration
Expand Down Expand Up @@ -356,7 +356,7 @@ ErrorCodeEnum TrajectoryGenerator::synchronizeTrajComponents(std::vector<JointTr
}
}

return ErrorCodeEnum::kNoError;
return ErrorCodeEnum::NO_ERROR;
}

void TrajectoryGenerator::clipVectorsForOutput(std::vector<JointTrajectory>* trajectory)
Expand Down Expand Up @@ -391,7 +391,7 @@ void TrajectoryGenerator::clipVectorsForOutput(std::vector<JointTrajectory>* tra

ErrorCodeEnum TrajectoryGenerator::generateTrajectories(std::vector<JointTrajectory>* output_trajectories)
{
ErrorCodeEnum error_code = ErrorCodeEnum::kNoError;
ErrorCodeEnum error_code = ErrorCodeEnum::NO_ERROR;
// Generate individual joint trajectories
for (size_t joint = 0; joint < kNumDof; ++joint)
{
Expand Down
Loading