123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156 |
- #include "global.h"
- //轴实体
- axis_object_t axis_objects[AXIS_NUMBER];
- /**
- * 通过编号获取对象
- *
- * @author lxz
- *
- * @param index
- *
- * @return axis_t*
- */
- axis_object_t* axis_get_by_index(unsigned char index) {
- if (index < AXIS_NUMBER) {
- return &axis_objects[index];
- }
- return (void *)0;
- }
- /**
- * 通过轴号获取对象,必须在初始化后才能使用这个API
- *
- * @author lxz
- *
- * @param index
- *
- * @return axis_t*
- */
- axis_object_t* axis_get_by_axisno(unsigned char axisno) {
- unsigned char index = 0;
- while (index < AXIS_NUMBER) {
- if (axis_objects[index].axis_no == axisno) {
- return &axis_objects[index];
- }
- }
- return (void *)0;
- }
- typedef struct
- {
- unsigned short no;
- unsigned short speed;
- int position;
- int dst_position;
- unsigned short aac;
- unsigned short ddc;
- unsigned short max_acc;
- unsigned short max_dec;
- unsigned short min_speed;
- unsigned short max_speed;
- unsigned short time_uint;
- unsigned short speed_unit;
- } motion_parameter_t;
- /**
- * 轴初始化,包括参数初始化,回掉函数设置
- *
- * @author lxz
- *
- * @param void
- */
- void axis_app_init(void) {
- int index = 0;
- memset(&axis_objects[0], 0, sizeof(axis_objects));
- while (index < AXIS_NUMBER)
- {
- //注册中断与调用对象
- axis_object_t *axis = axis_get_by_index(index);
- axis->axis_no = index;
- hw_pwm_it_register(index, axis_it_handle, axis);
- axis->clock = hw_pwm_get_clk(index);
- axis->period = 1; //1个ms为一个时间单位
- axis->speed_unit = 1; //速度单位为1
- axis->min_steps = 1;
- axis->max_aac = 5000;
- axis->max_acc = 4000; //最大加速
- axis->max_dec = 4000; //最大减度
- axis->start_speed = 1000;
- axis->acc_time = 50;
- axis->dec_time = 50;
- axis->accdec_mode = 4; //加减模式清0
- axis->home_find_speed = 10;
- axis->home_high_speed = 100;
- axis->home_low_speed = 50;
- axis->inputs.home_high_speed_enable = 0;
- axis->home_offset = 0;
- axis->home_space = 200;
- axis->sw_positive_limit = 100000; //正软件限位
- axis->sw_negative_limit = -100; //负软件限位
- axis->position = 0; //当前位置清0
- // axis->accdec_mode = 0; //加减模式清0
- //默认正转
- axis_cw(axis);
- //axis_enable(axis);
- //(axis);
- index++;
- }
- axis_x = axis_get_by_index(0);
- axis_y = axis_get_by_index(1);
- axis_z = axis_get_by_index(2);
- //设置方向输出电平
- axis_x->inputs.dir_reverse = 1;
- axis_y->inputs.dir_reverse = 1;
- axis_z->inputs.dir_reverse = 1;
- //设置使能输出电平
- axis_x->inputs.en_reverse = 1;
- axis_y->inputs.en_reverse = 1;
- axis_z->inputs.en_reverse = 1;
-
- // if(X_USE_OLD_DRIVE) ResetServoDrv_CPU(X_AXIS);
- // if(Y_USE_OLD_DRIVE) ResetServoDrv_CPU(Y_AXIS);
-
- }
- /**
- * 轴应用函数
- *
- * @author lxz
- *
- * @param void
- */
- void axis_app_run(void) {
- int index = 0;
- while (index < AXIS_NUMBER) {
- axis_run(&axis_objects[index]);
- index++;
- }
- }
|