Skip to content

Commit 987543a

Browse files
committed
examples/foc: set direction when updating new setpoint
1 parent ac64c7d commit 987543a

File tree

2 files changed

+14
-10
lines changed

2 files changed

+14
-10
lines changed

examples/foc/foc_motor_b16.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -441,7 +441,7 @@ static int foc_motor_torq(FAR struct foc_motor_b16_s *motor, uint32_t torq)
441441
tmp1 = itob16(motor->envp->cfg->torqmax / 1000);
442442
tmp2 = b16mulb16(ftob16(SETPOINT_INTF_SCALE), tmp1);
443443

444-
motor->torq.des = b16muli(tmp2, torq);
444+
motor->torq.des = b16mulb16(motor->dir, b16muli(tmp2, torq));
445445

446446
return OK;
447447
}
@@ -466,7 +466,7 @@ static int foc_motor_vel(FAR struct foc_motor_b16_s *motor, uint32_t vel)
466466
tmp1 = itob16(motor->envp->cfg->velmax / 1000);
467467
tmp2 = b16mulb16(ftob16(SETPOINT_INTF_SCALE), tmp1);
468468

469-
motor->vel.des = b16muli(tmp2, vel);
469+
motor->vel.des = b16mulb16(motor->dir, b16muli(tmp2, vel));
470470

471471
return OK;
472472
}
@@ -491,7 +491,7 @@ static int foc_motor_pos(FAR struct foc_motor_b16_s *motor, uint32_t pos)
491491
tmp1 = itob16(motor->envp->cfg->posmax / 1000);
492492
tmp2 = b16mulb16(ftob16(SETPOINT_INTF_SCALE), tmp1);
493493

494-
motor->pos.des = b16muli(tmp2, pos);
494+
motor->pos.des = b16mulb16(motor->dir, b16muli(tmp2, pos));
495495

496496
return OK;
497497
}
@@ -914,7 +914,9 @@ static int foc_motor_run(FAR struct foc_motor_b16_s *motor)
914914
#ifdef CONFIG_EXAMPLES_FOC_HAVE_TORQ
915915
case FOC_MMODE_TORQ:
916916
{
917-
motor->torq.set = b16mulb16(motor->dir, motor->torq.des);
917+
/* Torque setpoint */
918+
919+
motor->torq.set = motor->torq.des;
918920

919921
q_ref = motor->torq.set;
920922
d_ref = 0;
@@ -931,7 +933,7 @@ static int foc_motor_run(FAR struct foc_motor_b16_s *motor)
931933
/* Run velocity ramp controller */
932934

933935
ret = foc_ramp_run_b16(&motor->ramp,
934-
motor->dir * motor->vel.des,
936+
motor->vel.des,
935937
motor->vel.now,
936938
&motor->vel.set);
937939
if (ret < 0)

examples/foc/foc_motor_f32.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -431,7 +431,7 @@ static int foc_motor_torq(FAR struct foc_motor_f32_s *motor, uint32_t torq)
431431

432432
/* Update motor torque destination */
433433

434-
motor->torq.des = (torq * SETPOINT_INTF_SCALE *
434+
motor->torq.des = (motor->dir * torq * SETPOINT_INTF_SCALE *
435435
motor->envp->cfg->torqmax / 1000.0f);
436436

437437
return OK;
@@ -449,7 +449,7 @@ static int foc_motor_vel(FAR struct foc_motor_f32_s *motor, uint32_t vel)
449449

450450
/* Update motor velocity destination */
451451

452-
motor->vel.des = (vel * SETPOINT_INTF_SCALE *
452+
motor->vel.des = (motor->dir * vel * SETPOINT_INTF_SCALE *
453453
motor->envp->cfg->velmax / 1000.0f);
454454

455455
return OK;
@@ -467,7 +467,7 @@ static int foc_motor_pos(FAR struct foc_motor_f32_s *motor, uint32_t pos)
467467

468468
/* Update motor position destination */
469469

470-
motor->pos.des = (pos * SETPOINT_INTF_SCALE *
470+
motor->pos.des = (motor->dir * pos * SETPOINT_INTF_SCALE *
471471
motor->envp->cfg->posmax / 1000.0f);
472472

473473
return OK;
@@ -897,7 +897,9 @@ static int foc_motor_run(FAR struct foc_motor_f32_s *motor)
897897
#ifdef CONFIG_EXAMPLES_FOC_HAVE_TORQ
898898
case FOC_MMODE_TORQ:
899899
{
900-
motor->torq.set = motor->dir * motor->torq.des;
900+
/* Torque setpoint */
901+
902+
motor->torq.set = motor->torq.des;
901903

902904
q_ref = motor->torq.set;
903905
d_ref = 0.0f;
@@ -914,7 +916,7 @@ static int foc_motor_run(FAR struct foc_motor_f32_s *motor)
914916
/* Run velocity ramp controller */
915917

916918
ret = foc_ramp_run_f32(&motor->ramp,
917-
motor->dir * motor->vel.des,
919+
motor->vel.des,
918920
motor->vel.now,
919921
&motor->vel.set);
920922
if (ret < 0)

0 commit comments

Comments
 (0)