-
Notifications
You must be signed in to change notification settings - Fork 3
Feature/pm 524 Generalize motor controller #284
base: develop
Are you sure you want to change the base?
Changes from all commits
6abd775
c8f3af5
f07ebf8
1db4b01
7cf1336
9d320e5
fffab68
ae33d44
00e9bad
2e1b2f4
ef553b9
a60801f
087227e
9d8bc65
81423e5
5e73645
f0c296f
ea89e8e
03c994a
df36bbf
5edecb5
58fbd2f
855e436
e68a574
0a1c16a
c49c6b3
0fbe358
4f66858
b48674d
81f0db4
41257c8
79a93a3
1e55adb
ea171c0
9b5cc5c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,7 +24,7 @@ namespace march | |
class EthercatMaster | ||
{ | ||
public: | ||
EthercatMaster(std::string ifname, int max_slave_index, int cycle_time, int slave_timeout); | ||
EthercatMaster(std::string ifname, std::vector<std::shared_ptr<Slave>>, int cycle_time, int slave_timeout); | ||
~EthercatMaster(); | ||
|
||
/* Delete copy constructor/assignment since the member thread can not be copied */ | ||
|
@@ -45,12 +45,20 @@ class EthercatMaster | |
*/ | ||
int getCycleTime() const; | ||
|
||
/** | ||
* Returns the largest slave index. | ||
*/ | ||
int getMaxSlaveIndex(); | ||
|
||
bool hasValidSlaves(); | ||
|
||
/** | ||
* Initializes the ethercat train and starts a thread for the loop. | ||
* @throws HardwareException If not the configured amount of slaves was found | ||
* or they did not all reach operational state | ||
* @returns true if one of the slaves requires resetting ethercat, false otherwise | ||
*/ | ||
bool start(std::vector<Joint>& joints); | ||
bool start(); | ||
|
||
/** | ||
* Stops the ethercat loop and joins the thread. | ||
|
@@ -67,8 +75,10 @@ class EthercatMaster | |
|
||
/** | ||
* Configures the found slaves to operational state. | ||
* | ||
* @returns true if one of the slaves requires resetting ethercat, false otherwise | ||
*/ | ||
bool ethercatSlaveInitiation(std::vector<Joint>& joints); | ||
bool ethercatSlaveInitiation(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you explain why the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See above |
||
|
||
/** | ||
* The ethercat train PDO loop. If the working counter is lower than | ||
|
@@ -112,6 +122,7 @@ class EthercatMaster | |
std::atomic<bool> is_operational_; | ||
|
||
const std::string ifname_; | ||
std::vector<std::shared_ptr<Slave>> slave_list_; | ||
const int max_slave_index_; | ||
const int cycle_time_ms_; | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,10 +7,10 @@ | |
#include <utility> | ||
#include <vector> | ||
|
||
#include <march_hardware/imotioncube/imotioncube.h> | ||
#include <march_hardware/motor_controller/imotioncube/imotioncube.h> | ||
#include <march_hardware/power/power_distribution_board.h> | ||
#include <march_hardware/temperature/temperature_ges.h> | ||
#include <march_hardware/imotioncube/imotioncube_state.h> | ||
#include <march_hardware/motor_controller/motor_controller_states.h> | ||
|
||
namespace march | ||
{ | ||
|
@@ -26,107 +26,57 @@ class Joint | |
/** | ||
* Initializes a Joint with motor controller and without temperature slave. | ||
*/ | ||
Joint(std::string name, int net_number, bool allow_actuation, std::unique_ptr<IMotionCube> imc); | ||
Joint(std::string name, int net_number, bool allow_actuation, std::shared_ptr<MotorController> controller); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why has this been changed from a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same reason for the ges, there is now one pointer in EthercatMaster, and one in the MarchRobot |
||
|
||
/** | ||
* Initializes a Joint with motor controller and temperature slave. | ||
*/ | ||
Joint(std::string name, int net_number, bool allow_actuation, std::unique_ptr<IMotionCube> imc, | ||
std::unique_ptr<TemperatureGES> temperature_ges); | ||
Joint(std::string name, int net_number, bool allow_actuation, std::shared_ptr<MotorController> controller, | ||
std::shared_ptr<TemperatureGES> temperature_ges); | ||
|
||
virtual ~Joint() noexcept = default; | ||
|
||
/* Delete copy constructor/assignment since the unique_ptr cannot be copied */ | ||
/* Delete copy constructor/assignment since the shared_ptr cannot be copied */ | ||
Joint(const Joint&) = delete; | ||
Joint& operator=(const Joint&) = delete; | ||
|
||
void resetIMotionCube(); | ||
void resetMotorController(); | ||
|
||
/* Delete move assignment since string cannot be move assigned */ | ||
Joint(Joint&&) = default; | ||
Joint& operator=(Joint&&) = delete; | ||
|
||
bool initialize(int cycle_time); | ||
void prepareActuation(); | ||
|
||
void actuateRad(double target_position); | ||
void actuateTorque(int16_t target_torque); | ||
void actuateTorque(double target_torque); | ||
void readEncoders(const ros::Duration& elapsed_time); | ||
|
||
double getPosition() const; | ||
double getVelocity() const; | ||
double getVoltageVelocity() const; | ||
double getIncrementalPosition() const; | ||
double getAbsolutePosition() const; | ||
int16_t getTorque(); | ||
int32_t getAngleIUAbsolute(); | ||
int32_t getAngleIUIncremental(); | ||
double getVelocityIUAbsolute(); | ||
double getVelocityIUIncremental(); | ||
double getTorque(); | ||
float getTemperature(); | ||
IMotionCubeState getIMotionCubeState(); | ||
std::unique_ptr<MotorControllerStates> getMotorControllerStates(); | ||
|
||
std::string getName() const; | ||
int getTemperatureGESSlaveIndex() const; | ||
int getIMotionCubeSlaveIndex() const; | ||
int getNetNumber() const; | ||
|
||
ActuationMode getActuationMode() const; | ||
|
||
bool hasIMotionCube() const; | ||
bool hasMotorController() const; | ||
Roelemans marked this conversation as resolved.
Show resolved
Hide resolved
|
||
bool hasTemperatureGES() const; | ||
bool canActuate() const; | ||
bool receivedDataUpdate(); | ||
void setAllowActuation(bool allow_actuation); | ||
|
||
/** @brief Override comparison operator */ | ||
friend bool operator==(const Joint& lhs, const Joint& rhs) | ||
{ | ||
return lhs.name_ == rhs.name_ && ((lhs.imc_ && rhs.imc_ && *lhs.imc_ == *rhs.imc_) || (!lhs.imc_ && !rhs.imc_)) && | ||
((lhs.temperature_ges_ && rhs.temperature_ges_ && *lhs.temperature_ges_ == *rhs.temperature_ges_) || | ||
(!lhs.temperature_ges_ && !rhs.temperature_ges_)) && | ||
lhs.allow_actuation_ == rhs.allow_actuation_ && | ||
lhs.getActuationMode().getValue() == rhs.getActuationMode().getValue(); | ||
} | ||
|
||
friend bool operator!=(const Joint& lhs, const Joint& rhs) | ||
{ | ||
return !(lhs == rhs); | ||
} | ||
/** @brief Override stream operator for clean printing */ | ||
friend ::std::ostream& operator<<(std::ostream& os, const Joint& joint) | ||
{ | ||
os << "name: " << joint.name_ << ", " | ||
<< "ActuationMode: " << joint.getActuationMode().toString() << ", " | ||
<< "allowActuation: " << joint.allow_actuation_ << ", " | ||
<< "imotioncube: "; | ||
if (joint.imc_) | ||
{ | ||
os << *joint.imc_; | ||
} | ||
else | ||
{ | ||
os << "none"; | ||
} | ||
|
||
os << ", temperatureges: "; | ||
if (joint.temperature_ges_) | ||
{ | ||
os << *joint.temperature_ges_; | ||
} | ||
else | ||
{ | ||
os << "none"; | ||
} | ||
|
||
return os; | ||
} | ||
|
||
private: | ||
const std::string name_; | ||
const int net_number_; | ||
bool allow_actuation_ = false; | ||
float previous_imc_volt_ = 0.0; | ||
float previous_controller_volt_ = 0.0; | ||
float previous_motor_current_ = 0.0; | ||
float previous_motor_volt_ = 0.0; | ||
double previous_absolute_position_ = 0.0; | ||
|
@@ -139,8 +89,8 @@ class Joint | |
double absolute_position_ = 0.0; | ||
double velocity_ = 0.0; | ||
|
||
std::unique_ptr<IMotionCube> imc_ = nullptr; | ||
std::unique_ptr<TemperatureGES> temperature_ges_ = nullptr; | ||
std::shared_ptr<MotorController> controller_ = nullptr; | ||
std::shared_ptr<TemperatureGES> temperature_ges_ = nullptr; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why has this been changed to a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Because I now pass a list of ethercat slaves to ethercat_master (so that march_robot does not need to know which joints are ethercat slaves, and because it makes more sense anyway). So now there are two or three pointers to a a Ges, on in the EthercatMaster, and one in one or two of the joints (previously, the two joints had two separate ges objects for the same ges). |
||
}; | ||
|
||
} // namespace march | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you explain why the
joints
parameter has been removed and what the return value of this function indicates?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Previously, the joints parameter was used by the ethercat master to access the ethercat slaves to call initSdo on each. The EthercatMaster is now passed a list of ethercat slaves at initiation, making joints parameter unnecessary. The return value is now explained in the docstring