Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add parameters to specify maximum allowd time jump #202

Merged
merged 4 commits into from
Apr 22, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
8 changes: 8 additions & 0 deletions include/ypparam.h
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,8 @@ typedef enum
YP_PARAM_INDEX_GEAR,

YP_PARAM_DEVICE_TIMEOUT,
YP_PARAM_MAX_TIME_JUMP,
YP_PARAM_MAX_TIME_JUMP_NEG,

YP_PARAM_NUM ///< パラメータの最大値
} YPSpur_param;
Expand Down Expand Up @@ -296,6 +298,8 @@ typedef enum
"INDEX_FALL_ANGLE", \
"INDEX_GEAR", \
"DEVICE_TIMEOUT", \
"MAX_TIME_JUMP", \
"-MAX_TIME_JUMP", \
}

#define YP_PARAM_NECESSARY \
Expand Down Expand Up @@ -371,6 +375,8 @@ typedef enum
0, \
0, \
0, \
0, \
0, \
}

#define YP_PARAM_COMMENT \
Expand Down Expand Up @@ -447,6 +453,8 @@ typedef enum
"[rad] Index signal falling edge angle at CW rotation", \
"[in/out] Index signal gear ratio", \
"[s] Timeout of the communication with the device", \
"[s] Maximum allowed positive system time jump, used for --exit-on-time-jump", \
"[s] Maximum allowed negative system time jump, used for --exit-on-time-jump", \
}

enum motor_id
Expand Down
2 changes: 1 addition & 1 deletion src/control_vehicle.c
Original file line number Diff line number Diff line change
Expand Up @@ -560,7 +560,7 @@ void control_loop(void)
const double dt = now - last_time;
const double dt_error = dt - expected_dt;
last_time = now;
if (dt_error < -control_cycle || control_cycle < dt_error)
if (dt_error < -p(YP_PARAM_MAX_TIME_JUMP_NEG, 0) || p(YP_PARAM_MAX_TIME_JUMP, 0) < dt_error)
{
yprintf(OUTPUT_LV_ERROR, "Detected system time jump: %0.5fs\n", dt_error);
static int status = EXIT_FAILURE;
Expand Down
30 changes: 30 additions & 0 deletions src/param.c
Original file line number Diff line number Diff line change
Expand Up @@ -940,6 +940,36 @@ int set_paramptr(FILE* paramfile)
g_P_changed[YP_PARAM_TORQUE_UNIT][j] = ischanged_p(YP_PARAM_TORQUE_FINENESS, j);
}

if (g_P_set[YP_PARAM_MAX_TIME_JUMP][0])
{
if (g_P_set[YP_PARAM_MAX_TIME_JUMP][0] <= 0)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (g_P_set[YP_PARAM_MAX_TIME_JUMP][0] <= 0)
if (g_P[YP_PARAM_MAX_TIME_JUMP][0] <= 0)

{
yprintf(OUTPUT_LV_ERROR, "ERROR: MAX_TIME_JUMP must be > 0.0.\n");
param_error = 1;
}
}
else
{
g_P[YP_PARAM_MAX_TIME_JUMP][0] = g_P[YP_PARAM_CYCLE][0];
}
if (g_P_set[YP_PARAM_MAX_TIME_JUMP_NEG][0])
{
if (g_P_set[YP_PARAM_MAX_TIME_JUMP_NEG][0] <= 0)
{
yprintf(OUTPUT_LV_ERROR, "ERROR: -MAX_TIME_JUMP must be > 0.0.\n");
Copy link

@Taka-Kazu Taka-Kazu Apr 22, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[optional] MAX_TIME_JUMP is another parameter so use the name MAX_TIME_JUMP_NEG might be clearer here.

Suggested change
yprintf(OUTPUT_LV_ERROR, "ERROR: -MAX_TIME_JUMP must be > 0.0.\n");
yprintf(OUTPUT_LV_ERROR, "ERROR: MAX_TIME_JUMP_NEG must be > 0.0.\n");

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MAX_TIME_JUMP_NEG is internal enum name and user can only specify -MAX_TIME_JUMP in the parameter file.
(This format was originally introduced to support different friction parameters for each rotation direction)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand now.

param_error = 1;
}
}
else
{
g_P[YP_PARAM_MAX_TIME_JUMP_NEG][j] = g_P[YP_PARAM_CYCLE][j];
}

if (param_error)
{
return 0;
}

// パラメータの指定によって自動的に求まるパラメータの計算
calc_param_inertia2ff();

Expand Down
Loading