note: I have to go so I’m just copying and pasting my question from stack overflow which got deleted. please ask questions if need be.
I’m new here to the VEX website, and it’s only my second year working with vex, and I can’t find a reliable solution that’s already been said/asked. So I was hoping someone else could help me out?
Currently, I’m building a balance robot as part a project and my teacher and I are stumped where to go from where we currently are. Currently we’ve developed a PID with the input being the angle of the robot, which is coming form a VEX robotics inertial sensor. We’ve gotten pretty far just guessing and checking, changing one input at a time, but we’ve reached a standstill where no matter what we change or how little we change it, it won’t get any better(sometimes after changing it back to what worked better than the current iteration it gets worse which is actually really confusing).
So what he’s asked me to do(and what I’ve failed to find) is some sort of equation that may help is get to the final step of balancing(I understand this is highly improbable because all balancing bots use diff motors, inputs, and measurements in the code but any help is better than none)? Or some sort of additional eyes that may be able to give us the edge we need to fix our problem.
I’ll put our code below, and if you have questions about specifics I’ll do my best to answer but tbh I’m not a great coder and my teacher is doing most of the brain work for the PID & coding.
// Include the V5 Library
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <math.h>
#include <string.h>
#include "vex.h"
// Allows for easier use of the VEX Library
using namespace vex;
//robot configuration code
double err, lasterr = 0, sum = 0;
double kp = 1.4;
double kd = .08;
double ki = 0.04;
double speed = 0;
double target = -2.4;
double pidout;
int main() {
Inertial20.calibrate();
wait(2, sec);
// post event registration
// set default print color to black
printf("\033[30m");
while (true){
err = target -Inertial20.orientation(roll, degrees); //0 is my desired value.
speed = -Motor11.velocity(rpm);
lasterr = err;
sum+=err;
if (-.3 < err && err < .5) {sum = 0.5 * sum;}
pidout = err * kp + speed * kd + sum * ki; //I directly set my kp and kd without variables.
target = -2.3 + Motor11.position(turns) * 2;
Motor1.spin(forward, pidout, volt);
Motor11.spin(forward, pidout, volt);
wait(15,msec);
}
}
Really the only thing we’ve tried is derive this code from a basic pid to be able to move the wheel to keep robot upright. Than once we got this I don’t think we’ve changed the actual code more than 5-10 times or so, and the rest was us just plugging in diff numbers, watching the robot, and changing one of the manual inputs depending on what seemed off the most(jagged corrections, slow to sense something, etc.)
edit 1: Apparently I wasn’t specific enough the first time so I guess I’m trying again.
What’s wrong:
I’m realizing now that I didn’t say exactly how close we got. So unfortunately I’m at home right now and the bot is at school, but the longest we were able to get it to balance without assistance for was ~10 seconds. At which point it overcorrected and promptly fell right into my left hand. So, what we don’t know is how to stop it from over correcting and falling into my hands, and we think the best way to do that is to find the right PID values.
I can try to get a video of the robot tomorrow as well so you guys might have a better idea of what the problem is in case I’m missing something.
What I’m asking for:
What I need is either someone to tell me if there’s some sort of equation we can use to find definite values for our PID, OR If there’s another way to get said values. Like I said before, we’ve already tried manual input followed by testing and we think we’ve done it that way for as long as we could(and we got close), and I’m trying to find some way to solve for the variables.
Also, to Thomas Mathews, thank you for the advice. I’m sure that’s something that looks like it was overlooked but on the platform that I’m using, which is specifically for Vex Robotics called Vex V5 Pro, the things below have to be included otherwise the code produces errors and doesn’t work. I’ll also be adding spaces because I never realized how hard it was to read cause my eyes sort of glaze over when I try to read it.