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.
 
 
 

102 lines
1.9 KiB

/*
* BHBF_ROBOT.c
*
* Created on: Oct 26, 2023
* Author: shiya
*/
#include "fsm.h"
#include "BHBF_ROBOT.h"
#include <string.h>
#include "bsp_log.h"
#include "msp_DH_Remote_Controller.h"
#include "bsp_FDCAN.h"
#include "msp_DAM_Relay.h"
//7 motors
MotorParameters *Motor[7];
//Motor Error
int32_t *Motor_ID_Errors[7] =
{ 0 };
//ComError
int32_t* SystemTimeMiliSeconds;
int32_t SystemTimeMiliCount;
int32_t* SystemErrorCode;
ErrorData* SystemErrorData;
TT_MotorParameters* TT_Motor[4];
//Declare a CV and initialize CV
CV_struct_define CV =
{ 0 };
//Declare a GV and initialize CV
GV_struct_define GV =
{ 0 };
//Declare a PV and initialize CV
//PV_struct_define PV =
//{ 0 };
IV_struct_define IV ={ 0 };
void SET_BIT_1(int32_t* num,int32_t k)
{
*num=((*num) | (1 << (k)));
}
void SET_BIT_0(int32_t* num,int32_t k)
{
*num=((*num) & ~(1 << (k)));
}
int32_t Get_BIT(int32_t* num,int32_t k)
{
return (*num >> (k - 1)) & 1;
}
void SystemTimer_Intialize()
{
SystemTimeMiliCount=0;
GF_BSP_Interrupt_Add_CallBack(
DF_BSP_InterCall_TIM8_2ms_PeriodElapsedCallback, GF_Timer_Count);
}
void GF_Timer_Count()
{
SystemTimeMiliCount++;
}
Sys_timer_handler timer_handler_1;
Sys_timer_handler timer_handler_2;
Sys_timer_handler timer_handler_3;
Sys_timer_handler timer_handler_4;
int sys_timer_1_flag_count[4];
bool CompareTimer(int32_t DelayMiliSeconds,Sys_timer_handler * timer_handler)
{
if(timer_handler->start_timer==1)
{
timer_handler->sys_current_timer_count=DelayMiliSeconds/2+SystemTimeMiliCount;
timer_handler->start_timer=0;
}
if(timer_handler->sys_current_timer_count <= SystemTimeMiliCount)
{
return true;
}else
{
return false;
}
}
bool CompareTimer_Delay(int32_t Delay)
{
int32_t tickstart = SystemTimeMiliCount;
int32_t wait = Delay;
/* Add a freq to guarantee minimum wait */
if (wait < HAL_MAX_DELAY)
{
int32_t wait = Delay;
while ((SystemTimeMiliCount - tickstart) < wait/2)
{
}
}
}