Files
2026-11-18 17:19:36 +02:00

137 lines
3.9 KiB
C

#include "KPIRover.h"
#include "CAN_Test.h"
#include "ExternalI2C_Test.h"
#include "PCA9685_Test.h"
#include "ProtocolHandler.h"
#include "Servos_Test.h"
#include "Ultrasonic_Test.h"
#include "arbI2C.h"
#include "ulDatabase.h"
#include "ulDip.h"
#include "ulEncoder.h"
#include "ulImu.h"
#include "ulLEDMode.h"
#include "ulMotorsController.h"
//#include "Storage/ulStorage.h"
//#include "ulAdc.h"
#include "ulog.h"
#include "ulUlog.h"
//#include "cmsis_os.h"
static struct ulDatabase_ParamMetadata ulDatabase_params[] = {
{0, UINT16, true, 5}, // ENCODER_CONTROL_PERIOD_MS,
{0, FLOAT, true, 820.0f}, // ENCODER_TICKS_PER_REVOLUTION,
{0, FLOAT, true, 0.046f}, // MOTOR_FL_KP
{0, FLOAT, true, 0.013f}, // MOTOR_FL_KI
{0, FLOAT, true, 0.0001f}, // MOTOR_FL_KD
{0, FLOAT, true, 0.046f}, // MOTOR_FR_KP
{0, FLOAT, true, 0.013f}, // MOTOR_FR_KI
{0, FLOAT, true, 0.0001f}, // MOTOR_FR_KD
{0, FLOAT, true, 0.046f}, // MOTOR_RL_KP
{0, FLOAT, true, 0.013f}, // MOTOR_RL_KI
{0, FLOAT, true, 0.0001f}, // MOTOR_RL_KD
{0, FLOAT, true, 0.046f}, // MOTOR_RR_KP
{0, FLOAT, true, 0.013f}, // MOTOR_RR_KI
{0, FLOAT, true, 0.0001f}, // MOTOR_RR_KD
{0, INT32, true, 0}, // ADC_CAL_CH_11_OFFSET,
{0, INT32, true, 0}, // ADC_CAL_CH_TEMP_OFFSET,
{0, FLOAT, true, 0.0f}, // ADC_CAL_CH_11_SCALE,
{0, FLOAT, true, 0.0f}, // ADC_CAL_CH_TEMP_SCALE,
{0, INT32, false, 0}, // MOTOR_FL_SETPOINT,
{0, INT32, false, 0}, // MOTOR_RL_SETPOINT,
{0, INT32, false, 0}, // MOTOR_FR_SETPOINT,
{0, INT32, false, 0}, // MOTOR_RR_SETPOINT,
{0, INT32, false, 0}, // MOTOR_FL_RPM,
{0, INT32, false, 0}, // MOTOR_RL_RPM,
{0, INT32, false, 0}, // MOTOR_FR_RPM,
{0, INT32, false, 0}, // MOTOR_RR_RPM,
{0, FLOAT, false, 0.0f}, // IMU_ACCEL_X
{0, FLOAT, false, 0.0f}, // IMU_ACCEL_Y
{0, FLOAT, false, 0.0f}, // IMU_ACCEL_Z
{0, FLOAT, false, 0.0f}, // IMU_GYRO_X
{0, FLOAT, false, 0.0f}, // IMU_GYRO_Y
{0, FLOAT, false, 0.0f}, // IMU_GYRO_Z
{0, FLOAT, false, 0.0f}, // IMU_MAG_X
{0, FLOAT, false, 0.0f}, // IMU_MAG_Y
{0, FLOAT, false, 0.0f}, // IMU_MAG_Z
{0, FLOAT, false, 0.0f}, // IMU_QUAT_W
{0, FLOAT, false, 0.0f}, // IMU_QUAT_X
{0, FLOAT, false, 0.0f}, // IMU_QUAT_Y
{0, FLOAT, false, 0.0f}, // IMU_QUAT_Z
{0, UINT8, false, 0}, // IMU_CALIB_CMD
{0, UINT8, false, 0}, // IMU_CALIB_STATUS
{0, UINT8, false, 0}, // IMU_IS_CALIBRATED
{0, UINT8, false, 0}, // ADC_CALIBRATION_START,
{0, UINT8, false, 0}, // ADC_CALIBRATION_POINT,
{0, FLOAT, false, 0}, // ADC_CALIBRATION_POINT_VALUE,
{0, UINT8, false, 0}, // ADC_CALIBRATION_CHANNEL_ID
{0, FLOAT, false, 0}, // PARAM_BATTERY_VOLTAGE,
{0, FLOAT, false, 0}, // PARAM_MCU_TEMPERATURE
{0, UINT32, false, 0}, // UART_LINE_ERROR_COUNT
};
void KPIRover_Init(void) {
// boot mode check
ulDip_Init();
{
bool dip[4];
if (ulDip_Read(dip))
{
if (dip[0] == true)
{
arbI2C_Init();
(void) PCA9685_Test_Init();
Servos_Test_Init();
Ultrasonic_Test_Init();
ExternalI2C_Test_Init();
CAN_Test_Init();
ulLEDMode_Start();
return;
}
}
}
// normal boot sequence
// logger
ULOG_INIT();
ULOG_SUBSCRIBE(ul_ulog_send, ULOG_DEBUG_LEVEL);
// database
ulDatabase_init(ulDatabase_params, sizeof(ulDatabase_params) / sizeof(struct ulDatabase_ParamMetadata));
ProtocolHandler_init();
// arbiters
arbI2C_Init();
// components
//ulAdc_init();
ulMotorsController_init();
ulEncoder_Init();
ulImu_Init();
#if 0
ulStorage_init();
ulEncoder_Init();
//ulImu_Init(&hi2c3);
static const osThreadAttr_t MotorsCtrlTask_attributes = {
.name = "MotorsCtrlTask",
.priority = (osPriority_t) osPriorityNormal,
.stack_size = 1024 * 4
};
(void) osThreadNew(ulMotorsController_Task, NULL, &MotorsCtrlTask_attributes);
// ADC
const osThreadAttr_t adcTask_attributes = {
.name = "adcTask",
.priority = (osPriority_t) osPriorityNormal,
.stack_size = 256 * 4
};
(void) osThreadNew(ulAdc_task, NULL, &adcTask_attributes);
#endif
}