仓库提交练习
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

152 lines
5.2 KiB

/******************************************************************************
(C), 2018-2099, Radkil
******************************************************************************
: motor_adapter.c
: 稿
: radkil
: 2026421
:
:
:
1. : 2026421
: radkil
:
******************************************************************************/
#ifdef BUILD_MOTOR
#include "motor.h"
#include "msp_TTMotor_ZQ.h"
/*----------------------------------------------*
* *
*----------------------------------------------*/
/*----------------------------------------------*
* *
*----------------------------------------------*/
/*----------------------------------------------*
* *
*----------------------------------------------*/
/*----------------------------------------------*
* *
*----------------------------------------------*/
/*----------------------------------------------*
* *
*----------------------------------------------*/
/*----------------------------------------------*
* *
*----------------------------------------------*/
/*----------------------------------------------*
* *
*----------------------------------------------*/
static void WheelSendHeartbeat(TMotorCtrl *ptLeftMotorCtrl, TMotorCtrl *ptRightMotorCtrl)
{
static int Heartbeat_Flag_01;
Heartbeat_Flag_01++;
if(Heartbeat_Flag_01%7==0)
{
Consumer_Or_microcontroller_Heartbeat(ptLeftMotorCtrl, 4);
Consumer_Or_microcontroller_Heartbeat(ptRightMotorCtrl, 4);
Heartbeat_Flag_01=0;
}
}
void MotorGetState(TMotorCtrl *ptMotorCtrl, char *buffer)
{
TT_Analytic_Fun(ptMotorCtrl, buffer);
}
void WheelFuncInit(TMotorCtrl *ptLeftMotorCtrl, TMotorCtrl *ptRightMotorCtrl)
{
ActivateMotor(ptLeftMotorCtrl, 6000);
ActivateMotor(ptRightMotorCtrl, 2000);
ActivateMotor(ptLeftMotorCtrl, 2000);
ActivateMotor(ptRightMotorCtrl, 2000);
ActivateMotor(ptLeftMotorCtrl, 2000);
ActivateMotor(ptRightMotorCtrl, 2000);
ActivateMotor(ptLeftMotorCtrl, 2000);
ActivateMotor(ptRightMotorCtrl, 2000);
Enable_NMT(ptLeftMotorCtrl,1000);
Enable_NMT(ptRightMotorCtrl,1000);
Configure_Asynchronous_Mode(ptLeftMotorCtrl, 7,600);
Consumer_Or_microcontroller_Heartbeat(ptLeftMotorCtrl, 4);
Configure_Asynchronous_Mode(ptRightMotorCtrl, 8,600);
Consumer_Or_microcontroller_Heartbeat(ptLeftMotorCtrl, 4);
SpeedModeSetup(ptLeftMotorCtrl, 6, 500, 500, 0);
Consumer_Or_microcontroller_Heartbeat(ptRightMotorCtrl, 4);
SpeedModeSetup(ptRightMotorCtrl, 6, 500, 500, 0);
Consumer_Or_microcontroller_Heartbeat(ptLeftMotorCtrl, 4);
Consumer_Or_microcontroller_Heartbeat(ptRightMotorCtrl, 4);
WheelSendHeartbeat(ptLeftMotorCtrl, ptRightMotorCtrl);
}
void WheelFuncProc(TMotorCtrl *ptLeftMotorCtrl, TMotorCtrl *ptRightMotorCtrl)
{
TT_Request_Position(ptLeftMotorCtrl, 6);
TT_Request_Velocity(ptLeftMotorCtrl, 6);
TT_Request_Current(ptLeftMotorCtrl, 6);
TT_Request_Fault(ptLeftMotorCtrl, 6);
TT_Request_Position(ptRightMotorCtrl, 6);
TT_Request_Velocity(ptRightMotorCtrl, 6);
TT_Request_Current(ptRightMotorCtrl, 6);
TT_Request_Fault(ptRightMotorCtrl, 6);
TT_SpeedMode_Set_TargetSpeed(ptLeftMotorCtrl, 6, GV.LeftMotor.Target_Velcity);
TT_SpeedMode_Set_TargetSpeed(ptRightMotorCtrl, 6, GV.RightMotor.Target_Velcity);
WheelSendHeartbeat(ptLeftMotorCtrl, ptRightMotorCtrl);
}
void WheelSetVelcity(TMotorCtrl *ptMotorCtrl, float fSpeed_M_min)
{
ptMotorCtrl->pMotorParam->Target_Velcity = (int32_t)(fSpeed_M_min * Move_Base_Speed_Count_m_Min);
}
void SwingFuncInit(TMotorCtrl *ptMotorCtrl)
{
ActivateMotor(ptMotorCtrl, 6000);
ActivateMotor(ptMotorCtrl, 2000);
ActivateMotor(ptMotorCtrl, 2000);
ActivateMotor(ptMotorCtrl, 2000);
ActivateMotor(ptMotorCtrl, 2000);
Postion_Velcocity_Run_SetParameter(ptMotorCtrl, 0, 0, 500, 500, 100);
}
void SwingFuncProc(TMotorCtrl *ptMotorCtrl)
{
TT_Request_Position(ptMotorCtrl, 10);
TT_Request_Fault(ptMotorCtrl, 10);
switch(GV.SwingMotor.Position_immediately1_Lag2)
{
case 1:
Position_Immediately_Setting(ptMotorCtrl, GV.SwingMotor.Tar_Position_count,GV.SwingMotor.Tar_Position_Velcity_RPM,30);
break;
case 2:
Position_Lag_Setting(ptMotorCtrl, GV.SwingMotor.Tar_Position_count,GV.SwingMotor.Tar_Position_Velcity_RPM,30);
break;
}
}
void SwingSetPosition(TMotorCtrl *ptMotorCtrl, float fPositionAngle, int32_t iVelcityDegreeS)
{
ptMotorCtrl->pMotorParam->Tar_Position_count = (int32_t)(middle_position_motor - fPositionAngle * TT_One_Deg_Count_motor);
ptMotorCtrl->pMotorParam->Tar_Position_Velcity_RPM = iVelcityDegreeS*Swing_Speed_Deg_Sencond_motor;
}
#endif