Pages: [1]   Go Down
 Author Topic: syntax for fscale code  (Read 340 times) 0 Members and 1 Guest are viewing this topic.
South East USA
Offline
God Member
Karma: 5
Posts: 651
 « on: September 19, 2013, 05:51:57 pm » Bigger Smaller Reset

In reference to this code that changes the curve or scale of numbers:
http://playground.arduino.cc/main/fscale

I have this code that give my the desired curve on a reading that is from 1 to 64, but I can't figure out how to get the same result for the values -1 to -64
Code:
if (motor_speed > 0)  motor_speed = fscale( 1, 64, 1, 64, motor_speed, -1.5);

I thought this would do it, but all it gives me is zeros:
Code:
if (motor_speed < 0)  motor_speed = fscale( -1, -64, -1, -64, motor_speed, -1.5);
 Logged

Offline
Edison Member
Karma: 49
Posts: 1397
Coding Geezer
 « Reply #1 on: September 19, 2013, 06:00:42 pm » Bigger Smaller Reset

The motor still has a speed, yes?
I'm no math whiz, and I don't know what circuit you're using, but can't you just negate the value(s) returned from the function? In other words, feed it athe abs(motor_speed), then negate the reult and fee it to motor_speed.

If I'm actually way off, I beg your indulgence.
 Logged

There are 10 kinds of people in the world,
those who understand binary, and those who don't.

South East USA
Offline
God Member
Karma: 5
Posts: 651
 « Reply #2 on: September 19, 2013, 07:17:08 pm » Bigger Smaller Reset

-1 to -64 is the reverse speed...
 Logged

UK
Offline
Shannon Member
Karma: 223
Posts: 12577
-
 « Reply #3 on: September 19, 2013, 07:32:35 pm » Bigger Smaller Reset

I haven't tested that function but it appears to have explicit support for negative ranges. Have you got a sample sketch we could run showing the incorrect values when you try to apply it to a negative range?

If you can't be bothered figuring out what the problem is, you could just negate the input motor_speed if it was negative, and then invert the result too.
 Logged

I only provide help via the forum - please do not contact me for private consultancy.

South East USA
Offline
God Member
Karma: 5
Posts: 651
 « Reply #4 on: September 19, 2013, 07:54:37 pm » Bigger Smaller Reset

I think I got it:
Code:
if (motor_speed < 0)  motor_speed = fscale( -1, -64, -1, -64, motor_speed, -1.5);
This doesn't fit the rules:
originalMin - the minimum value of the original range - this MUST be less than origninalMax
originalMax - the maximum value of the original range - this MUST be greater than orginalMin

-1 isn't lower than -64
 Logged

Offline
Edison Member
Karma: 49
Posts: 1397
Coding Geezer
 « Reply #5 on: September 19, 2013, 10:20:56 pm » Bigger Smaller Reset

-1 to -64 is the reverse speed...
Yes, of course, but a value of, lets say, -10 is just the same speed as +10, but in the opposite direction, no?
If you want to increase the reverse speed, you send it a more negative number, right?
It would be worth a shot to try it. Just make all the values you pass the same as you would pass if it was a forward speed. Negate the result and set the speed. See if it works. It's what I would try right away, partly because it makes sense, and partly because it's dead easy to try.

 Logged

There are 10 kinds of people in the world,
those who understand binary, and those who don't.

Global Moderator
Netherlands
Offline
Shannon Member
Karma: 212
Posts: 13531
In theory there is no difference between theory and practice, however in practice there are many...
 « Reply #6 on: September 20, 2013, 04:49:09 am » Bigger Smaller Reset

In reference to this code that changes the curve or scale of numbers:
http://playground.arduino.cc/main/fscale

I have this code that give my the desired curve on a reading that is from 1 to 64, but I can't figure out how to get the same result for the values -1 to -64
Code:
if (motor_speed > 0)  motor_speed = fscale( 1, 64, 1, 64, motor_speed, -1.5);

I thought this would do it, but all it gives me is zeros:
Code:
if (motor_speed < 0)  motor_speed = fscale( -1, -64, -1, -64, motor_speed, -1.5);

use the positive working variation?
Code:
if (motor_speed < 0)  motor_speed = -fscale( 1, 64, 1, 64, -motor_speed, -1.5);
 Logged

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

 Pages: [1]   Go Up