14 const std::string bus_name = rokubimini_ethercat_setup->
ethercatBus_;
17 ROS_ERROR(
"[%s] The name of the bus is empty.", rokubimini_setup->name_.c_str());
21 const auto& it =
buses_.find(bus_name);
26 buses_.insert(std::make_pair(bus_name, std::unique_ptr<rokubimini::soem_interface::EthercatBusBase>(bus)));
31 bus = it->second.get();
36 if (
rokubimini->getName() == rokubimini_ethercat_setup->name_)
54 const std::shared_ptr<setup::RokubiminiEthercat>& rokubiminiEthercatSetup)
const 56 auto slave = std::make_shared<RokubiminiEthercatSlave>(rokubiminiEthercatSetup->name_, bus,
57 rokubiminiEthercatSetup->ethercatAddress_,
58 rokubiminiEthercatSetup->ethercatPdoTypeEnum_);
84 ROS_ERROR_STREAM(
"[RokubiminiEthercatBusManager::addEthercatBus] bus is nullptr");
88 std::lock_guard<std::recursive_mutex> lock(
busMutex_);
92 buses_.insert(std::make_pair(bus->
getName(), std::unique_ptr<rokubimini::soem_interface::EthercatBusBase>(bus)));
105 ROS_ERROR_STREAM(
"[RokubiminiEthercatBusManager::addEthercatBus] bus is nullptr");
109 std::lock_guard<std::recursive_mutex> lock(
busMutex_);
110 const auto& it =
buses_.find(bus->getName());
113 buses_.insert(std::make_pair(bus->getName(), std::move(bus)));
131 std::lock_guard<std::recursive_mutex> lock(
busMutex_);
141 std::lock_guard<std::recursive_mutex> lock(
busMutex_);
151 std::lock_guard<std::recursive_mutex> lock(
busMutex_);
160 const unsigned int maxRetries,
const double retrySleep)
162 std::lock_guard<std::recursive_mutex> lock(
busMutex_);
167 bus.second->waitForState(state, slave, maxRetries, retrySleep);
172 buses_.at(busName)->waitForState(state, slave, maxRetries, retrySleep);
178 std::lock_guard<std::recursive_mutex> lock(
busMutex_);
181 if (!bus.second->startup())
183 ROS_ERROR(
"Failed to startup bus %s.", bus.first.c_str());
192 std::lock_guard<std::recursive_mutex> lock(
busMutex_);
195 bus.second->updateRead();
201 std::lock_guard<std::recursive_mutex> lock(
busMutex_);
204 bus.second->updateWrite();
210 std::lock_guard<std::recursive_mutex> lock(
busMutex_);
213 bus.second->shutdown();
217 std::unique_ptr<rokubimini::soem_interface::EthercatBusBase>
220 std::unique_ptr<rokubimini::soem_interface::EthercatBusBase> bus_out = std::move(
buses_.at(name));
231 bus_map_out.insert(std::make_pair(bus.first, std::move(bus.second)));
void setConfigMode() override
bool addRokubiminiToBus(RokubiminiEthercat *rokubimini, rokubimini::soem_interface::EthercatBusBase *bus, const std::shared_ptr< setup::RokubiminiEthercat > &rokubiminiEthercatSetup) const
Adds a Rokubimini to Bus.
void threadSleep(const double duration)
The Rokubimini Ethercat class.
bool addEthercatBus(rokubimini::soem_interface::EthercatBusBase *bus)
Adds an ethercat bus to the manager. The manager takes ownership of the bus pointer.
std::recursive_mutex busMutex_
Mutex prohibiting simultaneous access to EtherCAT bus manager.
const std::string & getName() const
bool addSlave(const EthercatSlaveBasePtr &slave)
void setRunMode() override
bool loadSetup(std::vector< std::shared_ptr< rokubimini::Rokubimini >> &rokubiminis) override
Loads the Rokubimini Setups.
BusMap buses_
Map with all the Ethercat buses available.
std::unique_ptr< rokubimini::soem_interface::EthercatBusBase > extractBusByName(const std::string &name)
Returns an owning bus pointer. The manager is now not managing this bus anymore.
The Rokubimini RokubiminiEthercat Setup class.
std::unordered_map< std::string, std::unique_ptr< rokubimini::soem_interface::EthercatBusBase >> BusMap
void setBussesOperational()
Sets all busses to operational state.
void readAllBuses() override
Calls update read on all busses.
void setBussesPreOperational()
Sets all busses to pre operational state.
bool startupCommunication() override
Starts up all busses.
void setSlavePointer(const RokubiminiEthercatSlavePtr &slavePtr)
Sets a pointer to the implementation.
bool startupAllBuses()
Starts up all busses and puts them in operational mode.
std::vector< std::shared_ptr< setup::Rokubimini > > attachedRokubiminiSetups_
void writeToAllBuses() override
Calls update write on all busses.
BusMap extractBuses()
Extracts all buses from the manager. The manager is now not managing any buses anymore.
Class for managing an ethercat bus containing one or multiple slaves.
void shutdownAllBuses() override
Calls shutdown on all busses.
std::string ethercatBus_
The ethercat bus name.
#define ROS_ERROR_STREAM(args)
void setBussesSafeOperational()
Sets all busses to safe operational state.
void waitForState(const uint16_t state, const uint16_t slave=0, const std::string &busName="", const unsigned int maxRetries=40, const double retrySleep=0.001)
Waits for the slave to reach a state.