RobotC default PID for x-drives

So, I’ve been looking at different options in programming my x-drive to drive straight and turn spicific degrees value turns about its center. I want to use a PID controller for precision and I was wondering if the PID option in RobotC works with non-traditional drive styles?

it should, however you cant use it to drive specific distances, because the wheels are at a 45, they dont travel the same distance that your going, meaning, that because they slip they dont work for that, however if you want a passive wheel in the center attached to a censor, that would measure distance great
but you can use it to keep driving straight yes

Thank you. So, how precise is the default PID? Would it be worth it to write my own?

i highly recommend writing your own, just for the experience, and itll be tuned better to your needs, also its great for your programmer to DIY

So just a clarification,
PID’s generally work as follows
motorpower=(Pconsterror)+(Iconst(sum of all past error values))+(Dconst*(change in error from the last run))

yes? im not sure what your asking, but yes thats how they generally work

Well I found an example similar to the above code and I was wondering how those expressions based on the error in speed, add up to a proper motor input value.

ok, so the error is either the the speed diffference between two wheels or sompthing like (motor 1 speed(master) -motor two speed (slave)=(error), this is great, because one side is the base for readings, and the other esentially copies it, meaning you have two identical sides. another way ive seen it done is
(motor speed average)-(motor side one speed)= error side one and then another (motor average)-(motor side two speed)=error, does this awnser your question?

EDIT: ok, so i reread your question, the error is the difference between the two sides, and then the pid code tries to lessen that error by increasing or decreasing the speed of one side and vice versa the other

The constants are like unit conversion factors. They convert from speed to motor output.

You can absolutely use PID on an X drive. You just need to use two of PID loops and use them with the sets of motors in like directions (NW, SE and NE, SW). The PID will measure how far you are on that axis of travel. Figure out the NW/SE direction distance and the NE/SW direction distance and away you go.

You tune each direction independently (but they will most likely have nearly the same PID constants). You will see it moves to the shortest distance first and then goes along with the other motors for the rest of the way. So not the maximum torque to push cubes and stars around.

So, normally in my drive code, when I set the motors for the drive, I use proportional values.
like so:

setDriveMotors(power+(power/2), power-(power/2), power-(power/2), power+(power/2));
/*This function just sets the motors in the drive to those values. All positive values mean forward.
basically, it is setDriveMotors(backRight, backLeft, frontRight, frontLeft);
Each power value is calculated as:*/
/*So the first function call should move the robot straight with a heading about 30 degrees to the right of forward*/

So would I be able to find the slowest motor and slave the other three to values proportional to its speed?
What I mean is could I run a PID for each wheel to force its speed to something like “speed+(speed/2)” for the back right motor where “speed” is the speed of the slow wheel?

I ask mainly because it shouldn’t be to difficult to program and because it would allow the use of all motors simultaneously, rather than just two at a time.

I would check the internal gearing on all of your motors, you may mot have noticed it, it haplened on my bot. I would not do speed/2, because what wil happen is you will either move half speed or 10000000 speed what i wouls do is take speed(master)-speed(slave)=error for pid. You would be able to yse all 4 motors at once though, is it configuered correctly?

I have to think about this one some more. Yes want to make sure the NW/SE are tuned together and NE/SW are tuned together of master/slave speed control. Doing the same speed control values against all four wheels is not going to adjust as well as treating an X drive as two sets of two.

You are not always traveling in a direction where the other two sets of motors are full power. So you want to tune them down so you stay on the same direction heading. If one set of motors is off, you may have wanted to head at 30 degrees from north, but due to the other motors not working well, you may be going at 15 degrees. The gyro may not help much as the front facing heading is still going to be correct. You are just not driving in the correct direction.

This may be fairly sad, but I STILL don’t know how to make a PID control :L
I know PI, but not PID…
But I know a way to do something… What I did on another forum is I said to have one motor being the master of the other 3 motors… What you would do is set for example, the front-right motor to be 100, then what you will do with the rest of the motors is by comparing their encoders with the front-right encoder. So if the front-left encoder is slower than the front-right encoder, then the robot will tell the front-left wheel to add more speed/power to the front-left motor.