Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions boards/algorithm/src/AHRS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ namespace control {
cailb_done_ = false;
}

// 检测imu是否成功初始化
bool AHRS::IsCailbrated() {
return cailb_done_;
}
Expand Down
2 changes: 2 additions & 0 deletions boards/base/DM_MC01_general/Core/Inc/tim.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ extern TIM_HandleTypeDef htim8;

/* USER CODE BEGIN Private defines */

#define BOARD_TIM_SYS htim5

/* USER CODE END Private defines */

void MX_TIM1_Init(void);
Expand Down
22 changes: 2 additions & 20 deletions boards/base/DM_MC01_general/Core/Src/adc.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,13 @@ void MX_ADC1_Init(void)
hadc1.Instance = ADC1;
hadc1.Init.ClockPrescaler = ADC_CLOCK_SYNC_PCLK_DIV4;
hadc1.Init.Resolution = ADC_RESOLUTION_12B;
hadc1.Init.ScanConvMode = ENABLE;
hadc1.Init.ScanConvMode = DISABLE;
hadc1.Init.ContinuousConvMode = DISABLE;
hadc1.Init.DiscontinuousConvMode = DISABLE;
hadc1.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_NONE;
hadc1.Init.ExternalTrigConv = ADC_SOFTWARE_START;
hadc1.Init.DataAlign = ADC_DATAALIGN_RIGHT;
hadc1.Init.NbrOfConversion = 3;
hadc1.Init.NbrOfConversion = 1;
hadc1.Init.DMAContinuousRequests = DISABLE;
hadc1.Init.EOCSelection = ADC_EOC_SINGLE_CONV;
if (HAL_ADC_Init(&hadc1) != HAL_OK)
Expand All @@ -68,24 +68,6 @@ void MX_ADC1_Init(void)
{
Error_Handler();
}

/** Configure for the selected ADC regular channel its corresponding rank in the sequencer and its sample time.
*/
sConfig.Channel = ADC_CHANNEL_VREFINT;
sConfig.Rank = 2;
if (HAL_ADC_ConfigChannel(&hadc1, &sConfig) != HAL_OK)
{
Error_Handler();
}

/** Configure for the selected ADC regular channel its corresponding rank in the sequencer and its sample time.
*/
sConfig.Channel = ADC_CHANNEL_0;
sConfig.Rank = 3;
if (HAL_ADC_ConfigChannel(&hadc1, &sConfig) != HAL_OK)
{
Error_Handler();
}
/* USER CODE BEGIN ADC1_Init 2 */

/* USER CODE END ADC1_Init 2 */
Expand Down
10 changes: 2 additions & 8 deletions boards/base/DM_MC01_general/DM_MC01_general.ioc
Original file line number Diff line number Diff line change
@@ -1,17 +1,11 @@
#MicroXplorer Configuration settings - do not modify
ADC1.Channel-0\#ChannelRegularConversion=ADC_CHANNEL_TEMPSENSOR
ADC1.Channel-1\#ChannelRegularConversion=ADC_CHANNEL_VREFINT
ADC1.Channel-2\#ChannelRegularConversion=ADC_CHANNEL_0
ADC1.ClockPrescaler=ADC_CLOCK_SYNC_PCLK_DIV4
ADC1.IPParameters=Rank-0\#ChannelRegularConversion,master,Channel-0\#ChannelRegularConversion,SamplingTime-0\#ChannelRegularConversion,NbrOfConversionFlag,ClockPrescaler,NbrOfConversion,Rank-1\#ChannelRegularConversion,Channel-1\#ChannelRegularConversion,SamplingTime-1\#ChannelRegularConversion,Rank-2\#ChannelRegularConversion,Channel-2\#ChannelRegularConversion,SamplingTime-2\#ChannelRegularConversion
ADC1.NbrOfConversion=3
ADC1.IPParameters=Rank-0\#ChannelRegularConversion,master,Channel-0\#ChannelRegularConversion,SamplingTime-0\#ChannelRegularConversion,NbrOfConversionFlag,ClockPrescaler,NbrOfConversion
ADC1.NbrOfConversion=1
ADC1.NbrOfConversionFlag=1
ADC1.Rank-0\#ChannelRegularConversion=1
ADC1.Rank-1\#ChannelRegularConversion=2
ADC1.Rank-2\#ChannelRegularConversion=3
ADC1.SamplingTime-0\#ChannelRegularConversion=ADC_SAMPLETIME_3CYCLES
ADC1.SamplingTime-1\#ChannelRegularConversion=ADC_SAMPLETIME_3CYCLES
ADC1.SamplingTime-2\#ChannelRegularConversion=ADC_SAMPLETIME_3CYCLES
ADC1.master=1
CAD.formats=[]
CAD.pinconfig=Project naming
Expand Down
2 changes: 2 additions & 0 deletions boards/drivers/DM_MC01/include/bsp_batteryvol.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ namespace bsp {
void Start();
void Stop();
uint32_t Read();

// 读取处理后的电池电压值
float GetBatteryVol();
static float calcBatteryPercentage(float voltage);
float GetBatteryPercentage();
Expand Down
6 changes: 4 additions & 2 deletions boards/drivers/DM_MC01/src/bsp_batteryvol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@
namespace bsp {
BatteryVol::BatteryVol(ADC_HandleTypeDef* hadc, uint32_t channel, uint32_t rank, uint32_t sampling_time) {
adc_ = new bADC(hadc, channel, rank, sampling_time);
adc_vrefint_ = new bADC(&hadc1, ADC_CHANNEL_VREFINT, 2, ADC_SAMPLETIME_3CYCLES);
adc_vrefint_->Start();
adc_vrefint_ = new bADC(&hadc1, ADC_CHANNEL_VREFINT, 1, ADC_SAMPLETIME_3CYCLES);
}
void BatteryVol::InitVREF() {
unsigned char i = 0;
unsigned int total_adc = 0;
adc_vrefint_->Start();
for (i = 0; i < 200; i++) {
total_adc += adc_vrefint_->Read();
}
Expand All @@ -43,8 +43,10 @@ namespace bsp {
adc_->Stop();
}
uint32_t BatteryVol::Read() {
adc_->Start();
return adc_->Read();
}

float BatteryVol::GetBatteryVol() {
#ifdef DJI_BOARD_TYPE_C_GENERAL
return (float)Read() * voltage_vrefint_proportion * 10.090909090909090909090909090909f;
Expand Down
36 changes: 18 additions & 18 deletions boards/drivers/include/dji_remote.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,22 +36,22 @@ namespace remote {
typedef union {
uint16_t code;
struct {
uint16_t W : 1;
uint16_t S : 1;
uint16_t A : 1;
uint16_t D : 1;
uint16_t SHIFT : 1;
uint16_t CTRL : 1;
uint16_t Q : 1;
uint16_t E : 1;
uint16_t R : 1;
uint16_t F : 1;
uint16_t G : 1;
uint16_t Z : 1;
uint16_t X : 1;
uint16_t C : 1;
uint16_t V : 1;
uint16_t B : 1;
uint16_t W : 1; // 前
uint16_t S : 1; // 后
uint16_t A : 1; // 左
uint16_t D : 1; // 右
uint16_t SHIFT : 1; // boost
uint16_t CTRL : 1; // 切换 小陀螺/自瞄/坦克/标准 模式
uint16_t Q : 1; // 小陀螺加速/减速
uint16_t E : 1; // 小陀螺加速/减速
uint16_t R : 1; //
uint16_t F : 1; //
uint16_t G : 1; //
uint16_t Z : 1; // 摩擦轮
uint16_t X : 1; //
uint16_t C : 1; // 清除自定义UI
uint16_t V : 1; // 强制刷新自定义UI
uint16_t B : 1; //
} __packed bit;
} __packed keyboard_t;

Expand Down Expand Up @@ -89,8 +89,8 @@ namespace remote {
result.x = x;
result.y = y;
result.z = roll;
result.l = l;
result.r = r;
result.l = l; // shoot
result.r = r; // unload
return result;
}
} __packed vt13_mouse_t;
Expand Down
41 changes: 29 additions & 12 deletions programs/Hero/chassis/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,14 @@
#include "chassis.h"
#include "cmsis_os.h"
#include "supercap.h"

bsp::CAN* can1 = nullptr;
bsp::CAN* can2 = nullptr;
#include "bsp_batteryvol.h"
#include "bsp_os.h"

// bridge_can 是与顶部大疆c板进行通信的can通道
// chassis_can 是操控底盘四个电机的can通道
// damiao的can相对于大疆是反着的!!!一定要注意!
bsp::CAN* bridge_can = nullptr;
bsp::CAN* chassis_can = nullptr;
driver::DjiMotorBase* fl_motor = nullptr;
driver::DjiMotorBase* fr_motor = nullptr;
driver::DjiMotorBase* bl_motor = nullptr;
Expand All @@ -41,15 +46,22 @@ driver::SuperCap* super_cap = nullptr;
control::Chassis* chassis = nullptr;
communication::CanBridge* can_bridge = nullptr;

bsp::BatteryVol* battery_vol = nullptr;

void RM_RTOS_Init() {
HAL_Delay(100);
print_use_uart(&huart5);
can2 = new bsp::CAN(&hcan2, false);
can1 = new bsp::CAN(&hcan1, true);
fl_motor = new driver::Motor3508(can2, 0x202);
fr_motor = new driver::Motor3508(can2, 0x201);
bl_motor = new driver::Motor3508(can2, 0x203);
br_motor = new driver::Motor3508(can2, 0x204);
// 设置高精度定时器以能够获取微秒级别的精度的运行时间数据
bsp::SetHighresClockTimer(&BOARD_TIM_SYS);
print_use_rtt();
// print_use_uart(&huart4,false,921600);
print("helloworld!");

chassis_can = new bsp::CAN(&hcan1, true);
bridge_can = new bsp::CAN(&hcan2, false);
fl_motor = new driver::Motor3508(chassis_can, 0x202);
fr_motor = new driver::Motor3508(chassis_can, 0x201);
bl_motor = new driver::Motor3508(chassis_can, 0x203);
br_motor = new driver::Motor3508(chassis_can, 0x204);

control::ConstrainedPID::PID_Init_t omega_pid_init = {
.kp = 2500,
Expand Down Expand Up @@ -85,7 +97,7 @@ void RM_RTOS_Init() {
br_motor->SetTransmissionRatio(19);

driver::supercap_init_t supercap_init = {
.can = can1,
.can = bridge_can,
.tx_id = 0x02e,
.tx_settings_id = 0x02f,
.rx_id = 0x030,
Expand All @@ -101,7 +113,7 @@ void RM_RTOS_Init() {
super_cap->SetMaxDischargePower(250.0f);
super_cap->SetPerferBuffer(50.0f);

can_bridge = new communication::CanBridge(can1, 0x52);
can_bridge = new communication::CanBridge(bridge_can, 0x52);

driver::DjiMotorBase* motors[control::FourWheel::motor_num];
motors[control::FourWheel::front_left] = fl_motor;
Expand All @@ -124,6 +136,8 @@ void RM_RTOS_Init() {
can_bridge->RegisterRxCallback(0x72, chassis->CanBridgeUpdateEventPowerLimitWrapper, chassis);
can_bridge->RegisterRxCallback(0x73, chassis->CanBridgeUpdateEventCurrentPowerWrapper, chassis);

battery_vol = new bsp::BatteryVol(&hadc1, ADC_CHANNEL_0, 1, ADC_SAMPLETIME_3CYCLES);

HAL_Delay(300);
init_buzzer();
}
Expand All @@ -135,7 +149,10 @@ void RM_RTOS_Default_Task(const void* args) {
Buzzer_Sing(Mario);

while (true) {
chassis->UpdatePowerVoltage(battery_vol->GetBatteryVol());
chassis->Update();
osDelay(10);
print("helloworld\r\n");
Buzzer_Sing(Mario);
}
}
3 changes: 2 additions & 1 deletion programs/Hero/gimbal/include/chassis_task.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,10 @@ void chassisTask(void* arg);
void init_chassis();
void kill_chassis();

extern control::ChassisCanBridgeSender* chassis;
extern float chassis_vx;
extern float chassis_vy;
extern float chassis_vz;
extern float chassis_vt;
extern bool chassis_boost_flag;
const float chassis_vx_max = 660.0f;
const float chassis_vy_max = 660.0f;
Expand Down
74 changes: 73 additions & 1 deletion programs/Hero/gimbal/include/remote_task.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ enum ShootMode {
SHOOT_MODE_PREPARED = 2,
SHOOT_MODE_SINGLE = 3,
SHOOT_MODE_BURST = 4,
SHOOT_MODE_UNLOAD = 5, // 退弹
};
extern ShootMode shoot_load_mode;
extern osThreadId_t remoteTaskHandle;
Expand All @@ -71,4 +72,75 @@ const osThreadAttr_t remoteTaskAttribute =
.tz_module = 0,
.reserved = 0};
void remoteTask(void* arg);
void init_remote();
void init_remote();

inline const char* remote_mode_str(RemoteMode mode) {
switch (mode) {
case REMOTE_MODE_PREPARE:
return "PREPARE";
break;
case REMOTE_MODE_KILL:
return "KILL";
break;
case REMOTE_MODE_STOP:
return "STOP";
break;
case REMOTE_MODE_FOLLOW:
return "FOLLOW";
break;
case REMOTE_MODE_SPIN:
return "SPIN";
break;
case REMOTE_MODE_ADVANCED:
return "ADVANCED";
break;
default:
return "\033[31mUNKNOWN\033[0m";
break;
}
}

inline const char* shoot_fric_mode_str(ShootFricMode mode) {
switch (mode) {
case SHOOT_FRIC_MODE_DISABLE:
return "\033[31mDISABLE\033[0m";
break;
case SHOOT_FRIC_MODE_STOP:
return "STOP";
break;
case SHOOT_FRIC_MODE_PREPARING:
return "PREPARING";
break;
case SHOOT_FRIC_MODE_PREPARED:
return "PREPARED";
break;
default:
return "UNKNOWN";
break;
}
}

inline const char* shoot_load_mode_str(ShootMode mode) {
switch (mode) {
case SHOOT_MODE_DISABLE:
return "\033[31mDISABLE\033[0m";
break;
case SHOOT_MODE_STOP:
return "STOP";
break;
case SHOOT_MODE_SINGLE:
return "SINGLE";
break;
case SHOOT_MODE_BURST:
return "BURST";
break;
case SHOOT_MODE_PREPARED:
return "\033[31mREADY SHOOT!\033[0m";
default:
return "UNKNOWN";
break;
case SHOOT_MODE_UNLOAD:
return "UNLOAD";
break;
}
}
2 changes: 1 addition & 1 deletion programs/Hero/gimbal/include/shoot_task.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ const osThreadAttr_t shootTaskAttribute =
extern driver::Motor3508* flywheel_left;
extern driver::Motor3508* flywheel_right;
extern driver::Motor3508* steering_motor;
extern bool jam_notify_flags;
// extern bool jam_notify_flags;
void shootTask(void* arg);
void init_shoot();
void kill_shoot();
Loading
Loading