fix: the onepoint iterator should work
This commit is contained in:
		
							parent
							
								
									f67e7992ba
								
							
						
					
					
						commit
						80c76bfeb1
					
				| @ -1,6 +1,7 @@ | |||||||
| import ast | import ast | ||||||
| import math | import math | ||||||
| import struct | import struct | ||||||
|  | import sys | ||||||
| import time | import time | ||||||
| 
 | 
 | ||||||
| import numpy as np | import numpy as np | ||||||
| @ -93,34 +94,28 @@ class Status(object): | |||||||
|             for l in lines: |             for l in lines: | ||||||
|                 print(prefix + l) |                 print(prefix + l) | ||||||
| 
 | 
 | ||||||
| class OnePointIterator( ): |  | ||||||
| 
 |  | ||||||
|     def __init__(self, ref): |  | ||||||
|         self.ref = ref |  | ||||||
| 
 |  | ||||||
|     def __iter__(self): |  | ||||||
|         return self |  | ||||||
| 
 |  | ||||||
|     def __next__(self): |  | ||||||
| 
 | 
 | ||||||
|  | def OnePointIterator(pl): | ||||||
|     while True: |     while True: | ||||||
| 
 |         for indexpoint, currentpoint in enumerate(pl): | ||||||
|             # pdb.set_trace() |             print("cp", indexpoint, currentpoint) | ||||||
|             for indexpoint, currentpoint in enumerate(self.ref.pl): |             yield currentpoint[0], currentpoint[1], 255, 255, 255 | ||||||
|  |         continue | ||||||
|  |         for indexpoint, currentpoint in enumerate(pl): | ||||||
| 
 | 
 | ||||||
|             # We modify the point geometry according to warp settings |             # We modify the point geometry according to warp settings | ||||||
|             # print indexpoint, currentpoint |             # print indexpoint, currentpoint | ||||||
|             # xyc = [currentpoint[0], currentpoint[1], currentpoint[2]] |             # xyc = [currentpoint[0], currentpoint[1], currentpoint[2]] | ||||||
|                 # self.ref.xyrgb = self.ref.get_warped_point(xyc) |             # ref.xyrgb = ref.get_warped_point(xyc) | ||||||
|                 x, y = self.ref.get_warped_point(currentpoint[0], currentpoint[1]) |             x, y = ref.get_warped_point(currentpoint[0], currentpoint[1]) | ||||||
|                 r, g, b = self.ref.int_to_rgb(currentpoint[2]) |             r, g, b = ref.int_to_rgb(currentpoint[2]) | ||||||
| 
 | 
 | ||||||
|             # We modify the point color based on channel specific r,g,b intensity settings |             # We modify the point color based on channel specific r,g,b intensity settings | ||||||
|                 rgb = (round(r * self.ref.intred / 100), round(g * self.ref.intgreen / 100), |             rgb = (round(r * ref.intred / 100), round(g * ref.intgreen / 100), | ||||||
|                        round(b * self.ref.intblue / 100)) |                    round(b * ref.intblue / 100)) | ||||||
| 
 | 
 | ||||||
|             # We compute the delta with previous position |             # We compute the delta with previous position | ||||||
|                 delta_x, delta_y = x - self.ref.prev_x, y -self.ref.prev_y |             delta_x, delta_y = x - ref.prev_x, y - ref.prev_y | ||||||
| 
 | 
 | ||||||
|             # We compute the distance from previous postion |             # We compute the distance from previous postion | ||||||
|             if math.hypot(delta_x, delta_y) < 4000: |             if math.hypot(delta_x, delta_y) < 4000: | ||||||
| @ -137,13 +132,14 @@ class OnePointIterator( ): | |||||||
|                 step = e[0] |                 step = e[0] | ||||||
| 
 | 
 | ||||||
|                 for i in range(0, e[1]): |                 for i in range(0, e[1]): | ||||||
|                         self.ref.xyrgb_step = (self.ref.prev_x + step * delta_x, |                     ref.xyrgb_step = (ref.prev_x + step * delta_x, | ||||||
|                                            self.ref.prev_y + step * delta_y) + rgb  # + self.ref.xyrgb_prev[2:]# + rgb |                                       ref.prev_y + step * delta_y) + rgb  # + ref.xyrgb_prev[2:]# + rgb | ||||||
|                         # print(self.ref.xyrgb_step) |                     # print(ref.xyrgb_step) | ||||||
|                         yield self.ref.xyrgb_step |                     yield ref.xyrgb_step | ||||||
|  | 
 | ||||||
|  |             ref.prev_x, ref.prev_y = x, y | ||||||
|  |             ref.xyrgb_prev = [x, y] | ||||||
| 
 | 
 | ||||||
|                 self.ref.prev_x, self.ref.prev_y = x, y |  | ||||||
|                 self.ref.xyrgb_prev = [x, y] |  | ||||||
| 
 | 
 | ||||||
| class Tracer(object): | class Tracer(object): | ||||||
|     """A connection to a DAC.""" |     """A connection to a DAC.""" | ||||||
| @ -152,6 +148,8 @@ class Tracer(object): | |||||||
|     point_list_number: list |     point_list_number: list | ||||||
|     pl: list |     pl: list | ||||||
|     client_key: str  # /pl/<laser_id> by default |     client_key: str  # /pl/<laser_id> by default | ||||||
|  |     prev_x = 0 | ||||||
|  |     prev_y = 0 | ||||||
| 
 | 
 | ||||||
|     black_points = [(278.0, 225.0, 0), (562.0, 279.0, 0), (401.0, 375.0, 0), (296.0, 454.0, 0), (298.0, 165.0, 0)] |     black_points = [(278.0, 225.0, 0), (562.0, 279.0, 0), (401.0, 375.0, 0), (296.0, 454.0, 0), (298.0, 165.0, 0)] | ||||||
|     grid_points = [(300.0, 200.0, 0), (500.0, 200.0, 65280), (500.0, 400.0, 65280), (300.0, 400.0, 65280), |     grid_points = [(300.0, 200.0, 0), (500.0, 200.0, 65280), (500.0, 400.0, 65280), (300.0, 400.0, 65280), | ||||||
| @ -177,7 +175,7 @@ class Tracer(object): | |||||||
|     def set_status(self, status: int): |     def set_status(self, status: int): | ||||||
|         raise Exception("Please override the method") |         raise Exception("Please override the method") | ||||||
| 
 | 
 | ||||||
|     def get_warped_point(self, x, y ): |     def get_warped_point(self, x, y): | ||||||
|         """ |         """ | ||||||
|         A DAC specific point model, ex EtherPoint or HeliosPoint |         A DAC specific point model, ex EtherPoint or HeliosPoint | ||||||
|         :param xyc: x,y,color |         :param xyc: x,y,color | ||||||
| @ -191,9 +189,6 @@ class Tracer(object): | |||||||
|     # def set_ack_status(self, ack_status: int): |     # def set_ack_status(self, ack_status: int): | ||||||
|     #     raise Exception("Please override the method") |     #     raise Exception("Please override the method") | ||||||
| 
 | 
 | ||||||
| 
 |  | ||||||
| 
 |  | ||||||
| 
 |  | ||||||
|     def prepare(self): |     def prepare(self): | ||||||
|         raise Exception("Please override the method") |         raise Exception("Please override the method") | ||||||
| 
 | 
 | ||||||
| @ -254,6 +249,8 @@ class Tracer(object): | |||||||
|                 # @todo si la clef est vide utiliser les points noirs ?  -> syntax error -> black points. |                 # @todo si la clef est vide utiliser les points noirs ?  -> syntax error -> black points. | ||||||
|                 try: |                 try: | ||||||
|                     self.pl = ast.literal_eval(self.redis.get(self.clientkey + str(self.laser_id)).decode('ascii')) |                     self.pl = ast.literal_eval(self.redis.get(self.clientkey + str(self.laser_id)).decode('ascii')) | ||||||
|  |                     # print(self.clientkey + str(self.laser_id)) | ||||||
|  |                     # print(self.pl) | ||||||
| 
 | 
 | ||||||
|                 except SyntaxError: |                 except SyntaxError: | ||||||
|                     print("BAD POINTLIST on Tracer : laser", self.laser_id, " order 0 : pl : ", self.pl) |                     print("BAD POINTLIST on Tracer : laser", self.laser_id, " order 0 : pl : ", self.pl) | ||||||
| @ -284,7 +281,8 @@ class Tracer(object): | |||||||
| 
 | 
 | ||||||
|                 if order == 4: |                 if order == 4: | ||||||
|                     """ 4: Resampler Change, modify the automatic intermediary points settings """ |                     """ 4: Resampler Change, modify the automatic intermediary points settings """ | ||||||
|                     self.resampler = ast.literal_eval(self.redis.get('/resampler/' + str(self.laser_id)).decode('ascii')) |                     self.resampler = ast.literal_eval( | ||||||
|  |                         self.redis.get('/resampler/' + str(self.laser_id)).decode('ascii')) | ||||||
|                     print("Tracer", self.laser_id, " : resetting lsteps for", self.resampler) |                     print("Tracer", self.laser_id, " : resetting lsteps for", self.resampler) | ||||||
|                     gstt.stepshortline = self.resampler[0] |                     gstt.stepshortline = self.resampler[0] | ||||||
|                     gstt.stepslongline[0] = self.resampler[1] |                     gstt.stepslongline[0] = self.resampler[1] | ||||||
| @ -329,8 +327,9 @@ class Tracer(object): | |||||||
|             # pdb.set_trace() |             # pdb.set_trace() | ||||||
|             # How much room? |             # How much room? | ||||||
|             capacity = self.get_points_capacity() |             capacity = self.get_points_capacity() | ||||||
|  |             iterator = iter(OnePointIterator(self.pl)) | ||||||
|  | 
 | ||||||
|             self.redis.set('/cap/' + str(self.laser_id), capacity) |             self.redis.set('/cap/' + str(self.laser_id), capacity) | ||||||
|             iterator = OnePointIterator(self) |  | ||||||
|             points = [next(iterator) for i in range(capacity)] |             points = [next(iterator) for i in range(capacity)] | ||||||
|             self.write(points) |             self.write(points) | ||||||
|             if not started: |             if not started: | ||||||
|  | |||||||
| @ -33,7 +33,7 @@ class TracerHelios(Tracer): | |||||||
|         self.redis = redis |         self.redis = redis | ||||||
|         self.laser_id = laser_id |         self.laser_id = laser_id | ||||||
|         self.PL = PL |         self.PL = PL | ||||||
|         self.pl = [[0, 0, 0]] |         self.pl = [[0,0,0]] | ||||||
|         self.clientkey = self.redis.get("/clientkey").decode('ascii') |         self.clientkey = self.redis.get("/clientkey").decode('ascii') | ||||||
|         self.xyrgb = self.xyrgb_prev = (0, 0, 0, 0, 0) |         self.xyrgb = self.xyrgb_prev = (0, 0, 0, 0, 0) | ||||||
|         self.intensity = 65280 |         self.intensity = 65280 | ||||||
| @ -50,7 +50,7 @@ class TracerHelios(Tracer): | |||||||
|         pass |         pass | ||||||
| 
 | 
 | ||||||
|     def get_points_capacity(self): |     def get_points_capacity(self): | ||||||
|         return 1000 |         return 10 | ||||||
| 
 | 
 | ||||||
|     # def GetPoints(self, capacity): |     # def GetPoints(self, capacity): | ||||||
|     #     a = [2,3] |     #     a = [2,3] | ||||||
| @ -92,16 +92,7 @@ class TracerHelios(Tracer): | |||||||
|         # print("hello got {} points".format(len(points))) |         # print("hello got {} points".format(len(points))) | ||||||
|         points = [point for point in points] |         points = [point for point in points] | ||||||
|         for i, point in enumerate(points): |         for i, point in enumerate(points): | ||||||
|             a = 0 |             x, y, r, g, b = point | ||||||
|             # @todo why are there 2 tuples in the object ??? |  | ||||||
|             for one_point in point: |  | ||||||
|                 x, y, r, g, b = one_point |  | ||||||
|                 # x = random.randrange(1500,2500) |  | ||||||
|                 # y = random.randrange(1500,2500) |  | ||||||
|                 # r = 255 |  | ||||||
|                 # g = 255 |  | ||||||
|                 # b = 255 |  | ||||||
|                 break |  | ||||||
|             print(x,y,r,g,b) |             print(x,y,r,g,b) | ||||||
|             frame[i] = HeliosPoint(int(x), int(y), int(r), int(g), int(b), 255) |             frame[i] = HeliosPoint(int(x), int(y), int(r), int(g), int(b), 255) | ||||||
|         statusAttempts = 0 |         statusAttempts = 0 | ||||||
|  | |||||||
							
								
								
									
										4
									
								
								main.py
									
									
									
									
									
								
							
							
						
						
									
										4
									
								
								main.py
									
									
									
									
									
								
							| @ -80,10 +80,10 @@ def dac_process(number, pl, dac_family): | |||||||
|     from libs3 import gstt |     from libs3 import gstt | ||||||
| 
 | 
 | ||||||
|     print("Starting dac process", number) |     print("Starting dac process", number) | ||||||
| 
 |  | ||||||
|     while True: |  | ||||||
|     try: |     try: | ||||||
|         d = tracer.DAC(number, pl, dac_family=dac_family) |         d = tracer.DAC(number, pl, dac_family=dac_family) | ||||||
|  | 
 | ||||||
|  |         while True: | ||||||
|             d.play_stream() |             d.play_stream() | ||||||
| 
 | 
 | ||||||
|     except Exception as e: |     except Exception as e: | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user