Skip to content

Commit

Permalink
完善调试控制逻辑
Browse files Browse the repository at this point in the history
  • Loading branch information
sfxfs committed Oct 27, 2023
1 parent 980af8d commit 5fc0a64
Show file tree
Hide file tree
Showing 12 changed files with 44 additions and 19 deletions.
4 changes: 2 additions & 2 deletions protocols/jsonrpc-c.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion user/config/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"));
Expand Down
4 changes: 4 additions & 0 deletions user/config/parameters/dev_ctl.c
Original file line number Diff line number Diff line change
Expand Up @@ -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(&params->light);
Expand Down
16 changes: 10 additions & 6 deletions user/config/parameters/propeller.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -68,19 +68,23 @@ 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;
params->power_positive = 0.4;
params->power_negative = 0.4;
}

/**
* @brief 所有推进器参数初始化
* @param params propeller_attr_t 结构体参数
*/
void propeller_params_all_init(propeller_t *params)
{
propeller_params_init_freq(&params->pwm_freq_calibration);
Expand Down
9 changes: 8 additions & 1 deletion user/control/control.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
9 changes: 9 additions & 0 deletions user/control/ctrlPart/manual_ctl.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
1 change: 1 addition & 0 deletions user/control/ctrlPart/manual_ctl.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 1 addition & 0 deletions user/data-type/control.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
struct status_flag
{
bool lose_clt;
bool debug_mode;
};

struct pid_scale_attr
Expand Down
3 changes: 1 addition & 2 deletions user/device/device.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions user/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand Down
8 changes: 4 additions & 4 deletions user/main_app.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down
2 changes: 1 addition & 1 deletion user/server/handler/debug.c
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down

0 comments on commit 5fc0a64

Please sign in to comment.