Skip to content

Commit

Permalink
barrel heat control added, not fully tested
Browse files Browse the repository at this point in the history
  • Loading branch information
CuboiLeo committed May 29, 2024
1 parent 321a45b commit 878b34c
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 23 deletions.
9 changes: 6 additions & 3 deletions src/app/inc/launch_task.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,16 @@
#define FLYWHEEL_VELOCITY_23 (6000.0f * M3508_REDUCTION_RATIO)
#define FLYWHEEL_VELOCITY_30 (7000.0f * M3508_REDUCTION_RATIO)
#define FEED_HOLE_NUM (6.0f)
#define LAUNCH_FREQUENCY (12)
#define LAUNCH_FREQUENCY (10)
#define LAUNCH_PERIOD (1000.0f/LAUNCH_FREQUENCY)
#define FEED_1_PROJECTILE_ANGLE (2.0f*PI/FEED_HOLE_NUM)
#define FEED_FREQUENCY_6 (6.0f / FEED_HOLE_NUM * 60.0f)
#define FEED_FREQUENCY_12 (12.0f / FEED_HOLE_NUM * 60.0f)
#define FEED_FREQUENCY_18 (18.0f / FEED_HOLE_NUM * 60.0f)
#define FEED_FREQUENCY_30 (30.0f / FEED_HOLE_NUM * 60.0f)

#define HEAT_CONTROL

typedef struct
{
float flywheel_velocity;
Expand All @@ -25,8 +27,9 @@ typedef struct
uint8_t burst_launch_flag;
uint8_t flywheel_enabled;

uint8_t calculated_heat;
uint8_t referee_update_count;
int16_t calculated_heat;
uint16_t heat_count;
uint16_t launch_freq_count;
} Launch_Target_t;

void Launch_Task_Init(void);
Expand Down
4 changes: 2 additions & 2 deletions src/app/src/debug_task.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,14 @@ void Debug_Task_Loop(void)
DEBUG_PRINTF(&huart6, "%s", bottom_border);
}
#endif
DEBUG_PRINTF(&huart6, ">time:%.1f\n>ref:%f\n",(float) counter / 1000.0f * DEBUG_PERIOD,Referee_Robot_State.Chassis_Power);
//DEBUG_PRINTF(&huart6, ">time:%.1f\n>ref:%f\n",(float) counter / 1000.0f * DEBUG_PERIOD,Referee_Robot_State.Chassis_Power);
// DEBUG_PRINTF(&huart6, ">time:%.1f\n>yaw:%f\n>pitch:%f\n>roll:%f\n", (float) counter / 1000.0f * DEBUG_PERIOD,
// g_imu.deg.yaw, g_imu.deg.pitch, g_imu.deg.roll);
// DEBUG_PRINTF(&huart6, ">remote_daemon:%d\n", g_remote_daemon->counter);
counter++;
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, ">calc:%d\n>ref:%d\n",g_launch_target.calculated_heat,Referee_Robot_State.Shooter_Heat_1);
#endif
}
67 changes: 50 additions & 17 deletions src/app/src/launch_task.c
Original file line number Diff line number Diff line change
Expand Up @@ -90,21 +90,54 @@ void Launch_Ctrl_Loop() {

void Feed_Angle_Calc()
{
if (g_launch_target.single_launch_flag && !g_launch_target.single_launch_finished_flag) {
g_launch_target.feed_angle = DJI_Motor_Get_Total_Angle(g_motor_feed) + FEED_1_PROJECTILE_ANGLE;
g_launch_target.single_launch_finished_flag = 1;
}
else if (g_launch_target.single_launch_flag && g_launch_target.single_launch_finished_flag) {
DJI_Motor_Set_Control_Mode(g_motor_feed, POSITION_CONTROL_TOTAL_ANGLE);
DJI_Motor_Set_Angle(g_motor_feed,g_launch_target.feed_angle);
}
else if (g_launch_target.burst_launch_flag) {
g_launch_target.feed_velocity = FEED_FREQUENCY_12;
DJI_Motor_Set_Control_Mode(g_motor_feed, VELOCITY_CONTROL);
DJI_Motor_Set_Velocity(g_motor_feed,g_launch_target.feed_velocity);
}
else {
DJI_Motor_Set_Control_Mode(g_motor_feed, VELOCITY_CONTROL);
DJI_Motor_Set_Velocity(g_motor_feed,0);
}
#ifdef HEAT_CONTROL
if (Referee_System.Online_Flag)
{
if (g_launch_target.heat_count*2 % 100 == 0)
{
g_launch_target.calculated_heat -= Referee_Robot_State.Cooling_Rate/10;
__MAX_LIMIT(g_launch_target.calculated_heat,0,Referee_Robot_State.Heat_Max);
}
if (g_launch_target.heat_count*2 % 1000 == 0)
{
g_launch_target.calculated_heat = Referee_Robot_State.Shooter_Heat_1;
}
if (g_launch_target.burst_launch_flag)
{
if (g_launch_target.launch_freq_count*2 > LAUNCH_PERIOD)
{
g_launch_target.launch_freq_count = 0;
if((Referee_Robot_State.Heat_Max-g_launch_target.calculated_heat) > 10)
{
g_launch_target.calculated_heat += 10;
g_launch_target.feed_angle = DJI_Motor_Get_Total_Angle(g_motor_feed) + FEED_1_PROJECTILE_ANGLE;
DJI_Motor_Set_Control_Mode(g_motor_feed, POSITION_CONTROL_TOTAL_ANGLE);
DJI_Motor_Set_Angle(g_motor_feed,g_launch_target.feed_angle);
}
}
}
}
else
{
if (g_launch_target.single_launch_flag && !g_launch_target.single_launch_finished_flag) {
g_launch_target.feed_angle = DJI_Motor_Get_Total_Angle(g_motor_feed) + FEED_1_PROJECTILE_ANGLE;
g_launch_target.single_launch_finished_flag = 1;
}
else if (g_launch_target.single_launch_flag && g_launch_target.single_launch_finished_flag) {
DJI_Motor_Set_Control_Mode(g_motor_feed, POSITION_CONTROL_TOTAL_ANGLE);
DJI_Motor_Set_Angle(g_motor_feed,g_launch_target.feed_angle);
}
else if (g_launch_target.burst_launch_flag) {
g_launch_target.feed_velocity = FEED_FREQUENCY_12;
DJI_Motor_Set_Control_Mode(g_motor_feed, VELOCITY_CONTROL);
DJI_Motor_Set_Velocity(g_motor_feed,g_launch_target.feed_velocity);
}
else {
DJI_Motor_Set_Control_Mode(g_motor_feed, VELOCITY_CONTROL);
DJI_Motor_Set_Velocity(g_motor_feed,0);
}
}
#endif


}
5 changes: 4 additions & 1 deletion src/app/src/robot.c
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,8 @@ void Robot_Cmd_Loop()
/* Gimbal ends here */

/* Launch control starts here */
if (Referee_Robot_State.Shooter_Heat_1 < (Referee_Robot_State.Heat_Max-40))
g_launch_target.heat_count++;
if (Referee_Robot_State.Shooter_Heat_1 < Referee_Robot_State.Heat_Max)
{
if (g_remote.controller.wheel < -50.0f)
{ // dial wheel forward single fire
Expand All @@ -146,12 +147,14 @@ void Robot_Cmd_Loop()
{ // dial wheel backward burst fire
g_launch_target.single_launch_flag = 0;
g_launch_target.burst_launch_flag = 1;
g_launch_target.launch_freq_count++;
}
else
{ // dial wheel mid stop fire
g_launch_target.single_launch_flag = 0;
g_launch_target.single_launch_finished_flag = 0;
g_launch_target.burst_launch_flag = 0;
g_launch_target.launch_freq_count = 0;
}
}
else
Expand Down

0 comments on commit 878b34c

Please sign in to comment.