mirror of
https://github.com/okalachev/flix.git
synced 2026-02-17 07:31:56 +00:00
Apply motors configuration without reboot
This commit is contained in:
@@ -143,8 +143,6 @@ If using brushless motors and ESCs:
|
|||||||
1. Set the appropriate PWM using the parameters: `MOT_PWM_STOP`, `MOT_PWM_MIN`, and `MOT_PWM_MAX` (1000, 1000, and 2000 is typical).
|
1. Set the appropriate PWM using the parameters: `MOT_PWM_STOP`, `MOT_PWM_MIN`, and `MOT_PWM_MAX` (1000, 1000, and 2000 is typical).
|
||||||
2. Decrease the PWM frequency using the `MOT_PWM_FREQ` parameter (400 is typical).
|
2. Decrease the PWM frequency using the `MOT_PWM_FREQ` parameter (400 is typical).
|
||||||
|
|
||||||
Reboot the drone to apply the changes.
|
|
||||||
|
|
||||||
> [!CAUTION]
|
> [!CAUTION]
|
||||||
> **Remove the props when configuring the motors!** If improperly configured, you may not be able to stop them.
|
> **Remove the props when configuring the motors!** If improperly configured, you may not be able to stop them.
|
||||||
|
|
||||||
|
|||||||
@@ -94,7 +94,7 @@ void doCommand(String str, bool echo = false) {
|
|||||||
} else if (command == "p") {
|
} else if (command == "p") {
|
||||||
bool success = setParameter(arg0.c_str(), arg1.toFloat());
|
bool success = setParameter(arg0.c_str(), arg1.toFloat());
|
||||||
if (success) {
|
if (success) {
|
||||||
print("%s = %g\n", arg0.c_str(), arg1.toFloat());
|
print("%s = %g\n", arg0.c_str(), getParameter(arg0.c_str()));
|
||||||
} else {
|
} else {
|
||||||
print("Parameter not found: %s\n", arg0.c_str());
|
print("Parameter not found: %s\n", arg0.c_str());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ void setupMotors() {
|
|||||||
// configure pins
|
// configure pins
|
||||||
for (int i = 0; i < 4; i++) {
|
for (int i = 0; i < 4; i++) {
|
||||||
ledcAttach(motorPins[i], pwmFrequency, pwmResolution);
|
ledcAttach(motorPins[i], pwmFrequency, pwmResolution);
|
||||||
|
pwmFrequency = ledcChangeFrequency(motorPins[i], pwmFrequency, pwmResolution); // if re-initializing
|
||||||
}
|
}
|
||||||
sendMotors();
|
sendMotors();
|
||||||
print("Motors initialized\n");
|
print("Motors initialized\n");
|
||||||
|
|||||||
@@ -120,6 +120,11 @@ void setupParameters() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void afterParameterChange(String name, const float value) {
|
||||||
|
if (name == "MOT_PWM_FREQ" || name == "MOT_PWM_RES") setupMotors();
|
||||||
|
if (name == "MOT_PIN_FL" || name == "MOT_PIN_FR" || name == "MOT_PIN_RL" || name == "MOT_PIN_RR") setupMotors();
|
||||||
|
}
|
||||||
|
|
||||||
int parametersCount() {
|
int parametersCount() {
|
||||||
return sizeof(parameters) / sizeof(parameters[0]);
|
return sizeof(parameters) / sizeof(parameters[0]);
|
||||||
}
|
}
|
||||||
@@ -148,6 +153,7 @@ bool setParameter(const char *name, const float value) {
|
|||||||
if (strcasecmp(parameter.name, name) == 0) {
|
if (strcasecmp(parameter.name, name) == 0) {
|
||||||
if (parameter.integer && !isfinite(value)) return false; // can't set integer to NaN or Inf
|
if (parameter.integer && !isfinite(value)) return false; // can't set integer to NaN or Inf
|
||||||
parameter.setValue(value);
|
parameter.setValue(value);
|
||||||
|
afterParameterChange(name, value);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -165,6 +165,7 @@ void delay(uint32_t ms) {
|
|||||||
|
|
||||||
bool ledcAttach(uint8_t pin, uint32_t freq, uint8_t resolution) { return true; }
|
bool ledcAttach(uint8_t pin, uint32_t freq, uint8_t resolution) { return true; }
|
||||||
bool ledcWrite(uint8_t pin, uint32_t duty) { return true; }
|
bool ledcWrite(uint8_t pin, uint32_t duty) { return true; }
|
||||||
|
uint32_t ledcChangeFrequency(uint8_t pin, uint32_t freq, uint8_t resolution) { return freq; }
|
||||||
|
|
||||||
unsigned long __micros;
|
unsigned long __micros;
|
||||||
unsigned long __resetTime = 0;
|
unsigned long __resetTime = 0;
|
||||||
|
|||||||
Reference in New Issue
Block a user