diff --git a/protocols/jsonrpc-c.c b/protocols/jsonrpc-c.c index 1442dab..247d7f6 100644 --- a/protocols/jsonrpc-c.c +++ b/protocols/jsonrpc-c.c @@ -508,9 +508,9 @@ static int __jrpc_server_start(struct jrpc_server *server) { } int jrpc_server_init_with_ev_loop(struct jrpc_server *server, - int port_number, struct ev_loop *loop) { + int port_number, struct ev_loop *loop_ptr) { memset(server, 0, sizeof(struct jrpc_server)); - server->loop = loop; + server->loop = loop_ptr; server->port_number = port_number; char * debug_level_env = getenv("JRPC_DEBUG"); if (debug_level_env == NULL) diff --git a/user/config/config.c b/user/config/config.c index d30053d..cac8863 100644 --- a/user/config/config.c +++ b/user/config/config.c @@ -130,7 +130,7 @@ cJSON *rov_config_read_from_file_return_cjson() int rov_config_read_from_file(struct rov_info* info) { cJSON *params = rov_config_read_from_file_return_cjson(); - if (params != NULL) // propeller_parameters 非空,解析 + if (params != NULL) // 非空,解析 { propeller_params_read(info, cJSON_GetObjectItem(params, "propeller_params")); dev_ctl_params_read(info, cJSON_GetObjectItem(params, "dev_params")); diff --git a/user/config/parameters/dev_ctl.c b/user/config/parameters/dev_ctl.c index 2a0def1..83e6a59 100644 --- a/user/config/parameters/dev_ctl.c +++ b/user/config/parameters/dev_ctl.c @@ -57,6 +57,10 @@ void dev_ctl_params_init(pwmDev_attr_t *params) params->step = 50; } +/** + * @brief 所有PWM设备参数初始化 + * @param params 结构体参数 + */ void dev_ctl_params_all_init(device_t *params) { dev_ctl_params_init(¶ms->light); diff --git a/user/config/parameters/propeller.c b/user/config/parameters/propeller.c index f82c1c3..c9cab20 100644 --- a/user/config/parameters/propeller.c +++ b/user/config/parameters/propeller.c @@ -16,11 +16,11 @@ cJSON* propeller_params_add_to_root(propeller_attr_t *params) if (node == NULL) return NULL; - cJSON_AddItemToObject(node, "reversed", params->reversed == 1 ? cJSON_CreateTrue() : cJSON_CreateFalse()); - cJSON_AddItemToObject(node, "enabled", params->enabled == 1 ? cJSON_CreateTrue() : cJSON_CreateFalse()); + cJSON_AddItemToObject(node, "reversed", params->reversed == true ? cJSON_CreateTrue() : cJSON_CreateFalse()); + cJSON_AddItemToObject(node, "enabled", params->enabled == true ? cJSON_CreateTrue() : cJSON_CreateFalse()); cJSON_AddNumberToObject(node, "channel", params->channel); - cJSON_AddNumberToObject(node, "deadzone_lower", params->deadzone_lower); cJSON_AddNumberToObject(node, "deadzone_upper", params->deadzone_upper); + cJSON_AddNumberToObject(node, "deadzone_lower", params->deadzone_lower); cJSON_AddNumberToObject(node, "power_positive", params->power_positive); cJSON_AddNumberToObject(node, "power_negative", params->power_negative); @@ -68,12 +68,12 @@ void propeller_params_init_freq(uint16_t *params) /** * @brief 单个推进器参数初始化 - * @param params propeller_parameters结构体参数 + * @param params propeller_attr_t 结构体参数 */ void propeller_params_init(propeller_attr_t *params) { - params->enabled = 1; - params->reversed = 0; + params->enabled = true; + params->reversed = false; params->channel = 0; params->deadzone_upper = 25; params->deadzone_lower = -25; @@ -81,6 +81,10 @@ void propeller_params_init(propeller_attr_t *params) params->power_negative = 0.4; } +/** + * @brief 所有推进器参数初始化 + * @param params propeller_attr_t 结构体参数 + */ void propeller_params_all_init(propeller_t *params) { propeller_params_init_freq(¶ms->pwm_freq_calibration); diff --git a/user/control/control.c b/user/control/control.c index 956739b..43f5e88 100644 --- a/user/control/control.c +++ b/user/control/control.c @@ -22,7 +22,14 @@ void *control_thread(void *arg) { pthread_mutex_lock(&info->system.device.power_output_mtx); pthread_cond_wait(&info->system.server.recv_cmd_cond, &info->system.device.power_output_mtx); - rov_manual_control(info); + if (info->control.flag.debug_mode == false) + { + rov_manual_control(info); + } + else + { + rov_debug_control(info); + } pthread_mutex_unlock(&info->system.device.power_output_mtx); } return NULL; diff --git a/user/control/ctrlPart/manual_ctl.c b/user/control/ctrlPart/manual_ctl.c index c958bc0..56ba69a 100644 --- a/user/control/ctrlPart/manual_ctl.c +++ b/user/control/ctrlPart/manual_ctl.c @@ -60,3 +60,12 @@ void rov_manual_control(rov_info_t *info) CALL_FOR_ALL_PROPELLER(PROPELLER_VALUE_WRITE) #undef PROPELLER_VALUE_WRITE } + +void rov_debug_control(rov_info_t *info) +{ + #define PROPELLER_VALUE_WRITE(which) \ + info->propeller.which.power_cur = (float)info->propeller.which.power_debug / 500.0f; + + CALL_FOR_ALL_PROPELLER(PROPELLER_VALUE_WRITE) + #undef PROPELLER_VALUE_WRITE +} diff --git a/user/control/ctrlPart/manual_ctl.h b/user/control/ctrlPart/manual_ctl.h index b9e2ab4..6908ce4 100644 --- a/user/control/ctrlPart/manual_ctl.h +++ b/user/control/ctrlPart/manual_ctl.h @@ -4,5 +4,6 @@ #include "data_define.h" void rov_manual_control(rov_info_t *info); +void rov_debug_control(rov_info_t *info); #endif diff --git a/user/data-type/control.h b/user/data-type/control.h index 8be23cb..98b8562 100644 --- a/user/data-type/control.h +++ b/user/data-type/control.h @@ -7,6 +7,7 @@ struct status_flag { bool lose_clt; + bool debug_mode; }; struct pid_scale_attr diff --git a/user/device/device.c b/user/device/device.c index 12a0e23..2b1782a 100644 --- a/user/device/device.c +++ b/user/device/device.c @@ -30,7 +30,7 @@ static void write_to_propeller(propeller_t *param) { #define PWM_COTROLLER_WRITE(propeller) \ - pwm_controller_write(param->propeller.channel, 0.0f, 7.5 + constrain(2.5 * param->propeller.power_cur, -2.5, 2.5));\ + pwm_controller_write(param->propeller.channel, 0.0f, 7.5f + constrain(2.5f * param->propeller.power_cur, -2.5f, 2.5f));\ param->propeller.power_last = param->propeller.power_cur;\ param->propeller.power_cur = 0; @@ -50,7 +50,6 @@ void *propeller_thread(void *arg) for (int i = 0; i < 16; i++) pwm_controller_write(i, 0, 0); - for (;;) { pthread_mutex_lock(&info->system.device.power_output_mtx); diff --git a/user/main.c b/user/main.c index b7ab476..8ac638a 100644 --- a/user/main.c +++ b/user/main.c @@ -21,7 +21,7 @@ int main(int argc, char **argv) if (geteuid() != 0) { printf("please run as root...\n"); - exit(0); + exit(EXIT_SUCCESS); } signal(SIGINT, exit_uvm); @@ -30,7 +30,7 @@ int main(int argc, char **argv) if (debug_env == NULL) { pid_t pid = fork(); if (pid > 0) { - exit(1); // 退出父进程 + exit(EXIT_SUCCESS); // 退出父进程 } else if (pid == 0) { setsid(); // 创建守护进程 umask(0); diff --git a/user/main_app.c b/user/main_app.c index 6149d9b..86907ee 100644 --- a/user/main_app.c +++ b/user/main_app.c @@ -45,21 +45,21 @@ void uvm_init(bool debug_mode) } if (rov_config_init(&uvmInfo) < 0) - exit(-1); + exit(EXIT_FAILURE); if (jsonrpc_server_run(&uvmInfo) < 0) - exit(-1); + exit(EXIT_FAILURE); if (rov_device_run(&uvmInfo) < 0) { jsonrpc_server_stop(); - exit(-1); + exit(EXIT_FAILURE); } if (rov_control_run(&uvmInfo) < 0) { uvm_deinit(); - exit(-1); + exit(EXIT_FAILURE); } } diff --git a/user/server/handler/debug.c b/user/server/handler/debug.c index 3f6eb56..4a76100 100644 --- a/user/server/handler/debug.c +++ b/user/server/handler/debug.c @@ -18,7 +18,7 @@ cJSON *set_debug_mode_enabled_handler(jrpc_context *ctx, cJSON *params, cJSON *i { if (params == NULL) return cJSON_CreateNull(); - + ((struct status_flag *)ctx->data)->debug_mode = params->child->valueint; return cJSON_CreateNull(); }