![]() |
EtherCAT Control Framework v0.9
Implementation of EtherCAT protocol using IgH EtherCAT library for robot controller.
|
#include <iostream>
#include <cstring>
#include <limits.h>
#include <stdlib.h>
#include <pthread.h>
#include <errno.h>
#include <signal.h>
#include <stdio.h>
#include <string.h>
#include <sys/resource.h>
#include <sys/time.h>
#include <sys/types.h>
#include <unistd.h>
#include <time.h>
#include <sys/mman.h>
#include <malloc.h>
#include <sched.h>
#include <chrono>
#include <memory>
#include <vector>
#include "ecrt.h"
#include "object_dictionary.hpp"
Go to the source code of this file.
Classes | |
struct | Controller |
Xbox Controller values. More... | |
struct | SDO_data |
SDO_data Structure holding all data needed to send an SDO object. More... | |
struct | DataReceived |
Structure for data to be received from slaves. More... | |
struct | DataSent |
Structure for data to be sent to slaves. More... | |
struct | OffsetPDO |
offset for PDO entries to register PDOs. More... | |
struct | SdoRequest |
EtherCAT SDO request structure for configuration phase. More... | |
struct | ProfilePosParam |
Parameters that should be specified in position mode. More... | |
struct | CSPositionModeParam |
Struct contains configuration parameters for cyclic sync. position mode. More... | |
struct | VelControlParam |
Struct containing 'velocity control parameter set' 0x30A2 Has 4 sub index. Default values are from EPOS4 firmware manual. More... | |
struct | CSVelocityModeParam |
Struct contains configuration parameters for cyclic sync. velocity mode. More... | |
struct | CSTorqueModeParam |
Struct contains configuration parameters for cyclic sync. torque mode. More... | |
struct | HomingParam |
Homing mode configuration parameters. More... | |
struct | ProfileVelocityParam |
Profile velocity mode configuration parameters. More... | |
Macros | |
#define | NUM_OF_SLAVES 1 |
Total number of connected slave to the bus. More... | |
#define | CUSTOM_SLAVE 0 |
#define | FREQUENCY 1000 |
Ethercat PDO exchange loop frequency in Hz More... | |
#define | MEASURE_TIMING 1 |
If you want to measure timings leave it as one, otherwise make it 0. More... | |
#define | VELOCITY_MODE 1 |
set this to 1 if you want to use it in velocity mode (and set other modes 0) More... | |
#define | POSITION_MODE 0 |
set this to 1 if you want to use it in position mode (and set other modes 0) More... | |
#define | CYCLIC_POSITION_MODE 0 |
set this to 1 if you want to use it in cyclic synchronous position mode (and set other modes 0) More... | |
#define | CYCLIC_VELOCITY_MODE 0 |
set this to 1 if you want to use it in cyclic synchronous velocity mode (and set other modes 0) More... | |
#define | CYCLIC_TORQUE_MODE 0 |
set this to 1 if you want to use it in cyclic synchronous torque mode (and set other modes 0) More... | |
#define | DISTRIBUTED_CLOCK 1 |
set this to 1 if you want to activate distributed clock, by default leave it 1. More... | |
#define | GEAR_RATIO 103 |
#define | ENCODER_RESOLUTION 1024 |
Motor encoder resolution. More... | |
#define | INC_PER_ROTATION GEAR_RATIO*ENCODER_RESOLUTION*4 |
#define | FIVE_DEGREE_CCW int(INC_PER_ROTATION/72) |
#define | THIRTY_DEGREE_CCW int(INC_PER_ROTATION/12) |
#define | PERIOD_NS (g_kNsPerSec/FREQUENCY) |
#define | PERIOD_US (PERIOD_NS / 1000) |
#define | PERIOD_MS (PERIOD_US / 1000) |
#define | TEST_BIT(NUM, N) ((NUM & (1 << N))>>N) |
To sync every cycle. More... | |
#define | SET_BIT(NUM, N) (NUM | (1 << N)) |
#define | RESET_BIT(NUM, N) (NUM & ~(1 << N)) |
#define | TIMESPEC2NS(T) ((uint64_t) (T).tv_sec * g_kNsPerSec + (T).tv_nsec) |
Convert timespec struct to nanoseconds. More... | |
#define | DIFF_NS(A, B) (((B).tv_sec - (A).tv_sec) * g_kNsPerSec + (B).tv_nsec - (A).tv_nsec) |
#define | CLOCK_TO_USE CLOCK_MONOTONIC |
Using Monotonic system-wide clock. More... | |
Functions | |
struct timespec | timespec_add (struct timespec time1, struct timespec time2) |
Add two timespec struct. More... | |
static std::string | GetErrorMessage (const int &err_code) |
Variables | |
const uint32_t | g_kNumberOfServoDrivers = 1 |
const uint32_t | g_kNsPerSec = 1000000000 |
Nanoseconds per second. More... | |
static volatile sig_atomic_t | sig = 1 |
ec_master_t * | g_master |
Extern global variable declaration. More... | |
ec_master_state_t | g_master_state |
EtherCAT master. More... | |
ec_domain_t * | g_master_domain |
EtherCAT master state. More... | |
ec_domain_state_t | g_master_domain_state |
Ethercat data passing master domain. More... | |
struct timespec | g_sync_timer |
EtherCAT master domain state. More... | |
const struct timespec | g_cycle_time = {0, PERIOD_NS} |
timer for DC sync . More... | |
uint32_t | g_sync_ref_counter |
cycletime settings in ns. More... | |
#define CLOCK_TO_USE CLOCK_MONOTONIC |
Using Monotonic system-wide clock.
#define CUSTOM_SLAVE 0 |
If you have EtherCAT slave different than CiA402 supported motor drive, set this macro to 1
#define CYCLIC_POSITION_MODE 0 |
set this to 1 if you want to use it in cyclic synchronous position mode (and set other modes 0)
#define CYCLIC_TORQUE_MODE 0 |
set this to 1 if you want to use it in cyclic synchronous torque mode (and set other modes 0)
#define CYCLIC_VELOCITY_MODE 0 |
set this to 1 if you want to use it in cyclic synchronous velocity mode (and set other modes 0)
#define DIFF_NS | ( | A, | |
B | |||
) | (((B).tv_sec - (A).tv_sec) * g_kNsPerSec + (B).tv_nsec - (A).tv_nsec) |
#define DISTRIBUTED_CLOCK 1 |
set this to 1 if you want to activate distributed clock, by default leave it 1.
#define ENCODER_RESOLUTION 1024 |
Motor encoder resolution.
#define FIVE_DEGREE_CCW int(INC_PER_ROTATION/72) |
#define FREQUENCY 1000 |
Ethercat PDO exchange loop frequency in Hz
#define GEAR_RATIO 103 |
If you are using geared motor define ratio
#define INC_PER_ROTATION GEAR_RATIO*ENCODER_RESOLUTION*4 |
#define MEASURE_TIMING 1 |
If you want to measure timings leave it as one, otherwise make it 0.
#define NUM_OF_SLAVES 1 |
Total number of connected slave to the bus.
#define PERIOD_MS (PERIOD_US / 1000) |
#define PERIOD_NS (g_kNsPerSec/FREQUENCY) |
#define PERIOD_US (PERIOD_NS / 1000) |
#define POSITION_MODE 0 |
set this to 1 if you want to use it in position mode (and set other modes 0)
#define RESET_BIT | ( | NUM, | |
N | |||
) | (NUM & ~(1 << N)) |
#define SET_BIT | ( | NUM, | |
N | |||
) | (NUM | (1 << N)) |
#define TEST_BIT | ( | NUM, | |
N | |||
) | ((NUM & (1 << N))>>N) |
To sync every cycle.
#define THIRTY_DEGREE_CCW int(INC_PER_ROTATION/12) |
#define TIMESPEC2NS | ( | T | ) | ((uint64_t) (T).tv_sec * g_kNsPerSec + (T).tv_nsec) |
Convert timespec struct to nanoseconds.
#define VELOCITY_MODE 1 |
set this to 1 if you want to use it in velocity mode (and set other modes 0)
enum ControlStructureBits |
Control structure configuration for control mechanism to select sensor structure specific to hardware.
enum ErrorRegisterBits |
enum ErrorType |
enum LifeCycleState |
enum MotorStates |
enum OpMode |
enum SensorConfig |
Sensor Configuration for motor for more information
|
static |
|
inline |
Add two timespec struct.
time1 | Timespec struct 1 |
time2 | Timespec struct 2 |
const struct timespec g_cycle_time = {0, PERIOD_NS} |
timer for DC sync .
const uint32_t g_kNsPerSec = 1000000000 |
Nanoseconds per second.
const uint32_t g_kNumberOfServoDrivers = 1 |
Number of connected servo drives.
|
extern |
Extern global variable declaration.
|
extern |
EtherCAT master state.
|
extern |
Ethercat data passing master domain.
|
extern |
EtherCAT master.
|
extern |
cycletime settings in ns.
|
extern |
EtherCAT master domain state.
|
static |