Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 from .robotis_def import *
00023
00024
00025 class GroupSyncWrite:
00026 def __init__(self, port, ph, start_address, data_length):
00027 self.port = port
00028 self.ph = ph
00029 self.start_address = start_address
00030 self.data_length = data_length
00031
00032 self.is_param_changed = False
00033 self.param = []
00034 self.data_dict = {}
00035
00036 self.clearParam()
00037
00038 def makeParam(self):
00039 if not self.data_dict:
00040 return
00041
00042 self.param = []
00043
00044 for dxl_id in self.data_dict:
00045 if not self.data_dict[dxl_id]:
00046 return
00047
00048 self.param.append(dxl_id)
00049 self.param.extend(self.data_dict[dxl_id])
00050
00051 def addParam(self, dxl_id, data):
00052 if dxl_id in self.data_dict:
00053 return False
00054
00055 if len(data) > self.data_length:
00056 return False
00057
00058 self.data_dict[dxl_id] = data
00059
00060 self.is_param_changed = True
00061 return True
00062
00063 def removeParam(self, dxl_id):
00064 if dxl_id not in self.data_dict:
00065 return
00066
00067 del self.data_dict[dxl_id]
00068
00069 self.is_param_changed = True
00070
00071 def changeParam(self, dxl_id, data):
00072 if dxl_id not in self.data_dict:
00073 return False
00074
00075 if len(data) > self.data_length:
00076 return False
00077
00078 self.data_dict[dxl_id] = data
00079
00080 self.is_param_changed = True
00081 return True
00082
00083 def clearParam(self):
00084 self.data_dict.clear()
00085
00086 def txPacket(self):
00087 if len(self.data_dict.keys()) == 0:
00088 return COMM_NOT_AVAILABLE
00089
00090 if self.is_param_changed is True or not self.param:
00091 self.makeParam()
00092
00093 return self.ph.syncWriteTxOnly(self.port, self.start_address, self.data_length, self.param,
00094 len(self.data_dict.keys()) * (1 + self.data_length))