RegisterSearchFAQMemberlistUsergroupsLog in
Reply to topic Page 1 of 1
scripts for staged, variable blinking ShiftX light
Author Message
Reply with quote
Post scripts for staged, variable blinking ShiftX light 
I wanted the ShiftX lights to do something more than just turn on above a certain level. I wanted have them blink slowly once a lower threshold was exceeded, blink faster and faster as the upper threshold is reached, then stay on constant as that upper threshold is exceeded. Then repeat for the next light. In this manner they are staged, variable blinky. Cool

Here is my script to run this on the Digital I/O (GPIO) pins
Code:

--Pin assignments--
--RPM is pin 20 / PulseIn 1
--First light is pin 17 / GPIO1 10Hz Output / #2 on shift light - green
--Second light is pin 16 / GPIO2 10Hz Output / #1 on shift light - yellow
--Third light is pin 15 / GPIO3 10Hz Output / #3 on shift light - red

-- CONSTANTS --
FREQ_HZ = 25  --1000*1/FREQ_HZ=loop time in ms. e.g. 25Hz=40ms--
loop_time = 1000 * 1 / FREQ_HZ
MAX_BLINK_PERIOD = 1000 --in ms (1s or 1000ms is reasonable value)--
MAX_ON_TIME = 500 --in ms (0.5s or 500ms, half off/on is reasonable value--
testRPM = 3000  --test interface for use on bench--
LL1 = 1000 --light 1 lower threshold to start blinking--
UL1 = 1500 --light 1 upper threshold above which goes solid--
LL2 = 1500 --light 2 lower threshold to start blinking--
UL2 = 2000 --light 2 upper threshold above which goes solid--
LL3 = 2000 --light 3 lower threshold to start blinking--
UL3 = 2500 --light 3 upper threshold above which goes solid--
-- FUNCTIONS --
function ctON(ul,ll)
   --RPM=getTimerRpm(0)
   RPM=testRPM
   factor = 0.5 * FREQ_HZ * (1 - (ul - RPM) / (ul - ll))
   if factor >= 0.5 * FREQ_HZ then --can't blink faster than tickRate/2--
          on_time = MAX_ON_TIME
       elseif factor < 1 then --can't blink slower than max period--
          on_time = 0
       else
          on_time = MAX_ON_TIME / factor
   end   
   return on_time / loop_time
end

function ctMAX(ul,ll)
   --RPM=getTimerRpm(0)
   RPM=testRPM
   factor = 0.5 * FREQ_HZ * (1 - (ul - RPM) / (ul - ll))
   blink_period = MAX_BLINK_PERIOD / factor   
   return blink_period / loop_time
end

-- Ini --
setTickRate(FREQ_HZ)
j = 0
k = 0
l = 0
-- RUN --
function onTick()
--start light 1 section--
   if j < ctON(UL1,LL1) then
               setGpio(0,0)
        else
               setGpio(0,1)
   end       
   if j < ctMAX(UL1,LL1) then
      j = j + 1
   else
      j = 0
   end
--end light 1 section--
--start light 2 section--
   if k < ctON(UL2,LL2) then
               setGpio(1,0)
        else
               setGpio(1,1)
   end       
   if k < ctMAX(UL2,LL2) then
      k = k + 1
   else
      k = 0
   end
--end light 2 section--
--start light 3 section--
   if l < ctON(UL3,LL3) then
               setGpio(2,0)
        else
               setGpio(2,1)
   end       
   if l < ctMAX(UL3,LL3) then
      l = l + 1
   else
      l = 0
   end
--end light 3 section--
end


And here is my script to run this on the Analog/Pulse Output (Vout)

Code:

--Pin assignments--
--RPM is pin 20 / PulseIn 1
--set the jumpers to ON
--First light is pin 6 / Vout1 10Hz 100 100 0.1 / #2 on shift light - green
--Second light is pin 5 / Vout2 10Hz 100 100 0.1 / #1 on shift light - yellow
--Third light is pin 4 / Vout3 10Hz 100 100 0.1 / #3 on shift light - red

-- CONSTANTS --
FREQ_HZ = 25  --1000*1/FREQ_HZ=loop time in ms. e.g. 25Hz=40ms--
loop_time = 1000 * 1 / FREQ_HZ
MAX_BLINK_PERIOD = 1000 --in ms (1s or 1000ms is reasonable value)--
MAX_ON_TIME = 500 --in ms (0.5s or 500ms, half off/on is reasonable value--
testRPM = 3000  --test interface for use on bench--
LL1 = 1000 --light 1 lower threshold to start blinking--
UL1 = 1500 --light 1 upper threshold above which goes solid--
LL2 = 1500 --light 2 lower threshold to start blinking--
UL2 = 2000 --light 2 upper threshold above which goes solid--
LL3 = 2000 --light 3 lower threshold to start blinking--
UL3 = 2500 --light 3 upper threshold above which goes solid--
-- FUNCTIONS --
function ctON(ul,ll)
   --RPM=getTimerRpm(0)
   RPM=testRPM
   factor = 0.5 * FREQ_HZ * (1 - (ul - RPM) / (ul - ll))
   if factor >= 0.5 * FREQ_HZ then --can't blink faster than tickRate/2--
          on_time = MAX_ON_TIME
       elseif factor < 1 then --can't blink slower than max period--
          on_time = 0
       else
          on_time = MAX_ON_TIME / factor
   end   
   return on_time / loop_time
end

function ctMAX(ul,ll)
   --RPM=getTimerRpm(0)
   RPM=testRPM
   factor = 0.5 * FREQ_HZ * (1 - (ul - RPM) / (ul - ll))
   blink_period = MAX_BLINK_PERIOD / factor   
   return blink_period / loop_time
end

-- Ini --
setTickRate(FREQ_HZ)
j = 0
k = 0
l = 0
-- RUN --
function onTick()
--start light 1 section--
   if j < ctON(UL1,LL1) then
               setAnalogOut(0,0)
        else
               setAnalogOut(0,10) --with value of 5 measured 2.2V and dim light so set to 10, measured 4.75V
   end       
   if j < ctMAX(UL1,LL1) then
      j = j + 1
   else
      j = 0
   end
--end light 1 section--
--start light 2 section--
   if k < ctON(UL2,LL2) then
               setAnalogOut(1,0)
        else
               setAnalogOut(1,10) --with value of 5 measured 2.2V and dim light so set to 10, measured 4.75V
   end       
   if k < ctMAX(UL2,LL2) then
      k = k + 1
   else
      k = 0
   end
--end light 2 section--
--start light 3 section--
   if l < ctON(UL3,LL3) then
               setAnalogOut(2,0)
        else
               setAnalogOut(2,10) --with value of 5 measured 2.2V and dim light so set to 10, measured 4.75V
   end       
   if l < ctMAX(UL3,LL3) then
      l = l + 1
   else
      l = 0
   end
--end light 3 section--
end


Disclaimer I have only tested this on the bench by giving fixed RPM values through a calibration interface. To run in vehicle should only require commenting out the fixed RPM value and activating the getTimerRPM value.

Now I'm not a software engineer, calibration is my thing, but I know enough to dabble and be dangerous Laughing So improvement suggestions are welcome because I'm sure I didn't follow the best coding practices..... Embarassed

Oh, and this is running with RaceAnalyzer V1.1.15 on MK1 hardware running firmware 1.2.7. (A little hesitant to jump on the V2 release since it is so new and everything works now as I need it.)

View user's profile Send private message
Reply with quote
Post  
Evidence of the AnaOut script in action!

Yes, it was as easy as commenting out the fixed RPM test interface and activating the measured RPM values. May require a little tweaking, as the slowest blink rate, MAX_BLINK_PERIOD = 1000, seems faster in the car than on my sofa. May need to increase the max period to slow it down just a little.

Oops, can't upload .mov files. Best I can do is make a link to where I uploaded it to my Google+ site.

https://plus.google.com/u/0/106896010233655035500/posts/VtvhS9iU67f

View user's profile Send private message
Reply with quote
Post  
Wow, this is amazing! Thank you for sharing!


_________________
Ryan Doherty
Autosports Labs
View user's profile Send private message
Reply with quote
Post  
Your script is amazing! We will be sharing this video on facebook, unless you have a more extended video?

You should definitely try the latest firmware and app, you can always switch back, you know. Smile


_________________
Brent Picasso
CEO and Founder, Autosport Labs
Facebook | Twitter
View user's profile Send private message Send e-mail
Reply with quote
Post  
Shared here:
https://www.facebook.com/AutosportLabs/photos/a.424265584230.197157.34953614230/10152996962244231/?type=1


_________________
Brent Picasso
CEO and Founder, Autosport Labs
Facebook | Twitter
View user's profile Send private message Send e-mail
Reply with quote
Post  
Cool Cool I deliberately made a short video, mainly so I could text it to someone, but also because sometimes less is more to get people's attention!

After I refine the timing for use in vehicle I can post another video more clearly showing how it starts blinking slowly once the lower threshold is crossed and keeps blinking faster and faster and faster until it goes solid at the upper threshold.

View user's profile Send private message
Reply with quote
Post  
This script is really cool, thanks for posting it! I am using it on GPIO and had to flip the values passed to setGpio. The lights were off when they should have been on, and on when they should have been off. Other than that it works great.

View user's profile Send private message
Reply with quote
Post  
Hopefully someone can show me what I am overlooking. I recently installed my shift x light and loaded this script into my MK1 but am having an issue. As soon as I turn the key and my MK1 gets power all of the lights on the shift light turn on and are solid.

I opened up the unit and changed the dip switch to ON for 1-3.
I turned on the Analog outputs ( set at 10HZ, Analog, Voltage)
Changed --RPM=getTimerRpm(0) to --RPM=getTimerRpm(1) since it is input 1. (Should this stay (0)?)

View user's profile Send private message Send e-mail
Reply with quote
Post  
Ls_Rx7 wrote:
Hopefully someone can show me what I am overlooking. I recently installed my shift x light and loaded this script into my MK1 but am having an issue. As soon as I turn the key and my MK1 gets power all of the lights on the shift light turn on and are solid.

Changed --RPM=getTimerRpm(0) to --RPM=getTimerRpm(1) since it is input 1. (Should this stay (0)?)


Depends on which pin you are using. Please see the comments in the script, the script is configured to use pin 20 for the RPM input and wouldn't require any changes if you were using that same input pin for your RPM signal.

View user's profile Send private message
Reply with quote
Post  
GTIspirit wrote:
Ls_Rx7 wrote:
Hopefully someone can show me what I am overlooking. I recently installed my shift x light and loaded this script into my MK1 but am having an issue. As soon as I turn the key and my MK1 gets power all of the lights on the shift light turn on and are solid.

Changed --RPM=getTimerRpm(0) to --RPM=getTimerRpm(1) since it is input 1. (Should this stay (0)?)


Depends on which pin you are using. Please see the comments in the script, the script is configured to use pin 20 for the RPM input and wouldn't require any changes if you were using that same input pin for your RPM signal.


I changed the script back to what you originally had and verified I was using pin 20 for RPM. My shift light works but the lights are reversed. They are always on and turn off at the RPMs commanded. I am new to coding, what do I need to do to switch the lights so that they are normally off and only come on when the commanded RPMs are met?

EDIT: I think the script is fine. The issue is when all 4 wires of my shift light are connected the shift light turns on all lights even without a script loaded.

View user's profile Send private message Send e-mail
Reply with quote
Post  
Ls_Rx7 wrote:

...My shift light works but the lights are reversed. They are always on and turn off at the RPMs commanded. I am new to coding, what do I need to do to switch the lights so that they are normally off and only come on when the commanded RPMs are met?

EDIT: I think the script is fine. The issue is when all 4 wires of my shift light are connected the shift light turns on all lights even without a script loaded.


Hmm, here's my config:

Sounds like your settings are somehow inverted. I tried disconnecting the 5V supply and that didn't replicate the behavior, so I'm not sure what it could be.

@gizmodo, I remember having that problem too when using the GPIO channels, that the behavior was initially backwards from what I expected, so I had to reverse the one and off settings. Same principle would apply to the analog out, except that wouldn't affect the behavior when no script was even running.....

I believe the way the ShiftX works is the 5V supply from the RCPro unit to the V pad on the ShiftX provides power for all three sets of lights. If the signal for say the green was high, and high should be ~5V, there would be no potential difference and the light would be off. If the signal for green was pulled low, to near zero, there would be maximum potential difference and the light would be on brightest. Hence my comment in the script file regarding the voltage setting which at first glance wouldn't make sense.....

View user's profile Send private message
Reply with quote
Post  
Oh, and here's why I ended up using the Analog outputs, they make the lights brighter for whatever reason.
Why is ShiftX brighter on AnalogOut than GPIO?

View user's profile Send private message
Reply with quote
Post  
How would I apply this if I am getting my RPM from can bus through my AEM Infinity. I would prefer to use the analog out as we race during the day so Higher light output is best.. Thanks.

View user's profile Send private message
Reply with quote
Post  
roostinds wrote:
How would I apply this if I am getting my RPM from can bus through my AEM Infinity. I would prefer to use the analog out as we race during the day so Higher light output is best.. Thanks.


Hmmm, no CAN bus on a '87 GTI, so no first hand experience.

In theory, all instances of "RPM=getTimerRpm(0)" would be replaced by RPM=whatever corresponds to CAN RPM signal.

FYI, I just realized the original scripts may have mislead people who simply wanted to copy and paste without looking into the LUA script commands.

The two -- comment out that command, and leave active the test interface for bench testing on the comfort of your living room sofa. Laughing

Code:
   --RPM=getTimerRpm(0)
   RPM=testRPM


So to run the script in vehicle, the REM characters need to be moved as follows:
Code:
   RPM=getTimerRpm(0)
   --RPM=testRPM


View user's profile Send private message
Reply with quote
Post  
Sorry, i am such a noob at Lua scripting. currently this is my can bus information for the RPM

CAN_map = {
[32546816] = function(data)
map_chan(rpmId, data, 0, 2, 0.39063, 0)

How would i translate this?

RPM = [32546816] rpmId??

Sorry, still trying to wrap my head around Lua

View user's profile Send private message
Display posts from previous:
Reply to topic Page 1 of 1
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum