Skip to content
This repository has been archived by the owner on Dec 1, 2020. It is now read-only.

Feature/pm 524 Generalize motor controller #284

Draft
wants to merge 35 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 26 commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
6abd775
Create MotorController abstract class
Roelemans Jul 16, 2020
c8f3af5
Merge branch 'develop' into feature/PM-524-add-odrive-option
Roelemans Aug 5, 2020
f07ebf8
Have Joint.cpp use controller instead of imc
Roelemans Aug 6, 2020
1db4b01
Generalise hardware_builder, hardware_interface and ehtercat master a…
Roelemans Aug 7, 2020
7cf1336
Fix tests #1
Roelemans Aug 7, 2020
9d320e5
Fix tests #2
Roelemans Aug 8, 2020
fffab68
Throw a fatal when a joint has no controller defined and remove runti…
Roelemans Aug 8, 2020
ae33d44
Fix error msg
Roelemans Aug 11, 2020
00e9bad
Fix typos
Roelemans Aug 11, 2020
2e1b2f4
Merge branch 'develop' into feature/PM-524-add-odrive-option
Roelemans Aug 11, 2020
ef553b9
Namechange MotorControllerState to MotorControllerStates
Roelemans Aug 11, 2020
a60801f
Fix clang
Roelemans Aug 11, 2020
087227e
Remove tests untill it works
Roelemans Aug 12, 2020
9d8bc65
Fix build
Roelemans Aug 12, 2020
81423e5
Generalise imc_state change some naming and add docstrings
Roelemans Aug 13, 2020
5e73645
Moved checkState and getErrorStatus from MotorController to MotorCont…
Roelemans Aug 13, 2020
f0c296f
Clang
Roelemans Aug 13, 2020
ea89e8e
Reduce ethercat dependency in naming
Roelemans Aug 14, 2020
03c994a
Merge branch 'develop' into feature/PM-524-add-odrive-option
Roelemans Aug 14, 2020
df36bbf
Mock motor controller and fix bugs
Roelemans Aug 14, 2020
5edecb5
Revert generalise ethercat naming
Roelemans Aug 21, 2020
58fbd2f
Use Ampere instead of IU for torque, and change input/return type of …
Roelemans Aug 21, 2020
855e436
Rename variable in header
Roelemans Aug 21, 2020
e68a574
Return smart pointer instead of reference and minor fixes
Roelemans Aug 24, 2020
0a1c16a
Return smart pointer instead of reference and minor fixes #2
Roelemans Aug 24, 2020
c49c6b3
Merge branch 'develop' into feature/PM-524-add-odrive-option
Roelemans Aug 25, 2020
0fbe358
Create slave_list object
Roelemans Aug 25, 2020
4f66858
Pass a slave list to ethercat master
Roelemans Aug 25, 2020
b48674d
Fix tests
Roelemans Aug 25, 2020
81f0db4
Fix tests
Roelemans Aug 25, 2020
41257c8
Remove initialize from Joint and MotorController
Roelemans Aug 25, 2020
79a93a3
Move hasValidSlaves() to ethercat master
Roelemans Aug 25, 2020
1e55adb
Remove getSlaveIndex from MotorController
Roelemans Aug 25, 2020
ea171c0
Actually use make_shared for shared_ptrs
Roelemans Aug 26, 2020
9b5cc5c
Add docstring
Roelemans Aug 26, 2020
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
13 changes: 8 additions & 5 deletions march_hardware/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,13 @@ add_library(${PROJECT_NAME}
include/${PROJECT_NAME}/ethercat/pdo_types.h
include/${PROJECT_NAME}/ethercat/sdo_interface.h
include/${PROJECT_NAME}/ethercat/slave.h
include/${PROJECT_NAME}/imotioncube/actuation_mode.h
include/${PROJECT_NAME}/imotioncube/imotioncube.h
include/${PROJECT_NAME}/imotioncube/imotioncube_state.h
include/${PROJECT_NAME}/imotioncube/imotioncube_target_state.h
include/${PROJECT_NAME}/motor_controller/actuation_mode.h
include/${PROJECT_NAME}/motor_controller/imotioncube/imotioncube.h
include/${PROJECT_NAME}/motor_controller/imotioncube/imotioncube_states.h
include/${PROJECT_NAME}/motor_controller/imotioncube/imotioncube_state_of_operation.h
include/${PROJECT_NAME}/motor_controller/imotioncube/imotioncube_target_state.h
include/${PROJECT_NAME}/motor_controller/motor_controller.h
include/${PROJECT_NAME}/motor_controller/motor_controller_states.h
include/${PROJECT_NAME}/joint.h
include/${PROJECT_NAME}/march_robot.h
include/${PROJECT_NAME}/power/boot_shutdown_offsets.h
Expand Down Expand Up @@ -123,7 +126,7 @@ if(CATKIN_ENABLE_TESTING)
test/joint_test.cpp
test/mocks/mock_absolute_encoder.h
test/mocks/mock_encoder.h
test/mocks/mock_imotioncube.h
test/mocks/mock_motor_controller.h
test/mocks/mock_incremental_encoder.h
test/mocks/mock_joint.h
test/mocks/mock_pdo_interface.h
Expand Down
2 changes: 1 addition & 1 deletion march_hardware/include/march_hardware/ethercat/slave.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class Slave : public PdoSlaveInterface

~Slave() noexcept override = default;

uint16_t getSlaveIndex() const
int getSlaveIndex() const
Roelemans marked this conversation as resolved.
Show resolved Hide resolved
{
return this->slave_index_;
}
Expand Down
45 changes: 17 additions & 28 deletions march_hardware/include/march_hardware/joint.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -26,12 +26,12 @@ 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::unique_ptr<MotorController> controller);

/**
* Initializes a Joint with motor controller and 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::unique_ptr<MotorController> controller,
std::unique_ptr<TemperatureGES> temperature_ges);

virtual ~Joint() noexcept = default;
Expand All @@ -40,7 +40,7 @@ class Joint
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;
Expand All @@ -50,30 +50,26 @@ class Joint
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 getMotorControllerSlaveIndex() 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();
Expand All @@ -82,7 +78,10 @@ class Joint
/** @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_)) &&
return lhs.name_ == rhs.name_ &&
((lhs.controller_ && rhs.controller_ &&
lhs.controller_->getSlaveIndex() == rhs.controller_->getSlaveIndex()) ||
(!lhs.controller_ && !rhs.controller_)) &&
((lhs.temperature_ges_ && rhs.temperature_ges_ && *lhs.temperature_ges_ == *rhs.temperature_ges_) ||
(!lhs.temperature_ges_ && !rhs.temperature_ges_)) &&
lhs.allow_actuation_ == rhs.allow_actuation_ &&
Expand All @@ -99,17 +98,7 @@ class 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: ";
<< "imotioncube slave index: " << joint.getMotorControllerSlaveIndex() << ", temperatureges: ";
if (joint.temperature_ges_)
{
os << *joint.temperature_ges_;
Expand All @@ -126,7 +115,7 @@ class Joint
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;
Expand All @@ -139,7 +128,7 @@ class Joint
double absolute_position_ = 0.0;
double velocity_ = 0.0;

std::unique_ptr<IMotionCube> imc_ = nullptr;
std::unique_ptr<MotorController> controller_ = nullptr;
Olavhaasie marked this conversation as resolved.
Show resolved Hide resolved
std::unique_ptr<TemperatureGES> temperature_ges_ = nullptr;
};

Expand Down
4 changes: 2 additions & 2 deletions march_hardware/include/march_hardware/march_robot.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ class MarchRobot
MarchRobot(MarchRobot&&) = delete;
MarchRobot& operator=(MarchRobot&&) = delete;

void resetIMotionCubes();
void resetMotorControllers();

void startEtherCAT(bool reset_imc);
void startEtherCAT(bool reset_motor_controllers);

void stopEtherCAT();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@

#ifndef MARCH_HARDWARE_IMOTIONCUBE_H
#define MARCH_HARDWARE_IMOTIONCUBE_H
#include "actuation_mode.h"
#include "march_hardware/motor_controller/actuation_mode.h"
#include "march_hardware/ethercat/pdo_map.h"
#include "march_hardware/ethercat/pdo_types.h"
#include "march_hardware/ethercat/sdo_interface.h"
#include "march_hardware/ethercat/slave.h"
#include "imotioncube_state.h"
#include "march_hardware/motor_controller/motor_controller.h"
#include "march_hardware/motor_controller/motor_controller_states.h"
#include "imotioncube_target_state.h"
#include "march_hardware/encoder/absolute_encoder.h"
#include "march_hardware/encoder/incremental_encoder.h"
Expand All @@ -18,7 +19,7 @@

namespace march
{
class IMotionCube : public Slave
class IMotionCube : public MotorController, public Slave
{
public:
/**
Expand All @@ -36,42 +37,48 @@ class IMotionCube : public Slave
std::unique_ptr<IncrementalEncoder> incremental_encoder, std::string& sw_stream,
ActuationMode actuation_mode);

~IMotionCube() noexcept override = default;
virtual ~IMotionCube() noexcept override = default;

/* Delete copy constructor/assignment since the unique_ptrs cannot be copied */
IMotionCube(const IMotionCube&) = delete;
IMotionCube& operator=(const IMotionCube&) = delete;

virtual double getAngleRadAbsolute();
virtual double getAngleRadIncremental();
virtual double getAngleRadAbsolute() override;
virtual double getAngleRadIncremental() override;
double getAbsoluteRadPerBit() const;
double getIncrementalRadPerBit() const;
int16_t getTorque();
bool getIncrementalMorePrecise() const override;
double getTorque() override;
int32_t getAngleIUAbsolute();
int32_t getAngleIUIncremental();
double getVelocityIUAbsolute();
double getVelocityIUIncremental();
virtual double getVelocityRadAbsolute();
virtual double getVelocityRadIncremental();
virtual double getVelocityRadAbsolute() override;
virtual double getVelocityRadIncremental() override;

uint16_t getStatusWord();
uint16_t getMotionError();
uint16_t getDetailedError();
uint16_t getSecondDetailedError();

ActuationMode getActuationMode() const;
ActuationMode getActuationMode() const override;

virtual float getMotorCurrent();
virtual float getIMCVoltage();
virtual float getMotorVoltage();
virtual float getMotorCurrent() override;
virtual float getMotorControllerVoltage() override;
virtual float getMotorVoltage() override;

void setControlWord(uint16_t control_word);
std::unique_ptr<MotorControllerStates> getStates() override;

virtual void actuateRad(double target_rad);
virtual void actuateTorque(int16_t target_torque);
void setControlWord(uint16_t control_word);
virtual void actuateRad(double target_rad) override;
virtual void actuateTorque(double target_torque_ampere) override;

bool initialize(int cycle_time) override;
void goToTargetState(IMotionCubeTargetState target_state);
virtual void goToOperationEnabled();
virtual void prepareActuation() override;

int getSlaveIndex() const override;
virtual void reset() override;

/** @brief Override comparison operator */
friend bool operator==(const IMotionCube& lhs, const IMotionCube& rhs)
Expand All @@ -90,7 +97,9 @@ class IMotionCube : public Slave
constexpr static double MAX_TARGET_DIFFERENCE = 0.393;
// This value is slightly larger than the current limit of the
// linear joints defined in the URDF.
const static int16_t MAX_TARGET_TORQUE = 23500;
constexpr static double IPEAK = 40;
// See CoE manual page 222
constexpr static double AMPERE_TO_IU_FACTOR = 65520;

// Watchdog base time = 1 / 25 MHz * (2498 + 2) = 0.0001 seconds=100 µs
static const uint16_t WATCHDOG_DIVIDER = 2498;
Expand All @@ -104,6 +113,7 @@ class IMotionCube : public Slave

private:
void actuateIU(int32_t target_iu);
int16_t ampereToTorqueIU(double ampere);

void mapMisoPDOs(SdoSlaveInterface& sdo);
void mapMosiPDOs(SdoSlaveInterface& sdo);
Expand Down
Loading