MR2 Owners Club Forum banner

Controlling functions in the engine bay with Arduino and servo motor?

13K views 126 replies 11 participants last post by  Gandalf 
#1 ·
I have been thinking about this for a while, and I am going to try this out. The main motivation behind it is the fact that I am keeping my TVIS system and want to get the most out of it, and the oem ecu TVIS operation is far from performance-optimal. Hence, not only controlling its opening point but its opening rate. The reason being, it seems to me best to have it open based on RPM (which many have done), but not only that, to have it open progressively based on RPM.

From studying dyno charts of those that have dyno'd with the TVIS closed and then fully open, and then set their TVIS to open at a certain RPM, there is a bit to be gained, when all those dynos are overlayed. There always is a dip as the TVIS goes from fully closed to fully open rather quickly. This rate of opening is always the same regardless of the gear we are in.

Now what I am curious about, is whether the turbulence from a half-open TVIS will be too disruptive and negate the potential gains. It could be possible that this is the case. However, I am too curious not to try.

What some people have done to control things like throttle bodies on various motors is to use a suitable servo motor (originating from the RC hobby world). I want to control this servo motor using my Arduino (Freeduino actually) microcontroller, and then programming it with whatever parameters I want. Using correct resistors and circuitry, I get the tach signal (probably have to get it down from 12v to 5v (the Arduino needs 5v)... I think its all squarewave... and then write a small program that assigns servo motor positions based on those RPM numbers. So, I can start the motor's movement at 3700 RPM, and finish its movement at 4700 RPM (for example), if it is deemed to be most beneficial in that range. It also does not have to be a linear rate, it can be anything at all.

I am willing to bet that if we were able to dyno in every gear, we would find that one of our gears is closest to having the oem TVIS open at a rate that suits the RPM climb.This is probably first or second gear. The gears that this mod would benefit the most would be 3,4,5, since the TVIS normally opens at the same speed no matter the gear.

In addition, if I figure out that there are other conditions or scenerios in which to make exceptions to the RPM-based rate (such as boost for example), I can write another small program to perform that as well, and run input data from another source such as boost level (signal).

Has anybody done this, or something like it? Any thoughts welcome... Its going to take a bit of homework on my part to figure out the correct electronic parts... I already have the Arduino, and access to a great electro-acoustic lab at school tht is stuffed to the brim with resistors etc... I am studying what others have done to convert correctly from the tach signal to the Arduino so that it all works. Some things are less than 12v in our cars, so it may work to my advantage.

scarecrowX? :angel:
You usually have a way of simplifying over-complicated plans...

One thing I can see right away:
-moisture/heat protection for the servo motor. I can install the Arduino anywhere (like in the trunk for protection).
 
See less See more
#2 · (Edited)
scarecrowX confirmed tonight that apparently the timing related stuff is all logic level (5v) so that's definitely a step in the right direction... in the quest for coil-on-plug sequential ignition, the CYP (cylinder position sensor used to determine which cylinder is next in the firing order for sequential fuel injection) is tapped off the HIC1, and the TDC sensor can be tapped on the output of the HIC1 board as long as you're not loading it (affecting the signal). That would be a pulse per revolution.

I can work with that... I can write a little basic math program operation that relates these pulses to RPM (or borrow code from someone who has done it, for say, computer fan rpm, etc)... then assign positions for the servo motor based on the RPM range I want to target.
 
#3 · (Edited)
ultimately wouldnt the best input to guage how to open the tvis be mass air flow rather than just RPM? manifold pressure isnt exactly constant at any given rpm... That way you wouldnt be programming to a square wave, but you would have an analog signal. More complicated maths, but more accurate :)
 
#4 · (Edited)
ok so its not as complicated as I thought... what you do is you find out the optimal flow velocity through the tvis, and then maintain that flow value. For example, lets assume that the optimal flow velocity during a normal pull through the tvis with the valves closed happens at 2500 rpm using a given turbo and . This means that the motor is flowing some volume of air through one open tvis port.

Lets use this equasion (flow velocity through a pipe of given diameter) as a baseline @ 2500 rpm: v = 1.274 q / (d^2)

let v be the velocity, q be the m^3/s of air, and d be the diameter of a circle with equivalent area to the cross sectional area of the inlet (~1.5 in?) (we can calculate the exact flow later if we find the exact cross sectional area)

we know that for some range of air flow that we want v to be constant, airflow (m^3/s) will be our dependant variable, and d in meters will be our independant variable.

So for a hypothetical: we are doing a straight pull and @ 2500 RPM, the turbo is just starting to spool, and our map sensor and iat are measuring 1 bar in the manifold. This means that air flow through the tvis should be ~.0395 cubic meters a second. The corresponding velocity is ~34.67m/s ( i promise i did all my conversions :) )

We then want to keep our intake velocity at that value or greater from this point forward. This will require finding out which air flow value is required to keep the air velocity at this 34.67 when the butterfly valves are completely open. The d at this value will be calculated from 2A, which is: .002279m^2 (A is .0011395 m^3) the corresponding equivalent d is then: 5.38cm or 2.12in So then all you have to do is assign the closed position to the d value of 3.81cm, and then the open position the d value of 5.38cm.

d= sqrt(1.274q/v)

all you have to do from this point is to assign servo positions to values of d between 3.81 and 5.38 cm, or whatever the actual calculated values may be...
 
#5 · (Edited)
Thanks for the time and effort on the math and your reply :thumbup Ok, I follow what you are saying. Now, under which conditions (signal type aside) does it more accurately determine opening/closing points than RPM? Which driving conditions?

Those that have dyno'd the TVIS full open vs fully closed have found that the best opening point for the TVIS is around 3700 RPM. On my car, my GT3040 turbo spools around there and breaks 200 rwtorque at about 4000 RPM. So for me, the TVIS helps me with a little lower end grunt just prior to the turbo sweet spot. Every car will be different depending on the components of course, but I am wondering how using a flow velocity TVIS control will give me an advantage...

In order for it to be an advantage, it would have to be a situation where for a second or two the RPM is telling the TVIS to be closed (under 3700) but in fact the TVIS should be open? Or, the RPM is telling the TVIS to be open (above about 4500 RPM) but it should in fact be closed? I am finding it hard to imagine where the RPM system is inadequate, or not a decent solution... (Of course, this is testing the system under a dyno-condition only)

Right during shifts perhaps, when the turbo drops boost? The Neptune system I am going to run has full-throttle shifts, so I should lose little under those conditions...

I am still trying to fully grasp what the most crucial factor in a TVIS sytem is in terms of the air... so, another question: can it be said that it is most important to get maximum air velocity possible at anything below full boost? How is air velocity more crucial than boost to control the TVIS?
 
#7 · (Edited)
mass air flow isnt constant, especially with varying temperatures and barometric pressures. There is a good possibility that you may change the VE of your motor in the future (new better parts). And whenever you change your motor's VE the flow rates at any given point will change.

We have to go back and look at exactly why toyota put in the tvis.. It was put in to increase flow velocities and the force from the air on the fuel stream into the combustion chamber in low rpm's for greater low end torque. The thing is that if the mass air flow is different, then the velocities will be different, and the equivalent forces on the fuel will be different. If you guage off of mass air flow however, you can more adequately and more consistently open your tvis in exact proportion to the optimal air velocity demanded . If you guaged solely off of RPM, you couldnt account for any unforseen changes. The beauty of a setup like this is that it would run more intellegently and be self adjusting based on intake temperatures, manifold pressures, and VE.
As for optimal vs maximal velocity, you have to figure that because the intake ports on the genII motor are so retarded huge, that if left open the flow velocities at low RPM would be way too slow. But if they stayed closed all the time, we would quickly hit a maximum flow, but that would choke the engine. Which is why finding optimal flow is most important.

(this next part is hard to describe without visual aides)

If we trust that the OEM's had it right, we know that the tvis opens at 3700RPM because this is the point where the open and closed torque curves intersect. However if we had full control over how the butterfly valves open, essentially we would eliminate the sharp point in the torque curve. It would be perfectly smooth. with torque gains in both the low and high end.

But because in the real world that intersection point actually changes (with different intake temps, and pressures) if you really want to get the most out of the tvis, its important to go off of your variables, not just pick a point and hope its good enough.
 
#9 ·
l0ch0w said:
But because in the real world that intersection point actually changes (with different intake temps, and pressures) if you really want to get the most out of the tvis, its important to go off of your variables, not just pick a point and hope its good enough.
Are you just speculating? You must be, because if you had actually produced the torque curves at varying boost pressures on a dyno you would notice that the crossover point stays the same.

Also, the stock opening point is 4200 RPM, not 3700 RPM.

I agree that the VE of the motor will change the optimal opening point, but the air density doesn't. All that air density does is change the number of molecules that flow across the TVIS at a given RPM--it does not change the velocity of those molecules. This is why the code in the stock ECU switches only on RPM even though the mass flow values from the AFM are available.
 
#10 ·
RickyB said:
Are you just speculating? You must be, because if you had actually produced the torque curves at varying boost pressures on a dyno you would notice that the crossover point stays the same.

Also, the stock opening point is 4200 RPM, not 3700 RPM.

I agree that the VE of the motor will change the optimal opening point, but the air density doesn't. All that air density does is change the number of molecules that flow across the TVIS at a given RPM--it does not change the velocity of those molecules. This is why the code in the stock ECU switches only on RPM even though the mass flow values from the AFM are available.
Would you say then that the optimal opening point is a product of VE primarily? What other factors do I need to take into account if I design a mocrocontroller program? During off throttle or shifts for example?
 
#11 ·
Gandalf said:
Would you say then that the optimal opening point is a product of VE primarily? What other factors do I need to take into account if I design a mocrocontroller program? During off throttle or shifts for example?
VE is going to determine the VOLUME of air coming down the runner (not molecules, that's determined by the DENSITY of the air). The volume of air is going to determine the velocity of air (a direct correlation with the cross sectional area of the runner, which is what the TVIS is altering).

Thus, any changes to the engine that affect VE will require the TVIS opening point to be adjusted.
 
#12 ·
The stock opening point isnt exactly geared towards being super precise. I am assuming that you want to get absolutely the most out of your TVIS. Which means taking into account every variable.

RickyB, As for velocity and pressure both being important, you have to figure that pressure pretty much determines the number of air molecules in a given space. The force exerted on the fuel is then a determinant of both velocity as well as pressure. Velocity alone will not move fuel... If only a couple of molecules of air moving really fast (high temperature air) interupt the fuel flow not that much will happen, but if lots of air molecules moving really fast (cool air) interupt the fuel flow, then you will do alot more work. This was my point, its not just about air velocity.
 
#13 ·
RickyB said:
Are you just speculating? You must be, because if you had actually produced the torque curves at varying boost pressures on a dyno you would notice that the crossover point stays the same.
This statement would not hold water if you dynoed the same car at the same boost level in Denver vs lets say San Diego... The point is that the TVIS opening point does change based on many factors. I would be willing to bet it also changes if the turbo is swapped out. I never said the varying boost pressures change the opening point, but changes in ve or barometric pressure would...

Setting up the TVIS to open variably based on a greater range of inputs would make for a car that performs much more constanly given different external variables.
 
#14 · (Edited)
The stock TVIS opening point is barely important because there are sooo many other factors from the ecu that play around with the TVIS, leaving stock control of the TVIS as highly undesireable from a performance perspective, especially on a non-stock engine. Hence the key is to take control of the TVIS away from the ecu, as RickyB advised long ago.

Would it then not be best to write a program based on RPM and the engine's particular characteristics on a dyno, and then additionally write sub-routines that will influence the program to take into account variables such as altitude and any other non-constants? Similar to how a dyno corrects?

If I dyno and get the expected gains from the TVIS compared to open/closed TVIS pulls, and the curve is perfectly smooth like l0ch0w mentioned, then I know I've got it right. I think KBlake posted a dyno in which the TVIS actually provided peak torque (moved his torque peak up 1300 RPM or thereabouts).
Actually, I found it... This is a great example of not only what a TVIS can do, but what I want to do with it. See that concave curve in the torque between 3200 and 4700 RPM (green line)? I think I can flatten it. Now, in my case, with a GT3040 (3082) turbo, it will spool later, so the TVIS won't have as wide an RPM range to affect, but I believe if I set it up correctly, the TVIS can have a more profound effect on torque onset (and spool). The gains should be lesser on a spool-monger turbo. I'm sure KBlake is ok with me re-posting it:
 
#15 · (Edited)
On the microcontroller subject, I wonder if this can be of use... it is designed for the OBD2 ecu, and I have an OBD1, so it may not fit, but, perhaps it is a step in the right direction?

Maybe I should have mentioned for those that don't know, I am going the scarecrowX-route for an ems, using a Honda PO6 OBD1 ecu and Neptune software. Things are very similar to the oem 3sgte ecu, except fully programmable.

Anyways, I won't need their little display or anything since I will just look on my laptop, or eventually on a built-in car computer (which will also run all entertainment etc, and have any function display I want). Its an Arduino similar to mine with a program written to monitor several OBD2 inputs.

http://code.google.com/p/opengauge/wiki/OBDuino
 
#16 ·
What I am saying is that if you setup your tvis to open a certain way at a set RPM, you will not have as consistent of performance. That tune is only good for that day on that dyno. What happens when a high pressure system comes in and messes with the barometric pressure? what happens if you drive up to the mountains? what happens if you buy a sweet new exhaust manifold or intercooler and change the ve of the system? All of these things will require you to "re-tune" your tvis for optimal performance... Im saying set it up the more complicated way so that your motor can auto tune the opening point of the tvis. thats all...
 
#18 ·
The TVIS will be the last thing that gets tuned, after the cam gears. But it would be great to have an accurate compensation system for things like altitude, so that when I come down from high altitude and show up at sea level for a meet, that I still get the best performance.

So since the opening point is determined by VE, how will the particular factors such as you mentioned alter or affect the opening point? How can we compensate them accurately? We would almost need to dyno at two altitudes...
 
#19 ·
Update and video

I have designed a patcher using Max MSP, Maxuino, a freeduino microcontroller, and a Spectrum A6030 digital titanium-geared aircraft servo (280 oz of torque). It is capable of analog and digital inputs, and will give me precise control over every aspect of the TVIS, including rate and opening/closing points. It is not yet in communication with the ecu, that is the next step, and no other "variable parameters" such as altitude are at this stage taken into account. When I fully understand which factors need to be accomodated and how much, I can write them into the patcher.

I made a YouTube video detailing how it works, check it out:
http://www.youtube.com/watch?v=CQLr5fcW_e8
 
#20 ·
Second video, Part 2

I have completed the Max MSP patch that will control the TVIS. I have added dials to the interface that allow me to set the TVIS start-point and fully-open-points independantly to whatever RPMs I want. This gives a precise range and rate for this opening. It took a fair bit of head-scratching math, but it works flawlessly.

In the future I can also add any other exceptions I want, such as gear selection... just for example, if I find that in first gear, the engine whips through the RPM's faster than the fastest servo/TVIS opening rate, I can have the TVIS only engage from second gear onwards, etc.... It is currently mathematically a linear-rate of opening, but a servo arm actually naturally gives a scaled rate, having the fastest travel in the center of its range. As we select a longer servo arm (or larger-diameter wheel), this scale moves closer to being linear. I can play with the arm-length and servo range to get the best compromise.

What this interface has proven to me is that I can use this system to design ANY gauges, dials, readings, sensor inputs I want, and have them displayed in whatever manner or configuration I want to see. I can also add large numbers of sensor inputs independantly of my tuning software, or take/exchange data from my Neptune/Demon/Honda P06 combo and have it displayed in a nice layout. So it can go well beyond TVIS... but it was a good place to start :).

Here is the Part 2 video showing the new completed interface, patch, and servo control:

http://www.youtube.com/watch?v=43iBLhqMhII
 
#23 ·
The current setup I have using my Mac, MaxMSP (massive virtual circuitry) Maxuino (to liason between MaxMSP and Arduino) is so beyond overkill in capability and $ (I had all this equipment anyway), BUT... There will be a way to re-write or source the code that can be uploaded and stored directly into the Arduino, and it will perform everything in identical fashion as far as the TVIS goes, plus many other functions if you want. At some point I will have it down to such a code, and then all anyone would need is an Arduino, installed servo, and then this code uploaded into the Ardiuno. The servo part of things would have to be calibrated for range, etc, which would be car-specific of course. I also do not know how much force the TVIS requires at full throttle; its possible that my $85 titanium-gear 280oz-torque digital servo is also overkill, lol. I'm just putting together parts, software and my Mac I needed for school courses... putting it all to good use.

I am a ways away from having my car functioning on the new Neptune RTP software, though, with new parts swapped in, so the testing of the TVIS won't be for a while. For the moment, using a switch as you mentioned will be the best/simplest/cheapest option.

I am staggered by the limitless possibilities of having MaxMSP functioning on a Mac in the car. There is virtually no part of the car that you couldn't integrate... Unlimited vehicle security, GPS, uber entertainment 10.1 surround, remote control... a zillion apps of any kind... connected by virtually any sensor you can dream of... send it commands... log on remotely and check if your girlfriend left her purse on the seat :smile: Have every function be accessible via voice-command, have your car recognize exactly where your pupils are looking and you can select functions by merely looking at them... wouldn't even have to touch them.
But honestly, my goal isn't to add unnecessary stuff, but rather enhance performance, combine functions (no need for stereo deck+GPS+security+extra gauges+tuner interface), save space, reduce wiring, reduce electrical draw, update appearance, and shave weight.
 
#24 ·
Gandalf said:
The current setup I have using my Mac, MaxMSP (massive virtual circuitry) Maxuino (to liason between MaxMSP and Arduino) is so beyond overkill in capability and $ (I had all this equipment anyway), BUT... There will be a way to re-write or source the code that can be uploaded and stored directly into the Arduino, and it will perform everything in identical fashion as far as the TVIS goes, plus many other functions if you want. At some point I will have it down to such a code, and then all anyone would need is an Arduino, installed servo, and then this code uploaded into the Ardiuno. The servo part of things would have to be calibrated for range, etc, which would be car-specific of course. I also do not know how much force the TVIS requires at full throttle; its possible that my $85 titanium-gear 280oz-torque digital servo is also overkill, lol. I'm just putting together parts, software and my Mac I needed for school courses... putting it all to good use.

I am a ways away from having my car functioning on the new Neptune RTP software, though, with new parts swapped in, so the testing of the TVIS won't be for a while. For the moment, using a switch as you mentioned will be the best/simplest/cheapest option.

I am staggered by the limitless possibilities of having MaxMSP functioning on a Mac in the car. There is virtually no part of the car that you couldn't integrate... Unlimited vehicle security, GPS, uber entertainment 10.1 surround, remote control... a zillion apps of any kind... connected by virtually any sensor you can dream of... send it commands... log on remotely and check if your girlfriend left her purse on the seat :smile: Have every function be accessible via voice-command, have your car recognize exactly where your pupils are looking and you can select functions by merely looking at them... wouldn't even have to touch them.
But honestly, my goal isn't to add unnecessary stuff, but rather enhance performance, combine functions (no need for stereo deck+GPS+security+extra gauges+tuner interface), save space, reduce wiring, reduce electrical draw, update appearance, and shave weight.

Most of that is over my head. Completely unfamiliar with Macs, and any kind of servos and controls.
 
#25 ·
Its not just limited to Macs. :)
Max MSP can be run on PC's, our class had a mix of PC's and Macs.
An Arduino is basically a microcontroller not unlike the little circuit board we have in our doors to control our power windows, or the controller for pop-up headlights...
Except the Arduino has a chip in it that is programmable, and a bunch of analog input spots, and digital input/output and pwm spots. That lets us decide how to route info in and out of the Arduino. Then, using source code directly, we can program what the Arduino does with the inputs, and the outputs. We can also write to the Arduino with a fantastic program called Max MSP, via a liason program called Maxuino. The reason i do it that way, is because Max MSP is sooo much more up my alley than writing source code... because it has many pre-made objects that come pre-written to function and even look like electronic bits and pieces like buttons, switches, toggles, LED's, routers, faders, graphs. Each of these objects have inputs and outputs, and will respond to commands you give them.

For example, here, lets talk though it. If I want to create an LED that turns on whenever I push a button on my Max Display window, I select a button of my choice... say, a toggle switch, so the LED will turn on, stay on, until I push the toggle again. Then I pick out a virtual LED I want... blue... and draw a line between the output of the toggle and the input of the LED. Voila. I click out of edit mode, and flip my toggle... blue led comes on.

Now I know what you are thinking... "Gandalf. Big deal. So what!" lol

Well, using Maxuino, and the magic of OSC, open sound control, or open source, I can connect my little LED patch to an OSC object which assigns it to a particular digital pin on my Arduino microcontroller. The Arduino has a mini-USB connector, which connects via a USB cable to my computer USB port. Now, I connect a REAL LED to that actual pin on the Arduino, and connect the other end of the LED to ground directly on one of the Arduino ground pins, and, voila... I have a actual real-life LED which turns on with my mouse-click.

Now, imagine that I want to have a warning LED that turns on on my dash when my A2W IC temp hits 130 F. So, with a bit of testing, lets say we figure out that the temp sensor sends a range of voltage from .010 to .100 volts depending on its temp range from 0 to 200 degrees F. I run that voltage output from my temp sensor to one of my arduino inputs. It will register in Max MSP as a range of numbers. I assign this range to a dial, and throw numbers around it to match the temp range, 0 to 200 F. Lets say that 130 degrees is proportional to .065 volts. I assign another object that looks for any numbers higher than .065 volts. When it sees any such number, it sends out a "bang" message from its right output (all lower numbers it sends bangs out its left output). I assign the number zero to the right output, and the number 1 to the left output. Now I can connect both to the input of my toggle switch, since it toggles on with 1's and off with zeros. Input higher than .065v numbers turn on the toggle, lower than .065 numbers turn it off. And... voila. Once this toggle flips on, it sends the signal to my Arduino, and my warning light comes on on my dash.

Now, all of this can be made into a source-code that can be uploaded and saved directly in the ardiuno's chip. It will perform that same action without having any connection to my computer, when it sees that voltage from my A2W temp sensor. It will do this until the cows come home. It just needs 5 volts of power, and a ground. You can add to this newly written patch-program to utilize all of the Arduino inputs and ouputs, sending and receiving information from any parts of your car that has a readable voltage or number range, aka sensors. You can also connect to many servos or power-motors this way (using a relay switch if it needs higher voltage, etc).

I know it seems like a lot of hard-to-understand stuff... but it is extreeeemely addictive, the moment you begin to play with it and see real-world results.

The craziest stuff I have seen built this way in the world of robotics, is a robo-snake. Gorgeous movement. Life-like. Hollywood-bound for sure. And... they made one that swims underwater. Unbelievable. The movement is perfect.
Check it out:

http://www.youtube.com/watch?v=cJuNe50uuzk

http://www.youtube.com/watch?v=k8j0jNxMeSQ&feature=related
 
#26 ·
Today I looked into how I can run my Macbook in my car, tucked in the trunk, frunk, or under a seat, and still have a decent control interface that can select and control various programs (like itunes) right off my Mac, which I can have connected via firewire to the rest of my stereo system. Then I can also see readouts or gauges displaying several performance aspects like air-intake temps, or control other car functions.

One possible answer is my itouch. Using an app called TouchOSC, I can connect wirelessly (with an ad-hoc network) to my Macbook, and have it set up to control programs on my Macbook (play music, control things in Max MSP patches like my TVIS, or display oil temp) using numerous assignable knobs, sliders, buttons on my itouch. Plus, I can have the itouch relay accelerometer data to my Macbook, since that is what the itouch also is.

This eliminates needing a new stereo deck (mine is a about a dozen years old) and I can also remove my bulky 10-disc CD changer. Plus I won't need any new additional gauges or warning lights installed since the itouch can display them, or any additional wiring running to the "display" (unless I need to charge it or synchronize it to my Macbook)... did I mention its wireless ;) and touchscreen :smile:

I am just looking at how to put this gear I already have to good use. I barely use my itouch for anything. Now it could play some major roles.
 
This is an older thread, you may not receive a response, and could be reviving an old thread. Please consider creating a new thread.
Top