This commit is contained in:
NeoZng
2022-11-09 20:24:22 +08:00
parent 4d32450e3d
commit 35d88aaa93
10 changed files with 39 additions and 44 deletions

View File

@@ -22,7 +22,7 @@ static void DecodeJoint(can_instance* motor_instance)
uint16_t tmp;
for (size_t i = 0; i < HT_MOTOR_CNT; i++)
{
if(&joint_motor_info[i]->motor_can_instace==motor_instance)
if(joint_motor_info[i]->motor_can_instace==motor_instance)
{
tmp = (motor_instance->rx_buff[1] << 8) | motor_instance->rx_buff[2];
joint_motor_info[i]->last_ecd=joint_motor_info[i]->ecd;
@@ -40,7 +40,8 @@ joint_instance* HTMotorInit(can_instance_config config)
{
static uint8_t idx;
joint_motor_info[idx]=(joint_instance*)malloc(sizeof(joint_instance));
CANRegister(&joint_motor_info[idx++]->motor_can_instace,config);
CANRegister(joint_motor_info[idx++]->motor_can_instace,config);
return joint_motor_info[idx++];
}
void JointControl(joint_instance* _instance,float current)

View File

@@ -1,47 +1,47 @@
#include"LK9025.h"
#include "LK9025.h"
static driven_instance* driven_motor_info[LK_MOTOR_CNT];
static driven_instance *driven_motor_info[LK_MOTOR_CNT];
static void DecodeDriven(can_instance* _instance)
static void DecodeDriven(can_instance *_instance)
{
for (size_t i = 0; i < LK_MOTOR_CNT; i++)
{
if(&driven_motor_info[i]->motor_can_instance==_instance)
if (driven_motor_info[i]->motor_can_instance == _instance)
{
driven_motor_info[i]->last_ecd = driven_motor_info[i]->ecd;
driven_motor_info[i]->ecd = (uint16_t)((_instance->rx_buff[7]<<8) | _instance->rx_buff[6]);
driven_motor_info[i]->speed_rpm = (uint16_t)(_instance->rx_buff[5] << 8 | _instance->rx_buff[4]);
driven_motor_info[i]->given_current = (uint16_t)(_instance->rx_buff[3] << 8 | _instance->rx_buff[2]);
driven_motor_info[i]->last_ecd = driven_motor_info[i]->ecd;
driven_motor_info[i]->ecd = (uint16_t)((_instance->rx_buff[7] << 8) | _instance->rx_buff[6]);
driven_motor_info[i]->speed_rpm = (uint16_t)(_instance->rx_buff[5] << 8 | _instance->rx_buff[4]);
driven_motor_info[i]->given_current = (uint16_t)(_instance->rx_buff[3] << 8 | _instance->rx_buff[2]);
driven_motor_info[i]->temperate = _instance->rx_buff[1];
break;
}
}
}
driven_instance* LKMotroInit(can_instance_config config)
driven_instance *LKMotroInit(can_instance_config config)
{
static uint8_t idx;
driven_motor_info[idx]=(driven_instance*)malloc(sizeof(driven_instance));
config.can_module_callback=DecodeDriven;
CANRegister(driven_motor_info[idx++]->motor_can_instance,config);
driven_motor_info[idx] = (driven_instance *)malloc(sizeof(driven_instance));
config.can_module_callback = DecodeDriven;
CANRegister(driven_motor_info[idx]->motor_can_instance, config);
return driven_motor_info[idx++];
}
void DrivenControl(int16_t motor1_current,int16_t motor2_current)
void DrivenControl(int16_t motor1_current, int16_t motor2_current)
{
LIMIT_MIN_MAX(motor1_current, I_MIN, I_MAX);
LIMIT_MIN_MAX(motor2_current, I_MIN, I_MAX);
LIMIT_MIN_MAX(motor1_current, I_MIN, I_MAX);
LIMIT_MIN_MAX(motor2_current, I_MIN, I_MAX);
driven_motor_info[0]->motor_can_instance->tx_buff[0] = motor1_current;
driven_motor_info[0]->motor_can_instance->tx_buff[1] = motor1_current>>8;
driven_motor_info[0]->motor_can_instance->tx_buff[1] = motor1_current >> 8;
driven_motor_info[0]->motor_can_instance->tx_buff[2] = motor2_current;
driven_motor_info[0]->motor_can_instance->tx_buff[3] = motor2_current>>8;
driven_motor_info[0]->motor_can_instance->tx_buff[3] = motor2_current >> 8;
CANTransmit(driven_motor_info[0]->motor_can_instance);
}
void SetDrivenMode(driven_mode cmd,uint16_t motor_id)
void SetDrivenMode(driven_mode cmd, uint16_t motor_id)
{
static uint8_t buf[8] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00};
// code goes here ...
// CANTransmit(driven_mode)
}

View File

@@ -12,6 +12,8 @@
#ifndef MOTOR_DEF_H
#define MOTOR_DEF_H
#include "controller.h"
/**
* @brief 闭环类型,如果需要多个闭环,则使用或运算
* 例如需要速度环和电流环: CURRENT_LOOP|SPEED_LOOP