Motion Master
|
#include <chrono>
#include <cmath>
#include <deque>
#include <future>
#include <list>
#include <nlohmann/json.hpp>
#include <numeric>
#include <semver.hpp>
#include <string>
#include <thread>
#include <zmq.hpp>
#include "cia402_drive.h"
#include "motion-master.pb.h"
#include "notifier.h"
#include "standalone_autotuning.h"
#include "virtual_device.h"
Go to the source code of this file.
Classes | |
struct | PlantModel |
struct | AutoTuningDriveConfigurationClass |
struct | SystemParametersClass |
struct | TuningParametersClass |
class | LowPassFilter |
This filter is second order with binomial coefficients, damping ratio xi = 1. More... | |
class | HighPassFilter |
This is a fourth order filter with binomial coefficients. More... | |
Macros | |
#define | JSON_TO_DOUBLE(jx) jx.is_number() ? double(jx) : 0.0 |
Typedefs | |
typedef struct AutoTuningDriveConfigurationClass | AutoTuningDriveConfiguration |
typedef struct SystemParametersClass | SystemParameters |
typedef struct TuningParametersClass | TuningParameters |
typedef enum MotionMasterWarning | MotionMasterWarning |
Enumerations | |
enum class | ControllerType { kPiP , kPpi } |
enum class | CirculoType { kUnspecified , kCirculo7 , kCirculo7Smm , kCirculo9 , kCirculo9Smm } |
enum class | CirculoEncoderType { kUndefined = 0 , kCirculo7Inner , kCirculo7Outer , kCirculo9Inner , kCirculo9Outer } |
enum class | EncoderLocation { kUnspecified , kMotorShaft , kDrivingShaft } |
enum class | PositionControlStrategy { kNone = 0 , kSimple , kCascaded } |
enum | MotionMasterWarning : unsigned int { WAR_NONE = 0 , WAR_PROFILE_TARGET_LIMITED , WAR_INTERNAL_LIMIT_REACHED } |
enum class | EcatSlaveFoeError { kNotFound = 0x00008001 , kAccessDenied = 0x00008002 , kDiskFull = 0x00008003 , kIllegal = 0x00008004 , kPacketNumberWrong = 0x00008005 , kAlreadyExists = 0x00008006 , kNoUser = 0x00008007 , kBootstrapOnly = 0x00008008 , kNotBootstrap = 0x00008009 , kNoRights = 0x0000800a , kProgramError = 0x0000800b } |
Functions | |
std::string | controllerTypeToString (ControllerType ct) |
std::string | get_master_warning_message (MotionMasterWarning warning) |
Return the appropriate warning message. More... | |
std::string | get_slave_error_message (int32_t error_code) |
Return the appropriate error message. More... | |
void | send (zmq::socket_t &socket, const std::string &connection_id, const motionmaster::MotionMasterMessage &message) |
Send regular Google Protocol Buffers message over ZeroMQ. More... | |
std::string | etg1004_unit_string (uint32_t etg1004_unit_value) |
Convert ETG.1004 unit format to string. More... | |
int32_t | get_pdo_id (uint16_t index, uint8_t subindex, std::map< int32_t, int32_t > &pdo_position_map) |
Uses a special map and its keys to get the PDO array positions. More... | |
const std::string | current_date_time () |
Get the current time and date as a custom string. More... | |
bool | abs_compare (float a, float b) |
Compare absolute values of the input parameters. More... | |
template<typename T > | |
bool | opposite_signs (const T &a, const T &b) |
Check if parameters have opposite signs. More... | |
void | interruptable_wait (size_t seconds) |
Blocks for the set amount of time, but allows to be interrupted. More... | |
int32_t | wrap_target_position (int32_t target, int32_t max_limit, int32_t min_limit) |
Wrap the target position over limit. More... | |
uint32_t | register_sync_signal () |
Register a thread sync signal. More... | |
void | unregister_sync_signal (uint32_t signal_id) |
Unregister a thread sync signal. More... | |
uint64_t | wait_for_sync_signal (uint32_t signal_id) |
Wait for the system sync signal. More... | |
uint64_t | wait_for_signal (int signal_fd) |
Wait for the system signal. More... | |
uint64_t | wait_for_signal (uint32_t signal_id) |
std::vector< double > | linspace (double lb, double ub, size_t n) |
Generate equally spaced points inside an interval. More... | |
ControllerGains | get_position_controller_gains (Cia402Drive &cia402_drive) |
Get the current position controller gains of a drive. More... | |
bool | set_position_controller_gains (Cia402Drive &cia402_drive, const ControllerGains &gains) |
Set the position controller gains. More... | |
bool | set_velocity_controller_gains (Cia402Drive &cia402_drive, const ControllerGains &gains) |
Set the velocity controller gains. More... | |
bool | check_gains (Cia402Drive &cia402_drive) |
Check if the required gains are properly set. More... | |
bool | string_ends_with (const std::string &value, const std::string &ending) |
Check if a string ends with another string. More... | |
std::vector< uint8_t > | read_file_content (const std::string &path) |
Read a file into a byte (uint8_t) vector. More... | |
void | set_csv_configuration (VirtualDevice *virtual_device, const std::vector< uint8_t > &csv_data) |
Set the configuration parameter values from CSV data. More... | |
uint8_t | calculate_crc (const std::vector< uint8_t > &data) |
uint32_t | random_uint32 (uint32_t min=0, uint32_t max=UINT32_MAX) |
Generate a random unsigned 32-bit integer in a certain range. More... | |
unsigned char | random_char () |
Generate a random character. More... | |
std::string | generate_uuid (size_t length) |
Generate a UUID of a custom length. More... | |
int32_t | limit_int32_target (int64_t target) |
Limit a target to integer 32 if necessary. More... | |
std::string | run_env_info () |
Get all sorts of run environment information. More... | |
bool | validate_sii_data (const std::vector< uint8_t > &content, uint32_t device_id) |
Validate an SII data before writing. More... | |
bool | file_exists (const std::string &path) |
Check if a file exists on the system where Motion Master is running. More... | |
std::string | string_bytes_to_hex_array_string (const std::string &bytes) |
Convert bytes (as string) to a string of hex values. More... | |
std::string | get_firmware_version_string (Cia402Drive &cia402_drive) |
Get the (string) version of the used firmware. More... | |
semver::version | get_firmware_version (Cia402Drive &cia402_drive) |
Get the (semver) version of the used firmware. More... | |
bool | get_plant_model_from_flash (Cia402Drive &cia402_drive, PlantModel *m) |
Get the plant model from the flash memory of the device. More... | |
AutoTuningDriveConfiguration | get_auto_tuning_drive_configuration (Cia402Drive &cia402_drive) |
Get the configuration required for full auto-tuning. More... | |
ControllerGains | convert_auto_tuning_controller_gains (ControllerGains gains, uint32_t singleturn_resolution) |
Convert gains to inc pos values and rpm velocity values. More... | |
CirculoType | get_circulo_type (int32_t hardware_id) |
Get the Circulo type based on the hardware ID. More... | |
bool | is_fw_based_on_v5 (Cia402Drive &cia402_drive) |
Check if the device requires the newer encoder configuration (FW >= v5 or FW >= v0.3.8-calibration), or the older encoder configuration (FW < v5 or FW < v0.3.8-calibration) More... | |
bool | is_fw_at_least (Cia402Drive &cia402_drive, const std::string &version) |
Check if the drive uses at least a certain FW version. More... | |
std::vector< uint8_t > | zip (const std::string &file_name, std::vector< uint8_t > data) |
Zip a single file. More... | |
std::vector< uint8_t > | unzip (const std::vector< uint8_t > &data) |
Unzip data containing a single file. More... | |
uint32_t | generate_od_entry_map_key (uint16_t index, uint8_t subindex) |
Generate a map key for an OD entry using index/subindex. More... | |
std::list< std::string > | get_file_parts (std::list< std::string > file_list, const std::string &file_name) |
Process the provided file list and find the file or its parts. More... | |
EncoderLocation | get_encoder_location (Cia402Drive &cia402_drive, uint8_t encoder_ordinal) |
Get the location of an encoder. More... | |
template<typename T > | |
int32_t | find_local_min_index_from_right (std::vector< T > &x) |
Find a local minimum (from right) in the supplied vector. More... | |
template<typename T > | |
double | compute_mean (const std::vector< T > &numbers) |
Compute mean given a vector of numbers. More... | |
template<typename T > | |
double | compute_standard_deviation (const std::vector< T > &numbers) |
Compute the standard deviation given a vector of numbers. More... | |
template<typename T > | |
double | compute_section_mean (const std::vector< T > &numbers, size_t start, size_t end) |
Compute the mean of a section of a given vector of integers. More... | |
template<typename T > | |
std::vector< T > | erase_edge_elements (std::vector< T > v, size_t length) |
Remove a number of the first and last elements in the vector. More... | |
template<typename R > | |
bool | is_future_done (std::future< R > const &f) |
Check if the future has finished executing. More... | |
template<typename T > | |
auto | to_integral (T e) |
Return an integral type value of an enum class. More... | |
template<typename... Args> | |
std::string | string_format (const std::string &format, Args... args) |
Format a string like printf() More... | |
int | get_soem_slaves_responding () |
bool | compareStringsCaseInsensitive (const std::string &s1, const std::string &s2) |
Variables | |
const char *const | HARDWARE_DESCRIPTION_FILENAME = ".hardware_description" |
const char *const | STACK_INFO_FILENAME = "stack_info.json" |
const char *const | STACK_IMAGE_FILENAME = "stack_image.svg" |
const char *const | ESI_FILENAME = "SOMANET_CiA_402.xml" |
const char *const | CONFIG_FILENAME = "config.csv" |
const char *const | PLANT_MODEL_FILENAME = "plant_model.csv" |
const char *const | VARIANT_FILENAME = ".variant" |
const std::map< MotionMasterWarning, std::string > | motion_master_warning_to_message_map_ |
const std::map< int32_t, std::string > | slave_error_map_ |
const std::map< int32_t, std::map< int32_t, int32_t > > | adc_current_ratio_fw_v4_4_1_map |
const std::map< int32_t, std::map< int32_t, int32_t > > | adc_current_ratio_fw_v4_4_2_map |
#define JSON_TO_DOUBLE | ( | jx | ) | jx.is_number() ? double(jx) : 0.0 |
typedef struct AutoTuningDriveConfigurationClass AutoTuningDriveConfiguration |
typedef enum MotionMasterWarning MotionMasterWarning |
typedef struct SystemParametersClass SystemParameters |
typedef struct TuningParametersClass TuningParameters |
|
strong |
|
strong |
|
strong |
|
strong |
|
strong |
enum MotionMasterWarning : unsigned int |
|
strong |
bool abs_compare | ( | float | a, |
float | b | ||
) |
Compare absolute values of the input parameters.
a | first parameter |
b | second parameter |
uint8_t calculate_crc | ( | const std::vector< uint8_t > & | data | ) |
Calculates the SII checksum field.
The checksum is generated with the polynomial x^8+x^2+x+1 (0x07) and an initial value of 0xff (see IEC 61158-6-12 ch. 5.4).
data | vector of data |
bool check_gains | ( | Cia402Drive & | cia402_drive | ) |
Check if the required gains are properly set.
Given the set position control strategy check if the gains have been properly set (and the crucial gains are set to non-zero values)
cia402_drive |
bool compareStringsCaseInsensitive | ( | const std::string & | s1, |
const std::string & | s2 | ||
) |
double compute_mean | ( | const std::vector< T > & | numbers | ) |
Compute mean given a vector of numbers.
numbers | a vector of numbers |
double compute_section_mean | ( | const std::vector< T > & | numbers, |
size_t | start, | ||
size_t | end | ||
) |
Compute the mean of a section of a given vector of integers.
numbers | a vector of integers |
start | index of the first element of the section |
end | index of the last element of the section |
double compute_standard_deviation | ( | const std::vector< T > & | numbers | ) |
Compute the standard deviation given a vector of numbers.
numbers | a vector of numbers |
std::string controllerTypeToString | ( | ControllerType | ct | ) |
ControllerGains convert_auto_tuning_controller_gains | ( | ControllerGains | gains, |
uint32_t | singleturn_resolution | ||
) |
Convert gains to inc pos values and rpm velocity values.
gains | controller gains |
singleturn_resolution | the resolution of the used encoder |
const std::string current_date_time | ( | ) |
Get the current time and date as a custom string.
std::vector< T > erase_edge_elements | ( | std::vector< T > | v, |
size_t | length | ||
) |
Remove a number of the first and last elements in the vector.
vector | vector to shorted |
length | the number of elements to erase |
std::string etg1004_unit_string | ( | uint32_t | etg1004_unit_value | ) |
Convert ETG.1004 unit format to string.
etg1004_unit_value | 4 byte integer (prefix, numerator, denominator, reserved) |
bool file_exists | ( | const std::string & | path | ) |
Check if a file exists on the system where Motion Master is running.
path | path to the file |
int32_t find_local_min_index_from_right | ( | std::vector< T > & | x | ) |
Find a local minimum (from right) in the supplied vector.
x | supplied vector of values |
uint32_t generate_od_entry_map_key | ( | uint16_t | index, |
uint8_t | subindex | ||
) |
Generate a map key for an OD entry using index/subindex.
index | OD entry index |
subindex | OD entry subindex |
std::string generate_uuid | ( | size_t | length | ) |
Generate a UUID of a custom length.
length | length of the generated UUID |
AutoTuningDriveConfiguration get_auto_tuning_drive_configuration | ( | Cia402Drive & | cia402_drive | ) |
Get the configuration required for full auto-tuning.
Fetch all of the parameters required by the full auto-tuning and return them as AutoTuningDriveConfiguration
cia402_drive |
MotionMasterError |
CirculoType get_circulo_type | ( | int32_t | hardware_id | ) |
Get the Circulo type based on the hardware ID.
hardware_id |
EncoderLocation get_encoder_location | ( | Cia402Drive & | cia402_drive, |
uint8_t | encoder_ordinal | ||
) |
Get the location of an encoder.
cia402_drive | a reference to a drive |
encoder_ordinal | encoder ordinal |
std::list< std::string > get_file_parts | ( | std::list< std::string > | file_list, |
const std::string & | file_name | ||
) |
Process the provided file list and find the file or its parts.
file_list | Obtained via do_get_file_list() |
file_name | File name to be found (single file, or its parts) |
semver::version get_firmware_version | ( | Cia402Drive & | cia402_drive | ) |
Get the (semver) version of the used firmware.
cia402_drive |
an | exception if there are any errors |
std::string get_firmware_version_string | ( | Cia402Drive & | cia402_drive | ) |
Get the (string) version of the used firmware.
cia402_drive |
an | exception if there are any errors |
std::string get_master_warning_message | ( | MotionMasterWarning | warning | ) |
Return the appropriate warning message.
warning | MotionMasterWarning |
int32_t get_pdo_id | ( | uint16_t | index, |
uint8_t | subindex, | ||
std::map< int32_t, int32_t > & | pdo_position_map | ||
) |
Uses a special map and its keys to get the PDO array positions.
index | object index |
subindex | object subindex |
bool get_plant_model_from_flash | ( | Cia402Drive & | cia402_drive, |
PlantModel * | m | ||
) |
Get the plant model from the flash memory of the device.
cia402_drive | to get the plant model from |
m | a pointer to the fetched model if any |
ControllerGains get_position_controller_gains | ( | Cia402Drive & | cia402_drive | ) |
Get the current position controller gains of a drive.
cia402_drive |
std::string get_slave_error_message | ( | int32_t | error_code | ) |
Return the appropriate error message.
error_code |
int get_soem_slaves_responding | ( | ) |
void interruptable_wait | ( | size_t | seconds | ) |
Blocks for the set amount of time, but allows to be interrupted.
seconds | amount of time to block for |
bool is_future_done | ( | std::future< R > const & | f | ) |
Check if the future has finished executing.
f | future |
bool is_fw_at_least | ( | Cia402Drive & | cia402_drive, |
const std::string & | version | ||
) |
Check if the drive uses at least a certain FW version.
cia402_drive | drive |
version | version as a string |
bool is_fw_based_on_v5 | ( | Cia402Drive & | cia402_drive | ) |
Check if the device requires the newer encoder configuration (FW >= v5 or FW >= v0.3.8-calibration), or the older encoder configuration (FW < v5 or FW < v0.3.8-calibration)
cia402_drive |
int32_t limit_int32_target | ( | int64_t | target | ) |
Limit a target to integer 32 if necessary.
target |
std::vector< double > linspace | ( | double | lb, |
double | ub, | ||
size_t | n | ||
) |
Generate equally spaced points inside an interval.
lb | lower boundary |
ub | upper boundary |
n | number of elements |
bool opposite_signs | ( | const T & | a, |
const T & | b | ||
) |
Check if parameters have opposite signs.
a | first number |
b | second number |
unsigned char random_char | ( | ) |
Generate a random character.
uint32_t random_uint32 | ( | uint32_t | min = 0 , |
uint32_t | max = UINT32_MAX |
||
) |
Generate a random unsigned 32-bit integer in a certain range.
min | minimum value |
max | maximum value |
std::vector< uint8_t > read_file_content | ( | const std::string & | path | ) |
Read a file into a byte (uint8_t) vector.
path | file path |
uint32_t register_sync_signal | ( | ) |
Register a thread sync signal.
std::string run_env_info | ( | ) |
Get all sorts of run environment information.
void send | ( | zmq::socket_t & | socket, |
const std::string & | connection_id, | ||
const motionmaster::MotionMasterMessage & | message | ||
) |
Send regular Google Protocol Buffers message over ZeroMQ.
socket | ZeroMQ socket used for sending messages |
connection_id | connection ID as a string |
message | Google Protocol Buffers message to be sent |
void set_csv_configuration | ( | VirtualDevice * | virtual_device, |
const std::vector< uint8_t > & | csv_data | ||
) |
Set the configuration parameter values from CSV data.
virtual_device | pointer to the device to set the configuration on |
csv_data | CSV data |
bool set_position_controller_gains | ( | Cia402Drive & | cia402_drive, |
const ControllerGains & | gains | ||
) |
Set the position controller gains.
cia402_drive | |
gains |
bool set_velocity_controller_gains | ( | Cia402Drive & | cia402_drive, |
const ControllerGains & | gains | ||
) |
Set the velocity controller gains.
cia402_drive | |
gains |
std::string string_bytes_to_hex_array_string | ( | const std::string & | bytes | ) |
Convert bytes (as string) to a string of hex values.
bytes | bytes as a string |
bool string_ends_with | ( | const std::string & | value, |
const std::string & | ending | ||
) |
Check if a string ends with another string.
value | string to check in |
ending | string to check for |
std::string string_format | ( | const std::string & | format, |
Args... | args | ||
) |
Format a string like printf()
auto to_integral | ( | T | e | ) |
Return an integral type value of an enum class.
e | value of an enum class type |
void unregister_sync_signal | ( | uint32_t | signal_id | ) |
Unregister a thread sync signal.
signal_id |
std::vector< uint8_t > unzip | ( | const std::vector< uint8_t > & | data | ) |
Unzip data containing a single file.
data |
std::runtime_error |
bool validate_sii_data | ( | const std::vector< uint8_t > & | content, |
uint32_t | device_id | ||
) |
Validate an SII data before writing.
content | file content |
device_id | ID of the device to validate the SII for (log only) |
uint64_t wait_for_signal | ( | int | signal_fd | ) |
Wait for the system signal.
signal_fd | the file descriptor used for signaling |
uint64_t wait_for_signal | ( | uint32_t | signal_id | ) |
uint64_t wait_for_sync_signal | ( | uint32_t | signal_id | ) |
Wait for the system sync signal.
signal_id | unique ID of the waited signal |
int32_t wrap_target_position | ( | int32_t | target, |
int32_t | max_limit, | ||
int32_t | min_limit | ||
) |
Wrap the target position over limit.
\parameter target position to wrap \parameter max_limit max limit to wrap the target position around \parameter min_limit min limit to wrap the target position around
std::vector< uint8_t > zip | ( | const std::string & | file_name, |
std::vector< uint8_t > | data | ||
) |
Zip a single file.
file_name | |
data |
const std::map<int32_t, std::map<int32_t, int32_t> > adc_current_ratio_fw_v4_4_1_map |
const std::map<int32_t, std::map<int32_t, int32_t> > adc_current_ratio_fw_v4_4_2_map |
const char* const CONFIG_FILENAME = "config.csv" |
const char* const ESI_FILENAME = "SOMANET_CiA_402.xml" |
const char* const HARDWARE_DESCRIPTION_FILENAME = ".hardware_description" |
const std::map<MotionMasterWarning, std::string> motion_master_warning_to_message_map_ |
const char* const PLANT_MODEL_FILENAME = "plant_model.csv" |
const std::map<int32_t, std::string> slave_error_map_ |
const char* const STACK_IMAGE_FILENAME = "stack_image.svg" |
const char* const STACK_INFO_FILENAME = "stack_info.json" |
const char* const VARIANT_FILENAME = ".variant" |