Skip to content

Commit

Permalink
added basic barrel heat control
Browse files Browse the repository at this point in the history
  • Loading branch information
CuboiLeo committed May 28, 2024
1 parent 544b4b7 commit 4b19efc
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 16 deletions.
1 change: 1 addition & 0 deletions src/app/inc/launch_task.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,6 @@ void Launch_Task_Init(void);
void Launch_Ctrl_Loop(void);

extern Launch_Target_t g_launch_target;
extern DJI_Motor_Handle_t *g_flywheel_left, *g_flywheel_right, *g_motor_feed;

#endif // LAUNCH_TASK_H
4 changes: 2 additions & 2 deletions src/app/src/debug_task.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "referee_system.h"
#include "jetson_orin.h"
#include "bsp_daemon.h"
#include "launch_task.h"

extern Robot_State_t g_robot_state;
extern DJI_Motor_Handle_t *g_yaw;
Expand Down Expand Up @@ -51,7 +52,6 @@ void Debug_Task_Loop(void)
// if (counter > 0xFFFFFFFF) {
// counter = 0;
// }
DEBUG_PRINTF(&huart6, "/*%f,%f*/", g_swerve_fl.drive_motor->velocity_pid->ref,g_swerve_fl.drive_motor->stats->current_vel_rpm);
//DEBUG_PRINTF(&huart6, "/*%f,%f*/", g_robot_state.chassis_total_power, Referee_Robot_State.Chassis_Power);
DEBUG_PRINTF(&huart6, ">ref:%f\n>act:%f\n",g_motor_feed->velocity_pid->ref,g_motor_feed->stats->current_vel_rpm);
#endif
}
4 changes: 3 additions & 1 deletion src/app/src/launch_task.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
extern Robot_State_t g_robot_state;
extern Remote_t g_remote;
extern IMU_t g_imu;
DJI_Motor_Handle_t *g_flywheel_left, *g_flywheel_right, *g_motor_feed, *g_motor_feed;
DJI_Motor_Handle_t *g_flywheel_left, *g_flywheel_right, *g_motor_feed;
Launch_Target_t g_launch_target;

void Feed_Angle_Calc(void);
Expand Down Expand Up @@ -50,6 +50,8 @@ void Launch_Task_Init() {
.velocity_pid =
{
.kp = 500.0f,
.kd = 200.0f,
.kf = 100.0f,
.output_limit = M2006_MAX_CURRENT,
},
.angle_pid =
Expand Down
3 changes: 1 addition & 2 deletions src/app/src/robot.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ void Robot_Ctrl_Loop()
{
// Control loop for the robot
Robot_Cmd_Loop();
Referee_Get_Data();
Referee_Set_Robot_State();
Chassis_Ctrl_Loop();
Gimbal_Ctrl_Loop();
Expand Down Expand Up @@ -147,7 +146,7 @@ void Robot_Cmd_Loop()
/* Gimbal ends here */

/* Launch control starts here */
if (Referee_System.Power_Heat.Shooter_1_17mm_Heat < 200)
if (Referee_Robot_State.Shooter_Heat_1 < (Referee_Robot_State.Heat_Max-40))
{
if (g_remote.controller.wheel < -50.0f)
{ // dial wheel forward single fire
Expand Down
2 changes: 1 addition & 1 deletion src/bsp/inc/bsp_uart.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@ typedef struct _UART_Instance
} UART_Instance_t;

void UART_Service_Init(UART_Instance_t *uart_insatce);
UART_Instance_t *UART_Register(UART_HandleTypeDef *huart, uint8_t *rx_buffer, uint8_t rx_buffer_size, void (*callback)(UART_Instance_t *uart_instance));
UART_Instance_t *UART_Register(UART_HandleTypeDef *huart, uint8_t *rx_buffer, uint16_t rx_buffer_size, void (*callback)(UART_Instance_t *uart_instance));
HAL_StatusTypeDef UART_Transmit(UART_Instance_t *uart_instance, uint8_t *tx_buffer, uint16_t tx_buffer_size, uint8_t send_type);
#endif // BSP_UART_H
2 changes: 1 addition & 1 deletion src/bsp/src/bsp_uart.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ void UART_Service_Init(UART_Instance_t *uart_insatce)
* @param rx_buffer_size size of the buffer
* @param callback callback function when UART receive is complete
*/
UART_Instance_t *UART_Register(UART_HandleTypeDef *huart, uint8_t *rx_buffer, uint8_t rx_buffer_size, void (*callback)(UART_Instance_t *uart_instance))
UART_Instance_t *UART_Register(UART_HandleTypeDef *huart, uint8_t *rx_buffer, uint16_t rx_buffer_size, void (*callback)(UART_Instance_t *uart_instance))
{
UART_Instance_t *uart_instance = (UART_Instance_t *)malloc(sizeof(UART_Instance_t));
uart_instance->uart_handle = huart;
Expand Down
7 changes: 5 additions & 2 deletions src/devices/inc/referee_system.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,13 @@

#include "bsp_crc.h"
#include "dma.h"
#include "usart.h"
#include "bsp_uart.h"
#include "bsp_daemon.h"
#include <stdint.h>
#include <stdbool.h>

#define REFEREE_TIMEOUT_MS 500

//Standard Confrontation
#define V1_STANDARD_POWER_MAX 120
#define V1_STANDARD_HP_MAX 200
Expand Down Expand Up @@ -296,7 +299,7 @@ typedef struct
uint8_t Offline_Flag;
} Referee_System_t;

void Referee_Get_Data(void);
void Referee_Get_Data(UART_Instance_t *uart_instance);
void Referee_Set_Robot_State(void);
void Referee_System_Init(UART_HandleTypeDef *huart);

Expand Down
27 changes: 20 additions & 7 deletions src/devices/src/referee_system.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,11 @@
*
*/
#include "referee_system.h"
#include "usart.h"

Referee_System_t Referee_System;
Referee_Robot_State_t Referee_Robot_State;

void Referee_Get_Data(void);
void Referee_Set_Robot_State(void);
UART_Instance_t *g_referee_uart_instance_ptr;
Daemon_Instance_t *g_referee_daemon_instance_ptr;

void Referee_Set_Robot_State(void)
{
Expand All @@ -35,20 +33,35 @@ void Referee_Set_Robot_State(void)
Referee_Robot_State.Shooting_Frequency = Referee_System.Shooter.Frequency;
Referee_Robot_State.Shooting_Speed = Referee_System.Shooter.Speed;
}
void Referee_System_Timeout_Callback()
{
// Attemp to reinitialize UART service
UART_Service_Init(g_referee_uart_instance_ptr);
}

void Referee_System_Init(UART_HandleTypeDef *huart)
{
Referee_System.huart = huart;
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);

// register Daemon instance
// timeout is defined in the header file
uint16_t reload_value = REFEREE_TIMEOUT_MS / DAEMON_PERIOD;
uint16_t initial_counter = reload_value;
g_referee_daemon_instance_ptr = Daemon_Register(reload_value, initial_counter, Referee_System_Timeout_Callback);
}

// Get referee system data based on ID
void Referee_Get_Data(void)
void Referee_Get_Data(UART_Instance_t *uart_instance)
{
UNUSED(uart_instance);
for (int n = 0; n < REFEREE_BUFFER_LEN;)
{
if (Referee_System.Buffer[n] == REFEREE_FRAME_HEADER_START)
{
Daemon_Reload(g_referee_daemon_instance_ptr);
switch (Referee_System.Buffer[n + 5] | Referee_System.Buffer[n + 6] << 8)
{
case REFEREE_GAME_STATUS:
Expand Down Expand Up @@ -151,10 +164,10 @@ void Referee_Get_Data(void)
n++;
break;
case REFEREE_AERIAL_DATA:
if (Verify_CRC16_Check_Sum(Referee_System.Buffer + n, REFEREE_AERIAL_DATA))
if (Verify_CRC16_Check_Sum(Referee_System.Buffer + n, REFEREE_AERIAL_DATA_LEN))
{
memcpy(&Referee_System.Aerial_Data, &Referee_System.Buffer[n + 7], sizeof(uint8_t[REFEREE_AERIAL_DATA_LEN-9]));
n += REFEREE_AERIAL_DATA;
n += REFEREE_AERIAL_DATA_LEN;
}
else
n++;
Expand Down

0 comments on commit 4b19efc

Please sign in to comment.