syntax for fscale code

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.