将[-180,180]到[0,180]的角度归一化 [英] normalize angles from [-180,180] to [0,180]

查看:1139
本文介绍了将[-180,180]到[0,180]的角度归一化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的伺服电机只能从0旋转到180 我有从-180到180度的角度范围可以发送给伺服 我如何在这两个范围之间进行归一化? 如果有任何MATLAB函数可以做到这一点? 谢谢

I have servo motor can rotate from 0 to 180 only And I have angles range from -180 to 180 to send to servo how can i normalize between those two ranges?? And if there is any MATLAB function to do that?? thanks

推荐答案

您可以添加180并除以2,如@High Performance Mark针对您的特定问题所建议的,或者这是基于

You could Add 180 and divide by 2 as @High Performance Mark suggests for your specific problem or here is a generalized version of it based on This post.

此等式适用于任何限制

我已经根据等式编写了一个简单的函数:

I have written a simple function based on the equation:

function [out] = normalizeLim( A,oldL,oldR,newL,newR )

    out = newL*(1-((A-oldL)./(oldR-oldL))) + newR*((A-oldL)./(oldR-oldL));

end

示例:

x = randi([-180,180],1,8); %//  Generating a random vector within the range -180 to 180

>> x

x =

-153  -161    11   101   157  -134    25   -11

>> normalizeLim(x,-180,180,0,180) %// Specifying old and new required limits

ans =

13.5000    9.5000   95.5000  140.5000  168.5000   23.0000  102.5000   84.5000

如果希望它们为整数,则可以使用round函数将它们四舍五入

If you want them as integers, you might round them using round function

希望这会有所帮助!

这篇关于将[-180,180]到[0,180]的角度归一化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆