summaryrefslogtreecommitdiff
path: root/gr-input/python/gr_ramp_source.py
blob: 687ffb9578b84a8d86bf7039568b049b451885e3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#!/usr/bin/python

import gras
import numpy
# Serial is imported in __init__
class ramp(gras.Block):
	

        def __init__(self):
                gras.Block.__init__(self,
                        name="ser",
                        in_sig=[numpy.float32],
                        out_sig=[numpy.float32])
		self.i = 0
		self.flag=True
        
	def set_parameters(self, ramp_slope, height_Offset, width_Offset):
		self.slope = ramp_slope	
		self.width = width_Offset
		self.offset = height_Offset

        def work(self, input_items, output_items):
		
                out = output_items[0][0]
		input_stream = input_items[0][0]
		
		if self.flag:
			for j in range(self.width):
				out = self.offset
				print "OUT", out

				self.produce(0,1) # Produce from port 0 output_items
				self.consume(0,1) # Consume from port 0 input_items
			
			self.flag = False

		else:

			self.i = self.i + 1
			out =self.offset + self.i*input_stream*self.slope
		
			print "OUT", out
			
		self.produce(0,1) # Produce from port 0 output_items
		self.consume(0,1) # Consume from port 0 input_items