示例#1
0
 def test_bigmat(self):
     sci.eval("x=rand(1000,800)")
     y = sci.read("x")
     sci.write("xx", y)
     sci.eval("dist = sum((x - xx).^2)")
     dist = sci.read("dist")
     assert(dist[0] == 0)
 def test_bigmat(self):
     sci.eval("x=rand(1000,800)")
     y = sci.read("x")
     sci.write("xx", y)
     sci.eval("dist = sum((x - xx).^2)")
     dist = sci.read("dist")
     assert (dist[0] == 0)
示例#3
0
def run_scilab_cmd(cmd_str):
    """ Defines the Scilab start command (with error handle) """
    new_cmd = "_ier_ = execstr('%s', 'errcatch'); _er_msg_ = lasterror() ;" % cmd_str
    eval(new_cmd)
    ier = read("_ier_")
    if ier != 0 and ier != [0]:
        lasterror = read("_er_msg_")
        raise ScilabError, lasterror
示例#4
0
    def find_roots(self, n):
        string1 = "s=%s;"
        string2 = "h2=" + str(n[3]) + "*s^3+" + str(n[2]) + "*s^2+" + str(
            n[1]
        ) + "*s+" + str(
            n[0]
        ) + ";[E1]=roots(h2);a11=real(E1(1));a12=imag(E1(1));b11 = real(E1(2));b12 = imag(E1(2));c11 = real(E1(3));c12 = imag(E1(3)); d11 = real(E1(4)); d12 = imag(E1(4)); e11 = real(E1(5)); e12 = imag(E1(5));"
        string = string1 + string2
        print "This is string\n", string
        sciscipy.eval(string)

        try:
            self.a11 = sciscipy.read("a11")
            print "I am a11", self.a11
        except TypeError:
            self.a11 = 0
        try:
            self.a12 = sciscipy.read("a12")
            print "I am a12", self.a12
        except TypeError:
            self.a12 = 0
        try:
            self.b11 = sciscipy.read("b11")
            print "I am b11", self.b11
        except TypeError:
            self.b11 = 0
        try:
            self.b12 = sciscipy.read("b12")
        except TypeError:
            self.b12 = 0
        try:
            self.c11 = sciscipy.read("c11")
            print "I am c11\n", self.c11
        except TypeError:
            self.c11 = 0
        try:
            self.c12 = sciscipy.read("c12")
            print "I am c12\n", self.c12
        except TypeError:
            self.c12 = 0
        try:
            self.d11 = sciscipy.read("d11")
            print "I am d11\n", self.d11
        except TypeError:
            self.d11 = 0
        try:
            self.d12 = sciscipy.read("d12")
        except TypeError:
            self.d12 = 0
        try:
            self.e11 = sciscipy.read("e11")
        except TypeError:
            self.e11 = 0
        try:
            self.e12 = sciscipy.read("e12")
        except TypeError:
            self.e12 = 0
示例#5
0
 def test_readwrite(self):              
     sci.eval("x=[1,2,3 ; 4,5,6]")
     y = sci.read("x")
     sci.write("z", y)
     w = sci.read("z")
     if numpy_is_avail:
         assert(numpy.alltrue(numpy.equal(y, w)))
     else:
         assert(y == w)
 def test_readwrite(self):
     sci.eval("x=[1,2,3 ; 4,5,6]")
     y = sci.read("x")
     sci.write("z", y)
     w = sci.read("z")
     if numpy_is_avail:
         assert (numpy.alltrue(numpy.equal(y, w)))
     else:
         assert (y == w)
示例#7
0
 def test_complex(self):
     sci.eval("x=[1+11*%i, 2+222*%i, 3+333*%i ; 4+444*%i , 5+55*%i, 6+66*%i]")
     y = sci.read("x")
     sci.write("z", y)
     w = sci.read("z")
     
     if numpy_is_avail:
         assert(numpy.alltrue(numpy.equal(y, w)))
     else:
         assert(y == w)
    def test_readwrite1dT(self):
        sci.eval("x=rand(100, 1)")
        sci.eval("my_sum=sum(x)")
        x = sci.read("x")
        my_sum = 0
        for i in range(len(x)):
            my_sum += x[i]

        my_other_sum = sci.read("my_sum")
        assert (my_other_sum[0] == my_sum)
示例#9
0
 def test_readwrite1dT(self):
     sci.eval("x=rand(100, 1)")
     sci.eval("my_sum=sum(x)")
     x = sci.read("x")
     my_sum = 0
     for i in range(len(x)):
         my_sum += x[i]
     
     my_other_sum = sci.read("my_sum")
     assert(my_other_sum[0] == my_sum)        
    def test_complex(self):
        sci.eval(
            "x=[1+11*%i, 2+222*%i, 3+333*%i ; 4+444*%i , 5+55*%i, 6+66*%i]")
        y = sci.read("x")
        sci.write("z", y)
        w = sci.read("z")

        if numpy_is_avail:
            assert (numpy.alltrue(numpy.equal(y, w)))
        else:
            assert (y == w)
示例#11
0
    def find_roots(self,n):
	string1 = "s=%s;"
	string2 = "h2="+str(n[3])+"*s^3+"+str(n[2])+"*s^2+"+str(n[1])+"*s+"+str(n[0])+";[E1]=roots(h2);a11=real(E1(1));a12=imag(E1(1));b11 = real(E1(2));b12 = imag(E1(2));c11 = real(E1(3));c12 = imag(E1(3)); d11 = real(E1(4)); d12 = imag(E1(4)); e11 = real(E1(5)); e12 = imag(E1(5));"
        string = string1+string2
	print "This is string\n", string
        sciscipy.eval(string)


        try:
            self.a11 = sciscipy.read("a11")
            print "I am a11", self.a11
        except TypeError:
            self.a11 = 0
        try:
            self.a12 = sciscipy.read("a12")
            print "I am a12", self.a12
        except TypeError:
            self.a12 = 0
        try:
            self.b11 = sciscipy.read("b11")
            print "I am b11", self.b11
        except TypeError:
            self.b11 = 0
        try:
            self.b12 = sciscipy.read("b12")
        except TypeError:
            self.b12 = 0
        try:
            self.c11 = sciscipy.read("c11")
	    print "I am c11\n", self.c11
        except TypeError:
            self.c11 = 0
        try:
            self.c12 = sciscipy.read("c12")
	    print "I am c12\n", self.c12
        except TypeError:
            self.c12 = 0
        try:
            self.d11 = sciscipy.read("d11")
	    print "I am d11\n", self.d11
        except TypeError:
            self.d11 = 0
        try:
            self.d12 = sciscipy.read("d12")
        except TypeError:
            self.d12 = 0
        try:
            self.e11 = sciscipy.read("e11")
        except TypeError:
            self.e11 = 0
        try:
            self.e12 = sciscipy.read("e12")
        except TypeError:
            self.e12 = 0
def csim(P,I,D,n0,n1,n2,n3,d0,d1,d2,d3,u):
	
	code_string1 = "s = %s;"

	# If the plant simulation is not required, the block functions as a controller block.
	if n0 == 0 and n1 == 0 and n2 == 0 and n3 == 0 and d0 == 0 and d1 == 0 and d2 == 0 and d3 == 0:
		code_string2 = "Gc = syslin('c'," + str(P*I) + "*s + " + str(D) + "*s^2 + 1," + str(I) + "*s);"
		code_string3 = "r = tf2ss(Gc);"
		code_string4 = "u = " + str(u) + ";"
		code_string5 = "y = csim(u,1:length(u),r)"
		code_string = code_string1 + code_string2 + code_string3 + code_string4 + code_string5
	# If the Controller simulation is not required, the block functions as a plant block
	elif P == 0 and I ==0 and D == 0:
		code_string2 = "G = syslin('c'," + str(n0) + "*s^3 + " + str(n1) + "*s^2 + " + str(n2) + "*s + "+ str(n3)+ "," + str(d0) + "*s^3 + " + str(d1) + "*s^2 + " + str(d2) + "*s + " + str(d3) + ");"
                code_string3 = "r = tf2ss(G);"
                code_string4 = "u = " + str(u) + ";"
                code_string5 = "y = csim(u,1:length(u),r)"
                code_string = code_string1 + code_string2 + code_string3 + code_string4 + code_string5
	# If combined plant and controller dynamics are required
	else:
		code_string2 = "Gc = syslin('c'," + str(P*I) + "*s + " + str(D) + "*s^2 + 1," + str(I) + "*s);"

		code_string3 = "G = syslin('c'," + str(n0) + "*s^3 + " + str(n1) + "*s^2 + " + str(n2) + "*s + "+ str(n3)+ "," + str(d0) + "*s^3 + " + str(d1) + "*s^2 + " + str(d2) + "*s + " + str(d3) + ");"
	
		code_string4 = "r = tf2ss(G*Gc);"
		code_string5 = "u = " + str(u)+ ";"
		code_string6 = "y = csim(u,1:length(u),r)"

		code_string = code_string1 + code_string2 + code_string3 + code_string4 + code_string5 + code_string6

	sciscipy.eval(code_string)
	y = sciscipy.read("y")
	return y
示例#13
0
def csim(P, I, D, string1, u):

    code_string1 = "s = %s;"
    code_string_u = "u = " + str(u) + ";"

    #If the controller simulation is not required, the block functions as a plant block.
    if P == 0 and I == 0 and D == 0:
        code_string2 = "G = syslin('c'," + str(string1) + ");"
        code_string3 = "r = tf2ss(G);"
        code_string4 = "y = csim(u,1:length(u),r)"
        code_string = code_string1 + code_string2 + code_string3 + code_string_u + code_string4

    # If the Plant simulation is not required, the block functions as a controller block.
    elif string1 == "":
        code_string2 = "Gc = syslin('c'," + str(P * I +
                                                D) + "*s,(" + str(I) + ")*s);"
        code_string3 = "r = tf2ss(Gc);"
        code_string4 = "y = csim(u,1:length(u),r)"
        code_string = code_string1 + code_string2 + code_string3 + code_string_u + code_string4

    # Combining the plant and controller dynamics
    else:
        code_string2 = "Gc=syslin('c',(" + str(P * I + D) + "*s)" + "," + str(
            I) + "*s);"
        code_string3 = "G = syslin('c'," + str(string1) + ");"
        code_string4 = "r=tf2ss(G*Gc);"
        code_string5 = "y = csim(u,1:length(u),r)"
        code_string = code_string1 + code_string2 + code_string3 + code_string4 + code_string_u + code_string5

    import sciscipy
    sciscipy.eval(code_string)
    y = sciscipy.read("y")
    return y
示例#14
0
def csim(P,I,D,string1,u):
	
	code_string1 = "s = %s;"
	code_string_u = "u = "+str(u)+";"


	#If the controller simulation is not required, the block functions as a plant block.
	if P == 0 and I == 0 and D==0:
		code_string2 = "G = syslin('c'," + str(string1) +  ");"
		code_string3 = "r = tf2ss(G);"
		code_string4 = "y = csim(u,1:length(u),r)"
		code_string = code_string1 + code_string2 + code_string3 + code_string_u + code_string4

	# If the Plant simulation is not required, the block functions as a controller block.
	elif string1 == "":
		code_string2 = "Gc = syslin('c'," + str(P*I+D)+"*s,("+str(I)+")*s);"
		code_string3 = "r = tf2ss(Gc);"
		code_string4 = "y = csim(u,1:length(u),r)"
		code_string = code_string1 + code_string2 + code_string3 + code_string_u + code_string4

	# Combining the plant and controller dynamics
	else:
		code_string2 = "Gc=syslin('c',("+str(P*I+D)+"*s)"+","+str(I)+"*s);"
		code_string3 = "G = syslin('c'," + str(string1) +  ");"
		code_string4 = "r=tf2ss(G*Gc);"
		code_string5 = "y = csim(u,1:length(u),r)"
		code_string = code_string1 + code_string2 + code_string3 + code_string4 + code_string_u + code_string5
	

	import sciscipy
	sciscipy.eval(code_string)
	y = sciscipy.read("y")
	return y
示例#15
0
def find_output_param(macro_name):
    """
    Find out the number of output param of macro_name


    First we look in the __known_func dico to see
    if we have a special case for that macro. If not,
    we use macrovar for type 13 functions. Otherwise,
    we return 1.

    @param macro_name: the name of a scilab macro
    @type macro_name: string
    @return: number of ouput param of macro_name
    @rtype: integer
    """
    if type(macro_name) != type(""):
        raise TypeError, "macro_name must be a string"

    if macro_name in __known_func.keys():
        return __known_func[macro_name]

    if find_scilab_type(macro_name) == 13:
        eval("_tmp1_ = macrovar(" + macro_name + ");")
        eval("_tmp2_ = length(length(_tmp1_(2)))")
        res = read("_tmp2_")
        eval("clear _tmp1_, _tmp2_")
        return int(res[0])

    return 1
示例#16
0
	def test_spec(self):
		""" [test_call] Testing spec
		"""
		spec1 = self.sci.spec([[1, 2],[3, 4]])
		sciscipy.eval("spec1 = spec([1,2;3,4])")
		spec2 = sciscipy.read("spec1")
		for l1, l2 in zip(spec1, spec2):
			self.assertAlmostEqual(l1, l2)
示例#17
0
	def test_strcat(self):
		""" [test_call] Testing strcat
		"""
		strcat1 = self.sci.strcat(["1", "4"], "x")
		sciscipy.eval("strcat1 = strcat(['1', '4'], 'x')")
		strcat2 = sciscipy.read("strcat1")
		comp = strcat1 == strcat2
		assert(comp)
示例#18
0
	def test_length(self):
		""" [test_call] Testing length
		"""
		strlength1 = self.sci.length(["3ch","5char","plenty of char"])
		sciscipy.eval("strlength = length(['3ch','5char','plenty of char'])")
		strlength2 = sciscipy.read("strlength")
		for l1, l2 in zip(strlength1, strlength2):
			self.assertEquals(l1, l2)
示例#19
0
	def test_mean(self):
		""" [test_call] Testing mean
		"""
		mean1 = self.sci.mean([[1, 2],[3, 4]])
		sciscipy.eval("mean1 = mean([1,2;3,4])")
		mean2 = sciscipy.read("mean1")
		comp = mean1 == mean2
		assert(comp)
示例#20
0
 def test_read_tlist(self):
     eval("x=tlist(['test','a','b'],12,'item')")
     x=read('x')
     if numpy_is_avail:
         num = numpy.array(12)
     else:
         num = 12
     py_x = {'__tlist_name': 'test', 'a': num, 'b': ['item']}
     assert x == py_x, str(py_x) + " != tlist(['test','a','b'],12,'item')"
示例#21
0
def calc_op(n0,n1,n2,  d0,d1,d2):
	string1 = "s=%s; h=syslin('c',"
	string2 = str(n0)+"*s^2+"+str(n1)+"*s+"+str(n2)+","
	string3 = str(d0)+"*s^2+"+str(d1)+"*s+"+str(d2)+");"
	string4 = "t=0:0.01:10;"
	string5 = "deff('u=input(t)','u=50');"
	string6 = "r=tf2ss(h); a=csim(input,t,r);"

	full_string = string1+string2+string3+string4+string5+string6
	
	print "ex:"

	print full_string

	import sciscipy
	sciscipy.eval(full_string)
	b = sciscipy.read("a")
	t = sciscipy.read("t")
	print "output is ",b
	return b
示例#22
0
def calc_op(n0, n1, n2, d0, d1, d2):
    string1 = "s=%s; h=syslin('c',"
    string2 = str(n0) + "*s^2+" + str(n1) + "*s+" + str(n2) + ","
    string3 = str(d0) + "*s^2+" + str(d1) + "*s+" + str(d2) + ");"
    string4 = "t=0:0.01:10;"
    string5 = "deff('u=input(t)','u=50');"
    string6 = "r=tf2ss(h); a=csim(input,t,r);"

    full_string = string1 + string2 + string3 + string4 + string5 + string6

    print "ex:"

    print full_string

    import sciscipy
    sciscipy.eval(full_string)
    b = sciscipy.read("a")
    t = sciscipy.read("t")
    print "output is ", b
    return b
示例#23
0
    def file_import(self):
        import sciscipy
        f = open(self.path)
        x = f.read()
        x = x.split("\n")
        code_string = ""

        for i in range(0, len(x)):
            code_string += x[i]

        sciscipy.eval(code_string)
        self.ret_array = sciscipy.read(self.var_name)
示例#24
0
    def file_import(self):
	import sciscipy
	f = open(self.path)
	x = f.read()
	x = x.split("\n")
	code_string = ""
	
	for i in range(0,len(x)):
		code_string += x[i]

	sciscipy.eval(code_string)
	self.ret_array = sciscipy.read(self.var_name)
示例#25
0
def csim(P,I,D,n0,n1,d0,d1,u):
        code_string1 = "s=%s;"
        code_string2 = "Gc=syslin('c',("+str(P*I+D)+"*s)"+","+str(I)+"*s);"
        code_string3 = "G=syslin("
        code_string4 = "'c'"+","+str(n0)+"*s"+"+"+str(n1)+","+str(d0)+"*s"+"+"+str(d1)+");"
        code_string5 = "r=tf2ss(G*Gc);"
        code_string6 = "u="+str((u))+";"
        code_string7 = "y=csim(u,1:length(u),r)"
        code_string = code_string1+code_string2+code_string3+code_string4+code_string5+code_string6+code_string7

	import sciscipy
        sciscipy.eval(code_string)
        y = sciscipy.read("y")
        return y
示例#26
0
 def find_resp(self,b,c):
     if (self.itype == 11):
         typo = "'imp'"
     elif (self.itype == 12):
         typo = "'step'"
     else:
         typo = "t"
     string1 = "s=%s; h=syslin('c',"
     string2 = str(b[4])+"*s^4+"+str(b[3])+"*s^3+"+str(b[2])+"*s^2+"+str(b[1])+"*s+"+str(b[0])+","
     string3 = str(c[4])+"*s^4+"+str(c[3])+"*s^3+"+str(c[2])+"*s^2+"+str(c[1])+"*s+"+str(c[0])+");"
     string4 = "t="+str(self.tstart)+":"+str(self.tstep)+":"+str(self.tstop)+";"
     string5 = "deff('u=input(t)','u=50');"
     string6 = "r=tf2ss(h); a=csim("+typo+",t,r);"
     string = string1+string2+string3+string4+string5+string6
     sciscipy.eval(string)
     self.a = sciscipy.read("a")
示例#27
0
def find_scilab_type(var_name):
    """
    Find the scilab type of var_name

    @param var_name: name of a scilab variable
    @type var_name: string
    @return: type(var_name)
    """
    if type(var_name) != type(""):
        raise TypeError, "var_name must be a string"

    run_scilab_cmd("_tmp1_ = type(" + var_name + ")")
    res = read("_tmp1_")
    eval("clear _tmp1_")

    return res[0]
示例#28
0
def csim(P, I, D, n0, n1, d0, d1, u):
    code_string1 = "s=%s;"
    code_string2 = "Gc=syslin('c',(" + str(P * I +
                                           D) + "*s)" + "," + str(I) + "*s);"
    code_string3 = "G=syslin("
    code_string4 = "'c'" + "," + str(n0) + "*s" + "+" + str(n1) + "," + str(
        d0) + "*s" + "+" + str(d1) + ");"
    code_string5 = "r=tf2ss(G*Gc);"
    code_string6 = "u=" + str((u)) + ";"
    code_string7 = "y=csim(u,1:length(u),r)"
    code_string = code_string1 + code_string2 + code_string3 + code_string4 + code_string5 + code_string6 + code_string7

    import sciscipy
    sciscipy.eval(code_string)
    y = sciscipy.read("y")
    return y
示例#29
0
def discrete_sim(P,I,D,n0,n1,st,d0,d1,u):
        code_string1 = "s=%s;"
	code_string2 = "Gc=syslin("+str(st)+",("+str(P*I+D)+"*s)"+","+str(I)+"*s);"
        code_string3 = "G=syslin("
        code_string4 = str(st)+","+str(n0)+"*s"+"+"+str(n1)+","+str(d0)+"*s"+"+"+str(d1)+");"
        code_string5 = "r=tf2ss(G*Gc);"
        code_string6 = "u="+str((u))+";"
        code_string7 = "y=dsimul(r,u)"
        code_string = code_string1+code_string2+code_string3+code_string4+code_string5+code_string6+code_string7

	# Check complete_code_string 
	#print code_string

	import sciscipy
	sciscipy.eval(code_string)
	y = sciscipy.read("y")
	return y
示例#30
0
def discrete_sim(P, I, D, n0, n1, st, d0, d1, u):
    code_string1 = "s=%s;"
    code_string2 = "Gc=syslin(" + str(st) + ",(" + str(
        P * I + D) + "*s)" + "," + str(I) + "*s);"
    code_string3 = "G=syslin("
    code_string4 = str(st) + "," + str(n0) + "*s" + "+" + str(n1) + "," + str(
        d0) + "*s" + "+" + str(d1) + ");"
    code_string5 = "r=tf2ss(G*Gc);"
    code_string6 = "u=" + str((u)) + ";"
    code_string7 = "y=dsimul(r,u)"
    code_string = code_string1 + code_string2 + code_string3 + code_string4 + code_string5 + code_string6 + code_string7

    # Check complete_code_string
    #print code_string

    import sciscipy
    sciscipy.eval(code_string)
    y = sciscipy.read("y")
    return y
def csim(n0,n1,st,d0,d1,u):
        string1 = "s=%s;"
        string2 = "h=syslin("
        string3 = str(st)+","+str(n0)+"*s"+"+"+str(n1)+","+str(d0)+"*s"+"+"+str(d1)+");"
        string4 = "r=tf2ss(h);"
        string5 = "u="+str(u)+";"
	string5 = u+";"
        string6 = "y=csim(u,1:length(u),r)"
        string = string1+string2+string3+string4+string5+string6

	# Check complete_string 
	#print string

	import sciscipy
	sciscipy.eval(string)
	y = sciscipy.read("y")
	#plt.plot(y)
	#plt.show()
	return y
示例#32
0
    def find_resp(self,b,c):
        if (self.itype == 11):
            typo = "'imp'"
        elif (self.itype == 12):
            typo = "'step'"
        else:
            typo = "t"
#        print "self b",self.b
        string1 = "s=%s; h=syslin('c',"
        string2 = str(b[4])+"*s^4+"+str(b[3])+"*s^3+"+str(b[2])+"*s^2+"+str(b[1])+"*s+"+str(b[0])+","
        string3 = str(c[4])+"*s^4+"+str(c[3])+"*s^3+"+str(c[2])+"*s^2+"+str(c[1])+"*s+"+str(c[0])+");"
        string4 = "t="+str(self.tstart)+":"+str(self.tstep)+":"+str(self.tstop)+";"
        string5 = "deff('u=input(t)','u=50');"
        string6 = "r=tf2ss(h); a=csim("+typo+",t,r);"
        string = string1+string2+string3+string4+string5+string6
        print "I am strin g",string
        sciscipy.eval(string)
        self.a = sciscipy.read("a")
        print "value of a\n",self.a
示例#33
0
def csim(n0, n1, st, d0, d1, u):
    string1 = "s=%s;"
    string2 = "h=syslin("
    string3 = str(st) + "," + str(n0) + "*s" + "+" + str(n1) + "," + str(
        d0) + "*s" + "+" + str(d1) + ");"
    string4 = "r=tf2ss(h);"
    string5 = "u=" + str(u) + ";"
    string5 = u + ";"
    string6 = "y=csim(u,1:length(u),r)"
    string = string1 + string2 + string3 + string4 + string5 + string6

    # Check complete_string
    #print string

    import sciscipy
    sciscipy.eval(string)
    y = sciscipy.read("y")
    #plt.plot(y)
    #plt.show()
    return y
def csim(P, I, D, n0, n1, n2, n3, d0, d1, d2, d3, u):

    code_string1 = "s = %s;"

    # If the plant simulation is not required, the block functions as a controller block.
    if n0 == 0 and n1 == 0 and n2 == 0 and n3 == 0 and d0 == 0 and d1 == 0 and d2 == 0 and d3 == 0:
        code_string2 = "Gc = syslin('c'," + str(
            P * I) + "*s + " + str(D) + "*s^2 + 1," + str(I) + "*s);"
        code_string3 = "r = tf2ss(Gc);"
        code_string4 = "u = " + str(u) + ";"
        code_string5 = "y = csim(u,1:length(u),r)"
        code_string = code_string1 + code_string2 + code_string3 + code_string4 + code_string5
    # If the Controller simulation is not required, the block functions as a plant block
    elif P == 0 and I == 0 and D == 0:
        code_string2 = "G = syslin('c'," + str(n0) + "*s^3 + " + str(
            n1) + "*s^2 + " + str(n2) + "*s + " + str(n3) + "," + str(
                d0) + "*s^3 + " + str(d1) + "*s^2 + " + str(
                    d2) + "*s + " + str(d3) + ");"
        code_string3 = "r = tf2ss(G);"
        code_string4 = "u = " + str(u) + ";"
        code_string5 = "y = csim(u,1:length(u),r)"
        code_string = code_string1 + code_string2 + code_string3 + code_string4 + code_string5
    # If combined plant and controller dynamics are required
    else:
        code_string2 = "Gc = syslin('c'," + str(
            P * I) + "*s + " + str(D) + "*s^2 + 1," + str(I) + "*s);"

        code_string3 = "G = syslin('c'," + str(n0) + "*s^3 + " + str(
            n1) + "*s^2 + " + str(n2) + "*s + " + str(n3) + "," + str(
                d0) + "*s^3 + " + str(d1) + "*s^2 + " + str(
                    d2) + "*s + " + str(d3) + ");"

        code_string4 = "r = tf2ss(G*Gc);"
        code_string5 = "u = " + str(u) + ";"
        code_string6 = "y = csim(u,1:length(u),r)"

        code_string = code_string1 + code_string2 + code_string3 + code_string4 + code_string5 + code_string6

    sciscipy.eval(code_string)
    y = sciscipy.read("y")
    return y
示例#35
0
    def __call__(self, *args):
        """
        TODO: add a named argument outp=...
            if you want to force the number of output arguments
        """
        cmd = self.name + "("

        in_args = []
        for (i, arg) in enumerate(args):
            arg_name = "__arg" + str(i)
            in_args += [arg_name]
            write(arg_name, arg)

        out = find_output_param(self.name)

        out_args = []
        for i in range(out):
            out_args += ["__out" + str(i)]

        if out != 0:
            cmd = "[%s] = %s(%s)" % (",".join(out_args), self.name,
                                     ",".join(in_args))
        else:
            cmd = "%s(%s)" % (self.name, ",".join(in_args))

        run_scilab_cmd(cmd)

        if out == 0:
            return None

        res = []
        for i in range(out):
            item = read("__out" + str(i))
            res += [item]

        if len(res) == 1:
            return res[0]
        else:
            return tuple(res)
示例#36
0
import sciscipy 
import scilab
code_string1 = "s = %s;"
code_string2 = "Gc = syslin('c'," + str(2*1) + "*s + " + str(2) + "*s^2 + 1," + str(3) + "*s);"
code_string3 = "r = tf2ss(Gc);"
code_string4 = "u = " + str(3) + ";"
code_string5 = "y = csim(u,1:length(u),r)"
code_string = code_string1 + code_string2 + code_string3 + code_string4 + code_string5
sciscipy.eval(code_string)
y = sciscipy.read("y")
示例#37
0
import sciscipy
import scilab

code_string1 = "s = %s;"
code_string2 = "Gc = syslin('c'," + str(
    2 * 1) + "*s + " + str(2) + "*s^2 + 1," + str(3) + "*s);"
code_string3 = "r = tf2ss(Gc);"
code_string4 = "u = " + str(3) + ";"
code_string5 = "y = csim(u,1:length(u),r)"
code_string = code_string1 + code_string2 + code_string3 + code_string4 + code_string5
sciscipy.eval(code_string)
y = sciscipy.read("y")
示例#38
0
# -*- coding: utf-8 -*-
"""
Created on Wed May 30 13:27:52 2018

@author: BB-8
"""

import sciscipy
              
       # create 'x' in scilab
x = sciscipy.read("x")           # read 'x' from scilab
示例#39
0
def scilab_evaluate(request):
	
	try:
		user_id = request.session['user_id']
	except:
		return HttpResponseRedirect("/login")
        all_code = request.POST.get('scilab_code')
        if not all_code:
		return HttpResponseRedirect("/scilab_view")
	all_code = all_code.replace(" ","")
	graphics_mode = request.POST.get('graphicsmode')
	all_code = all_code.replace("//Type Code Here","")
	filter_for_system = re.compile("unix_g|unix_x|unix_w|unix_s")
	if not (filter_for_system.findall(all_code)):
			split_code = all_code.split()
			plot_filter = re.compile("plot2d\(.*\)")
			function_filter = re.compile("deff\(.*\)") 
			variable =[]
			expression = []
			the_data_set = {}
			output = ""
			the_variable = ""
			graphs = []
			links = []
			for i in range(0,len(split_code)):
				plot_data = plot_filter.findall(split_code[i])
				function_data = function_filter.findall(split_code[i])
				if function_data:
					#a=sciscipy.eval(split_code[i])
					#re_fnname = re.compile("\[.*\]=.*\(.*,.\)")	
					#fn_data = re_fnname.findall(split_code[i])
					return_variables = scilab_instances(split_code,all_code)	
					#eval("function_name = fn_data[0].split('=')[1]")
					return render_to_response('default.html',{'input':all_code,             'output':return_variables , 'username':request.session['username']})
					#return_variables = eval('sci.function_name')
					#print return_variables	
					#return HttpResponse(return_variables)
				split_more = split_code[i].split("=")
				if (len(split_more)>1):
					expression.append(split_more[1])
					evaluated_code = sciscipy.eval(split_code[i])
					the_variable = split_code[i].split("=")[0]
					the_variable_value =  sciscipy.read(the_variable)
					the_data_set[the_variable] = the_variable_value
					output = output +str(the_variable) + " =\n " + "    " + str(the_variable_value) + "\n"
				if plot_data:
					coordinates = plot_data[0].split("(")[1].split(")")[0].split(",")
					x=coordinates[0]
					y=coordinates[1]
					pylab.plot(the_data_set[x],the_data_set[y])
		           	        graphs.append('simple_plot' + str(i))
					cwd = str(os.getcwd()) + "/graphs/" + str(request.session['user_id'])
					cwdsf = cwd + str(graphs[-1])
					if not os.path.exists(cwd):
					    os.makedirs(cwd)
					pylab.savefig(cwdsf)
			for graph in graphs:
				p = canvas.Canvas(cwd+str(graph)+".pdf",pagesize=letter)
				links.append(str(request.META['SERVER_NAME'])+":"+str(request.META['SERVER_PORT']) + str(graph))
                        	p.drawImage(cwd+str(graph)+".png", 1*inch,1*inch, width=5*inch,height=5*inch,mask=None)
                       		p.showPage()
	                   	p.save()
			return render_to_response('default.html',{'input':all_code,  		'output':output , "graphs":graphs,'username':request.session['username'],"links":links})
        else:
		return render_to_response('default.html',{'input':all_code,'output':"error"})