#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 <sys/mman.h>
#include <rtdm/rtdm.h>
#include <native/task.h>
#include <native/sem.h>
#include <native/mutex.h>
#include <native/timer.h>
#include <rtdk.h>
#include <pthread.h>
#include <math.h>
#define PI 3.1415926535898
#include "ecrt.h"
#define Bool int
#define false 0
#define true 1
#define ETHERCAT_STATUS_OP 0x08
#define STATUS_SERVO_ENABLE_BIT (0x04)
//master status
typedef enum _SysWorkingStatus
{
SYS_WORKING_POWER_ON,
SYS_WORKING_SAFE_MODE,
SYS_WORKING_OP_MODE,
SYS_WORKING_LINK_DOWN,
SYS_WORKING_IDLE_STATUS //系统空闲
}SysWorkingStatus;
typedef struct _GSysRunningParm
{
SysWorkingStatus m_gWorkStatus;
}GSysRunningParm;
GSysRunningParm gSysRunning;
RT_TASK InterpolationTask;
int run = 1;
int ecstate = 0;
#define CLOCK_TO_USE CLOCK_REALTIME
#define NSEC_PER_SEC (1000000000L)
#define TIMESPEC2NS(T) ((uint64_t) (T).tv_sec * NSEC_PER_SEC + (T).tv_nsec)
static int64_t system_time_base = 0LL;
//获取当前系统时间
RTIME system_time_ns(void)
{
struct timespec rt_time;
clock_gettime(CLOCK_TO_USE, &rt_time);
RTIME time = TIMESPEC2NS(rt_time);
return time - system_time_base;
}
/****************************************************************************/
// EtherCAT
ec_master_t *master = NULL;
static ec_master_state_t master_state = {};
static ec_domain_t *domainServoInput = NULL;
static ec_domain_state_t domainServoInput_state = {};
static ec_domain_t *domainServoOutput = NULL;
static ec_domain_state_t domainServoOutput_state = {};
static uint8_t *domainOutput_pd = NULL;
static uint8_t *domainInput_pd = NULL;
static ec_slave_config_t *sc_estun;
static ec_slave_config_state_t sc_estun_state;
/****************************************************************************/
#define estun_Pos0 0, 0
//#define estun 0x0000060a, 0x00000001
#define estun 0x00681168,0x00464445/*Vendor ID, product code*/
// offsets for PDO entries
static unsigned int cntlwd;
static unsigned int ipData;
static unsigned int modes_of_operation;
static unsigned int status;
static unsigned int actpos;
static unsigned int modes_of_operation_display;
static unsigned int Homing_method;
static unsigned int speed_during_search_for_switch;
static unsigned int speed_during_search_for_zero;
static unsigned int homing_acceleration;
static unsigned int home_offset;
static unsigned int cur_status;
static unsigned int cur_mode;
// process data
ec_pdo_entry_reg_t domainServoOutput_regs[] = {
{estun_Pos0, estun, 0x6040, 0x00, &cntlwd, NULL},
{estun_Pos0, estun, 0x607a, 0x00, &ipData, NULL},
{estun_Pos0, estun, 0x6060, 0x00, &modes_of_operation, NULL}, //6060 模式选择
{}
};
ec_pdo_entry_reg_t domainServoInput_regs[] = {
{estun_Pos0, estun, 0x6064, 0x00, &actpos, NULL},
{estun_Pos0, estun, 0x6041, 0x00, &status, NULL},
{estun_Pos0, estun, 0x6061, 0x00, &modes_of_operation_display, NULL},
{}
};
/****************************************************************************/
/* Master 0, Slave 0, "MBDLN25BE"
* Vendor ID: 0x0000066f
* Product code: 0x60380006
* Revision number: 0x00010000
*/
ec_pdo_entry_info_t estun_pdo_entries[] = {
{0x6040, 0x00, 16}, /* Controlword */
{0x6060, 0x00, 8}, /* Modes of operation */
{0x607a, 0x00, 32}, /* Target position */
{0x60b8, 0x00, 16}, /* Touch probe function */
{0x603f, 0x00, 16}, /* Error code */
{0x6041, 0x00, 16}, /* Statusword */
{0x6061, 0x00, 8}, /* Modes of operation display */
{0x6064, 0x00, 32}, /* Position actual value */
{0x60b9, 0x00, 16}, /* Touch probe status */
{0x60ba, 0x00, 32}, /* Touch probe pos1 pos value */
{0x60f4, 0x00, 32}, /* Following error actual value */
{0x60fd, 0x00, 32}, /* Digital inputs */
};
ec_pdo_info_t estun_pdos[] = {
{0x1600, 4, estun_pdo_entries + 0}, /* Receive PDO mapping 1 */
{0x1a00, 8, estun_pdo_entries + 4}, /* Transmit PDO mapping 1 */
};
ec_sync_info_t estun_syncs[] = {
{0, EC_DIR_OUTPUT, 0, NULL, EC_WD_DISABLE},
{1, EC_DIR_INPUT, 0, NULL, EC_WD_DISABLE},
{2, EC_DIR_OUTPUT, 1, estun_pdos + 0, EC_WD_ENABLE},
{3, EC_DIR_INPUT, 1, estun_pdos + 1, EC_WD_DISABLE},
{0xff}
};
/****************************************************************************/
int ConfigPDO()
{
/********************/
printf("xenomai Configuring PDOs...\n");
domainServoOutput = ecrt_master_create_domain(master);
if (!domainServoOutput) {
return -1;
}
domainServoInput = ecrt_master_create_domain(master);
if (!domainServoInput) {
return -1;
}
/********************/
printf("xenomai Creating slave configurations...\n");
sc_estun =
ecrt_master_slave_config(master, estun_Pos0, estun);
if (!sc_estun) {
fprintf(stderr, "Failed to get slave configuration.\n");
return -1;
}
/********************/
if (ecrt_slave_config_pdos(sc_estun, EC_END, estun_syncs)) {
fprintf(stderr, "Failed to configure PDOs.\n");
return -1;
}
/********************/
if (ecrt_domain_reg_pdo_entry_list(domainServoOutput, domainServoOutput_regs)) {
fprintf(stderr, "PDO entry registration failed!\n");
return -1;
}
if (ecrt_domain_reg_pdo_entry_list(domainServoInput, domainServoInput_regs)) {
fprintf(stderr, "PDO entry registration failed!\n");
return -1;
}
fprintf(stderr, "Creating SDO requests...\n");
// ecrt_slave_config_sdo8(sc_estun, 0x6060, 0, 8);
// ecrt_slave_config_sdo8(sc_estun, 0x60C2, 1, 1);
return 0;
}
/*****************************************************************************
* Realtime task
****************************************************************************/
void rt_check_domain_state(void)
{
ec_domain_state_t ds = {};
ec_domain_state_t ds1 = {};
//domainServoInput
ecrt_domain_state(domainServoInput, &ds);
if (ds.working_counter != domainServoInput_state.working_counter) {
rt_printf("domainServoInput: WC %u.\n", ds.working_counter);
}
if (ds.wc_state != domainServoInput_state.wc_state) {
rt_printf("domainServoInput: State %u.\n", ds.wc_state);
}
domainServoInput_state = ds;
//domainServoOutput
ecrt_domain_state(domainServoOutput, &ds1);
if (ds1.working_counter != domainServoOutput_state.working_counter) {
rt_printf("domainServoOutput: WC %u.\n", ds1.working_counter);
}
if (ds1.wc_state != domainServoOutput_state.wc_state) {
rt_printf("domainServoOutput: State %u.\n", ds1.wc_state);
}
domainServoOutput_state = ds1;
}
/****************************************************************************/
void rt_check_master_state(void)
{
ec_master_state_t ms;
ecrt_master_state(master, &ms);
if (ms.slaves_responding != master_state.slaves_responding) {
rt_printf("%u slave(s).\n", ms.slaves_responding);
}
if (ms.al_states != master_state.al_states) {
rt_printf("AL states: 0x%02X.\n", ms.al_states);
}
if (ms.link_up != master_state.link_up) {
rt_printf("Link is %s.\n", ms.link_up ? "up" : "down");
}
master_state = ms;
}
/****************************************************************************/
void check_slave_config_states(void)
{
ec_slave_config_state_t s;
ecrt_slave_config_state(sc_estun,&s);
if (s.al_state != sc_estun_state.al_state)
printf("sc_estun_state: State 0x%02X.\n", s.al_state);
if (s.online != sc_estun_state.online)
printf("sc_estun_state: %s.\n", s.online ? "online" : "offline");
if (s.operational != sc_estun_state.operationa
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
共307个文件
h:161个
0:22个
la:13个
IGH,xenomai控制电机,下载解压后,需要修改在mian.c里面把自己电机的ID换一下就能运行了。这里面是视频演示( https://www.bilibili.com/video/BV1rg411A7Mm/ )。这里面是搭建IGH的教程( https://blog.csdn.net/qq_50808730/category_11470195.html )
资源推荐
资源详情
资源评论
收起资源包目录
igh实时控制电机动起来的一个小项目,包括编译环境,及代码 (307个子文件)
libcobalt.so.2.0.0 194KB
libethercat.so.1.1.0 157KB
libethercat_rtdm.so.1.1.0 157KB
libcopperplate.so.0.0.0 71KB
libcopperplate.so.0 71KB
libalchemy.so.0.0.0 65KB
libalchemy.so.0 65KB
libvxworks.so.0.0.0 50KB
libvxworks.so.0 50KB
libpsos.so.0 44KB
libpsos.so.0.0.0 44KB
libanalogy.so.1.0.0 32KB
libsmokey.so.0.0.0 24KB
libsmokey.so.0 24KB
libtrank.so.0.0.0 20KB
libtrank.so.0 20KB
libalchemy-test.so.0 13KB
libalchemy-test.so.0.0.0 13KB
libposix-test.so.0.0.0 8KB
libposix-test.so.0 8KB
libmodechk.so.0 8KB
libmodechk.so.0.0.0 8KB
libethercat.so.1 157KB
libethercat_rtdm.so.1 157KB
libanalogy.so.1 32KB
libcobalt.so.2 194KB
libethercat.a 267KB
libethercat_rtdm.a 266KB
libcobalt.a 250KB
libalchemy.a 84KB
libcopperplate.a 83KB
libvxworks.a 71KB
libpsos.a 52KB
libanalogy.a 37KB
libsmokey.a 20KB
libtrank.a 17KB
libalchemy-test.a 6KB
libposix-test.a 5KB
libmodechk.a 4KB
altency 29KB
analogy_calibrate 113KB
analogy_config 31KB
autotune 19KB
bufp-label 15KB
bufp-readwrite 15KB
main.c 15KB
can_rtt 20KB
clocktest 19KB
cmd_bits 30KB
cmd_read 41KB
cmd_write 43KB
ethercat.conf 4KB
rtnet.conf 2KB
tdma.conf 491B
corectl 14KB
cross-link 18KB
cyclictest 60KB
dlopentest 9KB
dohell 2KB
eth_p_all 14KB
ethercat 8.09MB
ethercat 8KB
ethercat 4KB
ethercat_mbg 410KB
ethercatctl 7KB
gpiopwm 24KB
gpiotest 19KB
ecrt.h 97KB
can.h 29KB
ipc.h 28KB
obstack.h 19KB
analogy.h 17KB
avl-inner.h 15KB
threadobj.h 13KB
heapobj.h 12KB
serial.h 10KB
shared-list.h 10KB
can.h 9KB
psos.h 8KB
libc.h 7KB
smokey.h 7KB
analogy.h 7KB
xeno_config.h 7KB
cluster.h 7KB
lock.h 7KB
clockobj.h 6KB
private-list.h 6KB
hash.h 6KB
rtdm.h 5KB
pthread.h 5KB
syncobj.h 5KB
testing.h 5KB
thread.h 5KB
signal.h 5KB
task.h 5KB
rtdm.h 5KB
heapmem.h 4KB
queue.h 4KB
cobalt.h 4KB
ectty.h 4KB
共 307 条
- 1
- 2
- 3
- 4
常驻客栈
- 粉丝: 1w+
- 资源: 1359
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
- 1
- 2
- 3
- 4
- 5
前往页