Sometimes motor holds, sometime it slides, so the distances travelled are different.
Often, when I pose a question on the internet, I like to imagine myself as the answerer, analyzing the information provided and developing a solution to the problem. This helps protect me from asking useless questions.
For example, if I asked “Why does my robot fall apart?”, the answerer would have no choice but to declare it a useless question and move on. As the answerer, (though only an imagined one) I’d have no information to analyze. I know there is a problem somewhere, but it could be that the asker is using bad screws, or bent metal, or not tightening their structure, or not bracing their towers well.
Perhaps if I asked “How can I keep my screws from loosening? - I use keps nuts with steel hex screws” I might have better results. This is because I have provided information and context surrounding my problem. The answerer has information to analyze and a much clearer solution becomes apparents (switch to locking nuts).
Imagine, if you will, that I wished to ask a question about a malfunctioning PID. If I were the answerer, I would probably want information about the code, as it is a code-oriented question. Ideally, I would have access to the entire codebase, with the PID functions and calls highlighted, to best analyze the information surrounding the problem. I would want to know if this PID function was user-developed, or part of a pre-made library. I would want to know what might cause this change in brake type. Does it depend on how quickly the robot settles? Does it depend on the battery voltage, or placement in the code, or time the code is run? Better still, as the answerer I would want to see a video of each case to best analyze whether the motor’s brake type is really the issue at hand. These things would give the answerer some information to analyze, and to thereby develop a solution to my problem.
All purely hypothetically, of course.
Thank you @2775Josh , I would add to that, if you have a programming issue, post your code. ( ``` on the line above and below). No-one is going to steal your code, and chances are, if you are posting it here, there is something wrong with it. If we can see what is wrong with it, we can help.
void PIDDrive(double target, double kp, double ki, double kd, double integral_limit, int speedlimit){
tareMotorsPositions();
double output;
double error = target - ((rightFront.get_position() - leftFront.get_position())/2);
double past_error = 0;
double integral = 0;
double derivative = 0;
while(fabs(error) > 5){
past_error = error;
error = target - rightFront.get_position();
if(fabs(error) < integral_limit){
integral += error;
}
else{
integral = 0;
}
derivative = error - past_error;
output = (error * kp) + (integral * ki) + (derivative * kd);
if(output > speedlimit){
output = speedlimit;
}
if(output < -speedlimit){
output = -speedlimit;
}
leftFront = -output;
leftBack = -output;
leftMiddle = output; //stacked motor reverses directions
rightFront = output;
rightBack = output;
rightMiddle = -output; //stacked motor reverses directions
}
}