Search code examples
python-2.7ros

How to convert the range of 1000 to 2000 to 0 to 1024 for throttle itself in python 2.7?


I've tried this equation but still getting error and not updated automatically. Let's say given throttle value 1500

NewValue = (((OldValue - OldMin) * (NewMax - NewMin)) / (OldMax - OldMin)) + NewMin
self.prev_values = [0,0,0]
self.min_values = [0, 0, 0, 0]
self.max_values = [1024, 1024, 1024, 1024]

self.setpoint_euler[3] = (((self.setpoint_cmd[3] - self.min_values[3]) * (1024 - 0)) /(2000 -1000))+0
        

Solution

  • 1.024 * (value - 1000)


    if you value 1500

    1.024 * (1500 - 1000) = 512

    if you value 2000

    1.024 * (2000 - 1000) = 1024

    if you value 1000

    1.024 * (1000 - 1000) = 0

    apply round or something btw