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

industry/foc: fix direction alignment #2204

Merged
merged 1 commit into from
Nov 18, 2023
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
9 changes: 7 additions & 2 deletions industry/foc/fixed16/foc_align.c
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,8 @@ static void foc_align_dir_move_b16(FAR struct foc_align_b16_s *align,
static void foc_align_dir_hold_b16(FAR struct foc_align_b16_s *align,
b16_t dir, bool last, bool diff)
{
b16_t tmp = 0;

DEBUGASSERT(align);

/* Lock angle */
Expand All @@ -422,13 +424,16 @@ static void foc_align_dir_hold_b16(FAR struct foc_align_b16_s *align,

if (diff == true)
{
tmp = align->angle_now - align->angle_last;
angle_norm_2pi_b16(&tmp, -b16PI, b16PI);

if (dir == DIR_CW_B16)
{
align->diff_cw += (align->angle_now - align->angle_last);
align->diff_cw += tmp;
}
else if (dir == DIR_CCW_B16)
{
align->diff_ccw += (align->angle_now - align->angle_last);
align->diff_ccw += tmp;
}
else
{
Expand Down
9 changes: 7 additions & 2 deletions industry/foc/float/foc_align.c
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,8 @@ static void foc_align_dir_move_f32(FAR struct foc_align_f32_s *align,
static void foc_align_dir_hold_f32(FAR struct foc_align_f32_s *align,
float dir, bool last, bool diff)
{
float tmp = 0.0f;

DEBUGASSERT(align);

/* Lock angle */
Expand All @@ -422,13 +424,16 @@ static void foc_align_dir_hold_f32(FAR struct foc_align_f32_s *align,

if (diff == true)
{
tmp = align->angle_now - align->angle_last;
angle_norm_2pi(&tmp, -M_PI_F, M_PI_F);

if (dir == DIR_CW)
{
align->diff_cw += (align->angle_now - align->angle_last);
align->diff_cw += tmp;
}
else if (dir == DIR_CCW)
{
align->diff_ccw += (align->angle_now - align->angle_last);
align->diff_ccw += tmp;
}
else
{
Expand Down
Loading