Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set/Get regeneration-current-limit #18

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions SoloPy/ConstantCanopen.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,3 +81,5 @@
Object_MotionProfileVariable3 = 0x3042
Object_MotionProfileVariable4 = 0x3043
Object_MotionProfileVariable5 = 0x3044

Object_RegenerationCurrentLimit = 0x304B
6 changes: 5 additions & 1 deletion SoloPy/ConstantUart.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@
WriteMotionProfileVariable4 = 0x34
WriteMotionProfileVariable5 = 0x35

WriteRegenerationCurrentLimit = 0x39

ReadDeviceAddress = 0x81
ReadPhaseAVoltage = 0x82
ReadPhaseBVoltage = 0x83
Expand Down Expand Up @@ -139,4 +141,6 @@
ReadMotionProfileVariable2 = 0xBD
ReadMotionProfileVariable3 = 0xBE
ReadMotionProfileVariable4 = 0xBF
ReadMotionProfileVariable5 = 0xC0
ReadMotionProfileVariable5 = 0xC0

ReadRegenerationCurrentLimit = 0xC8
33 changes: 33 additions & 0 deletions SoloPy/SOLOMotorControllersCanopen.py
Original file line number Diff line number Diff line change
Expand Up @@ -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---------------------
# ----------------------------------------------
Expand Down Expand Up @@ -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
35 changes: 35 additions & 0 deletions SoloPy/SOLOMotorControllersUart.py
Original file line number Diff line number Diff line change
Expand Up @@ -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---------------------
# ----------------------------------------------
Expand Down Expand Up @@ -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
5 changes: 5 additions & 0 deletions SoloPy/SOLOMotorControllersUtils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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, ""