Measuring Distance vs speed need ideas

hey guys, I’m trying to accurately measure distance vs time to get a shock speed.

I currently have a Pot on a suspension joint.

Need to be able to determine if it is moving 0-2"/2-4"/4-8" per second.

if it is moving within one of the ranges it needs to be a boolean value(or ADDR) since I have an EEPROM Lookup value.

  1. You will need fewer calculations if you convert your inches/sec speed to POT_value/millisecond since that is what Arduino will be measuring.

  2. You will need to convert between POT reading and distance. POT will return value between 0 and 1. If the POT does not have full range in your application, it will have a shorter range (for example maybe 0.2 to 0.75, giving a range of 0.55). Use this to determine how much POT changes for 1" travel. For example, if shock can travel 18", that is 0.55/18 = 0.0611 POT change for each inch of travel (assuming POT output is linear…). Since you are measuring in 2" increments, you will want to know if POT changed by more than 0.122/second or 0.244/second

  3. I assume you are trying to stiffen the shock if it is moving too quickly, so you need quick reaction and will not be waiting 1 second to take 2nd POT measurement. You can setup clock ticks to take measurements at known intervals if that will be fast enough; otherwise you will need to record a timestamp for each measurement so you can determine how long since the last measurement (requiring more calculations). If 10 milliseconds is fast enough sample time, you can use a clock node to sample every 0.01 seconds. Using the example above, that means you are looking for a 0.00122 change each time. I would think that small of a change would get lost in noise converting POT reading from analog to digital, but it might work OK.

  4. To determine change of POT value over time, you are going to need old value and new value, so you will need a buffer node to store old value. You will need to update the buffer with previous value before getting new value.

  5. If you care about speed in either direction, you’ll need absolute value of the change in POT

  6. You only care about <2" or >4" per second. Dividing POT change by 0.00122 (using example numbers from above) will give us a number 0 if <2"/sec, 1 if <4"/sec, or a number larger than 1 for >4"/sec. Using nth-input, we can map that to your EEPROM lookup values. If you want a different value for >8"/sec, you will need to expand nth-input by 2 input nodes because the X3 will be 6"/sec and X4 will be 8"/sec.


The defer node is to make sure buffer updates old value before a new value is calculated. Floor is to give us an integer value after dividing; it might not be needed depending on implementation of nth-input node.

If you are trying to stiffen the shock as it moves faster, it would be WAY simpler to stiffen as it moves farther from “natural” or “neutral/resting” position. This could even be done mechanically so you don’t have to worry about sample speed, calculations during travel, software bugs/glitches, etc. Adjusting based on speed might give better dynamic performance (stiffening starts while shock is still near resting position when you hit a large bump), but it might also result in oscillations (moving too fast stiffens shock, which slows it down, which softens shock, which increases speed, which…).

That’s Great gweimer. that makes way more sense to me, I wouldn’t want the shock to get stiffer in a Linear motion, it needs to be Digressive. Digressive gives way better steering feedback and allows the car to be Stiff for great feedback but soft for large bumps

I was using Delta to figure it out but your method is way more precise.

Direction is also important as i’m trying to control compression and rebound.

Faster is better, the shocks are capable of changing stiffness in .001 of a second.

the signal from the “Pot” is a digital processed signal but still 0-5V So i just call it a simple Pot.

I know Shocks really well, just getting it to work digitally is tricky.

Works perfect in this setup! Now I just need to get comp and rebound setup and do this 3 more times lol

There is probably no reason to read eeprom as quickly as possible. Unless it is changing, you can just read it on boot. If it might change during program run, you could just read every X seconds instead of continuously.

Didn’t think of that one, How exactly would I do direction? remove Abs to get a Negative value? Would NTH input work with a negative value?

I havent used nth input before this point

nth-input does not work with negative numbers.

If you know the max value you could ever get, the easiest solution is probably to drop the abs node and add the max value after the divide. If the result of divide could never be outside of the range -4…4, then you could add 4, giving a new range of 0…8.

If that is not an option, then you will need to split your code to handle both positive and negative numbers. Invert the negative (multiple by -1) and do a separate nth-input lookup. You’ll probably need to blindly do both calculations, then use an if-else node to select which nth-input value to use.

Note: others have commented that nth-input is a very “expensive” node (requires quite a bit of memory), so you may want to try to limit how many you are using, or at least keep an eye on how much memory you have free after downloading your code.

Ok that makes sense, I think lol.

Now the operation of the nth node, if the input goes past the end of the scale say (0,8) say to 10 will it stay at the 8 value?

or should I employ a pulse to change to hold the latest value.

Pretty sure nth-input returns X0 for zero or less, X1 for IDX >0 but <=1, and the last Xn for that IDX or higher (so if nth-input has X0-X8, it will return X8 for IDX 8 or higher). A simple debug with tweak-number, nth-input, and watch node could quickly confirm actual function.

that’s a great idea, You are a Huge help to the community, anyway I can repay you?

this is what it looks like so far. i’m using an EEPROM Table to look up my g force values, this has allowed the program to get considerably lighter on memory.

Right now i’m using analog input values, one day if i can get a canbus node it will replace the analog values.

Just a thought could I use Map Clip for any negative values to create the right scale that nth input can use?

right now i’m only using 14% of my storage space and 19% dynamic on my mega 2560.

the next big hurdle for me is going to be changing a clock speed so i can get in to the 20khz range on my pwm outputs.

Figured it how to do it on a DUE, but it doesn’t have an EEPROM so that chip is out for now.

The best repayment is to pass on the knowledge, or make a donation to the XOD developers for creating/maintaining this awesome product for us. I’m sure they put a lot more time into it than I do.

map-clip might work. You’ll have to test to see if it will map negative numbers in the way you want it to.

Ok so this works well, only 1 drawback

When Going positive, we don’t go to X4 until we have a Value of at least 1.x when going negative as soon as it goes .0X it moves right to X2.

I thought about offsetting map clip on Tmax by 1 but then i don’t get even numbers coming out of map clip.

:confused:

You programmed map-clip to only handle negative numbers, then sent it a positive number…

Ok! final iteration.

this handles compression and rebound by using an If and less than statement. this is far far simpler than what i came up with a couple months ago.

just need to plug in the EEPROM Nodes, and step filtering

Much appreciate your patience Gweimer

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.