invert.comp

来自「CNC 的开放码,EMC2 V2.2.8版」· COMP 代码 · 共 41 行

COMP
41
字号
//   This is a component for EMC2 HAL//   Copyright 2008 Stephen Wille Padnos <swpadnos at sourceforge dot net>////   This program is free software; you can redistribute it and/or//   modify it under the terms of version 2 of the GNU General//   Public License as published by the Free Software Foundation.////   This program is distributed in the hope that it will be useful,//   but WITHOUT ANY WARRANTY; without even the implied warranty of//   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the//   GNU General Public License for more details.////   You should have received a copy of the GNU General Public License//   along with this program; if not, write to the Free Software//   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USAcomponent invert """Compute the inverse of the input signalThe output will be the mathematical inverse of the input, ie \\fBout\\fR = 1/\\fBin\\fR.The parameter \\fBdeadband\\fR can be used to control how close to 0 the denominator can bebefore the output is clamped to 0.  \\fBdeadband\\fR must be at least 1e-8, and must be positive.""";pin in float in "Analog input value" ;pin out float out "Analog output value";param rw float deadband "The \\fBout\\fR will be zero if \\fBin\\R is between -\\fBdeadband\\fR and +\\fBdeadband\\fR" ;function _;license "GPL";;;#include <rtapi_math.h>FUNCTION(_) {    float tmp = in;    if (deadband < 1e-12) deadband = 1e-12;    if ( tmp > -deadband && tmp <0)	out = -1/deadband;    else if (tmp >= 0 && tmp <deadband)	out = 1/deadband;    else	out = 1/tmp;}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?