HPM APP
HPMicro Application solution
hpm_motor library test demo

Depend on SDK1.10.0

introduction

In order to facilitate users to use and understand the functions of the motor library, a test demo is set up for the motor library.

Version 1.0 of the library contains only trajectory planning algorithms.

[hpm_motor library instruction 2.0](hpm_motor_instruction_en)

Sample

Define trajectory planning structure variables

CMDGENE_PARA cmdpar;
CMDGENE_PARA cmdpar
Definition: libcmdtest.c:4

Define the position mode/speed mode

#define POS_MODE 1

Define an array of shift instructions and speed instructions

double poscmd[5000]={0};
double velcmd[5000]={0};
double velcmd[5000]
Definition: libcmdtest.c:6
double poscmd[5000]
Definition: libcmdtest.c:5

Define a 10ms timer

void timer_init(void)
{
gptmr_channel_config_t config;
gptmr_channel_get_default_config(BOARD_BLDC_TMR_MS, &config);
config.cmp[0] = BOARD_BLDC_TMR_RELOAD;
config.debug_mode = 0;
config.reload = BOARD_BLDC_TMR_RELOAD+1;
gptmr_enable_irq(BOARD_BLDC_TMR_MS, GPTMR_CH_CMP_IRQ_MASK(BOARD_BLDC_TMR_CH, BOARD_BLDC_TMR_CMP));
gptmr_channel_config(BOARD_BLDC_TMR_MS, BOARD_BLDC_TMR_CH, &config, true);
intc_m_enable_irq_with_priority(BOARD_BLDC_TMR_IRQ, 2);
}
void timer_init(void)
timer init ;定时器初始化
Definition: libcmdtest.c:13
#define BOARD_BLDC_TMR_IRQ
Definition: libcmdtest.h:12
#define BOARD_BLDC_TMR_MS
Definition: libcmdtest.h:9
#define BOARD_BLDC_TMR_CH
Definition: libcmdtest.h:10
#define BOARD_BLDC_TMR_RELOAD
Definition: libcmdtest.h:13
#define BOARD_BLDC_TMR_CMP
Definition: libcmdtest.h:11

Configure trajectory planning entry parameters

cmdpar.cmdgene_in_par.poscfgpar.q0 = 0;
cmdpar.cmdgene_in_par.poscfgpar.q1 = MOVE_BASOLUTE_POS_R;
cmdpar.cmdgene_in_par.poscfgpar.v0 = 0;
cmdpar.cmdgene_in_par.poscfgpar.v1 = 0;
cmdpar.cmdgene_in_par.poscfgpar.vmax = MOVE_SPEED;
cmdpar.cmdgene_in_par.poscfgpar.amax = MOVE_ACC;
cmdpar.cmdgene_in_par.poscfgpar.jmax = MOVE_JERK;
cmdpar.cmdgene_in_par.poscfgpar.cyclecnt = CYCLE_CNT;
cmdpar.cmdgene_in_par.poscfgpar.cycletype = MULTIPLE_MOVE_TYPE;
cmdpar.cmdgene_in_par.poscfgpar.dwelltime = DWELLTIME_MS;
cmdpar.cmdgene_in_par.poscfgpar.isr_time_s = ISR_TIME_S;
cmdpar.cmdgene_in_par.velcfgpar.q0 = 0;
cmdpar.cmdgene_in_par.velcfgpar.Tv = CONSTANT_SPEED_TIME_S;
cmdpar.cmdgene_in_par.velcfgpar.v0 = 0;
cmdpar.cmdgene_in_par.velcfgpar.v1 = 0;
cmdpar.cmdgene_in_par.velcfgpar.vmax =MOVE_SPEED;
cmdpar.cmdgene_in_par.velcfgpar.amax = MOVE_ACC;
cmdpar.cmdgene_in_par.velcfgpar.jmax = MOVE_JERK;
cmdpar.cmdgene_in_par.velcfgpar.isr_time_s = ISR_TIME_S;
#define MOVE_SPEED
user define motor move speed ;运动速度,单位:r/s
Definition: libcmdtest.h:26
#define ISR_TIME_S
set isr time ;更新位置/速度序列的中断时间,与定时器中断时间保持一致,单位:s
Definition: libcmdtest.h:57
#define MOVE_ACC
user define motor move acc ;运动加速度,单位:r/s/s
Definition: libcmdtest.h:31
#define CYCLE_CNT
user define motor move cycle count ;位置模式下,电机轴往返运动次数
Definition: libcmdtest.h:46
#define DWELLTIME_MS
user define motor dwell time ;位置模式下,运行相对位置后轴停止时间,单位:ms
Definition: libcmdtest.h:52
@ MULTIPLE_MOVE_TYPE
user define motor in multiple move type ;位置模式下,电机轴以多次往返模式运动
Definition: libcmdtest.h:74
#define CONSTANT_SPEED_TIME_S
user define motor move time with constant speed ;速度模式下,匀速运动时间,单位:s
Definition: libcmdtest.h:41
#define MOVE_BASOLUTE_POS_R
user define motor relative position ;相对运动距离,单位:r
Definition: libcmdtest.h:21
#define MOVE_JERK
user define motor move jerk ;运动加加速度,单位:r/s/s/s
Definition: libcmdtest.h:36

Trajectory planning call function

void libcall(void)
{
#ifdef POS_MODE
pos_cmd_gene(&cmdpar);
#else
vel_cmd_gene(&cmdpar);
#endif
}
void libcall(void)
trajectory planning function call ;轨迹规划调用函数
Definition: libcmdtest.c:61

ISR

void isr_gptmr(void)
{
volatile uint32_t s = BOARD_BLDC_TMR_MS->SR;
if (s & GPTMR_CH_CMP_STAT_MASK(BOARD_BLDC_TMR_CH, BOARD_BLDC_TMR_CMP))
{
if(ii==5000)
{
return;
}
poscmd[ii] = cmdpar.cmdgene_out_par.poscmd;
velcmd[ii] = cmdpar.cmdgene_out_par.velcmd;
ii++;
}
}
SDK_DECLARE_EXT_ISR_M(BOARD_BLDC_TMR_IRQ, isr_gptmr)
uint32_t ii
Definition: libcmdtest.c:7
void isr_gptmr(void)
ISR ;中断函数内调用轨迹规划函数
Definition: libcmdtest.c:76

DEMO

int main (void)
{
board_init();
}
void lib_params_cfg(void)
config trajectory planning parameters ;配置轨迹规划参数
Definition: libcmdtest.c:32
int main(void)
Definition: libcmdtest.c:97

Code Path

  • Code Path:lib_demo/software

Code Configuration

Code Build

  • Build for windows WIN build

Hardware

  • The hpm_6200_FourMotor_MB_RevA used in this routine
  • Users can use the others EVK board

Code Run

  • run the project
  • Save location instructions and speed instructions to local txt
  • excel graphics process

code run

test content

speed mode,vel 10r/s,acc 100r/s/s,jerk 1000r/s/s/s

Code configuration

  • Comment out the macro definition POS_MODE in the libcmdtest.c file;
  • Change MOVE_SPEED to 10, MOVE_ACC to 100, and MOVE_JERK to 1000 in the libcmdtest.h file.
  • Observe the value of the velcmd array with the following test results:

test result

speed mode,vel 10r/s,acc 10r/s/s,jerk 100r/s/s/s

Code configuration

  • Comment out the macro definition POS_MODE in the libcmdtest.c file;
  • Change MOVE_SPEED to 10, MOVE_ACC to 10, and MOVE_JERK to 100 in the libcmdtest.h file.
  • Observe the value of the velcmd array with the following test results:

test result

position mode,vel 10r/s,acc 100r/s/s,jerk 1000r/s/s/s,absolute position 20,move mode:continuous round mode

Code configuration

  • Open macro definition POS_MODE in libcmdtest.c file;
  • Change MOVE_RABSOLUTE_POS_r in the libcmdtest.h file to 20, MOVE_SPEED to 10, MOVE_ACC to 100, and MOVE_JERK to 1000.
  • Change the value of cmdpar.cmdgene_in_par.poscfgpar.cycle in the lib_params_cfg function in the libcmdtest.c file to CONTINOUS_RONUD_MOVE_TYPE;
  • Observe the values of the velcmd and poscmd arrays with the following test results:

test result

position mode,vel 10r/s,acc 100r/s/s,jerk 1000r/s/s/s,absolute position 20,move mode:single

Code configuration

  • Open macro definition POS_MODE in libcmdtest.c file;
  • Change MOVE_ABSOLUTE_POS_r in the libcmdtest.h file to 20, MOVE_SPEED to 10, MOVE_ACC to 100, and MOVE_JERK to 1000.
  • Change the value of cmdpar.cmdgene_in_par.poscfgpar.cycle in the libcmdtest.c file lib_params_cfg to SIGNLE_MOVE_TYPE;
  • Observe the values of the velcmd and poscmd arrays with the following test results:

test result

position mode,vel 10r/s,acc 100r/s/s,jerk 1000r/s/s/s,absolute position 20,move mode:multiple ,move cycle :2

Code configuration

  • Open macro definition POS_MODE in libcmdtest.c file;
  • Change MOVE_ABSOLUTE_POS_r in the libcmdtest.h file to 20, MOVE_SPEED to 10, MOVE_ACC to 100, MOVE_JERK to 1000, and CYCLE_CNT to 2.
  • Change the value of cmdpar.cmdgene_in_par.poscfgpar.cycle in the libcmdtest.c file lib_params_cfg to MULTIPLE_MOVE_TYPE;
  • Observe the values of the velcmd and poscmd arrays with the following test results:

test result

Licensing

HPM APP is permissively licensed using the BSD 3-clause license