【问题标题】:Mapping a magnetometer data in python在python中映射磁力计数据
【发布时间】:2013-08-20 10:18:11
【问题描述】:

我正在通过 Python 破解自己的方式;

现在我正在尝试使用 Python 的磁力计获取机器人的航向。问题是我希望能够通过将基于度数的值映射到我自己的集合来设置“北”。如果我正在对 Arduino 进行编程,我会使用 map() 函数。 Python中有没有类似的东西?

// how many degrees are we off
int diff = compassValue-direc;

// modify degress 
if(diff > 180)
    diff = -360+diff;
else if(diff < -180)
    diff = 360+diff;

// Make the robot turn to its proper orientation
diff = map(diff, -180, 180, -255, 255);

【问题讨论】:

标签: python arduino magnetometer


【解决方案1】:

解决方案在Mapping a range of values to another:

def translate(value, leftMin, leftMax, rightMin, rightMax):
    # Figure out how 'wide' each range is
    leftSpan = leftMax - leftMin
    rightSpan = rightMax - rightMin

    # Convert the left range into a 0-1 range (float)
    valueScaled = float(value - leftMin) / float(leftSpan)

    # Convert the 0-1 range into a value in the right range.
    return rightMin + (valueScaled * rightSpan)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-08-12
    • 1970-01-01
    • 1970-01-01
    • 2023-03-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多