Skip to content

Commit

Permalink
ben's winter break
Browse files Browse the repository at this point in the history
  • Loading branch information
wehnertben committed Jan 4, 2025
1 parent 1740eea commit 4fde0c7
Show file tree
Hide file tree
Showing 3 changed files with 127 additions and 41 deletions.
97 changes: 56 additions & 41 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -1,45 +1,60 @@
{
"version": "0.2.0",
"configurations": [
"version": "0.2.0",
"configurations": [
{
"name": "CMSIS-DAP",
"cwd": "${workspaceRoot}",
"executable": "${workspaceRoot}${/}build${/}control-template.elf",
"request": "launch",
"type": "cortex-debug",
"svdFile": "STM32F407.svd",
"servertype": "openocd",
"configFiles": [
"${workspaceRoot}${/}control-base${/}config${/}openocd_cmsis_dap.cfg"
],
"rtos": "FreeRTOS",
"liveWatch": {
"enabled": true,
"samplesPerSecond": 4
},
"preLaunchTask": "build"
},
{
"name": "ST-LINK",
"cwd": "${workspaceRoot}",
"executable": "${workspaceRoot}${/}build${/}control-template.elf",
"request": "launch",
"type": "cortex-debug",
"svdFile": "STM32F407.svd",
"servertype": "openocd",
"configFiles": [
"${workspaceRoot}${/}control-base${/}config${/}openocd_stlink.cfg"
],
"rtos": "FreeRTOS",
"liveWatch": {
"enabled": true,
"samplesPerSecond": 4
},
"preLaunchTask": "build"
},
{
"name": "C/C++ Runner: Debug Session",
"type": "cppdbg",
"request": "launch",
"args": [],
"stopAtEntry": false,
"externalConsole": true,
"cwd": "c:/Users/wehne/Documents/RoboMasters/Sentry/app/src",
"program": "c:/Users/wehne/Documents/RoboMasters/Sentry/app/src/build/Debug/outDebug",
"MIMode": "gdb",
"miDebuggerPath": "gdb",
"setupCommands": [
{
"name": "CMSIS-DAP",
"cwd": "${workspaceRoot}",
"executable": "${workspaceRoot}${/}build${/}control-template.elf",
"request": "launch",
"type": "cortex-debug",
"svdFile": "STM32F407.svd",
"servertype": "openocd", //GDB server
"configFiles": [
"${workspaceRoot}${/}control-base${/}config${/}openocd_cmsis_dap.cfg" // config
],
//"runToEntryPoint": "main", // stop at main
//"showDevDebugOutput": "raw", // enable debug output
"rtos": "FreeRTOS",
"liveWatch": {
"enabled": true,
"samplesPerSecond": 4
},
"preLaunchTask": "build" // build before debug
},
{
"name": "ST-LINK",
"cwd": "${workspaceRoot}",
"executable": "${workspaceRoot}${/}build${/}control-template.elf",
"request": "launch",
"type": "cortex-debug",
"svdFile": "STM32F407.svd",
"servertype": "openocd", //GDB server
"configFiles": [
"${workspaceRoot}${/}control-base${/}config${/}openocd_stlink.cfg" // config
],
//"runToEntryPoint": "main", // stop at main
//"showDevDebugOutput": "raw", // enable debug output
"rtos": "FreeRTOS",
"liveWatch": {
"enabled": true,
"samplesPerSecond": 4
},
"preLaunchTask": "build" // build before debug
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
]
}
]
}
1 change: 1 addition & 0 deletions app/inc/launch_task.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@

void Launch_Task_Init(void);
void Launch_Ctrl_Loop(void);
void Launch_Speed_Test(void);

#endif // LAUNCH_TASK_H
70 changes: 70 additions & 0 deletions app/src/launch_task.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,85 @@
#include "user_math.h"
#include "referee_system.h"

#include <time.h>

extern Robot_State_t g_robot_state;
extern Remote_t g_remote;

DJI_Motor_Handle_t *leftFlywheel;
DJI_Motor_Handle_t *rightFlywheel;

clock_t lastHeatTick = 0;
clock_t currentTime = 0;
float barrelHeat = 0;
int maxHeat = 0;
int projectileHeat = 10;
float coolingPerTick = 0;
float timeSinceCheck = 0;
int botLvl = 1;

void Launch_Task_Init()
{
// Init Launch Hardware
Motor_Config_t flywheel_config = {
.can_bus = 1,
.speed_controller_id = 0,
.offset = 0,
.control_mode = VELOCITY_CONTROL,
.motor_reversal = MOTOR_REVERSAL_NORMAL,
.velocity_pid = {
.kp = 500.0f,
.ki = 0.0f,
.kd = 0.0f,
.output_limit = M3508_MAX_CURRENT

}
};

flywheel_config.speed_controller_id = 1;
leftFlywheel = DJI_Motor_Init(&flywheel_config, M3508);
flywheel_config.speed_controller_id = 2;
rightFlywheel = DJI_Motor_Init(&flywheel_config, M3508);

time(&lastHeatTick);

}

void Launch_Ctrl_Loop()
{
// Control loop for launch

// heat is checked every 1/10 a second, one "tick"
maxHeat = 170 + 30*botLvl;
coolingPerTick = (32 + 8*botLvl) / 10;
time(&currentTime);

if (currentTime-lastHeatTick > .1f ){
time(&lastHeatTick);

if (barrelHeat >= coolingPerTick){
barrelHeat - coolingPerTick;
}
}

}

void Launch_Speed_Test(){
float speeds[20] = {};
int vel = 100;
for (int i = 0; i < 8; i++){
DJI_Motor_Set_Velocity(leftFlywheel,vel);
DJI_Motor_Set_Velocity(rightFlywheel,vel);
while (DJI_Motor_Get_Velocity(leftFlywheel) < vel && DJI_Motor_Get_Velocity(rightFlywheel) < vel)
{
//wait
}

//fire();
speeds[i] = Referee_Robot_State.Shooting_Speed;

vel += 50;

}
printf(speeds);
}

0 comments on commit 4fde0c7

Please sign in to comment.