Pages: [1]   Go Down
Author Topic: Arduino, closed Loop, fly by wire, throttle body controller  (Read 1125 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 32
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Here's a link to a short video showing the little controller i pieced together over the weekend. http://youtu.be/tUXB4cQ28zA It's very simple to open and close the throttle butterfly with just PWM at 500Hz, but the butterfly drifts making it completely unusable on a running engine, tried it, you cant control engine rpm. So I attached one of the two internal Throttle position sensors and created a closed loop system that works like the internals of a hobby servo. I still have some tweaking to do. The program is pretty sloppy so if you see a better way to do it, please let me know.
Charley
Quote
int potpin = A0;
int tps = A1;
int val1;
int val2;
int val3;
void setup() {

}

void loop() {
  val1 = analogRead(potpin);
  val2 = analogRead(tps);
  val1 = map(val1, 0, 1023, 0, 120);
  val1 = constrain(val1, 0, 120);
  val2 = map(val2, 320, 498, 0, 120);
  val2 = constrain(val2, 0, 120);
  val3 = val1;

   while(val2 > val1) {
     
  val3--; 
   val3 = constrain(val3, 0, 120);
  
  analogWrite(3, val3);
  delay(2);
  val1 = analogRead(potpin);
  val2 = analogRead(tps);
  }
   
   while(val2 < val1) {
     
  val3++; 
    val3 = constrain(val3, 0, 120);
  
 analogWrite(3, val3);
  delay(2);
  val1 = analogRead(potpin);
  val2 = analogRead(tps);
   }

}


Logged

0
Offline Offline
Jr. Member
**
Karma: 1
Posts: 67
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I am pretty sure that you don't need the constrains right after you first read in from the analog pins in the top of your loop, the analog read will never return a value outside of the range of 0 and 1023 and so the map function will never return a value outside of 0 and 120. Also, you don't need the analog reads at the end of the while loops, they do the same thing as at the top of your code, that is, if I am reading it correctly.  Are you at all concerned about safety if the arduino fails and leaves you with no way to control the engine rpms? I don't know much about throttle butterflies but I would think it would be a bad thing if one went on the fritz.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 32
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I probably don't need the constraints on the read functions, but I definitely do on the output variable as it was getting negative numbers and every time it did the throttle butterfly would slam to full throttle. The 0 - 120 sets the max output voltage of the Darlington at 5 volts. The throttle butterfly is heavily spring loaded so it automatically returns to idle when de energised.
   As for the analogue reads at the end of the while loops, it won't work without them there, I didn't think they needed to be there, but without them, it won't leave idle, and if you comment out the -- while loop, as soon as you turn the pot it goes to full throttle and stays there, I think I have some other error in my code that requires the analogue reads at the end of the while loops.
Charley
Logged

0
Offline Offline
Jr. Member
**
Karma: 1
Posts: 67
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Oh, I see now, the reads at the ends of the while loops are to update the position of where the butterfly valve sensor says it is. If the sensors reading does not match that of the pot pin, then it will move the motor in the throttle body. Sorry for the confusion, I didn't read through it as carefully as I should have. Its not an error, just how your code is set up. I don't personally see anything wrong with it, you might want to change the names "val1, val2 and val3" to something more descriptive to improve readability but that really is just personal preference. Good luck!
Logged

Pages: [1]   Go Up
Jump to: