With almost any program that involves a motor speed or sensor value, I end up scaling numbers. I don't know if anyone is interested, but for those who are, I posted on my blog an NXC function that does the math. Using this, I don't have to come up with everything I need every time. You just enter the original number as well as the lowest and highest the value can be and the lowest and highest you want it to be, and it returns the scaled result.
When I say "lowest and highest you want it to be", I mean the two numbers you want it scaled to. It doesn't matter if the first is higher than the second.
Scaling ranges of numbers
-
- Posts: 1818
- Joined: 02 Oct 2010, 02:19
- Location: Michigan USA
- Contact:
Scaling ranges of numbers
Matt
http://mattallen37.wordpress.com/
I'm all for gun control... that's why I use both hands when shooting
http://mattallen37.wordpress.com/
I'm all for gun control... that's why I use both hands when shooting
Re: Scaling ranges of numbers
could you please explain a little more, maybe with some examples? I don't understand your function so far.
-
- Posts: 48
- Joined: 12 Jan 2011, 18:40
- Contact:
Re: Scaling ranges of numbers
there is an example in the blog post.doc-helmut wrote:could you please explain a little more, maybe with some examples? I don't understand your function so far.
link to my youtube channel under my avatar!
Re: Scaling ranges of numbers
can't find any. can you post it all in code tags? Is easier to read those codes here in this thread anyway.
-
- Posts: 1818
- Joined: 02 Oct 2010, 02:19
- Location: Michigan USA
- Contact:
Re: Scaling ranges of numbers
It's a function that takes a range of numbers, and scales it into a different range. Imagine you were to make a PID control loop for something like line following. If the control loop was looking for error values of -5 to 5, and your sensor returned values in the range of 74 to 192, you could scale it like this:
Code: Select all
char error = ScaleRange(Sensor, 74, 192, -5, 5);
Matt
http://mattallen37.wordpress.com/
I'm all for gun control... that's why I use both hands when shooting
http://mattallen37.wordpress.com/
I'm all for gun control... that's why I use both hands when shooting
Who is online
Users browsing this forum: No registered users and 1 guest