Hi there,
I am working on a project where I am using an Arduino nano as a PID controller for a 12v DC Motor. This is an automotive application, using OE Toyota componentry (Variable Nozzle Turbocharger)
The hardware consists of a DC motor connected to an arm, which decreases or increases the angle of the vanes inside the turbine housing of the turbo. Attached to the motors' shaft, is a position sensor that outputs a linear 0-5v signal based on motor angle/rotation/position (much the same as a TPS sensor for a throttle body) There are two independent sensor output channels for failsafe - both output the same scale and are equal to one another.
I have been working on trying to develop some code to drive this and have not been having much luck. I'm relatively new to programming and while I know enough to get by with most simple projects, I don't know enough to get this to where it needs to be.
I recently stumbled upon on some code a user on here (@system) created for a drive by wire (electric) throttle and had confirmed it working. The way the DBW throttle works is basically the exact same as this, however the sensor scales are inverse (one channel reads 0-5v, the other is 5-0v)
So i'm hoping there may be someone on here who could advise what I should change certain parts of the code to in order to suit my hardware/setup. Even better if the original creator of the code sees this and could help me out.
I will have an external ECU sending a 5v PWM to the Arduino which will be the set-point. The Arduino then needs to read the motors' current position and drive the motor forward or backward in order to achieve the commanded set-point value.
The lower and upper bounds of my motor are values of 280-900.
I understand most of the code, however the below sections I just don't understand enough about with the syntax etc.
myPID.SetTunings(0.15, 2.00, 0.00);
int TPS0 = constrain(analogRead(0), 663, 54); //Range: 663 - 54
int TPS1 = constrain(analogRead(1), 164, 970); //Range: 164 - 970
int diff0 = (TPS0-54)+map((TPS1-164), 0, 806, 0, 609);
Input = map(constrain((TPS1 - 164), 0, 806), 0, 806, 0, 380);
int Pedal0 = constrain(analogRead(2), 0, 180); //Range: 0 - 180
int Pedal1 = constrain(analogRead(3), 0, 380); //Range: 0 - 380
int diff1 = Pedal0 - map(Pedal1, 0, 380, 0, 180);
DBW_THROTTLE_PID_NOTED.ino (6.5 KB)
The full code for your reference. A lot of the other stuff for gear shifting etc isn't relevant to me. I have added notes next to the parts I need to change.
Hoping someone can give me a hand with this. I understand the values have been constrained and also remapped, I just don't know enough about these functions and how to adapt my values into this.
Thanks in advance!