RobotHardware-UESTC/Hardware/银星机器人底盘/PiRobot-YH_Firmware v1.0/STM32/Lib/DataHolder/data_holder.cpp

40 lines
1.2 KiB
C++
Raw Normal View History

2024-01-20 13:19:09 +08:00
#include "data_holder.h"
#include "board.h"
#include <stdio.h>
2024-01-23 15:06:39 +08:00
DataHolder::DataHolder()
2024-01-20 13:19:09 +08:00
{
strncpy((char*)&firmware_info.version, FW_VERSION, strlen(FW_VERSION)>sizeof(firmware_info.version)?sizeof(firmware_info.version):strlen(FW_VERSION));
sprintf(firmware_info.time, "%s", "20220301");
memset(&parameter, 0, sizeof(struct Robot_parameter));
memset(&velocity, 0, sizeof(struct Robot_velocity));
memset(&odom, 0, sizeof(struct Robot_odom));
memset(&pid_data, 0, sizeof(struct Robot_pid_data));
memset(imu_data, 0, sizeof(imu_data));
}
2024-01-23 15:06:39 +08:00
void DataHolder::loadParameter()
2024-01-20 13:19:09 +08:00
{
Board::get()->get_config((unsigned char*)&parameter, sizeof(parameter));
if (parameter.params.ko == 0)
parameter.params.ko = 1;
if (parameter.params.do_pid_interval == 0)
parameter.params.do_pid_interval = 10;
if (parameter.params.motor_ratio == (unsigned short)-1 || parameter.params.motor_ratio == 0) {
parameter.params.motor_ratio = 1;
}
parameter.params.model_type = MODEL_TYPE_2WD_DIFF; // in stm32f1 fix 2wd
}
2024-01-23 15:06:39 +08:00
void DataHolder::save_parameter()
2024-01-20 13:19:09 +08:00
{
Board::get()->set_config((unsigned char*)&parameter, sizeof(parameter));
parameter.params.model_type = MODEL_TYPE_2WD_DIFF; // in stm32f1 fix 2wd
}