From c22ba34b148ac59da7d1d887cdf7a9fa6c41583f Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 1 Jul 2019 15:31:54 +0800 Subject: [PATCH 1/6] Complete rough comment for drivers --- src/controller/drivers/dynamixel/README.md | 3 +++ src/controller/drivers/gpio/gpio.cpp | 7 ++++--- src/controller/drivers/gpio/gpio.hpp | 8 ++++++-- 3 files changed, 13 insertions(+), 5 deletions(-) create mode 100644 src/controller/drivers/dynamixel/README.md diff --git a/src/controller/drivers/dynamixel/README.md b/src/controller/drivers/dynamixel/README.md new file mode 100644 index 0000000..5b53d4b --- /dev/null +++ b/src/controller/drivers/dynamixel/README.md @@ -0,0 +1,3 @@ +# Fold for dynamixel + +Files here are for steers from *Dynamixel*. \ No newline at end of file diff --git a/src/controller/drivers/gpio/gpio.cpp b/src/controller/drivers/gpio/gpio.cpp index fe4372c..630fbc8 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_; -- Gitee From 571d137b9ba6d98973c8bc93e586f6ab5eb0ef27 Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 1 Jul 2019 16:14:54 +0800 Subject: [PATCH 2/6] Complete rough comment for options --- src/HELP.md | 20 ++++++++++++++++++++ src/controller/drivers/dynamixel/README.md | 3 --- src/controller/options/options.cpp | 4 +++- 3 files changed, 23 insertions(+), 4 deletions(-) create mode 100644 src/HELP.md delete mode 100644 src/controller/drivers/dynamixel/README.md diff --git a/src/HELP.md b/src/HELP.md new file mode 100644 index 0000000..2672aad --- /dev/null +++ b/src/HELP.md @@ -0,0 +1,20 @@ +# 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` + +### `>> 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**. + diff --git a/src/controller/drivers/dynamixel/README.md b/src/controller/drivers/dynamixel/README.md deleted file mode 100644 index 5b53d4b..0000000 --- a/src/controller/drivers/dynamixel/README.md +++ /dev/null @@ -1,3 +0,0 @@ -# Fold for dynamixel - -Files here are for steers from *Dynamixel*. \ No newline at end of file diff --git a/src/controller/options/options.cpp b/src/controller/options/options.cpp index c6883f9..3c116d6 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"); -- Gitee From caa43dfd3689394bfd60727f27d7128a37a17c35 Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 2 Jul 2019 16:56:59 +0800 Subject: [PATCH 3/6] Complete rough comment for player --- src/HELP.md | 58 ++++++++++++++++++++++++++ src/controller/player/core/adapter.hpp | 10 ++++- src/controller/player/core/clock.hpp | 4 +- 3 files changed, 69 insertions(+), 3 deletions(-) diff --git a/src/HELP.md b/src/HELP.md index 2672aad..1928201 100644 --- a/src/HELP.md +++ b/src/HELP.md @@ -1,5 +1,12 @@ # 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. @@ -14,7 +21,58 @@ 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. + +#### `>>> 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. \ No newline at end of file diff --git a/src/controller/player/core/adapter.hpp b/src/controller/player/core/adapter.hpp index 8b91180..428b435 100755 --- a/src/controller/player/core/adapter.hpp +++ b/src/controller/player/core/adapter.hpp @@ -15,6 +15,8 @@ public: Adapter() { } + + // 读取各个角度信息 inline std::map get_degs() { std::map degs; @@ -44,6 +46,7 @@ public: } return degs; } + inline std::map get_body_degs() const { bd_mutex_.lock(); @@ -51,6 +54,7 @@ public: bd_mutex_.unlock(); return res; } + inline std::map get_head_degs() const { hd_mutex_.lock(); @@ -58,6 +62,7 @@ public: hd_mutex_.unlock(); return res; } + inline bool add_body_degs(const std::map &jdmap) { if (!is_alive_) @@ -71,6 +76,7 @@ public: bd_mutex_.unlock(); return true; } + inline bool add_head_degs(std::map &jdmap) { if (!is_alive_) @@ -125,11 +131,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 3a05e4d..8f1300f 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_; -- Gitee From 34649c7ae6a036232f6d2ad8094010ab4d779b59 Mon Sep 17 00:00:00 2001 From: unknown Date: Wed, 3 Jul 2019 10:43:59 +0800 Subject: [PATCH 4/6] Complete rough comment for lib --- src/HELP.md | 24 ++++++++++++++++++++++-- src/lib/common.hpp | 2 +- src/lib/logger.hpp | 1 + 3 files changed, 24 insertions(+), 3 deletions(-) diff --git a/src/HELP.md b/src/HELP.md index 1928201..2cd3ba8 100644 --- a/src/HELP.md +++ b/src/HELP.md @@ -13,6 +13,8 @@ Comments start with a '?' mean that I'm not sure if my understanding is correct. ## `> controller` +*maxwell* responds to "止于至善"🙃. + ### `>> drivers` #### `>>> dynamixel` @@ -33,6 +35,8 @@ Files here realize **program_options**. For example, in `./a.out -help`, `-help` 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` @@ -73,6 +77,22 @@ Tasks are also combinations of serial actions, but skills tend to be mechanical *** -#### `> data` +## `> data` + +Files here store configurations of the robot. + +## `> lib` + +### `>> darknet` + +Lib for recognition. + +### `>> imageproc` + +### `>> math` + +### `>> parser` + +### `>> robot` -Files here store configurations of the robot. \ No newline at end of file +### `>> udp_data` \ No newline at end of file diff --git a/src/lib/common.hpp b/src/lib/common.hpp index e56f1a7..b0b2efe 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 aa73a3c..fc69572 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"< Date: Thu, 4 Jul 2019 10:14:24 +0800 Subject: [PATCH 5/6] Almost complete rough comment --- src/HELP.md | 6 +++++- src/scripts/start_robot.py | 4 ++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/HELP.md b/src/HELP.md index 2cd3ba8..30518c3 100644 --- a/src/HELP.md +++ b/src/HELP.md @@ -95,4 +95,8 @@ Lib for recognition. ### `>> robot` -### `>> udp_data` \ No newline at end of file +### `>> 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/scripts/start_robot.py b/src/scripts/start_robot.py index 44a8ecd..8669cfc 100755 --- a/src/scripts/start_robot.py +++ b/src/scripts/start_robot.py @@ -10,7 +10,7 @@ import time import signal import ssh_connection -if __name__ == '__main__': +if __name__ == '__main__': # 若正在直接运行本文件(即python start_robot.py) if not common.check_argv(sys.argv): common.print_error('no enough arguments') common.print_info('%s id params') @@ -22,7 +22,7 @@ if __name__ == '__main__': exit(3) j=2 for i in range(2,len(sys.argv)): - if '-j' in sys.argv[i]: + if '-j' in sys.argv[i]: # j 代表多线程 j=int(sys.argv[i][2:]) break -- Gitee From 7346a78b56009e2dece511005a4ba5d83645fc2a Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 11 Jul 2019 15:51:45 +0800 Subject: [PATCH 6/6] Complete rough comments --- src/controller/player/core/adapter.hpp | 1 + src/controller/player/core/worldmodel.hpp | 1 + src/controller/player/player.hpp | 2 +- src/controller/player/vision/vision.cpp | 2 +- src/lib/robot/robot.hpp | 1 + 5 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/controller/player/core/adapter.hpp b/src/controller/player/core/adapter.hpp index 428b435..0971de7 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 diff --git a/src/controller/player/core/worldmodel.hpp b/src/controller/player/core/worldmodel.hpp index 880cb82..86c014a 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 62f8a4b..1cddf99 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 33e248a..c510f39 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/robot/robot.hpp b/src/lib/robot/robot.hpp index 8ab3a76..bc6674f 100755 --- a/src/lib/robot/robot.hpp +++ b/src/lib/robot/robot.hpp @@ -1,3 +1,4 @@ +// 当前机器人数据模型,每次从缓冲区取出数据存到此处,再发给机器人 #ifndef __ROBOT_HPP #define __ROBOT_HPP -- Gitee