diff --git a/SoloPy/ConstantCanopen.py b/SoloPy/ConstantCanopen.py index 50853bc..1c70d7f 100644 --- a/SoloPy/ConstantCanopen.py +++ b/SoloPy/ConstantCanopen.py @@ -81,3 +81,5 @@ Object_MotionProfileVariable3 = 0x3042 Object_MotionProfileVariable4 = 0x3043 Object_MotionProfileVariable5 = 0x3044 + +Object_RegenerationCurrentLimit = 0x304B diff --git a/SoloPy/ConstantUart.py b/SoloPy/ConstantUart.py index e62c335..d4808c6 100644 --- a/SoloPy/ConstantUart.py +++ b/SoloPy/ConstantUart.py @@ -73,6 +73,8 @@ WriteMotionProfileVariable4 = 0x34 WriteMotionProfileVariable5 = 0x35 +WriteRegenerationCurrentLimit = 0x39 + ReadDeviceAddress = 0x81 ReadPhaseAVoltage = 0x82 ReadPhaseBVoltage = 0x83 @@ -139,4 +141,6 @@ ReadMotionProfileVariable2 = 0xBD ReadMotionProfileVariable3 = 0xBE ReadMotionProfileVariable4 = 0xBF -ReadMotionProfileVariable5 = 0xC0 \ No newline at end of file +ReadMotionProfileVariable5 = 0xC0 + +ReadRegenerationCurrentLimit = 0xC8 diff --git a/SoloPy/SOLOMotorControllersCanopen.py b/SoloPy/SOLOMotorControllersCanopen.py index b5ab3d6..3db10af 100644 --- a/SoloPy/SOLOMotorControllersCanopen.py +++ b/SoloPy/SOLOMotorControllersCanopen.py @@ -1170,6 +1170,24 @@ def set_motion_profile_variable5(self, motion_profile_variable5: float) -> list: result, error = self.CANOpenTransmit( self._address, ConstantCanopen.Object_MotionProfileVariable5, informationToSend) return result, error + + ## + #@brief This command defines the maximum allowed regeneration current sent back from the + # Motor to the Power Supply during decelerations + # .The method refers to the Object Dictionary: 0x304B + #@param regeneration_current_limit a float value [Amps] + #@retval List of [bool 0 fail / 1 for success, ERROR class/enumeration] + def set_regeneration_current_limit(self, regeneration_current_limit: float) -> list: + error = ERROR.NO_PROCESSED_COMMAND + InputValidate, error, logMsg = set_regeneration_current_limit_input_validation(regeneration_current_limit) + if (InputValidate is False): + self._logger.info(logMsg) + return False, error + regeneration_current_limit = float(regeneration_current_limit) + informationToSend = convert_to_data(regeneration_current_limit, DATA_TYPE.SFXT) + result, error = self.CANOpenTransmit( + self._address, ConstantCanopen.Object_RegenerationCurrentLimit, informationToSend) + return result, error # ---------------------------------------------- # ---------------------Read--------------------- # ---------------------------------------------- @@ -2074,3 +2092,18 @@ def get_motion_profile_variable5(self) -> list: if (error == ERROR.NO_ERROR_DETECTED) and (result is True): return convert_from_data(informationReceived, DATA_TYPE.SFXT), error return -1.0, error + + ## + #@brief This command reads the value of the regeneration current sent back from the + # Motor to the Power Supply during decelerations + # .The method refers to the Object Dictionary: 0x304B + #@retval List of [float [Amps], ERROR class/enumeration] + def get_current_limit(self) -> list: + informationToSend = [0x00, 0x00, 0x00, 0x00] + informationReceived = [] + error = ERROR.NO_PROCESSED_COMMAND + result, error, informationReceived = self.CANOpenReceive( + self._address, ConstantCanopen.Object_RegenerationCurrentLimit, informationToSend) + if (error == ERROR.NO_ERROR_DETECTED) and (result is True): + return convert_from_data(informationReceived, DATA_TYPE.SFXT), error + return -1.0, error \ No newline at end of file diff --git a/SoloPy/SOLOMotorControllersUart.py b/SoloPy/SOLOMotorControllersUart.py index a357a30..6873224 100644 --- a/SoloPy/SOLOMotorControllersUart.py +++ b/SoloPy/SOLOMotorControllersUart.py @@ -1128,6 +1128,26 @@ def set_motion_profile_variable5(self, motion_profile_variable5: float) -> list: data[0], data[1], data[2], data[3]] return self.__exec_cmd(cmd) + ## + #@brief This command reads the value of the regeneration current sent back from the + # Motor to the Power Supply during decelerations + # .The method refers to the Uart Write command: 0xC8 + #@param current_limit a float value [Amps] + #@retval List of [bool 0 fail / 1 for success, ERROR class/enumeration] + def set_regeneration_current_limit(self, regeneration_current_limit: float) -> list: + error = ERROR.NO_PROCESSED_COMMAND + InputValidate, error, logMsg = set_regeneration_current_limit_input_validation(regeneration_current_limit) + if (InputValidate is False): + self._logger.info(logMsg) + return False, error + + regeneration_current_limit = float(regeneration_current_limit) + data = convert_to_data(regeneration_current_limit, DATA_TYPE.SFXT) + cmd = [self._address, ConstantUart.WriteRegenerationCurrentLimit, + data[0], data[1], data[2], data[3]] + + return self.__exec_cmd(cmd) + # ---------------------------------------------- # ---------------------Read--------------------- # ---------------------------------------------- @@ -1997,3 +2017,18 @@ def get_motion_profile_variable5(self) -> list: return convert_from_data(data, DATA_TYPE.SFXT), ERROR.NO_ERROR_DETECTED else: return -1, error + + ## + #@brief This command reads the value of the regeneration current sent back from the + # Motor to the Power Supply during decelerations + # .The method refers to the Uart Read command: 0x39 + #@retval List of [float [Amps], ERROR class/enumeration] + def get_regeneration_current_limit(self) -> list: + cmd = [self._address, ConstantUart.ReadRegenerationCurrentLimit, + 0x00, 0x00, 0x00, 0x00] + result, error = self.__exec_cmd(cmd) + if (result): + data = get_data(cmd) + return convert_from_data(data, DATA_TYPE.SFXT), ERROR.NO_ERROR_DETECTED + else: + return -1, error diff --git a/SoloPy/SOLOMotorControllersUtils.py b/SoloPy/SOLOMotorControllersUtils.py index dc22e4c..38da611 100644 --- a/SoloPy/SOLOMotorControllersUtils.py +++ b/SoloPy/SOLOMotorControllersUtils.py @@ -383,4 +383,9 @@ def set_motion_profile_variable4_input_validation(motion_profile_variable4: floa def set_motion_profile_variable5_input_validation(motion_profile_variable5: float) -> list: if (motion_profile_variable5 < 0 or motion_profile_variable5 > 16000): return False, ERROR.OUT_OF_RANGE_SETTING, ConstantCommon.InputOutOfRange + return True, ERROR.NO_ERROR_DETECTED, "" + +def set_regeneration_current_limit_input_validation(regeneration_current_limit : float) -> list: + if (regeneration_current_limit < 0 or regeneration_current_limit > 32): + return False, ERROR.OUT_OF_RANGE_SETTING, ConstantCommon.InputOutOfRange return True, ERROR.NO_ERROR_DETECTED, "" \ No newline at end of file