I have been working on a self balancing robot. Its been great but now Im running into a problem that should just be basic math. I am using the PID v1 library that arduino gives examples for.
I got rid of the L's, still not working. I got rid of the whole function and the square root. The cos is messing it up for some reason. MPUdata works but MPUvelocity does not.
MPUdata = MPUloop(); //Gets complimentary angle in degrees, double
Serial.print("Angle: ");
Serial.println(MPUdata);
MPUradian = (MPUdata*71)/4068;
MPUvelocity =cos(MPUradian);
Serial.print("Velocity Needed: ");
Serial.println(MPUvelocity);
Out = PIDloop(MPUvelocity); //Places velocity into PIDloop, setpoint being 0.
Serial.print("PID Output: ");
Serial.println(Out);
rotilahp:
Everything is in double, what do I do now lol!!!
Post your entire sketch lol!!!
If the problem is not apparent from the part of the sketch we can see, then it most likely has to do with the part of the sketch we can't see. So, post your entire sketch, and that will help us to help you.
rotilahp:
I got rid of the L's, still not working. I got rid of the whole function and the square root. The cos is messing it up for some reason. MPUdata works but MPUvelocity does not.
This is not very helpful.
What do you mean by "works", exactly? What results are you hoping to see?
And what results do you actually see?
What behavior would constitute "working" for you?
So normally, my PID output is a double that is in the range of 0 to 255. But when I throw try to use a cos() on the MPUdata variable, suddenly the PID output is zero no matter what the movement is. Super lame, I think I am going to figure out another way to do cos() or maybe find a math library that isn't complete trash
sterretje:
No idea what the compiler does with something like 0.1524L. Why do you specify a float and next tell the compiler to use it as a long?
A floating point literal followed by the L suffix indicates a long double, which is a 128-bit quad-precision floating point type on at least some Linux systems, AFAIK. On other systems, it's the same as double. It probably doesn't do anything on an 8-bit AVR (could it be a 64-bit floating point type? Probably not, but worth checking).
Post your entire sketch. The whole thing. All of it.
Also, if you are using a library, please post a link to the Web page containing that library. That way, we can be reasonably sure that what we are seeing is the same as what you are using.