Class robot_fingers::NJointBlmcRobotDriver

template<typename Observation, size_t N_JOINTS, size_t N_MOTOR_BOARDS>
class NJointBlmcRobotDriver : public robot_interfaces::RobotDriver<robot_interfaces::NJointAction<N_JOINTS>, Observation>, public robot_interfaces::RobotDriver<robot_interfaces::NJointAction<N_JOINTS>, Observation>

Base class for n-joint BLMC robots.

This is a generic base class to easily implement drivers for simple BLMC robots that consist of N_JOINTS joints.

Template Parameters:
  • N_JOINTS – Number of joints.

  • N_MOTOR_BOARDS – Number of motor control boards that are used.

Subclassed by robot_fingers::NFingerDriver< 1 >, robot_fingers::NFingerDriver< 3 >, robot_fingers::NFingerDriver< 1 >, robot_fingers::NFingerDriver< 3 >, robot_fingers::SimpleNJointBlmcRobotDriver< 8, 4 >, robot_fingers::SimpleNJointBlmcRobotDriver< 2, 1 >, robot_fingers::SimpleNJointBlmcRobotDriver< 1, 1 >, robot_fingers::SimpleNJointBlmcRobotDriver< 8, 4 >, robot_fingers::SimpleNJointBlmcRobotDriver< 2, 1 >, robot_fingers::SimpleNJointBlmcRobotDriver< 1, 1 >, robot_fingers::NFingerDriver< N_FINGERS >, robot_fingers::NFingerDriver< N_FINGERS >

Public Types

typedef robot_interfaces::NJointAction<N_JOINTS> Action
typedef robot_interfaces::RobotInterfaceTypes<Action, Observation> Types
typedef Action::Vector Vector
typedef std::array<std::shared_ptr<blmc_drivers::MotorInterface>, N_JOINTS> Motors
typedef std::array<std::shared_ptr<blmc_drivers::CanBusMotorBoard>, N_MOTOR_BOARDS> MotorBoards
typedef robot_interfaces::NJointAction<N_JOINTS> Action
typedef robot_interfaces::RobotInterfaceTypes<Action, Observation> Types
typedef Action::Vector Vector
typedef std::array<std::shared_ptr<blmc_drivers::MotorInterface>, N_JOINTS> Motors
typedef std::array<std::shared_ptr<blmc_drivers::CanBusMotorBoard>, N_MOTOR_BOARDS> MotorBoards

Public Functions

inline NJointBlmcRobotDriver(const MotorBoards &motor_boards, const Motors &motors, const MotorParameters &motor_parameters, const Config &config)
inline Vector get_max_torques() const
void pause_motors()
Vector get_measured_index_angles() const
void initialize() override

Find home position of all joints and move to start position.

Homes all joints using home_on_index_after_negative_end_stop. When finished, move the joint to the starting position (defined in config_.initial_position_rad).

Action get_idle_action() override

Provide position command to initial position as idle action.

This will hold the joints in place after the initialisation.

virtual Observation get_latest_observation() override = 0
Action apply_action(const Action &desired_action) override
std::optional<std::string> get_error() override
void shutdown() override
bool is_within_hard_position_limits(const Observation &observation) const

Check if the joint position is within the hard limits.

See also

Config::is_within_hard_position_limits

inline NJointBlmcRobotDriver(const MotorBoards &motor_boards, const Motors &motors, const MotorParameters &motor_parameters, const Config &config)
inline Vector get_max_torques() const
void pause_motors()
Vector get_measured_index_angles() const
void initialize() override

Find home position of all joints and move to start position.

Homes all joints using home_on_index_after_negative_end_stop. When finished, move the joint to the starting position (defined in config_.initial_position_rad).

Action get_idle_action() override

Provide position command to initial position as idle action.

This will hold the joints in place after the initialisation.

virtual Observation get_latest_observation() override = 0
Action apply_action(const Action &desired_action) override
std::optional<std::string> get_error() override
void shutdown() override
bool is_within_hard_position_limits(const Observation &observation) const

Check if the joint position is within the hard limits.

See also

Config::is_within_hard_position_limits

Public Members

const bool has_endstop_

True if the joints have mechanical end stops, false if not.

If set to true, it is assumed that all joints of the robot have end stops that mechanically prevent them from moving out of the valid range.

If present, the end stops are used for a fully automated homing procedure in which the joints first move until they hit the end stop before starting the encoder index search. This way it is ensured that the correct index is used for homing without any need for manual set up.

Public Static Functions

static MotorBoards create_motor_boards(const std::array<std::string, N_MOTOR_BOARDS> &can_ports)
static Action process_desired_action(const Action &desired_action, const Observation &latest_observation, const double max_torque_Nm, const Vector &safety_kd, const Vector &default_position_control_kp, const Vector &default_position_control_kd, bool is_position_limit_enabled, const Vector &lower_position_limits = Vector::Constant(-std::numeric_limits<double>::infinity()), const Vector &upper_position_limits = Vector::Constant(std::numeric_limits<double>::infinity()))

Process the desired action provided by the user.

Takes the desired action from the user and does the following processing:

static MotorBoards create_motor_boards(const std::array<std::string, N_MOTOR_BOARDS> &can_ports)
static Action process_desired_action(const Action &desired_action, const Observation &latest_observation, const double max_torque_Nm, const Vector &safety_kd, const Vector &default_position_control_kp, const Vector &default_position_control_kd, bool is_position_limit_enabled, const Vector &lower_position_limits = Vector::Constant(-std::numeric_limits<double>::infinity()), const Vector &upper_position_limits = Vector::Constant(std::numeric_limits<double>::infinity()))

Process the desired action provided by the user.

Takes the desired action from the user and does the following processing:

Public Static Attributes

static constexpr size_t num_joints = N_JOINTS
static constexpr size_t num_motor_boards = N_MOTOR_BOARDS
struct Config

Configuration of the robot that can be changed by the user.

Public Types

typedef std::array<std::string, N_MOTOR_BOARDS> CanPortArray
typedef std::array<std::string, N_MOTOR_BOARDS> CanPortArray

Public Functions

bool is_within_hard_position_limits(const Vector &position) const

Check if the given position is within the hard limits.

Parameters:

position – Joint positions.

Returns:

True if hard_position_limits_lower <= position <= hard_position_limits_upper.

void print() const

Print the given configuration in a human-readable way.

bool is_within_hard_position_limits(const Vector &position) const

Check if the given position is within the hard limits.

Parameters:

position – Joint positions.

Returns:

True if hard_position_limits_lower <= position <= hard_position_limits_upper.

void print() const

Print the given configuration in a human-readable way.

Public Members

CanPortArray can_ports

List of CAN port names used by the robot.

For each motor control board used by the robot, this specifies the CAN port through which it is connected.

Example: {"can0", "can1"}

double max_current_A = 0.0

Maximum current that can be sent to the motor [A].

bool has_endstop = false

Whether the joints have physical end stops or not.

This is for example relevant for homing, where (in case this value is set to true) all joints move until they hit the end stop to determine their absolute position.

Note that not having end stops does not mean that the joint can rotate freely in general.

HomingMethod homing_method = HomingMethod::NONE

Which method to use for homing.

struct robot_fingers::NJointBlmcRobotDriver<Observation, N_JOINTS, N_MOTOR_BOARDS>::Config::CalibrationParameters calibration
double move_to_position_tolerance_rad = 0.0

Tolerance for reaching the target with NJointBlmcRobotDriver::move_to_position.

Vector safety_kd = Vector::Constant(0.1)

D-gain to dampen velocity. Set to zero to disable damping.

struct robot_fingers::NJointBlmcRobotDriver<Observation, N_JOINTS, N_MOTOR_BOARDS>::Config::PositionControlGains position_control_gains
Vector hard_position_limits_lower = Vector::Zero()

Hard lower limits for joint position.

Exceeding this limit results in an error and robot shutdown.

Vector hard_position_limits_upper = Vector::Zero()

Hard upper limits for joint position.

Exceeding this limit results in an error and robot shutdown.

Vector soft_position_limits_lower = Vector::Constant(-std::numeric_limits<double>::infinity())

Soft lower limits for joint position.

Exceeding this limit results in the action being adjusted to move the joint back inside the limits.

Vector soft_position_limits_upper = Vector::Constant(std::numeric_limits<double>::infinity())

Soft upper limits for joint position.

Exceeding this limit results in the action being adjusted to move the joint back inside the limits.

Vector home_offset_rad = Vector::Zero()

Offset between home position and zero.

Vector initial_position_rad = Vector::Zero()

Initial position to which the robot moves after initialization.

std::vector<TrajectoryStep> shutdown_trajectory

Trajectory which is executed in the shutdown method.

Use this to move the robot to a “rest position” during shutdown of the robot driver. It can consist of arbitrarily many steps. Leave it empty to not move during shutdown.

std::vector<std::string> run_duration_logfiles

List of file to which run duration logs are written.

You can specify multiple files here if you want to log the runtime of different independent components separately. For example on a robot with multiple manipulators, you can have a separate log for each manipulator, so if one of them is replaced, only the log file of this manipulator needs to be changed.

Public Static Functions

static Config load_config(const std::string &config_file_name)

Load driver configuration from file.

Load the configuration from the specified YAML file. The file is expected to have the same structure/key naming as the Config struct. If a value can not be read from the file, the application exists with an error message.

Parameters:

config_file_name – Path/name of the configuration YAML file.

Returns:

Configuration

static inline HomingMethod parse_homing_method_name(const std::string method_name)

Parse a homing method name.

Parameters:

method_name – Homing method name.

Throws:

std::invalid_argument – if the given string does not represent a valid homing method.

Returns:

The corresponding homing method.

static inline std::string get_homing_method_name(HomingMethod method)

Get the name of the specified homing method.

static Config load_config(const std::string &config_file_name)

Load driver configuration from file.

Load the configuration from the specified YAML file. The file is expected to have the same structure/key naming as the Config struct. If a value can not be read from the file, the application exists with an error message.

Parameters:

config_file_name – Path/name of the configuration YAML file.

Returns:

Configuration

static inline HomingMethod parse_homing_method_name(const std::string method_name)

Parse a homing method name.

Parameters:

method_name – Homing method name.

Throws:

std::invalid_argument – if the given string does not represent a valid homing method.

Returns:

The corresponding homing method.

static inline std::string get_homing_method_name(HomingMethod method)

Get the name of the specified homing method.

struct CalibrationParameters

Parameters related to calibration.

Public Members

Vector endstop_search_torques_Nm = Vector::Zero()

Torque that is used to find the end stop.

uint32_t move_steps = 0

Number of time steps for reaching the initial position.

struct PositionControlGains

Default control gains for the position PD controller.

Public Members

Vector kp = Vector::Zero()
Vector kd = Vector::Zero()
struct TrajectoryStep

A sub-goal of a trajectory.

Public Members

Vector target_position_rad = Vector::Zero()

Target position to which the joints should move.

uint32_t move_steps = 0

Number of time steps for reaching the target position.