RA Flexible Software Package Documentation  Release v5.2.0

 
Motor Position Controller (rm_motor_position)

Functions

fsp_err_t RM_MOTOR_POSITION_Open (motor_position_ctrl_t *const p_ctrl, motor_position_cfg_t const *const p_cfg)
 Opens and configures the Motor Position Module. Implements motor_position_api_t::open. More...
 
fsp_err_t RM_MOTOR_POSITION_Close (motor_position_ctrl_t *const p_ctrl)
 Disables specified Motor Position Module. Implements motor_position_api_t::close. More...
 
fsp_err_t RM_MOTOR_POSITION_Reset (motor_position_ctrl_t *const p_ctrl)
 Reset the variables of Motor Position Module. Implements motor_position_api_t::reset. More...
 
fsp_err_t RM_MOTOR_POSITION_PositionGet (motor_position_ctrl_t *const p_ctrl, int16_t *const p_position)
 Get Rotor Position Data [degree]. Implements motor_position_api_t::positionGet. More...
 
fsp_err_t RM_MOTOR_POSITION_PositionSet (motor_position_ctrl_t *const p_ctrl, float const position_rad)
 Set Position Data from Encoder [radian]. Implements motor_position_api_t::positionSet. More...
 
fsp_err_t RM_MOTOR_POSITION_PositionReferenceSet (motor_position_ctrl_t *const p_ctrl, int16_t const position_reference_deg)
 Set Position Reference Data [degree]. Implements motor_position_api_t::positionReferenceSet. More...
 
fsp_err_t RM_MOTOR_POSITION_ControlModeSet (motor_position_ctrl_t *const p_ctrl, motor_position_ctrl_mode_t const mode)
 Set Position Control Mode. Implements motor_position_api_t::controlModeSet. More...
 
fsp_err_t RM_MOTOR_POSITION_PositionControl (motor_position_ctrl_t *const p_ctrl)
 Calculates internal position reference.(Main process of Position Control) Implements motor_position_api_t::positionControl. More...
 
fsp_err_t RM_MOTOR_POSITION_IpdSpeedPControl (motor_position_ctrl_t *const p_ctrl, float const ref_speed_rad, float const speed_rad, float *const p_iq_ref)
 Calculates the q-axis current reference by P control. Implements motor_position_api_t::ipdSpeedPControl. More...
 
fsp_err_t RM_MOTOR_POSITION_SpeedReferencePControlGet (motor_position_ctrl_t *const p_ctrl, float *const p_speed_ref)
 Get Speed Reference by P Control. Implements motor_position_api_t::speedReferencePControlGet. More...
 
fsp_err_t RM_MOTOR_POSITION_SpeedReferenceIpdControlGet (motor_position_ctrl_t *const p_ctrl, float const max_speed_rad, float *const p_speed_ref)
 Get Speed Reference by IPD Control. Implements motor_position_api_t::speedReferenceIpdControlGet. More...
 
fsp_err_t RM_MOTOR_POSITION_SpeedReferenceFeedforwardGet (motor_position_ctrl_t *const p_ctrl, float *const p_speed_ref)
 Get Speed Reference by Feedforward. Implements motor_position_api_t::speedReferenceFeedforwardGet. More...
 
fsp_err_t RM_MOTOR_POSITION_InfoGet (motor_position_ctrl_t *const p_ctrl, motor_position_info_t *const p_info)
 Get position information. More...
 
fsp_err_t RM_MOTOR_POSITION_ParameterUpdate (motor_position_ctrl_t *const p_ctrl, motor_position_cfg_t const *const p_cfg)
 Update the parameters of Position Control Calculation. Implements motor_position_api_t::parameterUpdate. More...
 

Detailed Description

Calculation process for the motor control on RA MCUs. This module implements the Motor position Interface.

Overview

The motor position is used to control the position of motor rotor in an appication. This module should be called cyclically in an application (e.g. in cyclic timer interrupt). This module calculates speed reference with inputted position reference and current rotational speed.

Features

The Motor Position Module has below features.

Configuration

Build Time Configurations for rm_motor_position

The following build time configurations are defined in fsp_cfg/rm_motor_position_cfg.h:

ConfigurationOptionsDefaultDescription
Parameter Checking
  • Default (BSP)
  • Enabled
  • Disabled
Default (BSP) If selected code for parameter checking is included in the build.

Configurations for Motor > Motor Position Controller (rm_motor_position)

This module can be added to the Stacks tab via New Stack > Motor > Motor Position Controller (rm_motor_position).

ConfigurationOptionsDefaultDescription
General
NameName must be a valid C symbolg_motor_position0 Module name.
Position dead bandManual Entry1U Ignored area of position control.
Position band limitManual Entry3U Ignored area of position control.
Speed feedforward ratioMust be a valid value0.8F Speed feedforward ratio.
Encoder counts per one rotationMust be a valid value1200.0F Encoder counts per one rotation.
Position omegaMust be a valid value10.0F Position control omega.
Period of speed control (sec)Must be a valid value0.0005F Period of speed control.
IPD
IPD LPF
  • Disable
  • Enable
Disable IPD LPF process enable or disable
Position Kp ratioMust be a valid value0.3F Position Kp ratio.
Position feedforward ratioMust be a valid value0.0F Position feedforward ratio.
Speed K ratioMust be a valid value2.0F Speed K ratio
Error Limit #1Must be a valid value10.0F Error limitation #1
Error limit #2Must be a valid value0.2F Error limitation #2
LPF omegaMust be a valid value500.0F LPF omega.
LPF zetaMust be a valid value1.0F LPF zeta.
Position Profiling
Interval timeManual Entry400U Interval time.
Accel timeMust be a valid value0.3F Accel time.
Maximum accel time (sec)Must be a valid value8117.96F Maximum accelaration time (sec)
Accelaration maximum speedMust be a valid value2000.0F Accelaration maximum speed.
Update step of timerMust be a valid value0.0005F Update step of timer.
Motor Parameter
Pole pairManual Entry7 Pole pair
Resistance (ohm)Must be a valid value0.453F Resistance
Inductance of d-axis (H)Must be a valid value0.0009447F Inductance of d-axis
Inductance of q-axis (H)Must be a valid value0.0009447F Inductance of q-axis
Permanent magnetic flux (Wb)Must be a valid value0.006198F Permanent magnetic flux
Motor Parameter > Motor inertia (kgm^2)Must be a valid value0.00000962F Motor inertia

Clock Configuration

This module doesn't depend on clock setting, because this module is a simple calculation process.

Pin Configuration

This module does not use I/O pins.

Usage Notes

Limitations

Examples

Basic Example

This is a basic example of using the Motor Position module in an application.

void motor_position_basic_example (void)
{
fsp_err_t err = FSP_SUCCESS;
/* Initializes the module. */
err = RM_MOTOR_POSITION_Open(g_motor_position0.p_ctrl, g_motor_position0.p_cfg);
handle_error(err);
/* Set working mode */
RM_MOTOR_POSITION_ModeSet(g_motor_position0.p_ctrl, MOTOR_POSITION_CTRL_MODE_STEP);
/* Set position reference */
RM_MOTOR_POSITION_PositionReferenceSet(g_motor_position0.p_ctrl, 180U);
/* Basically run this module at cyclic interrupt (e.g. AGT timer).
* This implementation is an example. */
// while (true)
{
/* Application work here. */
/* Perform Position Control Process */
RM_MOTOR_POSITION_PositionControl(g_motor_position0.p_ctrl);
/* Perform Speed IPD Control Process */
RM_MOTOR_POSITION_IpdSpeedPControl(g_motor_position0.p_ctrl, 0.0F, 0.0F, &temp_iq_ref);
/* Get Position */
RM_MOTOR_POSITION_PositionGet(g_motor_position0.p_ctrl, &temp_position);
/* Update parameters */
RM_MOTOR_POSITION_ParameterUpdate(g_motor_position0.p_ctrl, &g_motor_position0.p_cfg);
}
/* Reset Speed Control */
RM_MOTOR_POSITION_Reset(g_motor_position0.p_ctrl);
/* Close Speed Control */
RM_MOTOR_POSITION_Close(g_motor_position0.p_ctrl);
}

Enumerations

enum  motor_position_ipd_lpf_t
 

Enumeration Type Documentation

◆ motor_position_ipd_lpf_t

Enumerator
MOTOR_POSITION_IPD_LPF_DISABLE 

ipd control is disabled

MOTOR_POSITION_IPD_LPF_ENABLE 

ipd control is enabled

Function Documentation

◆ RM_MOTOR_POSITION_Open()

fsp_err_t RM_MOTOR_POSITION_Open ( motor_position_ctrl_t *const  p_ctrl,
motor_position_cfg_t const *const  p_cfg 
)

Opens and configures the Motor Position Module. Implements motor_position_api_t::open.

Return values
FSP_SUCCESSMotor Position Module successfully configured.
FSP_ERR_ASSERTIONNull pointer, or one or more configuration options is invalid.
FSP_ERR_ALREADY_OPENModule is already open. This module can only be opened once.
FSP_ERR_INVALID_ARGUMENTSet parameter is invalid.

◆ RM_MOTOR_POSITION_Close()

fsp_err_t RM_MOTOR_POSITION_Close ( motor_position_ctrl_t *const  p_ctrl)

Disables specified Motor Position Module. Implements motor_position_api_t::close.

Return values
FSP_SUCCESSSuccessfully closed.
FSP_ERR_ASSERTIONNull pointer.
FSP_ERR_NOT_OPENModule is not open.

◆ RM_MOTOR_POSITION_Reset()

fsp_err_t RM_MOTOR_POSITION_Reset ( motor_position_ctrl_t *const  p_ctrl)

Reset the variables of Motor Position Module. Implements motor_position_api_t::reset.

Return values
FSP_SUCCESSSuccessfully reset.
FSP_ERR_ASSERTIONNull pointer.
FSP_ERR_NOT_OPENModule is not open.

◆ RM_MOTOR_POSITION_PositionGet()

fsp_err_t RM_MOTOR_POSITION_PositionGet ( motor_position_ctrl_t *const  p_ctrl,
int16_t *const  p_position 
)

Get Rotor Position Data [degree]. Implements motor_position_api_t::positionGet.

Return values
FSP_SUCCESSSuccessfully data is set.
FSP_ERR_ASSERTIONNull pointer.
FSP_ERR_NOT_OPENModule is not open.
FSP_ERR_INVALID_ARGUMENTOutput pointer is NULL.

◆ RM_MOTOR_POSITION_PositionSet()

fsp_err_t RM_MOTOR_POSITION_PositionSet ( motor_position_ctrl_t *const  p_ctrl,
float const  position_rad 
)

Set Position Data from Encoder [radian]. Implements motor_position_api_t::positionSet.

Return values
FSP_SUCCESSSuccessfully data is set.
FSP_ERR_ASSERTIONNull pointer.
FSP_ERR_NOT_OPENModule is not open.

◆ RM_MOTOR_POSITION_PositionReferenceSet()

fsp_err_t RM_MOTOR_POSITION_PositionReferenceSet ( motor_position_ctrl_t *const  p_ctrl,
int16_t const  position_reference_deg 
)

Set Position Reference Data [degree]. Implements motor_position_api_t::positionReferenceSet.

Return values
FSP_SUCCESSSuccessfully data is set.
FSP_ERR_ASSERTIONNull pointer.
FSP_ERR_NOT_OPENModule is not open.

◆ RM_MOTOR_POSITION_ControlModeSet()

fsp_err_t RM_MOTOR_POSITION_ControlModeSet ( motor_position_ctrl_t *const  p_ctrl,
motor_position_ctrl_mode_t const  mode 
)

Set Position Control Mode. Implements motor_position_api_t::controlModeSet.

Return values
FSP_SUCCESSSuccessfully data is set.
FSP_ERR_ASSERTIONNull pointer.
FSP_ERR_NOT_OPENModule is not open.

◆ RM_MOTOR_POSITION_PositionControl()

fsp_err_t RM_MOTOR_POSITION_PositionControl ( motor_position_ctrl_t *const  p_ctrl)

Calculates internal position reference.(Main process of Position Control) Implements motor_position_api_t::positionControl.

Return values
FSP_SUCCESSSuccessful data calculation.
FSP_ERR_ASSERTIONNull pointer.
FSP_ERR_NOT_OPENModule is not open.

◆ RM_MOTOR_POSITION_IpdSpeedPControl()

fsp_err_t RM_MOTOR_POSITION_IpdSpeedPControl ( motor_position_ctrl_t *const  p_ctrl,
float const  ref_speed_rad,
float const  speed_rad,
float *const  p_iq_ref 
)

Calculates the q-axis current reference by P control. Implements motor_position_api_t::ipdSpeedPControl.

Return values
FSP_SUCCESSSuccessful data calculation.
FSP_ERR_ASSERTIONNull pointer.
FSP_ERR_NOT_OPENModule is not open.
FSP_ERR_INVALID_ARGUMENTOutput pointer is NULL.

◆ RM_MOTOR_POSITION_SpeedReferencePControlGet()

fsp_err_t RM_MOTOR_POSITION_SpeedReferencePControlGet ( motor_position_ctrl_t *const  p_ctrl,
float *const  p_speed_ref 
)

Get Speed Reference by P Control. Implements motor_position_api_t::speedReferencePControlGet.

Return values
FSP_SUCCESSSuccessfully data is set.
FSP_ERR_ASSERTIONNull pointer.
FSP_ERR_NOT_OPENModule is not open.
FSP_ERR_INVALID_ARGUMENTOutput pointer is NULL.

◆ RM_MOTOR_POSITION_SpeedReferenceIpdControlGet()

fsp_err_t RM_MOTOR_POSITION_SpeedReferenceIpdControlGet ( motor_position_ctrl_t *const  p_ctrl,
float const  max_speed_rad,
float *const  p_speed_ref 
)

Get Speed Reference by IPD Control. Implements motor_position_api_t::speedReferenceIpdControlGet.

Return values
FSP_SUCCESSSuccessfully data is set.
FSP_ERR_ASSERTIONNull pointer.
FSP_ERR_NOT_OPENModule is not open.
FSP_ERR_INVALID_ARGUMENTOutput pointer is NULL.

◆ RM_MOTOR_POSITION_SpeedReferenceFeedforwardGet()

fsp_err_t RM_MOTOR_POSITION_SpeedReferenceFeedforwardGet ( motor_position_ctrl_t *const  p_ctrl,
float *const  p_speed_ref 
)

Get Speed Reference by Feedforward. Implements motor_position_api_t::speedReferenceFeedforwardGet.

Return values
FSP_SUCCESSSuccessfully data is set.
FSP_ERR_ASSERTIONNull pointer.
FSP_ERR_NOT_OPENModule is not open.
FSP_ERR_INVALID_ARGUMENTOutput pointer is NULL.

◆ RM_MOTOR_POSITION_InfoGet()

fsp_err_t RM_MOTOR_POSITION_InfoGet ( motor_position_ctrl_t *const  p_ctrl,
motor_position_info_t *const  p_info 
)

Get position information.

Return values
FSP_SUCCESSSuccessfully data is set.
FSP_ERR_ASSERTIONNull pointer.
FSP_ERR_NOT_OPENModule is not open.
FSP_ERR_INVALID_ARGUMENTOutput pointer is NULL.

◆ RM_MOTOR_POSITION_ParameterUpdate()

fsp_err_t RM_MOTOR_POSITION_ParameterUpdate ( motor_position_ctrl_t *const  p_ctrl,
motor_position_cfg_t const *const  p_cfg 
)

Update the parameters of Position Control Calculation. Implements motor_position_api_t::parameterUpdate.

Return values
FSP_SUCCESSSuccessfully data was updated.
FSP_ERR_ASSERTIONNull pointer.
FSP_ERR_NOT_OPENModule is not open.
FSP_ERR_INVALID_ARGUMENTConfiguration parameter error.