DBW With idle Control

The project that I would like to do is installing a Electronic Throttle Body from a 2015+ Mustang GT into my project drag/street car. The car in question is a 90 Eagle Talon TSi AWD that been auto swapped and is undergoing the normal mods for High power. The my goal would be to implement this TB which is 80MM in size and have a Arduino be able to fully control it with Cold start and idle. I found a sketch posted to Pastebin that use's PID control but its a simple sketch that just works. The accelerator pedal and TB have two POTS, Ill need to source a the throttle and then measure both to find out the min and max but they use two pots for safety reasons. I would like to, to continue to use both that way added safety can be had. Id also like to implement a cold start and idle control using coolant temp and RPM inputs. For the time being these are my only conditions for any outside control of the Throttle. Potentially open for future inputs as well. I don't have much background in coding, But i'm wanting to learn and have a very broad back background in electronics so i do understand how things works hardware wise. Its the software side i'm lacking. I'm in the process of securing the H-bridge and throttle Pedal assembly. the TB i already have as it came on a 18 GT intake manifold i purchased for my 14 GT. Below is the code that I found and would like to potentially use.

/*     DIY DBW Throttle Controller
 *            by: mattmon
 *        
 *     Constraint and PID variables are unique to each installation
 *     
 *     Your use of this software absolves me of any resulting liability
 *   
 */

#include <PID_v1.h>

// Inputs
const int POT_THROTTLE = A2; // Servo Position Input 
const int POT_PEDAL = A3; // Pedal Sensor Input

// Pins H bridge
const int HB_FORWARD = 9; // H bridge Forward
const int HB_REVERSE = 5; // H bridge Reverse
const int HB_PWM = 6;     // H bridge PWM (speed)
const int HB_ENABLE = 7;  // H bridge Enable

// Throttle constraints
const int THROTTLE_MIN = 82;
const int THROTTLE_MAX = 785;

//Pedal constraints
const int PEDAL_MIN = 56;
const int PEDAL_MAX = 748;

//Motor PWM range
const int PWM_MAX = 180;
const int PWM_MIN = 80;

int throttleRest; //Normalized throttle resting position

//PID Control variables
double kP = 2;
double kI = 0;
double kD = 0;

//Define the PID controller
double Input, Output, SetPoint;
PID throttlePID(&Input, &Output, &SetPoint, kP, kI, kD, DIRECT);

void setup() {
  
  //Determine pot value with throttle at rest 
  throttleRest = map(constrain(analogRead(POT_THROTTLE), THROTTLE_MIN, THROTTLE_MAX), THROTTLE_MIN, THROTTLE_MAX, 0, 1023);
  
  //Enable PID control
  throttlePID.SetMode(AUTOMATIC);
  
  //Enable motor controller
  digitalWrite(HB_ENABLE, HIGH);
}

void loop() {

  //Open throttle if pedal position > throttle position
  if (SetPoint > Input) {
    digitalWrite(HB_FORWARD, HIGH);
    digitalWrite(HB_REVERSE, LOW);
  //Close throttle
  //} else if (SetPoint < throttleRest && Input <= throttleRest) {
  //    digitalWrite(HB_FORWARD, LOW);
  //    digitalWrite(HB_REVERSE, HIGH);
  //Return throttle to resting position 
  } else {
    digitalWrite(HB_FORWARD, LOW);
    digitalWrite(HB_REVERSE, LOW);
  }
                                                                      
  // Read throttle position 
  Input = map(constrain(analogRead(POT_THROTTLE), THROTTLE_MIN, THROTTLE_MAX), THROTTLE_MIN, THROTTLE_MAX, 0, 1023);
  
  // Read pedal sensor position 
  SetPoint = map(constrain(analogRead(POT_PEDAL), PEDAL_MIN, PEDAL_MAX), PEDAL_MIN, PEDAL_MAX, 0, 1023);

  //Go PID, Go!
  throttlePID.Compute();

  // Map PID output to motor PWM range 
  Output = map(Output, 0, 255, PWM_MIN, PWM_MAX);
  analogWrite(HB_PWM, Output);

}
1 Like