Skip to content

Commit

Permalink
referee uart bug sometimes occur, level indicator added
Browse files Browse the repository at this point in the history
  • Loading branch information
CuboiLeo committed May 28, 2024
1 parent 2bfdf0a commit 0a99d52
Show file tree
Hide file tree
Showing 12 changed files with 214 additions and 135 deletions.
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ src/ui/src/ui_indicator_0_7.c \
src/ui/src/ui_indicator_0_8.c \
src/ui/src/ui_indicator_0_9.c \
src/ui/src/ui_indicator_0_10.c \
src/ui/src/ui_indicator_0_11.c \
src/ui/src/ui_indicator_1_0.c

# ASM sources
Expand Down
1 change: 1 addition & 0 deletions src/app/inc/robot.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ typedef struct
uint8_t prev_B;
uint8_t prev_G;
uint8_t prev_V;
uint8_t prev_Z;
uint8_t prev_left_switch;
} Key_Prev_t;

Expand Down
4 changes: 3 additions & 1 deletion src/app/src/debug_task.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ extern Launch_Target_t g_launch_target;
extern uint64_t t;
extern Daemon_Instance_t *g_daemon_instances[3];
extern Daemon_Instance_t *g_remote_daemon;
extern Daemon_Instance_t *g_referee_daemon_instance_ptr;
#define PRINT_RUNTIME_STATS
#ifdef PRINT_RUNTIME_STATS
char g_debug_buffer[1024*2] = {0};
Expand Down Expand Up @@ -52,6 +53,7 @@ void Debug_Task_Loop(void)
// if (counter > 0xFFFFFFFF) {
// counter = 0;
// }
DEBUG_PRINTF(&huart6, ">ref:%f\n>act:%f\n",g_motor_feed->velocity_pid->ref,g_motor_feed->stats->current_vel_rpm);
//DEBUG_PRINTF(&huart6, ">ref:%f\n>act:%f\n",g_motor_feed->velocity_pid->ref,g_motor_feed->stats->current_vel_rpm);
DEBUG_PRINTF(&huart6, ">ref:%d\n",g_referee_daemon_instance_ptr->counter);
#endif
}
5 changes: 5 additions & 0 deletions src/app/src/robot.c
Original file line number Diff line number Diff line change
Expand Up @@ -174,9 +174,14 @@ void Robot_Cmd_Loop()
{
_toggle_robot_state(&g_robot_state.UI_enabled);
}
if (g_remote.keyboard.Z == 1 && g_key_prev.prev_Z == 0)
{
Referee_Robot_State.Manual_Level++;
}
g_key_prev.prev_B = g_remote.keyboard.B;
g_key_prev.prev_G = g_remote.keyboard.G;
g_key_prev.prev_V = g_remote.keyboard.V;
g_key_prev.prev_Z = g_remote.keyboard.Z;
/* Keyboard Toggles Start Here */

/* AutoAiming Flag, not used only for debug */
Expand Down
107 changes: 57 additions & 50 deletions src/app/src/ui_task.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,54 +2,61 @@

void UI_Task_Loop(void)
{
ui_self_id = Referee_Robot_State.ID;
if (!g_robot_state.UI_enabled)
{
ui_remove_indicator_0();
ui_init_indicator_0();
ui_remove_indicator_1();
ui_init_indicator_1();
g_robot_state.UI_enabled = 1;
}
if (g_launch_target.flywheel_enabled)
{
ui_indicator_1_Flywheel_Select->start_x = 270;
ui_indicator_1_Flywheel_Select->end_x = 320;
}
else
{
ui_indicator_1_Flywheel_Select->start_x = 335;
ui_indicator_1_Flywheel_Select->end_x = 385;
}
if (g_robot_state.spintop_mode)
{
ui_indicator_1_Spintop_Select->start_x = 270;
ui_indicator_1_Spintop_Select->end_x = 320;
}
else
{
ui_indicator_1_Spintop_Select->start_x = 335;
ui_indicator_1_Spintop_Select->end_x = 385;
}
if (g_robot_state.autoaiming_enabled)
{
ui_indicator_1_Autoaim_Select->start_x = 270;
ui_indicator_1_Autoaim_Select->end_x = 320;
ui_indicator_1_Aim_H_Line->color = 2;
ui_indicator_1_Aim_V_Line->color = 2;
}
else
{
ui_indicator_1_Autoaim_Select->start_x = 335;
ui_indicator_1_Autoaim_Select->end_x = 385;
ui_indicator_1_Aim_H_Line->color = 3;
ui_indicator_1_Aim_V_Line->color = 3;
}
if (ui_indicator_1_Supercap->number>=99)
{
ui_indicator_1_Supercap->number = 0;
}
ui_indicator_1_Supercap->number++;

ui_update_indicator_1();
ui_self_id = Referee_Robot_State.ID;
if (!g_robot_state.UI_enabled)
{
ui_remove_indicator_0();
ui_init_indicator_0();
ui_remove_indicator_1();
ui_init_indicator_1();
g_robot_state.UI_enabled = 1;
}
if (g_launch_target.flywheel_enabled)
{
ui_indicator_1_Flywheel_Select->start_x = 270;
ui_indicator_1_Flywheel_Select->end_x = 320;
}
else
{
ui_indicator_1_Flywheel_Select->start_x = 335;
ui_indicator_1_Flywheel_Select->end_x = 385;
}
if (g_robot_state.spintop_mode)
{
ui_indicator_1_Spintop_Select->start_x = 270;
ui_indicator_1_Spintop_Select->end_x = 320;
}
else
{
ui_indicator_1_Spintop_Select->start_x = 335;
ui_indicator_1_Spintop_Select->end_x = 385;
}
if (g_robot_state.autoaiming_enabled)
{
ui_indicator_1_Autoaim_Select->start_x = 270;
ui_indicator_1_Autoaim_Select->end_x = 320;
ui_indicator_1_Aim_H_Line->color = 2;
ui_indicator_1_Aim_V_Line->color = 2;
}
else
{
ui_indicator_1_Autoaim_Select->start_x = 335;
ui_indicator_1_Autoaim_Select->end_x = 385;
ui_indicator_1_Aim_H_Line->color = 3;
ui_indicator_1_Aim_V_Line->color = 3;
}
if (ui_indicator_1_Supercap->number>=99)
{
ui_indicator_1_Supercap->number = 0;
}
if(Referee_System.Online_Flag)
{
ui_indicator_1_Level_Indicator->number = Referee_Robot_State.Level;
}
else
{
ui_indicator_1_Level_Indicator->number = Referee_Robot_State.Manual_Level;
}
ui_indicator_1_Supercap->number++;
ui_update_indicator_1();
}
89 changes: 21 additions & 68 deletions src/devices/inc/referee_system.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,75 +21,27 @@

#define REFEREE_TIMEOUT_MS 500

//Standard Confrontation
#define V1_STANDARD_POWER_MAX 120
#define V1_STANDARD_HP_MAX 200
#define V1_STANDARD_LAUNCH_SPEED_MAX 30
#define V1_STANDARD_HEAT_MAX 280
#define V1_STANDARD_COOLING_RATE 25
#define ROBOT_TYPE_STANDARD
//#define ROBOT_TYPE_HERO
//#define ROBOT_TYPE_SENTRY

#define V1_SBR_POWER_MAX 150
#define V1_SBR_HP_MAX 200
#define V1_SBR_LAUNCH_SPEED_MAX 30
#define V1_SBR_HEAT_MAX 280
#define V1_SBR_COOLING_RATE 50
//Standard Default Configuration
#define DEFAULT_STANDARD_POWER_MAX 200
#define DEFAULT_STANDARD_LAUNCH_SPEED_MAX 30
#define DEFAULT_STANDARD_HEAT_MAX 200
#define DEFAULT_STANDARD_COOLING_RATE 10

//Sentry Configuration
#define SENTRY_POWER_MAX 100
#define SENTRY_HP_MAX 600
#define SENTRY_LAUNCH_SPEED_MAX 30
#define SENTRY_HEAT_MAX 400
#define SENTRY_COOLING_RATE 80
//Sentry Default Configuration
#define DEFAULT_SENTRY_POWER_MAX 100
#define DEFAULT_SENTRY_LAUNCH_SPEED_MAX 30
#define DEFAULT_SENTRY_HEAT_MAX 400
#define DEFAULT_SENTRY_COOLING_RATE 80

//3V3 Confrontation
#define V3_STANDARD_LAUNCH_SPEED_MAX 30
#define V3_STANDARD_LV10_HP_MAX 400
#define V3_STANDARD_LV10_POWER_MAX 100

#define V3_HERO_LAUNCH_SPEED_MAX 16
#define V3_HERO_LV10_HP_MAX 500
#define V3_HERO_LV10_POWER_MAX 120

#define V3_HERO_POWER_FOCUSED_LV1_HP_MAX 200
#define V3_HERO_POWER_FOCUSED_HP_INCREMENT 25
#define V3_HERO_POWER_FOCUSED_LV1_POWER_MAX 70
#define V3_HERO_POWER_FOCUSED_POWER_INCREMENT 5

#define V3_HERO_HP_FOCUSED_LV1_HP_MAX 250
#define V3_HERO_HP_FOCUSED_HP_INCREMENT 25
#define V3_HERO_HP_FOCUSED_LV1_POWER_MAX 55
#define V3_HERO_HP_FOCUSED_POWER_INCREMENT 5
#define V3_HERO_HP_FOCUSED_LV9_POWER_MAX 100

#define V3_STANDARD_POWER_FOCUSED_LV1_HP_MAX 150
#define V3_STANDARD_POWER_FOCUSED_HP_INCREMENT 25
#define V3_STANDARD_POWER_FOCUSED_LV1_POWER_MAX 60
#define V3_STANDARD_POWER_FOCUSED_POWER_INCREMENT 5

#define V3_STANDARD_HP_FOCUSED_LV1_HP_MAX 200
#define V3_STANDARD_HP_FOCUSED_HP_INCREMENT 25
#define V3_STANDARD_HP_FOCUSED_LV1_POWER_MAX 45
#define V3_STANDARD_HP_FOCUSED_POWER_INCREMENT 5
#define V3_STANDARD_HP_FOCUSED_LV9_POWER_MAX 90

#define V3_STANDARD_BURST_FOCUSED_LV1_HEAT_MAX 200
#define V3_STANDARD_BURST_FOCUSED_HEAT_INCREMENT 50
#define V3_STANDARD_BURST_FOCUSED_LV1_COOLING_MAX 10
#define V3_STANDARD_BURST_FOCUSED_COOLING_INCREMENT 5

#define V3_STANDARD_COOLING_FOCUSED_LV1_HEAT_MAX 50
#define V3_STANDARD_COOLING_FOCUSED_HEAT_INCREMENT 35
#define V3_STANDARD_COOLING_FOCUSED_LV10_HEAT_MAX 400
#define V3_STANDARD_COOLING_FOCUSED_LV1_COOLING_MAX 40
#define V3_STANDARD_COOLING_FOCUSED_COOLING_INCREMENT 5
#define V3_STANDARD_COOLING_FOCUSED_LV10_COOLING_MAX 80

#define V3_HERO_LV1_HEAT_MAX 200
#define V3_HERO_LV10_HEAT_MAX 200
#define V3_HERO_HEAT_INCREMENT 30
#define V3_HERO_LV1_COOLING_MAX 40
#define V3_HERO_COOLING_INCREMENT 8
#define V3_HERO_LV10_COOLING_MAX 120
//Hero Default Configuration
#define DEFAULT_HERO_POWER_MAX 55
#define DEFAULT_HERO_LAUNCH_SPEED_MAX 16
#define DEFAULT_HERO_HEAT_MAX 200
#define DEFAULT_HERO_COOLING_RATE 40

#define REFEREE_BUFFER_LEN 273u //Buffer length to receive all data
#define REFEREE_FRAME_HEADER_START 0xA5 //Frame header
Expand Down Expand Up @@ -142,6 +94,7 @@ typedef struct
uint8_t Game_Type; //1 for 7v7, 4 for 3v3, 5 for 1v1
uint8_t ID; //3,4,5 Red Standard - 103,104,105 Blue Standard
uint8_t Level;
uint8_t Manual_Level;

uint16_t Cooling_Rate;
uint16_t Heat_Max;
Expand All @@ -151,7 +104,7 @@ typedef struct
float Chassis_Power;
float Power_Buffer;
uint16_t Shooter_Heat_1;
uint16_t Shooter_Heat_2;
uint16_t Shooter_Heat_2;
uint8_t Shooting_Frequency;
float Shooting_Speed;
}Referee_Robot_State_t;
Expand Down Expand Up @@ -296,7 +249,7 @@ typedef struct
}RFID;

uint16_t Info_Update_Frame;
uint8_t Offline_Flag;
uint8_t Online_Flag;
} Referee_System_t;

void Referee_Get_Data(UART_Instance_t *uart_instance);
Expand Down
55 changes: 42 additions & 13 deletions src/devices/src/referee_system.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,31 +17,59 @@ Daemon_Instance_t *g_referee_daemon_instance_ptr;

void Referee_Set_Robot_State(void)
{
Referee_Robot_State.Game_Type = Referee_System.Game_Status.Type;
Referee_Robot_State.ID = Referee_System.Robot_State.ID;
Referee_Robot_State.Level = Referee_System.Robot_State.Level;
if (Referee_System.Online_Flag)
{
Referee_Robot_State.Game_Type = Referee_System.Game_Status.Type;
Referee_Robot_State.ID = Referee_System.Robot_State.ID;
Referee_Robot_State.Level = Referee_System.Robot_State.Level;

Referee_Robot_State.Cooling_Rate = Referee_System.Robot_State.Shooter_Cooling_Value;
Referee_Robot_State.Heat_Max = Referee_System.Robot_State.Shooter_Heat_Max;
Referee_Robot_State.Launch_Speed_Max = DEFAULT_STANDARD_LAUNCH_SPEED_MAX;
Referee_Robot_State.Chassis_Power_Max = Referee_System.Robot_State.Chassis_Power_Max;

Referee_Robot_State.Chassis_Power = Referee_System.Power_Heat.Chassis_Power;
Referee_Robot_State.Power_Buffer = Referee_System.Power_Heat.Chassis_Power_Buffer;
Referee_Robot_State.Shooter_Heat_1 = Referee_System.Power_Heat.Shooter_1_17mm_Heat;
Referee_Robot_State.Shooter_Heat_2 = Referee_System.Power_Heat.Shooter_2_17mm_Heat;
Referee_Robot_State.Shooting_Frequency = Referee_System.Shooter.Frequency;
Referee_Robot_State.Shooting_Speed = Referee_System.Shooter.Speed;
}
else
{
#ifdef ROBOT_TYPE_STANDARD
Referee_Robot_State.Cooling_Rate = DEFAULT_STANDARD_COOLING_RATE+(Referee_Robot_State.Manual_Level-1)*5;
Referee_Robot_State.Heat_Max = DEFAULT_STANDARD_HEAT_MAX+(Referee_Robot_State.Manual_Level-1)*50;
Referee_Robot_State.Launch_Speed_Max = DEFAULT_STANDARD_LAUNCH_SPEED_MAX;
Referee_Robot_State.Chassis_Power_Max = DEFAULT_STANDARD_POWER_MAX+(Referee_Robot_State.Manual_Level-1)*5;
#endif

Referee_Robot_State.Cooling_Rate = Referee_System.Robot_State.Shooter_Cooling_Value;
Referee_Robot_State.Heat_Max = Referee_System.Robot_State.Shooter_Heat_Max;
Referee_Robot_State.Launch_Speed_Max = V3_STANDARD_LAUNCH_SPEED_MAX;
Referee_Robot_State.Chassis_Power_Max = Referee_System.Robot_State.Chassis_Power_Max;
#ifdef ROBOT_TYPE_HERO
Referee_Robot_State.Cooling_Rate = DEFAULT_HERO_COOLING_RATE+(Referee_Robot_State.Manual_Level-1)*8;
Referee_Robot_State.Heat_Max = DEFAULT_HERO_HEAT_MAX+(Referee_Robot_State.Manual_Level-1)*30;
Referee_Robot_State.Launch_Speed_Max = DEFAULT_HERO_LAUNCH_SPEED_MAX;
Referee_Robot_State.Chassis_Power_Max = DEFAULT_HERO_POWER_MAX+(Referee_Robot_State.Manual_Level-1)*5;
#endif

Referee_Robot_State.Chassis_Power = Referee_System.Power_Heat.Chassis_Power;
Referee_Robot_State.Power_Buffer = Referee_System.Power_Heat.Chassis_Power_Buffer;
Referee_Robot_State.Shooter_Heat_1 = Referee_System.Power_Heat.Shooter_1_17mm_Heat;
Referee_Robot_State.Shooter_Heat_2 = Referee_System.Power_Heat.Shooter_2_17mm_Heat;
Referee_Robot_State.Shooting_Frequency = Referee_System.Shooter.Frequency;
Referee_Robot_State.Shooting_Speed = Referee_System.Shooter.Speed;
#ifdef ROBOT_TYPE_SENTRY
Referee_Robot_State.Cooling_Rate = DEFAULT_SENTRY_COOLING_RATE;
Referee_Robot_State.Heat_Max = DEFAULT_SENTRY_HEAT_MAX;
Referee_Robot_State.Launch_Speed_Max = DEFAULT_SENTRY_LAUNCH_SPEED_MAX;
Referee_Robot_State.Chassis_Power_Max = DEFAULT_SENTRY_POWER_MAX;
#endif
}
}
void Referee_System_Timeout_Callback()
{
// Attemp to reinitialize UART service
UART_Service_Init(g_referee_uart_instance_ptr);
Referee_System.Online_Flag = 0;
}

void Referee_System_Init(UART_HandleTypeDef *huart)
{
Referee_System.huart = huart;
Referee_Robot_State.Manual_Level = 1;
HAL_UART_Receive_DMA(huart, Referee_System.Buffer, REFEREE_BUFFER_LEN);

g_referee_uart_instance_ptr = UART_Register(huart, Referee_System.Buffer, REFEREE_BUFFER_LEN, Referee_Get_Data);
Expand All @@ -62,6 +90,7 @@ void Referee_Get_Data(UART_Instance_t *uart_instance)
if (Referee_System.Buffer[n] == REFEREE_FRAME_HEADER_START)
{
Daemon_Reload(g_referee_daemon_instance_ptr);
Referee_System.Online_Flag = 1;
switch (Referee_System.Buffer[n + 5] | Referee_System.Buffer[n + 6] << 8)
{
case REFEREE_GAME_STATUS:
Expand Down
Loading

0 comments on commit 0a99d52

Please sign in to comment.