mirror of
https://github.com/modelec/odo_STM32.git
synced 2026-01-18 16:27:25 +01:00
fix some bugs
This commit is contained in:
@@ -7,6 +7,16 @@ cmake_minimum_required(VERSION 3.22)
|
||||
# User is free to modify the file as much as necessary
|
||||
#
|
||||
|
||||
# specify cross-compilers and tools
|
||||
set(CMAKE_C_COMPILER arm-none-eabi-gcc)
|
||||
set(CMAKE_CXX_COMPILER arm-none-eabi-g++)
|
||||
set(CMAKE_ASM_COMPILER arm-none-eabi-gcc)
|
||||
set(CMAKE_AR arm-none-eabi-ar)
|
||||
set(CMAKE_OBJCOPY arm-none-eabi-objcopy)
|
||||
set(CMAKE_OBJDUMP arm-none-eabi-objdump)
|
||||
set(SIZE arm-none-eabi-size)
|
||||
set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY)
|
||||
|
||||
# Setup compiler settings
|
||||
set(CMAKE_CXX_STANDARD 17)
|
||||
set(CMAKE_C_STANDARD 11)
|
||||
|
||||
74
CMakeLists_last.txt
Normal file
74
CMakeLists_last.txt
Normal file
@@ -0,0 +1,74 @@
|
||||
cmake_minimum_required(VERSION 3.22)
|
||||
|
||||
#
|
||||
# This file is generated only once,
|
||||
# and is not re-generated if converter is called multiple times.
|
||||
#
|
||||
# User is free to modify the file as much as necessary
|
||||
#
|
||||
|
||||
# Setup compiler settings
|
||||
set(CMAKE_CXX_STANDARD 17)
|
||||
set(CMAKE_C_STANDARD 11)
|
||||
|
||||
# Define the build type
|
||||
if(NOT CMAKE_BUILD_TYPE)
|
||||
set(CMAKE_BUILD_TYPE "Debug")
|
||||
endif()
|
||||
|
||||
# Set the project name
|
||||
set(CMAKE_PROJECT_NAME pcb_odo)
|
||||
|
||||
# Enable compile command to ease indexing with e.g. clangd
|
||||
set(CMAKE_EXPORT_COMPILE_COMMANDS TRUE)
|
||||
|
||||
# Core project settings
|
||||
project(${CMAKE_PROJECT_NAME})
|
||||
message("Build type: " ${CMAKE_BUILD_TYPE})
|
||||
|
||||
# Enable CMake support for ASM and C languages
|
||||
enable_language(C ASM CXX)
|
||||
|
||||
# Create an executable object type
|
||||
add_executable(${CMAKE_PROJECT_NAME})
|
||||
|
||||
# Add STM32CubeMX generated sources
|
||||
add_subdirectory(cmake/stm32cubemx)
|
||||
|
||||
# Link directories setup
|
||||
target_link_directories(${CMAKE_PROJECT_NAME} PRIVATE
|
||||
# Add user defined library search paths
|
||||
)
|
||||
|
||||
# Add sources to executable
|
||||
target_sources(${CMAKE_PROJECT_NAME} PRIVATE
|
||||
# Add user sources here
|
||||
Core/Src/CommCallbacks.cpp
|
||||
Core/Src/commSTM.cpp
|
||||
Core/Src/modelec.cpp
|
||||
Core/Src/motors.cpp
|
||||
Core/Src/pid.cpp
|
||||
Core/Src/point.cpp
|
||||
Core/Src/setup.cpp
|
||||
)
|
||||
|
||||
# Add include paths
|
||||
target_include_directories(${CMAKE_PROJECT_NAME} PRIVATE
|
||||
# Add user defined include paths
|
||||
Core/Inc/
|
||||
)
|
||||
|
||||
# Add project symbols (macros)
|
||||
target_compile_definitions(${CMAKE_PROJECT_NAME} PRIVATE
|
||||
# Add user defined symbols
|
||||
)
|
||||
|
||||
# Remove wrong libob.a library dependency when using cpp files
|
||||
list(REMOVE_ITEM CMAKE_C_IMPLICIT_LINK_LIBRARIES ob)
|
||||
|
||||
# Add linked libraries
|
||||
target_link_libraries(${CMAKE_PROJECT_NAME}
|
||||
stm32cubemx
|
||||
|
||||
# Add user defined libraries
|
||||
)
|
||||
@@ -23,8 +23,9 @@
|
||||
#define WHEEL_BASE 0.287f
|
||||
#define WHEEL_BASE_2 (WHEEL_BASE/2.0f)
|
||||
#define PRECISE_ANGLE 0.017f // radians
|
||||
#define PRECISE_POS_FINAL 0.005f // meters
|
||||
#define PRECISE_POS_FINAL 0.01f // meters
|
||||
#define PRECISE_POS 0.1f // meters
|
||||
#define V_MAX 0.643f // m/s
|
||||
|
||||
extern TIM_HandleTypeDef htim3;
|
||||
extern TIM_HandleTypeDef htim2;
|
||||
@@ -33,12 +34,15 @@ class DiffBot {
|
||||
public:
|
||||
Point pose;
|
||||
|
||||
Point targets[MAX_WAYPOINTS];
|
||||
Point targets[MAX_WAYPOINTS] = {
|
||||
Point(0, FINAL, 0, 0, 0),
|
||||
};
|
||||
|
||||
uint8_t index = 0;
|
||||
|
||||
Motor motor;
|
||||
|
||||
float vx, vy, vtheta;
|
||||
float vx = 0, vy = 0, vtheta = 0;
|
||||
|
||||
float dt;
|
||||
|
||||
|
||||
@@ -22,12 +22,15 @@ void Comm_GetPos(float& x, float& y, float& theta) {
|
||||
}
|
||||
|
||||
void Comm_SetPos(float x, float y, float theta) {
|
||||
bot.pose.x = x;
|
||||
bot.pose.y = y;
|
||||
bot.pose.x = x / 1000;
|
||||
bot.pose.y = y / 1000;
|
||||
bot.pose.theta = theta;
|
||||
}
|
||||
|
||||
void Comm_GetSpeed(float& vx, float& vy, float& omega){
|
||||
void Comm_GetSpeed(float& vx, float& vy, float& omega) {
|
||||
vx = bot.vx;
|
||||
vy = bot.vy;
|
||||
omega = bot.vtheta;
|
||||
}
|
||||
|
||||
bool Comm_GetPID(char *pid, float &p, float &i, float &d) {
|
||||
|
||||
@@ -4,11 +4,6 @@
|
||||
#include <algorithm>
|
||||
#include <cmath>
|
||||
|
||||
// #define COUNTS_PER_REV 2400.0f // 600 PPR × 4
|
||||
// #define WHEEL_DIAMETER 0.081f // meters
|
||||
// #define WHEEL_BASE 0.287f // meters
|
||||
// #define WHEEL_CIRCUMFERENCE (M_PI * WHEEL_DIAMETER)
|
||||
|
||||
bool DiffBot::isDelayPassedFrom(uint32_t delay, uint32_t &lastTick) {
|
||||
if (HAL_GetTick() - lastTick >= delay) {
|
||||
lastTick = HAL_GetTick();
|
||||
@@ -37,7 +32,7 @@ float DiffBot::readEncoderRight() {
|
||||
return (2.0f*M_PI*WHEEL_RADIUS*revs); // m
|
||||
}
|
||||
|
||||
DiffBot::DiffBot(Point pose, float dt) : pose(pose), motor(), dt(dt) {
|
||||
DiffBot::DiffBot(Point pose, float dt) : pose(pose), dt(dt) {
|
||||
};
|
||||
|
||||
void DiffBot::stop(bool stop) {
|
||||
@@ -48,8 +43,8 @@ void DiffBot::stop(bool stop) {
|
||||
void DiffBot::setup() {
|
||||
pidLeft = PID(1, 0.0, 0.0, -PWM_MAX, PWM_MAX);
|
||||
pidRight = PID(1, 0.0, 0.0, -PWM_MAX, PWM_MAX);
|
||||
pidPos = PID(1, 0.0, 0.0, -2, 2);
|
||||
pidTheta = PID(1, 0.0, 0.0, -M_PI, M_PI);
|
||||
pidPos = PID(1, 0.0, 0.0, -V_MAX, V_MAX);
|
||||
pidTheta = PID(1, 0.0, 0.0, -2.0f, 2);
|
||||
|
||||
prevCountLeft = __HAL_TIM_GET_COUNTER(&htim2);
|
||||
prevCountRight = __HAL_TIM_GET_COUNTER(&htim3);
|
||||
@@ -97,10 +92,6 @@ void DiffBot::update(float dt) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (targets[index].active == false) {
|
||||
targets[index].active = true;
|
||||
}
|
||||
|
||||
break;
|
||||
case INTERMEDIAIRE:
|
||||
|
||||
@@ -164,10 +155,8 @@ void DiffBot::update(float dt) {
|
||||
float vLeft = vRef - (WHEEL_BASE_2) * wRef;
|
||||
float vRight = vRef + (WHEEL_BASE_2) * wRef;
|
||||
|
||||
float v_max = 0.643f; // m/s
|
||||
|
||||
float pwm_ff_left = (vLeft / v_max) * PWM_MAX;
|
||||
float pwm_ff_right = (vRight / v_max) * PWM_MAX;
|
||||
float pwm_ff_left = (vLeft / V_MAX) * PWM_MAX;
|
||||
float pwm_ff_right = (vRight / V_MAX) * PWM_MAX;
|
||||
|
||||
float pwm_corr_left = pidLeft.compute(vLeft, leftVel, dt);
|
||||
float pwm_corr_right = pidRight.compute(vRight, rightVel, dt);
|
||||
|
||||
Reference in New Issue
Block a user