Motion Master
|
#include "util.h"
#include <sys/stat.h>
#include <bitset>
#include <cmath>
#include <csignal>
#include <fstream>
#include <iomanip>
#include <random>
#include <sstream>
#include "cia402_drive.h"
#include "dictionary_symbols.h"
#include "ethercat_master.h"
#include "ethercat_slave.h"
#include <zip/zip.h>
#include "ethercat.h"
#include "global.h"
#include "loguru.h"
#include "motion_master_error.h"
#include "notifier.h"
#include "virtual_device.h"
Macros | |
#define | __le16_to_cpup(x) (*((uint16_t*)(x))) |
Functions | |
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... | |
std::string | controllerTypeToString (ControllerType ct) |
std::string | escapeDoubleQuotes (const std::string &input) |
bool | abs_compare (float a, float b) |
Compare absolute values of the input parameters. More... | |
void | interruptable_wait (size_t seconds) |
Blocks for the set amount of time, but allows to be interrupted. More... | |
int | wrap_target_position (int target, int max_limit, int min_limit) |
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, uint32_t 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... | |
int | 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, unsigned int device_id) |
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 (int hardware_id) |
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... | |
int | get_soem_slaves_responding () |
bool | compareStringsCaseInsensitive (const std::string &s1, const std::string &s2) |
#define __le16_to_cpup | ( | x | ) | (*((uint16_t*)(x))) |
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 | ||
) |
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::string escapeDoubleQuotes | ( | const std::string & | input | ) |
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 |
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 | ( | int | 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_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 |
int 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 |
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 |
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::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, |
unsigned int | device_id | ||
) |
int wrap_target_position | ( | int | target, |
int | max_limit, | ||
int | min_limit | ||
) |
std::vector< uint8_t > zip | ( | const std::string & | file_name, |
std::vector< uint8_t > | data | ||
) |
Zip a single file.
file_name | |
data |