ExoData.h
- 文件定位
- 源代碼
- 1. 頭文件依賴
- 2. 核心類聲明
- 3. 主要成員函數
- 關節遍歷工具
- 關節與配置相關
- 數據/狀態操作
- 控制參數/校準
- 4. 主要成員變量
- 總結
文件定位
-
位置:
src/ExoData.h
-
作用:定義 ExoData 類,作為 Exo 系統全局數據的核心容器。它將設備的所有關鍵狀態、配置、各側關節/傳感器/控制器等,組織成統一接口供主控和其他模塊訪問。
-
背景備注:頭文件注釋里說,把數據類和主控制類分開,是為了支持多板協同(如主控和BLE/GUI通訊分開)。
源代碼
/*** @file Exo.h** @brief Declares exo class that all the other components will live in. * * @author P. Stegall * @date Jan. 2022
*/#ifndef Exo_h
#define Exo_h//Arduino compiles everything in the src folder even if not included so it causes an error for the nano if this is not included
#if defined(ARDUINO_TEENSY36) || defined(ARDUINO_TEENSY41)#include "Arduino.h"#include "Side.h"
#include <stdint.h>
#include "ParseIni.h"
#include "Board.h"
#include "Utilities.h"
#include "SyncLed.h"
#include "StatusLed.h"
#include "StatusDefs.h"
#include "Config.h"class Exo
{public:Exo(ExoData* exo_data); //Constructor: uses initializer list for the Side objects./*** @brief Reads motor data from each motor used on that side and stores the values* * @return true if the code ran, ie tiiming was satisfied* @return false */bool run(); ExoData *data; /**< Pointer to ExoData that is getting updated by the coms mcu so they share format.*/Side left_side; /**< Left side object that contains all the joints and sensors for that side */Side right_side; /**< Right side object that contains all the joints and sensors for that side */#ifdef USE_SPEED_CHECKutils::SpeedCheck speed_check; /**< Used to check the speed of the loop without needing prints */#endifSyncLed sync_led; /**< Used to syncronize data with a motion capture system */StatusLed status_led; /**< Used to display the system status */private:};
#endif#endif
1. 頭文件依賴
#include "Arduino.h"
#include "SideData.h"
#include <stdint.h>
#include "ParseIni.h"
#include "Board.h"
#include "StatusLed.h"
#include "StatusDefs.h"
-
SideData.h:定義了每一側(左/右)的數據結構。
-
ParseIni/Board/Status…:涉及配置解析、硬件定義和狀態管理。
2. 核心類聲明
class ExoData
{ public: ExoData(uint8_t* config_to_send); // 構造函數,傳入配置數組 void reconfigure(uint8_t* config_to_send); // 重新配置
- 構造時傳入配置數組,
reconfigure
可動態重加載參數。
3. 主要成員函數
關節遍歷工具
// 遍歷所有關節并執行回調
template <typename F>
void for_each_joint(F &&func)
{ func(&left_side.hip, NULL); func(&left_side.knee, NULL); func(&left_side.ankle, NULL); func(&left_side.elbow, NULL); func(&right_side.hip, NULL); func(&right_side.knee, NULL); func(&right_side.ankle, NULL); func(&right_side.elbow, NULL);
}
// 支持額外參數
template <typename F>
void for_each_joint(F &&func, float* args) { ... }
- 統一遍歷左右所有關節(髖、膝、踝、肘),批量操作非常方便。
關節與配置相關
uint8_t get_used_joints(uint8_t* used_joints); // 獲取正在用的關節ID列表
JointData* get_joint_with(uint8_t id); // 根據關節id返回指針
- 方便上層通過ID訪問各關節。
數據/狀態操作
void print(); // 打印所有數據
void set_status(uint16_t status_to_set); // 設置狀態
uint16_t get_status(void); // 獲取狀態
控制參數/校準
void set_default_parameters(); void set_default_parameters(uint8_t id); void start_pretrial_cal(); // 啟動實驗前校準
4. 主要成員變量
bool sync_led_state; // 同步LED狀態
bool estop; // 急停狀態
float battery_value; // 電池電壓或電量
SideData left_side; // 左側數據
SideData right_side; // 右側數據
uint32_t mark; // 計時用
uint8_t* config; // 配置參數數組
uint8_t config_len; // 配置長度
int error_code; // 錯誤碼
int error_joint_id; // 錯誤關節編號
bool user_paused; // 用戶暫停標志
int hip_torque_flag = 0; // 使用力矩傳感器標志(髖)
int knee_torque_flag = 0;
int ankle_torque_flag = 0;
int elbow_torque_flag = 0;
private: uint16_t _status; // 當前狀態
- SideData 下又分為各個關節(hip、knee、ankle、elbow),每個關節下有 motor/controller/sensor 等。
總結
-
ExoData 是整個外骨骼數據的“總線”,聚合了所有核心變量和狀態。
-
上層(如 Exo、通信模塊、控制/校準流程)通過 ExoData 讀寫系統數據。
-
提供遍歷/查找/配置/打印/校準/狀態管理等接口,極大方便模塊間解耦和靈活拓展。
-
結構清晰、面向對象,便于后續添加關節、傳感器或新功能。