Crashing?

Q&A For ShiftX2, RGB sequential shift light <a href="https://wiki.autosportlabs.com/ShiftX2">Installation and Operation Guide</a>
Post Reply
TXBDan
Posts: 69
Joined: Sat Mar 25, 2017 1:43 am

Crashing?

Post by TXBDan »

Hi all,

I just wired up my ShiftX2. Night before a road trip to Watkins Glen of course. I wired it to CAN2 and spliced its power into the RCPmk3's power by soldering.

I'm using the provided shift ligth + alerts script and edited a few number to fit my needs. It seems to work fine for a few minutes on the road, but then suddenly it'll revert back to the start up light sequence where the strip of lights bounce left to right and change colors. It starts doing that for about a minute and then goes blank and is dead until I cycle power. I only went on one test drive, but this happened to me consistently through out the 20min drive.

I came back to the garage the plugged in the laptop with the car running. I set the shift light thresholds down low so i could easily see it work without revving too high. It seemed to work well. I ran for a good 15min in the garage playing with the alarms and shift thresholds and all seemed well. I then unplugged the laptop and ran the car for about 10min and things seemed ok.

I'm going to go for another test drive now.

Here is my script as it currently sits. There are no LUA errors.

Code: Select all

setTickRate&#40;10&#41; --10Hz 

-- What CAN bus ShiftX2 is connected to. 0=CAN1, 1=CAN2
sxCan = 1
-- 0=first ShiftX2 on bus, 1=second ShiftX2 &#40;if ADR1 jumper is cut&#41;
sxId=0
--Brightness, 0-100. 0=automatic brightness
sxBright=0

sxCanId = 0xE3600 + &#40;256 * sxId&#41;
println&#40;'shiftx2 base id ' ..sxCanId&#41;


--virtual channels 
--addChannel&#40;"name",SR,prec,min,max,"unit"&#41; 
speeddiff_id = addChannel&#40;"Speed_",10,0,0,160,"MPH"&#41; 
gear_id = addChannel&#40;"Gear",5,0,0,5,"gear"&#41; 
brakeg_id = addChannel&#40;"BrakeG",10,2,0,2,"G"&#41;

--global constants 
first = 4.20 
second = 2.49 
third = 1.66 
fourth = 1.24 
fifth = 1.00 
final = 3.46 
tirediameter = 24.7 

--global variables 
rpm = 0 
rpm_diff = 0 
speed = 0 

function updateSpeedDiff&#40;&#41; 
   rpm_diff = getTimerRpm&#40;1&#41; 
   speed = rpm_diff*tirediameter*0.002975 
   speed = speed + 0.5 -- round because 0 prec. truncates 
   setChannel&#40;speeddiff_id, speed&#41; 
end 

function updateGear&#40;&#41; 
   rpm = getTimerRpm&#40;0&#41; 
   local gearErr = 0.15 
   local gear = 0 
    
   if speed > 2 then 
      ratio = rpm/&#40;rpm_diff*final&#41; 
      if &#40;&#40;first  - ratio&#41;^2&#41; < &#40;gearErr^2&#41; then gear = 1 end 
      if &#40;&#40;second - ratio&#41;^2&#41; < &#40;gearErr^2&#41; then gear = 2 end 
      if &#40;&#40;third  - ratio&#41;^2&#41; < &#40;gearErr^2&#41; then gear = 3 end 
      if &#40;&#40;fourth - ratio&#41;^2&#41; < &#40;gearErr^2&#41; then gear = 4 end 
      if &#40;&#40;fifth  - ratio&#41;^2&#41; < &#40;gearErr^2&#41; then gear = 5 end 
   end 
   setChannel&#40;gear_id, gear&#41; 
end 

function autoLog&#40;&#41; 
   if speed > 10 and rpm > 500 then 
      startLogging&#40;&#41; 
   end 
   if speed < 5 and rpm < 100 then 
      stopLogging&#40;&#41; 
   end 
end 

function sxOnUpdate&#40;&#41;
  --add your code to update ShiftX2 alerts or linear graph during run time.
  --Runs continuously based on tickRate.

  --uncomment the below for Direct RPM on input 0
  sxUpdateLinearGraph&#40;getTimerRpm&#40;0&#41;&#41;

  --update engine temp alert
  sxUpdateAlert&#40;0, getAnalog&#40;0&#41;&#41;

  --update oil pressure alert
  sxUpdateAlert&#40;1, getAnalog&#40;2&#41;&#41;
end

function sxOnInit&#40;&#41;
  --config shift light
  sxCfgLinearGraph&#40;0,0,0,7000&#41; --left to right graph, linear style, 0 - 7000 RPM range

  sxSetLinearThresh&#40;0,0,4000,0,255,0,0&#41; --green at 3000 RPM
  sxSetLinearThresh&#40;1,0,5400,255,255,0,0&#41; --yellow at 5000 RPM
  sxSetLinearThresh&#40;2,0,6800,255,0,0,10&#41; --red+flash at 6500 RPM

  --configure first alert &#40;right LED&#41; as engine temperature &#40;F&#41;
  sxSetAlertThresh&#40;0,0,215,255,255,0,5&#41; --yellow warning at 215F
  sxSetAlertThresh&#40;0,1,225,255,0,0,10&#41; -- red flash at 225F

  --configure second alert &#40;left LED&#41; as oil pressure &#40;PSI&#41;
  sxSetAlertThresh&#40;1,0,0,255,0,0,10&#41; --red flash below 8 psi
  sxSetAlertThresh&#40;1,1,8,255,255,0,5&#41; --yellow flash 8-12 PSI
  sxSetAlertThresh&#40;1,2,12,0,0,0,0&#41; --above 12, no alert
end

function sxOnBut&#40;b&#41;
  --called if the button state changes
  println&#40;'button&#58; ' ..b&#41;
end

---ShiftX2 functions
function sxSetLed&#40;i,l,r,g,b,f&#41;
  sxTx&#40;10,&#123;i,l,r,g,b,f&#125;&#41;
end

function sxSetLinearThresh&#40;id,s,th,r,g,b,f&#41;
  sxTx&#40;41,&#123;id,s,spl&#40;th&#41;,sph&#40;th&#41;,r,g,b,f&#125;&#41;
end

function sxSetAlertThresh&#40;id,tid,th,r,g,b,f&#41;
  sxTx&#40;21,&#123;id,tid,spl&#40;th&#41;,sph&#40;th&#41;,r,g,b,f&#125;&#41;
end

function setBaseConfig&#40;bright&#41;
  sxTx&#40;3,&#123;bright&#125;&#41;
end

function sxSetAlert&#40;id,r,g,b,f&#41;
  sxTx&#40;20,&#123;id,r,g,b,f&#125;&#41;
end

function sxUpdateAlert&#40;id,v&#41;
  if v~=nil then sxTx&#40;22,&#123;id,spl&#40;v&#41;,sph&#40;v&#41;&#125;&#41; end
end

function sxCfgLinearGraph&#40;rs,ls,lr,hr&#41; 
  sxTx&#40;40,&#123;rs,ls,spl&#40;lr&#41;,sph&#40;lr&#41;,spl&#40;hr&#41;,sph&#40;hr&#41;&#125;&#41;
end

function sxUpdateLinearGraph&#40;v&#41;
  if v ~= nil then sxTx&#40;42,&#123;spl&#40;v&#41;,sph&#40;v&#41;&#125;&#41; end
end

function sxInit&#40;&#41;
  println&#40;'config shiftX2'&#41;
  setBaseConfig&#40;sxBright&#41;
  if sxOnInit~=nil then sxOnInit&#40;&#41; end
end

function sxChkCan&#40;&#41;
  id,ext,data=rxCAN&#40;sxCan,0&#41;
  if id==sxCanId then sxInit&#40;&#41; end
  if id==sxCanId+60 and sxOnBut~=nil then sxOnBut&#40;data&#91;1&#93;&#41; end
end

function sxProcess&#40;&#41;
  sxChkCan&#40;&#41;
  if sxOnUpdate~=nil then sxOnUpdate&#40;&#41; end
end

function sxTx&#40;offset, data&#41;
  txCAN&#40;sxCan, sxCanId + offset, 1, data&#41;
  sleep&#40;10&#41;
end

function spl&#40;v&#41; return bit.band&#40;v,0xFF&#41; end
function sph&#40;v&#41; return bit.rshift&#40;bit.band&#40;v,0xFF00&#41;,8&#41; end


function onTick&#40;&#41;
  updateSpeedDiff&#40;&#41;
  updateGear&#40;&#41;
  autoLog&#40;&#41;
  sxProcess&#40;&#41;
end

sxInit&#40;&#41;
One last thing i noticed is when i first hit the green threshold RPM, four green LEDs light up and it then goes to 5, then, changes to yellow, then red. Why doesn't it start with one Green LED and progress from there with RPM?

Thanks

TXBDan
Posts: 69
Joined: Sat Mar 25, 2017 1:43 am

Post by TXBDan »

I'm getting LUA out of memory errors in the log when it crashes so that must be it. I'm going to trim out the alarm parts and hope it works for this weekend. I need the rest of my code in there.

TXBDan
Posts: 69
Joined: Sat Mar 25, 2017 1:43 am

Post by TXBDan »

I deleted the alarms and it ran we'll all day yesterday. Probably 8 power cycles.

Unfortunately this morning in tech it crashed again. Hopefully it'll work in my sessions and TT later today.

psfp
Posts: 49
Joined: Mon Aug 21, 2017 10:40 pm
Location: DF - Brazil

Post by psfp »

Try to delete all unused ShiftX2 functions and add collectgarbage() to your onTick function. It should help with memory issues.

psfp
Posts: 49
Joined: Mon Aug 21, 2017 10:40 pm
Location: DF - Brazil

Post by psfp »

Regarding the shift light behavior, would you mind to try the settings below?

Code: Select all


function sxOnUpdate&#40;&#41; 
  --add your code to update ShiftX2 alerts or linear graph during run time. 
  --Runs continuously based on tickRate. 

  --uncomment the below for Direct RPM on input 0 
local vRPM = getTimerRpm&#40;0&#41;
if vRPM < 4000 then vRPM = 0 else vRPM = vRPM - 4000
  sxUpdateLinearGraph&#40;vRPM&#41; 

  --update engine temp alert 
  sxUpdateAlert&#40;0, getAnalog&#40;0&#41;&#41; 

  --update oil pressure alert 
  sxUpdateAlert&#40;1, getAnalog&#40;2&#41;&#41; 
end 

function sxOnInit&#40;&#41; 
  --config shift light 
  sxCfgLinearGraph&#40;0,0,0,3000&#41; --left to right graph, linear style, 0 - 7000 RPM range 

  sxSetLinearThresh&#40;0,0,0,255,0,0&#41; --green at 3000 RPM  sxSetLinearThresh&#40;1,0,1400,255,255,0,0&#41; --yellow at 5000 RPM 
  sxSetLinearThresh&#40;2,0,2800,255,0,0,10&#41; --red+flash at 6500 RPM
I will be out of town for one week, so no tests for me.

brentp
Site Admin
Posts: 6282
Joined: Wed Jan 24, 2007 6:36 am

Post by brentp »

What's your latest script now so we can check it out?
Brent Picasso
CEO and Founder, Autosport Labs
Facebook | Twitter

Post Reply