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

Basic profiled position #95

Open
wants to merge 2 commits 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
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ enum DeviceState
STATE_OPERATION_ENABLED,
STATE_QUICK_STOP_ACTIVE,
STATE_FAULT_REACTION_ACTIVE,
STATE_FAULT
STATE_FAULT,
STATE_NEW_TARGET,
STATE_NEW_TARGET_RESET
};

enum ModeOfOperation
Expand All @@ -65,7 +67,9 @@ const std::map<DeviceState, std::string> DEVICE_STATE_STR = {
{STATE_QUICK_STOP_ACTIVE, "Quick Stop Active"},
{STATE_FAULT_REACTION_ACTIVE, "Fault Reaction Active"},
{STATE_FAULT, "Fault"},
{STATE_UNDEFINED, "Undefined State"}
{STATE_UNDEFINED, "Undefined State"},
{STATE_NEW_TARGET, "STATE_NEW_TARGET"},
{STATE_NEW_TARGET_RESET, "STATE_NEW_TARGET_RESET"}
};

#endif // ETHERCAT_GENERIC_PLUGINS__CIA402_COMMON_DEFS_HPP_
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,9 @@ class EcCiA402Drive : public GenericEcSlave
bool auto_state_transitions_ = true;
bool fault_reset_ = false;
int fault_reset_command_interface_index_ = -1;
int position_command_interface_index_ = -1;
bool last_fault_reset_command_ = false;
double previous_target_ = -1;
double last_position_ = std::numeric_limits<double>::quiet_NaN();

/** returns device state based upon the status_word */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,27 @@ void EcCiA402Drive::processData(size_t index, uint8_t * domain_address)
if (auto_state_transitions_) {
pdo_channels_info_[index].default_value = transition(
state_,
pdo_channels_info_[index].ec_read(domain_address));
pdo_channels_info_[index].ec_read(domain_address)
);
if(mode_of_operation_ == ModeOfOperation::MODE_PROFILED_POSITION) {
// Send New Target triggers if target position changes
if(state_ == STATE_OPERATION_ENABLED && position_command_interface_index_ >= 0) {
uint16_t control_word = pdo_channels_info_[index].default_value;
double target_position = command_interface_ptr_->at(position_command_interface_index_);
if(!std::isnan(target_position) && target_position == previous_target_ && (control_word & 0b00010000) == 0b00000000) {
pdo_channels_info_[index].default_value = transition(
STATE_NEW_TARGET,
pdo_channels_info_[index].ec_read(domain_address)
);
} else if((!std::isnan(target_position) || !std::isnan(previous_target_)) && previous_target_ != target_position) {
previous_target_ = target_position;
pdo_channels_info_[index].default_value = transition(
STATE_NEW_TARGET_RESET,
pdo_channels_info_[index].ec_read(domain_address)
);
}
}
}
}
}
}
Expand All @@ -61,7 +81,7 @@ void EcCiA402Drive::processData(size_t index, uint8_t * domain_address)
pdo_channels_info_[index].offset;
}
pdo_channels_info_[index].override_command =
(mode_of_operation_display_ != ModeOfOperation::MODE_CYCLIC_SYNC_POSITION) ? true : false;
(mode_of_operation_display_ != ModeOfOperation::MODE_CYCLIC_SYNC_POSITION && mode_of_operation_display_ != ModeOfOperation::MODE_PROFILED_POSITION) ? true : false;
}

// setup mode of operation
Expand Down Expand Up @@ -135,6 +155,10 @@ bool EcCiA402Drive::setupSlave(
fault_reset_command_interface_index_ = std::stoi(paramters_["command_interface/reset_fault"]);
}

if (paramters_.find("command_interface/position") != paramters_.end()) {
position_command_interface_index_ = std::stoi(paramters_["command_interface/position"]);
}

return true;
}

Expand Down Expand Up @@ -206,6 +230,10 @@ uint16_t EcCiA402Drive::transition(DeviceState state, uint16_t control_word)
return (control_word & 0b01110111) | 0b00000111;
case STATE_SWITCH_ON: // -> STATE_OPERATION_ENABLED
return (control_word & 0b01111111) | 0b00001111;
case STATE_NEW_TARGET:
return control_word | 0b00010000;
case STATE_NEW_TARGET_RESET:
return control_word & 0b11101111;
case STATE_OPERATION_ENABLED: // -> GOOD
return control_word;
case STATE_QUICK_STOP_ACTIVE: // -> STATE_OPERATION_ENABLED
Expand Down