加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
PTrc2deg.m 1.34 KB
一键复制 编辑 原始数据 按行查看 历史
Brian White 提交于 2020-05-13 20:42 . Add files via upload
function [angleRate] = PTrc2deg(X,rcRate,rcExpo,superrate, rcRateConstant)
% raw RCcommand data to RCrate in deg/s, i.e. "set point"
% with help from: https://github.com/betaflight/betaflight-configurator/blob/master/src/js/RateCurve.js
% X is a vector containing a single axis of RCcommand data scaled from -500 to 500,
% rcRate(0-255),rcExpo(0-100),superrate(0-100)
expoPower=3;
rcRateConstant=rcRateConstant;
angleRate=[];
rcRate=rcRate/100;
rcExpo=(rcExpo/100);
superrate=superrate/100;
maxRC=500;
rcCommandf = X / maxRC;
rcCommandfAbs = abs(rcCommandf) / 1;%max(abs(rcCommandf));
if (rcRate > 2)
rcRate = rcRate + (rcRate - 2) * 14.54;
end
if (rcExpo > 0)
%disp('rcExpo > 0')
rcCommandf = rcCommandf .* power(rcCommandfAbs, expoPower) * rcExpo + rcCommandf * (1-rcExpo);
end
if (superrate > 0)
%disp('superrate > 0')
rcFactor = 1 ./ (1 - rcCommandfAbs * superrate); % this creates the super expo curve needed to convert RCcommand to RCrate
angleRate = (rcRateConstant * rcRate * rcCommandf);
angleRate = angleRate .* rcFactor;
% disp(['angleRate:' num2str(angleRate) ' rcFactor:' num2str(rcFactor)])
else
angleRate = (rcRateConstant * rcRate * rcCommandf);
end
end
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化