PID Tuning values
fcaponetto opened this issue · 5 comments
Hi Jorge!
I tried to use your GUI for SimpleFOC v2.0 but I was not able to change the PID parameters.
My loop function on the Arduino side looks like this:
void loop() {
// iterative setting FOC phase voltage
motor.loopFOC();
// iterative function setting the outer loop target
motor.move(target_angle*3.14/180);
motor.monitor();
// user communication
serialReceiveUserCommand();
}
In the C code, for example, I set P gain = 10 but, as shown in the image above, the value is set to zero. Even though I set some value from the GUI, nothing really changes on the motor controller side.
Do I need to integrate something else on the Arduino side? Thanks in advance for your help.
Hi @fcaponetto
This is the loop function that I use with the tool and it should work:
void loop() {
motor.loopFOC();
motor.move();
motor.monitor();
motor.command(serialReceiveUserCommand());
}
A suggestion of something you can try to see if the problem persists is to edit the /config.json file by changing the config parameter to:
{"configToolMode": "FormView"}
This parameter will load the interface of the program that was in the previous version, currently it remains intact but hidden. The operation of the application is exactly the same but with a different UI based on form instead of tree view.
I am going to investigate what may be happening with the tree view based interface to fix it, if I encounter any issues, as soon as I update the tool to adapt it to SimpleFOC v2.1.
Please let me know if the problem persists with the forms-based user interface.
Regards
Thanks for your help.
I introduced the function motor.command(serialReceiveUserCommand())
in the loop()
and now I am able to set gains/values throught your GUI.
As a reference, the new code looks like this:
String serialReceiveUserCommand() {
// a string to hold incoming data
static String received_chars;
String command = "";
while (Serial.available()) {
// get the new byte:
char inChar = (char)Serial.read();
// add it to the string buffer:
received_chars += inChar;
// end of user input
if (inChar == '\n') {
// execute the user command
command = received_chars;
// reset the command buffer
received_chars = "";
}
}
return command;
}
void loop() {
// iterative setting FOC phase voltage
motor.loopFOC();
motor.monitor();
// user communication
motor.command(serialReceiveUserCommand());
}
However, in the beginning, the GUI is still not able to read the current gain/values from the controller, as shown in the image below:
If I sent a command through the command-line interface within your python project, for example P and press "Send", the field in the GUI is set it up. Have a look at the image below:
I guess what may be happening :) Your MCU is not able to handle the requests for config information values that are made when connecting.
You can try to increase delay times at this line. As workaround, in principle, if yo push any button with a empty field it will be populated with the currently set value so delete the content of any config value and then press "Set XXX" button.
Let me know if this solves the problem.
regards
I increased the delay as you suggested from 0.005 s (5/1000) to 0.5 s:
def pullConfiguration(self):
self.sendControlType('')
time.sleep(0.5)
self.sendProportionalGain('')
time.sleep(0.5)
self.sendIntegralGain('')
time.sleep(0.5)
self.sendDerivativeGain('')
time.sleep(0.5)
self.sendVoltageRamp('')
time.sleep(0.5)
self.sendLowPassFilter('')
time.sleep(0.5)
self.sendPGain('')
time.sleep(0.5)
self.sendVelocityLimit('')
time.sleep(0.5)
self.sendVoltageLimit('')
However, the problem is still there except for the Voltage limit value, which is set:
Hi @fcaponetto
I think what is happening is that for some reason that I am not aware of, your MCU is ignoring all requests for configuration information except the last one that corresponds to the voltage limit.
As workaround if you left empty any field and then press "Set XXX" button it should get properly populated with the configuration parameter.