diff --git a/src/HELP.md b/src/HELP.md new file mode 100644 index 0000000000000000000000000000000000000000..30518c3c317c96db76170468da4855869e99d769 --- /dev/null +++ b/src/HELP.md @@ -0,0 +1,102 @@ +# Help document for `\src` + + + +This document along with comments in this repo is written while I'm reviewing the repo. Mistakes may have been made. + +Comments start with a '?' mean that I'm not sure if my understanding is correct. + +## `> controller` + +*maxwell* responds to "止于至善"🙃. + +### `>> drivers` + +#### `>>> dynamixel` + +Files here are for steers from *Dynamixel*. + +#### `>>> gpio` + +*** + +### `>> options` + +Files here realize **program_options**. For example, in `./a.out -help`, `-help` is a **program_option**. + +*** + +### `>> player` + +Most of this part are quite literally. + +> *gc* stands for *gamecontrol*. Gamecontrol, provided by the organizing committee, sends signals to robots telling them if they are about to be leave the game, they have goaled, or nothing happend. + +#### `>>> core` + +#### `>>> engine` + +Files here encapsulate functions that control motions of the robot. + +> *IK* stands for *Inverse Kinematics*. + +> [*Leph*](https://github.com/Leph) is a user on Github, while [*Rhoban*](https://github.com/Rhoban) is an organization with Leph inside. + +#### `>>> fsm` + +> *FSM* stands for *Finite State Machine*. + +> *SL* stands for *Self Localization*. + +#### `>>> localization` + +*inverse* and *kalman* (short for *kalman filter*) involve matrix calculation, which I am pretty weak at. + +Notice: It is said that the localization is realized mostly via *particle filter* instead of *kalman filter*, however I haven't found any evidence to support this point yet. + +#### `>>> sensor` + +> *Imu* stands for *Inertial measurement unit*. + +#### `>>> skill` + +Skills are combinations of serial motions. + +#### `>>> task` + +Tasks are also combinations of serial actions, but skills tend to be mechanical while tasks are not. + +#### `>>> vision` + +> *spf* stands for *support foot*. + +*** + +## `> data` + +Files here store configurations of the robot. + +## `> lib` + +### `>> darknet` + +Lib for recognition. + +### `>> imageproc` + +### `>> math` + +### `>> parser` + +### `>> robot` + +### `>> udp_data` + +## `> scripts` + +[What does if __name__ == “__main__”: do?](https://stackoverflow.com/questions/419163/what-does-if-name-main-do) This make sure that the file is run as the main file, which means that it's run directly instead of being called. \ No newline at end of file diff --git a/src/controller/drivers/gpio/gpio.cpp b/src/controller/drivers/gpio/gpio.cpp index fe4372c9724f5209705d60275d7bff18ef5fd804..630fbc836af924c3105fb32f61474775f078374f 100755 --- a/src/controller/drivers/gpio/gpio.cpp +++ b/src/controller/drivers/gpio/gpio.cpp @@ -33,7 +33,7 @@ bool Gpio::gpio_export() char fnBuffer[MAX_BUF]; fileDescriptor = open(SYSFS_GPIO_DIR "/export", O_WRONLY); - if (fileDescriptor < 0) + if (fileDescriptor < 0) // 若文件打开失败 { LOG(LOG_WARN) << "gpio_export unable to open gpio: "<< find_io(io_) << endll; return false; @@ -42,9 +42,10 @@ bool Gpio::gpio_export() length = snprintf(commandBuffer, sizeof(commandBuffer), "%d", io_); snprintf(fnBuffer, sizeof(fnBuffer), SYSFS_GPIO_DIR "/gpio%d", io_); - if(access(fnBuffer, F_OK) != 0) + + if(access(fnBuffer, F_OK) != 0) // 若文件存在 { - if (write(fileDescriptor, commandBuffer, length) != length) + if (write(fileDescriptor, commandBuffer, length) != length) // 写入, 若长度不一致则报错 { LOG(LOG_WARN) << "gpio "< gpio_map; + + // 根据给定GPIO编号找到对应GPIO对象 static std::string find_io(pin_number p) { for(auto &iom: gpio_map) @@ -44,7 +48,7 @@ public: bool set_value(pin_value v); bool set_edge(char *edge); int get_value(); - bool gpio_unexport(); + bool gpio_unexport(); // ? 与gpio_export()相反, 移除一个GPIO节点 inline bool opened() { @@ -52,7 +56,7 @@ public: } private: - bool gpio_export(); + bool gpio_export(); // ? 通过写GPIO的号码到此文件,用户空间可以要求内核导出一个GPIO的控制到用户空间 bool opened_; pin_number io_; diff --git a/src/controller/options/options.cpp b/src/controller/options/options.cpp index c6883f9d09adf90835c450591083d9862ab19a6c..3c116d6ebfc341c003c7237c920d304523727955 100755 --- a/src/controller/options/options.cpp +++ b/src/controller/options/options.cpp @@ -7,6 +7,7 @@ using namespace boost::program_options; Options::Options(): opts_desc_(" Options description") { + // 向option_description对象添加选项 opts_desc_.add_options() ("help,h", "Print this message and exit.") ("player,p", value()->default_value(0), @@ -33,7 +34,8 @@ bool Options::init(int argc, char **argv) { try { - store(parse_command_line(argc, argv, opts_desc_), var_map_); + store(parse_command_line(argc, argv, opts_desc_), var_map_); // 解析命令行输入的参数,并存储至variables_map中 + // ? 更新外部变量 id_ = arg("player"); use_debug_ = arg("debug"); use_camera_ = arg("camera"); diff --git a/src/controller/player/core/adapter.hpp b/src/controller/player/core/adapter.hpp index 8b911804fb4b5a323d40a4c3b4150b9f1278c696..0971de710ac77a77a776f2b620a6b0e5e0087238 100755 --- a/src/controller/player/core/adapter.hpp +++ b/src/controller/player/core/adapter.hpp @@ -1,3 +1,4 @@ +// 缓冲队列 #ifndef __ADAPTER_HPP #define __ADAPTER_HPP @@ -15,6 +16,8 @@ public: Adapter() { } + + // 读取各个角度信息 inline std::map get_degs() { std::map degs; @@ -44,6 +47,7 @@ public: } return degs; } + inline std::map get_body_degs() const { bd_mutex_.lock(); @@ -51,6 +55,7 @@ public: bd_mutex_.unlock(); return res; } + inline std::map get_head_degs() const { hd_mutex_.lock(); @@ -58,6 +63,7 @@ public: hd_mutex_.unlock(); return res; } + inline bool add_body_degs(const std::map &jdmap) { if (!is_alive_) @@ -71,6 +77,7 @@ public: bd_mutex_.unlock(); return true; } + inline bool add_head_degs(std::map &jdmap) { if (!is_alive_) @@ -125,11 +132,11 @@ public: std::atomic_bool run_action_; private: - std::list< std::map > head_degs_list; + std::list< std::map > head_degs_list; // 角度list用于存储角度map std::list< std::map > body_degs_list; std::map latest_head_deg; std::map latest_body_deg; - mutable std::mutex bd_mutex_, hd_mutex_; + mutable std::mutex bd_mutex_, hd_mutex_; // 此二互斥锁分别对应上述两个list bool is_alive_; }; diff --git a/src/controller/player/core/clock.hpp b/src/controller/player/core/clock.hpp index 3a05e4df64e8c713305323e513d1938e4cb038b1..8f1300f7420ca45280c39cdb96bea0da7b28eaf8 100644 --- a/src/controller/player/core/clock.hpp +++ b/src/controller/player/core/clock.hpp @@ -14,6 +14,7 @@ public: timestamp_ = 0; } + // 初始化计时器 void start() { start_timer(); @@ -23,7 +24,8 @@ public: { delete_timer(); } - + + // 开始计时 void run() { timestamp_ += period_ms_; diff --git a/src/controller/player/core/worldmodel.hpp b/src/controller/player/core/worldmodel.hpp index 880cb8239efce802c47505371d460616db9f32b1..86c014a1e8b3b8a5d3819b27ba39aa34fcf65f96 100755 --- a/src/controller/player/core/worldmodel.hpp +++ b/src/controller/player/core/worldmodel.hpp @@ -1,3 +1,4 @@ +// 几乎订阅了所有信息 #ifndef __WORLD_MODEL_HPP #define __WORLD_MODEL_HPP diff --git a/src/controller/player/player.hpp b/src/controller/player/player.hpp index 62f8a4bfe7fba49b2ac4e13d5eae0f24ccdf9ab8..1cddf99de27feda0926365593d41516c1edc2c3d 100755 --- a/src/controller/player/player.hpp +++ b/src/controller/player/player.hpp @@ -33,7 +33,7 @@ private: std::list play_without_gc(); std::list think(); - bool regist(); + bool regist(); // 注册传感器 void unregist(); sensor_ptr get_sensor(const std::string &name); private: diff --git a/src/controller/player/vision/vision.cpp b/src/controller/player/vision/vision.cpp index 33e248a435dfc5e4e3c4351f4e2ae165c6e992e8..c510f393109cf13539d10cbb7b9202bc53b76dce 100755 --- a/src/controller/player/vision/vision.cpp +++ b/src/controller/player/vision/vision.cpp @@ -182,7 +182,7 @@ void Vision::run() cudaMemcpy(dev_undis_, dev_ori_, ori_size_, cudaMemcpyDeviceToDevice); //cudaBGR2YUV422(dev_undis_, dev_yuyv_, w_, h_); cudaResizePacked(dev_undis_, w_, h_, dev_sized_, net_.w, net_.h); - cudaBGR2RGBfp(dev_sized_, dev_rgbfp_, net_.w, net_.h); + cudaBGR2RGBfp(dev_sized_, dev_rgbfp_, net_.w, net_.h); // 转为浮点型供神经网络使用 /* const int *fieldBorders; if(detect_filed_) diff --git a/src/lib/common.hpp b/src/lib/common.hpp index e56f1a7f557bd9ff4bf252fcd2ebdcf7832fe892..b0b2efea3f44536c0f14d068d53f3eb6565e1c4e 100755 --- a/src/lib/common.hpp +++ b/src/lib/common.hpp @@ -19,7 +19,7 @@ inline std::string get_time() inline std::string get_project_dir() { char buf1[256]; - getcwd(buf1, sizeof(buf1)); + getcwd(buf1, sizeof(buf1)); // get Current Working Directory std::string cwd(buf1); std::string::size_type pos = cwd.find("/bin"); if(pos == std::string::npos) diff --git a/src/lib/logger.hpp b/src/lib/logger.hpp index aa73a3cbe6501d2969f3c602ba4a686f96d2373a..fc695726feb2d718a262c8beb207e1b46729a932 100755 --- a/src/lib/logger.hpp +++ b/src/lib/logger.hpp @@ -12,6 +12,7 @@ enum log_level LOG_HIGH }; +// print without specified colour inline std::ostream& endll(std::ostream &os) { return os<<"\033[0m"<