Thanks Colin you are a super star.
one more issue.
From the dashboard, start run button is not clearing the counter. inject CLEAR COUNTER is msg.topic = reset
I need to run this command from the start run button
That is exactly the same issue as the thresholds isn't it? Set the topic in the button and send it to the revs function.
My start button drives
RIP-dht22
date
count revs
and resets time, rpm and chart
I added a function between start button and count revs
line 1 msg.payload and that seems to fix the reset problem
now i just need the start button to reset the chart
I have a function to reset
msg.payload = ;
msg.topic = 0
msg.payload = []
That should do it, is it not working?
When posting code please remember to use the same technique as when posting a flow, so the forum does not mess up the text.
i did not have a connection from function to chart revs. I only had a connection from function to chart.
So now it works.
I now have found a problem.
The low and high thresholds can not be count revs.
Start the engine. now the counter is counting because the flywheel is turning making hall effects count.
low threshold will be made before i start the run.
I would need flywheel reading in RPM.
Engine running, flywheel directly coupled. The flywheel is turning the same speed as the engine.
when the engine accelerates, node red waiting for the flywheel to reach 3000 rpm to start the test.
And finish the test when the fly wheel reaches highthreshold of 13000.
Is it doing what you asked for?
I gave this explanation in the beginning
This is an inertia dyno spinning a fly wheel.
Node red push a start button, have a servo to open the throttle, when the hall effects read 3000rpm start counting
run up to 13000 rpm and stop the test. servo closes the throttle.
record the time it takes to reach 13000 rpm.
I would like to be able to set the Max rpm for different tests,
They way program is running will not make a test run
the count revs is setup to read counts can we modify it to read rpm?
count revs
[{"id":"db9f7109.1198a","type":"function","z":"c502d54b.368d98","name":"Count Revs","func":"// starts timing when counts reach low threshold\n// when high threshold is reached then passes on time difference in msec\n// Count can be reset by passing a message with topic \"reset\"\n// Set low and high thresholds by passing in topic of \"lowThreshold\" or \"highThreshold\"\n// with value in payload.\n// Any other topic is assumed to be a sensor input\n\nswitch(msg.topic) {\n case \"reset\":\n // reset counter\n context.set(\"counter\", 0)\n msg = null\n break;\n \n case \"lowThreshold\":\n context.set(\"lowThreshold\", msg.payload)\n msg = null\n break;\n \n case \"highThreshold\":\n context.set(\"highThreshold\", msg.payload)\n msg = null\n break;\n \n default:\n // sensor input\n handleSensor()\n break;\n}\nreturn msg\n\nfunction handleSensor() {\n const lowThreshold = context.get(\"lowThreshold\")\n const highThreshold = context.get(\"highThreshold\")\n counter = context.get(\"counter\") || 0\n counter++\n if (counter == lowThreshold) {\n // we have hit the first threshold, remember the current time in msec\n const now = new Date().getTime()\n context.set(\"startTime\", now)\n node.warn(`startTime: ${now}`)\n msg = null // don't send anything\n } else if (counter == highThreshold) {\n const highNow = new Date().getTime()\n // we have hit the second threshold, work out the time difference\n msg.payload = highNow - context.get(\"startTime\")\n } else {\n // neither threshold so do nothing\n msg = null\n }\n context.set(\"counter\", counter)\n}\n","outputs":1,"noerr":0,"initialize":"","finalize":"","x":390,"y":400,"wires":[["50cf5284.3f22ac","4ee39ede.8ba78"]]}]
In post 11 you said
I said
Then you said
Several times I tried to convince you that it was the speed you wanted but you insisted it was counts of the sensor that you wanted. The code you have now does exactly what you asked for.
Sorry for the miscommunication
You gave me code to capture RPM. I will try and import that code into the count revs function and get the data I need.
Thanks you for all your help.
Donn
Colin
I have tried all day to change the count revs into RPM.
I guess i don't have a clue how you did it.
If you get a chance can you please take a look.
Thanks
Donn
[{"id":"83cd19a4.941a08","type":"function","z":"83e7ad7e.f26f7","name":"ver 2 Count Revs","func":"// starts timing when counts reach low threshold\n// when high threshold is reached then passes on time difference in msec\n// Count can be reset by passing a message with topic \"reset\"\n// Set low and high thresholds by passing in topic of \"lowThreshold\" or \"highThreshold\"\n// with value in payload.\n// Any other topic is assumed to be a sensor input\n\nswitch(msg.topic) {\n case \"reset\":\n // reset counter\n context.set(\"counter\", 0)\n msg = null\n break;\n \n case \"lowThreshold\":\n context.set(\"lowThreshold\", msg.payload)\n msg = null\n break;\n \n case \"highThreshold\":\n context.set(\"highThreshold\", msg.payload)\n msg = null\n break;\n \n default:\n // sensor input\n handleSensor()\n break;\n}\nreturn msg\n\nfunction handleSensor() {\n const lowThreshold = context.get(\"lowThreshold\")\n const highThreshold = context.get(\"highThreshold\")\n counter = context.get(\"counter\") || 0\n counter++\n if (counter == lowThreshold) {\n // we have hit the first threshold, remember the current time in msec\n const now = new Date().getTime()\n context.set(\"startTime\", now)\n node.warn(`startTime: ${now}`)\n msg = null // don't send anything\n } else if (counter == highThreshold) {\n const highNow = new Date().getTime()\n // we have hit the second threshold, work out the time difference\n msg.payload = highNow - context.get(\"startTime\")\n } else {\n // neither threshold so do nothing\n msg = null\n }\n context.set(\"counter\", counter)\n}\n","outputs":1,"noerr":0,"initialize":"","finalize":"","x":610,"y":760,"wires":[["f5c7a5e9.972df8"]]}]
I will understand if you don't want to.
Try this. Feed it with output of the RPM function.
[{"id":"9d4b9f4a.070d6","type":"function","z":"84405ff5.25fa6","name":"RPM Timing","func":"// starts timing when rpm reach low threshold\n// when high threshold is reached then passes on time difference in msec\n// Reset by passing a message with topic \"reset\"\n// Set low and high thresholds by passing in topic of \"lowThreshold\" or \"highThreshold\"\n// with value in payload.\n// Any other topic is assumed to be an rpm input\n\nswitch(msg.topic) {\n case \"reset\":\n // reset rpm\n context.set(\"lastRPM\", 0)\n msg = null\n break;\n \n case \"lowThreshold\":\n context.set(\"lowThreshold\", msg.payload)\n msg = null\n break;\n \n case \"highThreshold\":\n context.set(\"highThreshold\", msg.payload)\n msg = null\n break;\n \n default:\n // rmp input\n handleRPM()\n break;\n}\nreturn msg\n\nfunction handleRPM() {\n const lowThreshold = context.get(\"lowThreshold\")\n const highThreshold = context.get(\"highThreshold\")\n let complete = false\n \n lastRPM = context.get(\"lastRPM\") || 0\n thisRPM = msg.payload\n if (lastRPM < lowThreshold && thisRPM >= lowThreshold) {\n // we have hit the first threshold, remember the current time in msec\n const now = new Date().getTime()\n context.set(\"startTime\", now)\n node.warn(`startTime: ${now}`)\n }\n if (lastRPM < highThreshold && msg.payload >= highThreshold) {\n const highNow = new Date().getTime()\n // we have hit the second threshold, work out the time difference\n msg.payload = highNow - context.get(\"startTime\")\n complete = true\n }\n // delete the message if we haven't finished yet\n if (!complete) {\n msg = null\n }\n // Don't save the rpm if it has gone down\n if (thisRPM > lastRPM) {\n context.set(\"lastRPM\", thisRPM)\n }\n}\n","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":410,"y":1980,"wires":[["a9c69d5e.91d708"]]},{"id":"272a0f46.abe8","type":"inject","z":"84405ff5.25fa6","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"2000","payloadType":"num","x":170,"y":1920,"wires":[["9d4b9f4a.070d6"]]},{"id":"3bdf8b78.d7dd4c","type":"inject","z":"84405ff5.25fa6","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"3000","payloadType":"num","x":170,"y":1960,"wires":[["9d4b9f4a.070d6"]]},{"id":"9dd9d8e9.299e28","type":"inject","z":"84405ff5.25fa6","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"9000","payloadType":"num","x":170,"y":2000,"wires":[["9d4b9f4a.070d6"]]},{"id":"a717ebea.471ef","type":"inject","z":"84405ff5.25fa6","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"13000","payloadType":"num","x":170,"y":2040,"wires":[["9d4b9f4a.070d6"]]},{"id":"efa3728b.06a788","type":"inject","z":"84405ff5.25fa6","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"14000","payloadType":"num","x":170,"y":2080,"wires":[["9d4b9f4a.070d6"]]},{"id":"e72b8039.f7333","type":"inject","z":"84405ff5.25fa6","name":"Reset","props":[{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"reset","x":270,"y":1760,"wires":[["9d4b9f4a.070d6"]]},{"id":"28a72db2.c11e1a","type":"inject","z":"84405ff5.25fa6","name":"Set low threshold 3000","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"lowThreshold","payload":"3000","payloadType":"num","x":200,"y":1800,"wires":[["9d4b9f4a.070d6"]]},{"id":"64fc5e63.ac8488","type":"inject","z":"84405ff5.25fa6","name":"Set high threshold 13000","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"highThreshold","payload":"13000","payloadType":"num","x":170,"y":1840,"wires":[["9d4b9f4a.070d6"]]},{"id":"a9c69d5e.91d708","type":"debug","z":"84405ff5.25fa6","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":590,"y":1980,"wires":[]}]
Thanks Colin
i have it dialed in looks and functions great
do you have a Venmo or Paypal
donnlange@hotmail.com
This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.