Motion Master
Loading...
Searching...
No Matches
soem_master.h
Go to the documentation of this file.
1#include <chrono>
2#include <map>
3#include <string>
4
5#include "ethercat_master.h"
6#include "ethercat_slave.h"
7#include "notifier.h"
8
9class SoemMaster : public EthercatMaster {
10 Notifier &notifier_;
11 const std::string &ifname_;
12 std::atomic_bool running_;
13 bool pdo_communication_possible_ = false;
14
15 std::chrono::time_point<std::chrono::steady_clock> start_;
16
17 // The slaveMap is static because other parts of the code, such as
18 // ParameterValueRefresher, might hold a raw pointer to an instance of
19 // SoemSlave (see SoemMaster::get_slaves()). If slaveMap were a member
20 // variable, it would be destroyed when the SoemMaster instance goes out of
21 // scope. Since it's a unique pointer, this destruction would also delete
22 // the slaves and OD entries, leading to ParameterValueRefresher potentially
23 // accessing an invalid memory location.
24
25 public:
26 static std::map<uint16_t, std::unique_ptr<EthercatSlave>> slaveMap;
27 explicit SoemMaster(Notifier &notifier, const std::string &ifname);
28 ~SoemMaster() override;
29 size_t start() override;
30 void stop() override;
31 size_t restart() override;
32 int32_t execute(uint64_t pending_signals) override;
33 bool is_running() override;
34 int get_slaves_responding() override;
35 std::list<VirtualDevice *> get_slaves() override;
36 bool disable_all_slaves() override;
37 void abort_all_client_requests() override {};
38 static void wait_for_slaves(Notifier &notifier, const std::string &ifname);
39 int roundtrip();
40 void checkstate();
41};
Definition: ethercat_master.h:9
Definition: notifier.h:10
Definition: soem_master.h:9
std::list< VirtualDevice * > get_slaves() override
Get all of the available slaves.
Definition: soem_master.cc:128
void checkstate()
Definition: soem_master.cc:206
bool disable_all_slaves() override
Switch all slaves to PREOP.
Definition: soem_master.cc:136
void stop() override
Stop the EtherCAT master.
Definition: soem_master.cc:86
~SoemMaster() override
Definition: soem_master.cc:73
static void wait_for_slaves(Notifier &notifier, const std::string &ifname)
Definition: soem_master.cc:146
int get_slaves_responding() override
Return the number of slaves actually responding on the bus.
Definition: soem_master.cc:126
static std::map< uint16_t, std::unique_ptr< EthercatSlave > > slaveMap
Definition: soem_master.h:26
void abort_all_client_requests() override
Definition: soem_master.h:37
int roundtrip()
Definition: soem_master.cc:180
size_t restart() override
Definition: soem_master.cc:104
bool is_running() override
Check if the EtherCAT master is currently running.
Definition: soem_master.cc:124
size_t start() override
Start the EtherCAT master.
Definition: soem_master.cc:75
int32_t execute(uint64_t pending_signals) override
Main EtherCAT master loop function to be executed at one millisecond interval.
Definition: soem_master.cc:106