def squareBlk(pout, Amp, Period, Width, Bias, Delay): """ Call: squareBlk(pout, Amp, Period, Width, Bias, Delay) Parameters ---------- pout: connected output port(s) Amp : Amplitude Period : Period Width : Width Bias : Bias Delay : Delay Returns ------- blk : RCPblk """ if (size(pout) != 1): raise ValueError("Block should have 1 output port; received %i." % size(pout)) blk = RCPblk('square', [], pout, [0, 0], 0, [Amp, Period, Width, Bias, Delay], []) return blk
def intgBlk(pin, pout, X0=0.0): """ Continous integral block Call: intgBlk(pin,pout,X0) Parameters ---------- pin: connected input port(s) pout: connected output port(s) X0 : Initial conditions Returns ------- blk : RCPblk """ nin = size(pin) if (nin != 1): raise ValueError("Block have 1 input: received %i input ports" % nin) nout = size(pout) if (nout != 1): raise ValueError("Block have 1 output1: received %i output ports" % nout) blk = RCPblk('integral', pin, pout, [1, 0], 0, [0.0, X0], []) return blk
def init_encBlk(pin, pout, trgtime, defv, offset): """ Call: init_encBlk(pin, pout, trgtime, defv, offset) Parameters ---------- pin: connected input port(s) pout: connected output port(s) trgtime : Trigger Time defv : Default Output offset : Offset Returns ------- blk : RCPblk """ if (size(pout) != 1) or (size(pin) != 1): raise ValueError( "Block should have 1 input and 1 output port; received %i and %i." % (size(pin), size(pout))) blk = RCPblk('init_enc', pin, pout, [0, 0], 1, [trgtime, defv, offset, 0.0], []) return blk
def sumBlk(pin, pout, Gains): """ Call: sumBlk(pin, pout, Gains) Parameters ---------- pin: connected input port(s) pout: connected output port(s) Gains : Gains Returns ------- blk : RCPblk """ if (size(pin) != size(Gains)): raise ValueError("Number of inputs (%i) should match Gain Size (%i)" % (size(pin), size(Gains))) if (size(pout) != 1): raise ValueError("Block should have 1 output port; received %i." % size(pout)) blk = RCPblk('sum', pin, pout, [0, 0], 1, Gains, []) return blk
def comediPWMBlk(pin, devicename, channel, prescaler, pfiout): """Create Comedi_PWM block Comedi_PWM Call: ComediPWMBlk(pin, devicename, channel, prescaler, pfiout) Parameters ---------- pin : connected input port devicename: Comedi device name /path channel : Channel prescaler: Clock Prescaler pfiout: Output pin Returns ------- blk : RCPblk """ if size(pin) != 1: raise ValueError("Block should have only 1 input port, receivesd %i" % size(pin)) blk = RCPblk("comedi_pwm_generator", pin, [], [0, 0], 1, [], [channel, prescaler, pfiout], devicename) return blk
def baumer_EncBlk(pout, candev, ID, res, encres): """ Call: baumer_EncBlk(pout, ID, res, encres) Parameters ---------- pout: connected output port(s) ID : Device ID res : Resolution encres : Encoder reset Returns ------- blk : RCPblk """ if (size(pout) != 1): raise ValueError("Block should have 1 output port; received %i." % size(pout)) blk = RCPblk('baumer_enc', [], pout, [0, 0], 0, [4 * res], [ID, encres], candev) return blk
def stm32DIBlk(pout, port, ch): """ Call: stm32DIBlk(pout, port, ch) Parameters ---------- pout: connected output port(s) port : Port ch : Channel Returns ------- blk: RCPblk """ p = port[-1] p = p.upper() pn = ord(p) - ord('A') if pn < 0 or pn > 6: raise ValueError("Port should be between PORTA and PORTG not %s", (port)) if ch < 0 or ch > 15: raise ValueError("Channel should be between 0 and 15 not %i", (ch)) blk = RCPblk('stm32DI', [], pout, [0, 0], 0, [], [pn, ch]) return blk
def zdelayBlk(pin, pout, X0=0.0): """ Call: zdelayBlk(pin, pout, X0=0.0) Parameters ---------- pin: connected input port(s) pout: connected output port(s) X0: Initial conditions Returns ------- blk : RCPblk """ nin = size(pin) if (nin != 1): raise ValueError("Block have 1 input: received %i input ports" % nin) nout = size(pout) if (nout != 1): raise ValueError("Block have 1 output1: received %i output ports" % nout) blk = RCPblk('unitDelay', pin, pout, [0, 1], 0, [X0], []) return blk
def saturBlk(pin, pout, satP, satN): """ Call: saturBlk(pin, pout, satP, satN) Parameters ---------- pin: connected input port(s) pout: connected output port(s) satP : Upper saturation satN : Lower saturation Returns ------- blk : RCPblk """ if (size(pin) != 1): raise ValueError("Block should have 1 input port; received %i." % size(pin)) if (size(pout) != 1): raise ValueError("Block should have 1 output port; received %i." % size(pout)) blk = RCPblk('saturation', pin, pout, [0, 0], 1, [satP, satN], []) return blk
def USB_OTG_InBlk(pout, defvals): """ Call: USB_OTG_InBlk(pout) Parameters ---------- pout: connected output port(s) Returns ------- blk: RCPblk """ outputs = len(pout) vals = zeros(outputs, float) if len(defvals) > outputs: N = outputs else: N = len(defvals) for n in range(N): vals[n] = defvals[n] blk = RCPblk('USB_OTG_In', [], pout, [0, 0], 0, vals, []) return blk
def maxon_MotBlk(pin, candev, ID, propGain, intGain): """ Maxon driver for torque control Call: maxon_MotBlk(pin, ID) Parameters ---------- pin: connected input port(s) ID : Device ID propGain : Prop. gain intGain : Integ. gain Returns ------- blk : RCPblk """ if (size(pin) != 1): raise ValueError("Block should have 1 input port; received %i." % size(pout)) blk = RCPblk('maxon_mot', pin, [], [0, 0], 1, [propGain, intGain], [ID], candev) return blk
def brikiESCBlk(pin, ch, umin, umax): """ Call: brikiESCBlk(pin, ch, umin, umax) Parameters ---------- pin: connected input port(s) ch : Pin umin : Umin [V] umax : Umax [V] Returns ------- blk: RCPblk """ PWMlist = [11, 13, 21, 22, 23, 24, 25] if ch not in PWMlist: raise ValueError( "You pass a channel which is not in the ABC Board PIN list: %i" % (ch)) blk = RCPblk('brikiESC', pin, [], [0, 0], 1, [umin, umax], [ch]) return blk
def cssBlk(pin, pout, sys, X0=[]): """ Continous state space block Call: cssBlk(pin,pout, sys,X0) Parameters ---------- pin : connected input ports pout: connected output ports sys: Discrete system in SS form X0: Initial conditions Returns ------- blk : RCPblk """ if isinstance(sys, TransferFunction): sys = tf2ss(sys) nin = size(pin) ni = shape(sys.B)[1] if (nin != ni): raise ValueError("Block Robi have %i inputs: received %i input ports" % (nin, ni)) no = shape(sys.C)[0] nout = size(pout) if (no != nout): raise ValueError("Block have %i outputs: received %i output ports" % (nout, no)) a = reshape(sys.A, (1, size(sys.A)), 'C') b = reshape(sys.B, (1, size(sys.B)), 'C') c = reshape(sys.C, (1, size(sys.C)), 'C') d = reshape(sys.D, (1, size(sys.D)), 'C') nx = shape(sys.A)[0] if (size(X0) == nx): X0 = reshape(X0, (1, size(X0)), 'C') else: X0 = mat(zeros((1, nx))) indA = 1 indB = indA + nx * nx indC = indB + nx * ni indD = indC + nx * no indX = indD + ni * no intPar = [nx, ni, no, indA, indB, indC, indD, indX] realPar = hstack((mat([0.0]), a, b, c, d, X0)) if d.any() == True: uy = 1 else: uy = 0 blk = RCPblk('css', pin, pout, [nx, 0], uy, realPar, intPar) return blk
def brikiDCMotBlk(pin, enCh, in1Ch, in2Ch): """ Call: brikiDCMotBlk(pin, enCh, in1Ch, in2Ch) Parameters ---------- pin: connected input port(s) enCh : Enable Pin in1Ch : In1 Pin in2Ch : In2 Pin Returns ------- blk: RCPblk """ CHlist = [11, 13, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31] if enCh not in CHlist: raise ValueError("You pass a channel which is not in the ABC Board PIN list: %i" % (enCh)) if in1Ch not in CHlist: raise ValueError("You pass a channel which is not in the ABC Board PIN list: %i" % (in1Ch)) if in2Ch not in CHlist: raise ValueError("You pass a channel which is not in the ABC Board PIN list: %i" % (in2Ch)) blk = RCPblk('brikiDCMot', pin, [], [0,0], 1, [], [enCh, in1Ch, in2Ch]) return blk
def sineBlk(pout, Amp, Freq, Phase, Bias, Delay): """ Call: sineBlk(pout, Amp, Freq, Phase, Bias, Delay) Parameters ---------- pout: connected output port(s) Amp : Amplitude Freq : Freq Phase : Phase Bias : Bias Delay : Delay Returns ------- blk : RCPblk """ if (size(pout) != 1): raise ValueError("Block should have 1 output port; received %i." % size(pout)) blk = RCPblk('sinus', [], pout, [0, 0], 0, [Amp, Freq, Phase, Bias, Delay], []) return blk
def unixsocketSBlk(pout, sockname, defvals): """ Call: unixsocketSBlk(pout, sockname, defvals) Parameters ---------- pout: connected output port(s) sockname : Socket defvals : Default outputs Returns ------- blk : RCPblk """ outputs = len(pout) vals = zeros(outputs, float) if len(defvals) > outputs: N = outputs else: N = len(defvals) for n in range(N): vals[n] = defvals[n] blk = RCPblk('unixsockS', [], pout, [0, 0], 0, vals, [0, 0], '/tmp/' + sockname) return blk
def lutBlk(pin, pout, coeff): """ Call: lutBlk(pin, pout, coeff) Parameters ---------- pin: connected input port(s) pout: connected output port(s) coeff : Coeff Returns ------- blk : RCPblk """ if(size(pin) != 1): raise ValueError("Block should 1 input port; received %i." % size(pin)) if(size(pout) != 1): raise ValueError("Block should have 1 output port; received %i." % size(pout)) blk = RCPblk('lut',pin,pout,[0,0],1,[coeff],[size(coeff)]) return blk
def stm32DOBlk(pin, port, ch, Th): """ Call: stm32_OBlk(pin, port, ch, Th) Parameters ---------- pin: connected input port(s) port : Port ch : Channel [0-15] Th : Threshold Returns ------- blk: RCPblk """ p = port[-1] p = p.upper() pn = ord(p) - ord('A') if pn < 0 or pn > 6: raise ValueError("Port should be between PORTA and PORTG not %s", (port)) if ch < 0 or ch > 15: raise ValueError("Channel should be between 0 and 15 not %i", (ch)) blk = RCPblk('stm32DO', pin, [], [0, 0], 0, [Th], [pn, ch]) return blk
def switchBlk(pin, pout, cond, val, pers): """ Call: switchBlk(pin, pout, cond, val, pers) Parameters ---------- pin: connected input ports (3) pout: connected output port cond: 0 >, 1 < val: value to compare pers: switch can change again (0) or is fixed (1) Output switches from input 1 to input 2 if the condition is reached (input 3 > or <) than val; If pers is 1 the system doesn't switch back again if the condition is no more satisfied Returns ------- blk : RCPblk """ if (size(pin) != 3): raise ValueError("Block should have 3 input ports; received %i." % size(pin)) if (size(pout) != 1): raise ValueError("Block should have 1 output port; received %i." % size(pout)) blk = RCPblk('switcher', pin, pout, [0, 0], 1, [val], [cond, pers]) return blk
def scopeStream(pin, decim=1): """Create an interactive scope.""" decim = int(decim) blk = RCPblk("scope", pin, [], [0, 0], 1, [], [decim, 0]) return blk
def epos_MotXBlk(pin, candev, ID): """ Call: epos_MotXBlk(pin, ID) Parameters ---------- pin: connected input port(s) ID : Device ID propGain : Prop. gain intGain : Integ. gain derGain : Deriv. gain Vff : Vel. FeedForw Aff : Acc. Feed Forw. Returns ------- blk : RCPblk """ if (size(pin) != 1): raise ValueError("Block should have 1 input port; received %i." % size(pout)) blk = RCPblk('epos_canopen_motX', pin, [], [0, 0], 1, [], [ID], candev) return blk
def matmultBlk(pin, pout, Gains): """ Matrix multiplication of the input signals Call: matmultBlk(pin,pout, Gains) Parameters ---------- pin: connected input port(s) pout: connected output port(s) Gains : Gains Returns ------- blk : RCPblk """ Gains = mat(Gains) n, m = shape(Gains) if (size(pin) != m): raise ValueError("Block should have %i input port; received %i." % (m, size(pin))) if (size(pout) != n): raise ValueError("Block should have %i output port; received %i." % (n, size(pout))) realPar = reshape(Gains, (1, size(Gains)), 'C') blk = RCPblk('mxmult', pin, pout, [0, 0], 1, realPar, [n, m]) return blk
def brikiDOBlk(pin, ch, thr): """ Call: brikiDOBlk(pin, ch, thr) Parameters ---------- pin: connected input port(s) ch : Channel thr : Threshold Returns ------- blk: RCPblk """ DOlist = [9, 11, 13, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31] if ch not in DOlist: raise ValueError( "You pass a channel which is not in the ABC Board PIN list: %i" % (ch)) blk = RCPblk('brikiDO', pin, [], [0, 0], 1, [thr], [ch]) return blk
def brikiDIBlk(pout, ch): """ Call: brikiDIBlk(pout, ch) Parameters ---------- pout: connected output port(s) ch : Channel Returns ------- blk: RCPblk """ DIlist = [11, 13, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31] if ch not in DIlist: raise ValueError( "You pass a channel which is not in the ABC Board PIN list: %i" % (ch)) blk = RCPblk('brikiDI', [], pout, [0, 0], 0, [], [ch]) return blk
def trigBlk(pin, pout, tp): """ Call: trigBlk(pin, pout, tp) Parameters ---------- pin: connected input port(s) pout: connected output port(s) tp : sin->1 cos->2 tan->3 Returns ------- blk : RCPblk """ nin = size(pin) if (nin != 1): raise ValueError("Block have 1 input: received %i input ports" % nin) nout = size(pout) if (nout != 1): raise ValueError("Block have 1 output1: received %i output ports" % nout) blk = RCPblk('trigo', pin, pout, [0, 0], 1, [], [tp]) return blk
def stm32DCMotBlk(pin, pwmCh, dir1Port, dir1Ch, dir2Port, dir2Ch, umin, umax): """ Call: stm32DCMotBlk(pin, pwmCh, dir1Port, dir1Ch, dir2Port, dir2Ch, umin, umax) Parameters ---------- pin: connected input port(s) pwmCh : PWM CHannel dir1Port : Direction 1 Port dir1Ch : Direction 1 Channel dir2Port : Direction 2 Port dir2Ch : Direction 2 Channel umin : Umin umax : Umax Returns ------- blk: RCPblk """ p1 = dir1Port[-1] p1 = p1.upper() pn1 = ord(p1) - ord('A') p2 = dir2Port[-1] p2 = p2.upper() pn2 = ord(p2) - ord('A') if pn1 < 0 or pn1 > 6: raise ValueError("Port should be between PORTA and PORTG not %s", (dir1Port)) if dir1Ch < 0 or dir1Ch > 15: raise ValueError("Channel should be between 0 and 15 not %i", (dir1Ch)) if pn2 < 0 or pn2 > 6: raise ValueError("Port should be between PORTA and PORTG not %s", (dir2Port)) if dir2Ch < 0 or dir2Ch > 15: raise ValueError("Channel should be between 0 and 15 not %i", (dir2Ch)) if pwmCh < 1 or pwmCh > 4: raise ValueError("Channel should have value 1 2 3 or 4 not %d" % pwmCh) blk = RCPblk('stm32DCMot', pin, [], [0, 0], 1, [umin, umax], [pwmCh, pn1, dir1Ch, pn2, dir2Ch]) return blk
def FmuBlk(*args): if len(args) == 8: pin, pout, IN_ref, OUT_ref, file, ts, dt, ft = args elif len(args) == 7: pout, IN_ref, OUT_ref, file, ts, dt, ft = args pin = [] else: raise ValueError("Not enough arguments received!") if np.size(pin) != np.size(IN_ref): raise ValueError("Input references not correct; received %i." % np.size(IN_ref)) if np.size(pout) != np.size(OUT_ref): raise ValueError("Input references not correct; received %i." % np.size(OUT_ref)) intPar = np.zeros(2 + np.size(pin) + np.size(pout), dtype=np.int16) intPar[0] = np.size(pin) intPar[1] = np.size(pout) spl_name = file.split('.') name = '/tmp/' + spl_name[0] cmd = 'unzip -o -d ' + name + ' ' + file + ' >/dev/null' system(cmd) pos = 0 for ref in IN_ref: ind = getXMLindex(name, ref) if ind == -1: raise ValueError('Reference value not found!') else: intPar[pos + 2] = ind pos += 1 for ref in OUT_ref: ind = getXMLindex(name, ref) if ind == -1: raise ValueError('Reference value not found!') else: intPar[pos + 2] = ind pos += 1 system('rm -fr ' + name) blk = RCPblk('FMUinterface', pin, pout, [0, 0], ft, [ts, dt], intPar, file) return blk
def stm32Ads1018Blk(pout, port, pin, channel, rng, single): """ Call: stm32Ads1018Blk(pout, port, pin, channel) Parameters ---------- pout: connected output port(s) port : CS Port pin : CS PIN channel : Channel Returns ------- blk: RCPblk """ if port == 'NSS': pn = -1 pin = 0 else: p = port[-1] p = p.upper() pn = ord(p) - ord('A') if pn < 0 or pn > 6: raise ValueError("Port should be between PORTA and PORTG not %s", (port)) if pin < 0 or pin > 15: raise ValueError("PIN should be between 0 and 15 not %i", (pin)) if channel < 0 or channel > 3: raise ValueError("PIN should be between 0 and 3 not %i", (channel)) if rng < 2 or rng > 7: raise ValueError("Voltage range should be between 2 and 7 not %i", (rng)) if single > 0: single = 1 else: single = 0 blk = RCPblk('stm32Ads1018', [], pout, [0, 0], 0, [0], [pn, pin, channel, rng, single]) return blk
def plotBlk(pin, fname): """ Call: plotBlk(pin) Parameters ---------- pin: connected input port(s) Returns ------- blk : RCPblk """ blk = RCPblk('plot',pin,[],[0,0],1,[],[], fname) return blk
def brikiLuxBlk(pout): """ Call: brikiLuxBlk(pout) Parameters ---------- pout: connected output port(s) Returns ------- blk: RCPblk """ blk = RCPblk('brikiLux', [], pout, [0, 0], 0, [], []) return blk