Pages: [1]   Go Down
Author Topic: syntax for fscale code  (Read 252 times)
0 Members and 1 Guest are viewing this topic.
South East USA
Offline Offline
God Member
*****
Karma: 4
Posts: 636
View Profile
 Bigger Bigger  Smaller Smaller  Reset 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

Saskatchewan, Canada
Offline Offline
Edison Member
*
Karma: 34
Posts: 1203
Coding Geezer
View Profile
 Bigger Bigger  Smaller Smaller  Reset 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

South East USA
Offline Offline
God Member
*****
Karma: 4
Posts: 636
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

UK
Offline Offline
Shannon Member
****
Karma: 184
Posts: 11179
-
View Profile
 Bigger Bigger  Smaller Smaller  Reset 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 Offline
God Member
*****
Karma: 4
Posts: 636
View Profile
 Bigger Bigger  Smaller Smaller  Reset 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

Saskatchewan, Canada
Offline Offline
Edison Member
*
Karma: 34
Posts: 1203
Coding Geezer
View Profile
 Bigger Bigger  Smaller Smaller  Reset 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

Global Moderator
Netherlands
Offline Offline
Shannon Member
*****
Karma: 170
Posts: 12465
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset 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
Jump to: