Skip to content

Commit

Permalink
修改 pwm 频率为 uint16_t
Browse files Browse the repository at this point in the history
  • Loading branch information
sfxfs committed Oct 9, 2023
1 parent 57f6dbd commit 2f21403
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 36 deletions.
3 changes: 0 additions & 3 deletions user/config/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,8 @@ static void rov_info_write_initial_value(struct rov_info* info)
memset(info, 0, sizeof(rov_info_t));//变量初始化

propeller_params_all_init(&info->propeller);

rocket_ratio_params_all_init(&info->rocket);

pid_ctl_params_all_init(&info->pidScale);

dev_ctl_params_all_init(&info->devCtl);
}

Expand Down
6 changes: 3 additions & 3 deletions user/config/parameters/propeller.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ cJSON* propeller_params_add_to_root(struct propeller_parameters *params)
return node;
}

void propeller_freq_read_from_root(double *freq, cJSON *node)
void propeller_freq_read_from_root(uint16_t *freq, cJSON *node)
{
if (node == NULL)
return;
*freq = node->valuedouble;
*freq = node->valueint;
}

/**
Expand All @@ -54,7 +54,7 @@ void propeller_params_read_from_root(struct propeller_parameters *params, cJSON
* @brief 单个推进器频率初始化(默认50 HZ )
* @param params 推进器PWM频率参数(propeller.pwm_freq_calibration)
*/
void propeller_params_init_freq(double *params)
void propeller_params_init_freq(uint16_t *params)
{
*params = 50;
}
Expand Down
4 changes: 2 additions & 2 deletions user/config/parameters/propeller.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
#include "data_define.h"

cJSON* propeller_params_add_to_root(struct propeller_parameters *params);
void propeller_freq_read_from_root(double *freq, cJSON *node);
void propeller_freq_read_from_root(uint16_t *freq, cJSON *node);
void propeller_params_read_from_root(struct propeller_parameters *params, cJSON *node);
void propeller_params_init_freq(double *params);
void propeller_params_init_freq(uint16_t *params);
void propeller_params_init(struct propeller_parameters *params);

void propeller_params_all_init(propeller_t *params);
Expand Down
2 changes: 1 addition & 1 deletion user/data-type/propeller.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ struct propeller_parameters

typedef struct propeller
{
double pwm_freq_calibration;
uint16_t pwm_freq_calibration;
struct propeller_parameters front_left;
struct propeller_parameters front_right;
struct propeller_parameters center_left;
Expand Down
14 changes: 1 addition & 13 deletions user/server/handler/control.c
Original file line number Diff line number Diff line change
@@ -1,20 +1,8 @@
#include "config/parameters/utils.h"
#include "data_define.h"

#include "control.h"

static double cjson_value_analysis_double(cJSON *params,const char *str)
{
cJSON* cjson_temp = NULL;
double value;
cjson_temp = cJSON_GetObjectItem(params, str);
if (cjson_temp != NULL) //如果没收到则返回
{
value = cjson_temp->valuedouble;
}
else value = 0;
return value;
}

static cJSON *move_analysis(cJSON* params, struct rov_info* info, move_mode_t mode)
{
if (params == NULL)
Expand Down
16 changes: 2 additions & 14 deletions user/server/handler/debug.c
Original file line number Diff line number Diff line change
@@ -1,25 +1,13 @@
#include "config/parameters/pid_ctl.h"
#include "config/parameters/propeller.h"
#include "device/application/pwm_controller.h"
#include "config/parameters/utils.h"

#include "config/config.h"
#include "data_define.h"

#include "debug.h"

static int cjson_value_analysis_int(cJSON *params, const char *str)
{
cJSON* cjson_temp = NULL;
int value;
cjson_temp = cJSON_GetObjectItem(params, str);
if (cjson_temp != NULL) //如果没收到则返回
{
value = cjson_temp->valueint;
}
else value = 0;
return value;
}

cJSON *set_debug_mode_enabled_handler(jrpc_context *ctx, cJSON *params, cJSON *id)
{
if (params == NULL)
Expand All @@ -32,7 +20,7 @@ cJSON *set_propeller_pwm_freq_calibration_handler(jrpc_context *ctx, cJSON *para
{
if (params == NULL)
return cJSON_CreateNull();
pwm_controller_set_freq((uint16_t)params->child->valuedouble);
pwm_controller_set_freq((uint16_t)params->child->valueint);
return cJSON_CreateNull();
}

Expand Down

0 comments on commit 2f21403

Please sign in to comment.