mirror of
https://github.com/odriverobotics/ODrive.git
synced 2026-09-15 17:38:37 +08:00
- Disable interrupts before setting the reboot cookie - Delay after NVIC_SystemReset before jumping to bootloader (see comment for an explanation) - Make a variable for the reboot cookie - Do reboot cookie checks before C++ static initializers
78 lines
3.5 KiB
C++
78 lines
3.5 KiB
C++
#ifndef __ODRIVE_MAIN_HPP
|
|
#define __ODRIVE_MAIN_HPP
|
|
|
|
// stdlib includes
|
|
#include <functional>
|
|
|
|
// System includes
|
|
#include <cmsis_os.h>
|
|
|
|
// STM specific includes
|
|
#include <stm32f4xx_hal.h> // Sets up the correct chip specifc defines required by arm_math
|
|
#define ARM_MATH_CM4 // TODO: might change in future board versions
|
|
#include <arm_math.h>
|
|
|
|
// Hardware configuration
|
|
#if HW_VERSION_MAJOR == 3
|
|
#include <board_config_v3.h>
|
|
#else
|
|
#error "unknown board version"
|
|
#endif
|
|
|
|
// @brief general user configurable board configuration
|
|
struct BoardConfig_t {
|
|
bool enable_uart = true;
|
|
float brake_resistance = 0.47f; // [ohm]
|
|
float dc_bus_undervoltage_trip_level = 8.0f; //<! [V] minimum voltage below which the motor stops operating
|
|
float dc_bus_overvoltage_trip_level = 1.08f * HW_VERSION_VOLTAGE; //<! [V] maximum voltage above which the motor stops operating.
|
|
//<! This protects against cases in which the power supply fails to dissipate
|
|
//<! the brake power if the brake resistor is disabled.
|
|
//<! The default is 26V for the 24V board version and 52V for the 48V board version.
|
|
};
|
|
|
|
class Axis;
|
|
class Motor;
|
|
|
|
//default timeout waiting for phase measurement signals
|
|
#define PH_CURRENT_MEAS_TIMEOUT 2 // [ms]
|
|
|
|
static const float current_meas_period = CURRENT_MEAS_PERIOD;
|
|
static const int current_meas_hz = CURRENT_MEAS_HZ;
|
|
extern float vbus_voltage;
|
|
extern bool brake_resistor_armed_;
|
|
extern const float elec_rad_per_enc;
|
|
extern BoardConfig_t board_config;
|
|
|
|
constexpr size_t AXIS_COUNT = 2;
|
|
extern Axis *axes[AXIS_COUNT];
|
|
|
|
extern uint32_t _reboot_cookie;
|
|
|
|
// TODO: move
|
|
// this is technically not thread-safe but practically it might be
|
|
#define DEFINE_ENUM_FLAG_OPERATORS(ENUMTYPE) \
|
|
inline ENUMTYPE operator | (ENUMTYPE a, ENUMTYPE b) { return static_cast<ENUMTYPE>(static_cast<std::underlying_type_t<ENUMTYPE>>(a) | static_cast<std::underlying_type_t<ENUMTYPE>>(b)); } \
|
|
inline ENUMTYPE operator & (ENUMTYPE a, ENUMTYPE b) { return static_cast<ENUMTYPE>(static_cast<std::underlying_type_t<ENUMTYPE>>(a) & static_cast<std::underlying_type_t<ENUMTYPE>>(b)); } \
|
|
inline ENUMTYPE operator ^ (ENUMTYPE a, ENUMTYPE b) { return static_cast<ENUMTYPE>(static_cast<std::underlying_type_t<ENUMTYPE>>(a) ^ static_cast<std::underlying_type_t<ENUMTYPE>>(b)); } \
|
|
inline ENUMTYPE &operator |= (ENUMTYPE &a, ENUMTYPE b) { return reinterpret_cast<ENUMTYPE&>(reinterpret_cast<std::underlying_type_t<ENUMTYPE>&>(a) |= static_cast<std::underlying_type_t<ENUMTYPE>>(b)); } \
|
|
inline ENUMTYPE &operator &= (ENUMTYPE &a, ENUMTYPE b) { return reinterpret_cast<ENUMTYPE&>(reinterpret_cast<std::underlying_type_t<ENUMTYPE>&>(a) &= static_cast<std::underlying_type_t<ENUMTYPE>>(b)); } \
|
|
inline ENUMTYPE &operator ^= (ENUMTYPE &a, ENUMTYPE b) { return reinterpret_cast<ENUMTYPE&>(reinterpret_cast<std::underlying_type_t<ENUMTYPE>&>(a) ^= static_cast<std::underlying_type_t<ENUMTYPE>>(b)); } \
|
|
inline ENUMTYPE operator ~ (ENUMTYPE a) { return static_cast<ENUMTYPE>(~static_cast<std::underlying_type_t<ENUMTYPE>>(a)); }
|
|
|
|
|
|
// ODrive specific includes
|
|
#include <protocol.hpp>
|
|
#include <utils.h>
|
|
#include <low_level.h>
|
|
#include <encoder.hpp>
|
|
#include <sensorless_estimator.hpp>
|
|
#include <controller.hpp>
|
|
#include <motor.hpp>
|
|
#include <axis.hpp>
|
|
|
|
// defined in main.cpp
|
|
void save_configuration(void);
|
|
void erase_configuration(void);
|
|
|
|
#endif /* __ODRIVE_MAIN_HPP */
|