ethercatcpp
example_EL1018_2008.cpp
/* File: example_EL1018_2008.cpp
* This file is part of the program ethercatcpp-core
* Program description : EtherCAT driver libraries for UNIX
* Copyright (C) 2017-2024 - Robin Passama (LIRMM / CNRS) Arnaud Meline
* (LIRMM / CNRS) Benjamin Navarro (LIRMM / CNRS). All Right reserved.
*
* This software is free software: you can redistribute it and/or modify
* it under the terms of the CeCILL-C license as published by
* the CEA CNRS INRIA, either version 1
* of the License, or (at your option) any later version.
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* CeCILL-C License for more details.
*
* You should have received a copy of the CeCILL-C License
* along with this software. If not, it can be found on the official
* website of the CeCILL licenses family (http://www.cecill.info/index.en.html).
*/
#include <pid/signal_manager.h>
#include <pid/log.h>
#include <pid/real_time.h>
#include <pid/synchro.h>
#include <CLI11/CLI11.hpp>
#include <chrono>
int main(int argc, char* argv[]) {
CLI::App app{"EL1018 driver example"};
std::string network_interface;
app.add_option("-i,--interface", network_interface, "Network interface")
->required();
double control_period{0.001};
app.add_option("-p,--period", control_period, "Control period (seconds)");
CLI11_PARSE(app, argc, argv);
auto memory_locker = pid::make_current_thread_real_time();
// Master creation
// Adding network interface
master.set_primary_interface(network_interface);
// Device definition
// Linking device to bus in hardware order !!
master.add(EK1100);
master.add(EL1018);
master.add(EL2008);
master.add(EK1110);
// Initilize the network
master.init();
bool stop = false;
pid::SignalManager::add(pid::SignalManager::Interrupt, "SigInt stop",
[&stop]() { stop = true; });
const auto period = std::chrono::duration<double>(control_period);
pid::Period loop(period);
pid_log << "Starting periodic loop" << pid::endl;
while (not stop) {
// If cycle is correct read data
if (master.next_cycle()) {
pid_log << "EL1018 state:" << pid::endl;
pid_log << "Channel 1 state = "
<< pid::endl;
pid_log << "Channel 2 state = "
<< pid::endl;
pid_log << "Channel 3 state = "
<< pid::endl;
pid_log << "Channel 4 state = "
<< pid::endl;
pid_log << pid::flush;
}
loop.sleep();
}
pid::SignalManager::remove(pid::SignalManager::Interrupt, "SigInt stop");
}
ethercatcpp::EL2008::set_channel_state
void set_channel_state(channel_id_t channel, bool state)
Set state of an output channel.
ethercatcpp::EL2008::channel_1
@ channel_1
Channel 1.
Definition: EL2008.h:61
ethercatcpp::EL1018
This class describe the EtherCAT driver for a beckhoff EL1018 device.
Definition: EL1018.h:51
ethercatcpp::EL1018::print_all_channels
void print_all_channels() const
Print all available data.
ethercatcpp::EK1110
This class is used to add a Beckhoff EK1110 device on EtherCAT buss.
Definition: EK1110.h:44
ethercatcpp::Master
This class define The EtherCAT Master.
Definition: master.h:50
ethercatcpp::Master::next_cycle
bool next_cycle()
Launch next ethercat communication cycle.
ethercatcpp::EL1018::channel_state
bool channel_state(channel_id_t channel) const
Get state of a channel.
ethercatcpp::Master::set_primary_interface
void set_primary_interface(const std::string &interface_primary)
Set the primary network interface to the EtherCAT system (Master)
ethercatcpp::EL1018::channel_3
@ channel_3
Channel 3.
Definition: EL1018.h:63
ethercatcpp::EL2008
This class describe the EtherCAT driver for a beckhoff EL2008 device.
Definition: EL2008.h:51
ethercatcpp::EL1018::channel_4
@ channel_4
Channel 4.
Definition: EL1018.h:64
ethercatcpp::EK1100
This class is used to add a Beckhoff EK1100 device on EtherCAT buss.
Definition: EK1100.h:46
core.h
Main header file for ethercatcpp-core.
ethercatcpp::EL2008::channel_4
@ channel_4
Channel 4.
Definition: EL2008.h:64
ethercatcpp::Master::add
void add(Device &device)
Add a new device to the global Ethercat bus. The order of addition must match the hardware order....
ethercatcpp::EL2008::channel_7
@ channel_7
Channel 7.
Definition: EL2008.h:67
ethercatcpp::EL1018::channel_1
@ channel_1
Channel 1.
Definition: EL1018.h:61
ethercatcpp::Master::init
void init()
Initializes network interface(s) then detect and match all devices on hardware bus.
ethercatcpp::EL1018::channel_2
@ channel_2
Channel 2.
Definition: EL1018.h:62