mirror of
https://github.com/PX4/PX4-Autopilot.git
synced 2026-05-21 04:33:10 +08:00
Make PWM_RATE configurable via QGroundControl
This commit is contained in:
committed by
Lorenz Meier
parent
81dc20ea86
commit
4edd12c44a
@@ -10,13 +10,13 @@ then
|
||||
param set PWM_DISARMED 900
|
||||
param set PWM_MIN 1075
|
||||
param set PWM_MAX 1950
|
||||
param set PWM_RATE 400
|
||||
|
||||
param set RTL_LAND_DELAY 0
|
||||
fi
|
||||
|
||||
# set environment variables (!= parameters)
|
||||
set PWM_RATE 400
|
||||
# tell the mixer to use parameters for these instead
|
||||
set PWM_RATE p:PWM_RATE
|
||||
set PWM_DISARMED p:PWM_DISARMED
|
||||
set PWM_MIN p:PWM_MIN
|
||||
set PWM_MAX p:PWM_MAX
|
||||
|
||||
@@ -3134,6 +3134,24 @@ PARAM_DEFINE_INT32(SENS_EN_TRONE, 0);
|
||||
*/
|
||||
PARAM_DEFINE_INT32(SENS_EN_SF1XX, 0);
|
||||
|
||||
/**
|
||||
* Set the PWM output frequency for the MAIN outputs
|
||||
*
|
||||
* IMPORTANT: CHANGING THIS PARAMETER REQUIRES A COMPLETE SYSTEM
|
||||
* REBOOT IN ORDER TO APPLY THE CHANGES. COMPLETELY POWER-CYCLE
|
||||
* THE SYSTEM TO PUT CHANGES INTO EFFECT.
|
||||
*
|
||||
* Set to 400 for industry default or 1000 for high frequency ESCs.
|
||||
*
|
||||
* @reboot_required true
|
||||
*
|
||||
* @min -1
|
||||
* @max 2000
|
||||
* @unit Hz
|
||||
* @group PWM Outputs
|
||||
*/
|
||||
PARAM_DEFINE_INT32(PWM_RATE, 400);
|
||||
|
||||
/**
|
||||
* Set the minimum PWM for the MAIN outputs
|
||||
*
|
||||
|
||||
@@ -750,6 +750,7 @@ Sensors::Sensors() :
|
||||
(void)param_find("SYS_PARAM_VER");
|
||||
(void)param_find("SYS_AUTOSTART");
|
||||
(void)param_find("SYS_AUTOCONFIG");
|
||||
(void)param_find("PWM_RATE");
|
||||
(void)param_find("PWM_MIN");
|
||||
(void)param_find("PWM_MAX");
|
||||
(void)param_find("PWM_DISARMED");
|
||||
|
||||
+41
-40
@@ -112,6 +112,44 @@ usage(const char *reason)
|
||||
|
||||
}
|
||||
|
||||
static unsigned
|
||||
get_parameter_value(const char *option, const char* paramDescription)
|
||||
{
|
||||
unsigned result_value = 0;
|
||||
|
||||
/* check if this is a param name */
|
||||
if (strncmp("p:", option, 2) == 0) {
|
||||
|
||||
char paramName[32];
|
||||
strncpy(paramName, option + 2, 16);
|
||||
/* user wants to use a param name */
|
||||
param_t parm = param_find(paramName);
|
||||
|
||||
if (parm != PARAM_INVALID) {
|
||||
int32_t pwm_parm;
|
||||
int gret = param_get(parm, &pwm_parm);
|
||||
|
||||
if (gret == 0) {
|
||||
result_value = pwm_parm;
|
||||
} else {
|
||||
errx(gret, "PARAM '%s' LOAD FAIL", paramDescription);
|
||||
}
|
||||
} else {
|
||||
errx(1, "PARAM '%s' NAME NOT FOUND", paramName);
|
||||
}
|
||||
|
||||
} else {
|
||||
char *ep;
|
||||
result_value = strtoul(option, &ep, 0);
|
||||
|
||||
if (*ep != '\0') {
|
||||
errx(1, "BAD '%s'", paramDescription);
|
||||
}
|
||||
}
|
||||
|
||||
return result_value;
|
||||
}
|
||||
|
||||
int
|
||||
pwm_main(int argc, char *argv[])
|
||||
{
|
||||
@@ -190,48 +228,12 @@ pwm_main(int argc, char *argv[])
|
||||
|
||||
break;
|
||||
|
||||
case 'p': {
|
||||
/* check if this is a param name */
|
||||
if (strncmp("p:", optarg, 2) == 0) {
|
||||
|
||||
char buf[32];
|
||||
strncpy(buf, optarg + 2, 16);
|
||||
/* user wants to use a param name */
|
||||
param_t parm = param_find(buf);
|
||||
|
||||
if (parm != PARAM_INVALID) {
|
||||
int32_t pwm_parm;
|
||||
int gret = param_get(parm, &pwm_parm);
|
||||
|
||||
if (gret == 0) {
|
||||
pwm_value = pwm_parm;
|
||||
|
||||
} else {
|
||||
usage("PARAM LOAD FAIL");
|
||||
}
|
||||
|
||||
} else {
|
||||
usage("PARAM NAME NOT FOUND");
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
pwm_value = strtoul(optarg, &ep, 0);
|
||||
}
|
||||
|
||||
if (*ep != '\0') {
|
||||
usage("BAD PWM VAL");
|
||||
}
|
||||
}
|
||||
|
||||
case 'p':
|
||||
pwm_value = get_parameter_value(optarg, "PWM Value");
|
||||
break;
|
||||
|
||||
case 'r':
|
||||
alt_rate = strtoul(optarg, &ep, 0);
|
||||
|
||||
if (*ep != '\0') {
|
||||
usage("BAD rate VAL");
|
||||
}
|
||||
alt_rate = get_parameter_value(optarg, "PWM Rate");
|
||||
|
||||
break;
|
||||
|
||||
@@ -888,4 +890,3 @@ pwm_main(int argc, char *argv[])
|
||||
usage(NULL);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user