@@ -251,12 +251,12 @@ def set_color(self, rgb):
251251 rgs (str): example 'ff0000'
252252
253253 '''
254- command = 'fe fe 05 6a {} fa' .format (rgb )
254+ command = 'fefe056a{} fa' .format (rgb )
255255 # print(command)
256256 self ._write (command )
257257
258258 def is_moving (self ):
259- command = 'fe fe 02 2b fa '
259+ command = 'fefe022bfa '
260260 self ._write (command )
261261 data = self ._read (2 )
262262 # print(data)
@@ -269,25 +269,25 @@ def is_moving(self):
269269 return False
270270
271271 def pause (self ):
272- self ._write ('fe fe 02 26 fa ' )
273-
272+ self ._write ('fefe0226fa ' )
273+
274274 def resume (self ):
275- self ._write ('fe fe 02 28 fa ' )
275+ self ._write ('fefe0228fa ' )
276276
277277 def stop (self ):
278- self ._write ('fe fe 02 29 fa ' )
278+ self ._write ('fefe0229fa ' )
279279
280280 def is_paused (self ):
281- self ._write ('fe fe 02 27 fa ' )
281+ self ._write ('fefe0227fa ' )
282282 data = self ._read ()
283283 flag = int (data .hex (), 16 )
284284 return False if flag else True
285-
285+
286286 def is_in_position (self , coords ):
287287 if len (coords ) != 6 :
288288 print ('The lenght of coords is not right' )
289289 return
290- command = 'fe fe 0d 2a '
290+ command = 'fefe0d2a '
291291 for coord in coords :
292292 _hex = self ._coord_to_hex (coord )
293293
@@ -301,7 +301,7 @@ def is_in_position(self, coords):
301301 return False if flag else True
302302
303303 def get_speed (self ):
304- self ._write ('fe fe 02 40 fa ' )
304+ self ._write ('fefe0240fa ' )
305305 data = self ._read ()
306306 if data :
307307 return int (data .hex (), 16 )
@@ -316,29 +316,37 @@ def set_speed(self, speed):
316316 if not 0 <= speed <= 100 :
317317 raise Exception ('speed value out of range (0 ~ 100)' )
318318 _hex = str (hex (speed ))[2 :]
319- self ._write ('fe fe 03 41 {} fa' .format (_hex ))
319+ self ._write ('fefe0341{} fa' .format (_hex ))
320320
321321 def _parse_data (self , data , name ):
322322 data_list = []
323323 data = data .hex ()
324324 data = data [- 28 :]
325- if not (data .startswith ('20' ) and data .endswith ('fa' )):
326- return []
327325 if name == 'get_angles' :
326+ if not (data .startswith ('20' ) and data .endswith ('fa' )):
327+ return []
328328 data = data [- 26 :- 2 ]
329329 for i in range (6 ):
330330 _hex = data [i * 4 : (i * 4 ) + 4 ]
331331 degree = self ._hex_to_degree (_hex )
332332 data_list .append (degree )
333333
334334 elif name == 'get_coords' :
335+ if not (data .startswith ('23' ) and data .endswith ('fa' )):
336+ return []
335337 data = data [- 26 :- 2 ]
336- for i in range (6 ):
338+ for i in range (3 ):
337339 _hex = data [i * 4 : (i * 4 ) + 4 ]
338340 _coord = self ._hex_to_int (_hex ) / 10.0
339341 data_list .append (_coord )
342+ for i in range (3 , 6 ):
343+ _hex = data [i * 4 : (i * 4 ) + 4 ]
344+ _coord = self ._hex_to_int (_hex ) / 1000.0
345+ data_list .append (_coord )
340346
341347 elif name == 'get_angles_of_radian' :
348+ if not (data .startswith ('20' ) and data .endswith ('fa' )):
349+ return []
342350 data = data [- 26 :- 2 ]
343351 for i in range (6 ):
344352 _hex = data [i * 4 : (i * 4 ) + 4 ]
@@ -350,7 +358,7 @@ def _parse_data(self, data, name):
350358 def _hex_to_degree (self , _hex : str ):
351359 _int = self ._hex_to_int (_hex )
352360 return _int * 18 / 314
353-
361+
354362 def _hex_to_int (self , _hex : str ):
355363 _int = int (_hex , 16 )
356364 if _int > 0x8000 :
@@ -378,7 +386,7 @@ def _coord_to_hex(self, coord):
378386 s = str (hex (coord ))[2 :]
379387 s = self ._complement_zero (s )
380388 return s
381-
389+
382390 def _complement_zero (self , s , digit = 4 ):
383391 s_len = len (s )
384392 if s_len == digit :
0 commit comments