RokubiminiEthercatSlave.hpp
Go to the documentation of this file.
1 #pragma once
2 
4 // soem_interface
7 
8 #include <rokubimini/Reading.hpp>
12 
15 
16 #define MAX_FILE_SIZE_FIRMWARE (0x100000)
17 
18 namespace rokubimini
19 {
20 namespace ethercat
21 {
33 const static std::map<uint8_t, std::string> STATE_TO_STRING = { { EC_STATE_INIT, "Initialization state" },
34  { EC_STATE_PRE_OP, "Pre-Operational state" },
35  { EC_STATE_SAFE_OP, "Safe-Operational state" },
36  { EC_STATE_OPERATIONAL, "Operational state" } };
38 {
39 public:
48  RokubiminiEthercatSlave() = delete;
49 
64  const uint32_t address, const PdoTypeEnum pdoTypeEnum);
65 
66  ~RokubiminiEthercatSlave() override = default;
67 
78  bool startup() override;
79 
87  void preSetupConfiguration();
88 
97  void updateRead() override;
98 
108  void updateWrite() override;
109 
118  void shutdown() override;
119 
130  void setState(const uint16_t state);
131 
142  bool waitForState(const uint16_t state);
143 
153  PdoInfo getCurrentPdoInfo() const override;
154 
164  std::string getName() const override
165  {
166  return name_;
167  }
168 
179  {
180  return currentPdoTypeEnum_;
181  }
182 
194  bool getSerialNumber(unsigned int& serialNumber) override;
195 
205  inline unsigned int fetchSerialNumber() const
206  {
207  return serialNumber_;
208  }
209 
222  bool getForceTorqueSamplingRate(int& samplingRate);
223 
237 
249  bool setAccelerationFilter(const unsigned int filter);
250 
262  bool setAngularRateFilter(const unsigned int filter);
263 
275  bool setAccelerationRange(const unsigned int range);
276 
288  bool setAngularRateRange(const unsigned int range);
289 
301  bool setForceTorqueOffset(const Eigen::Matrix<double, 6, 1>& forceTorqueOffset);
302 
314  bool setSensorConfiguration(const configuration::SensorConfiguration& sensorConfiguration);
315 
327  bool setSensorCalibration(const calibration::SensorCalibration& sensorCalibration);
328 
336  bool setConfigMode();
337 
345  bool setRunMode();
346 
356  bool saveConfigParameter();
357 
367  void getReading(rokubimini::Reading& reading) const;
368 
378  bool firmwareUpdate(const std::string& filePath, const std::string& fileName, const uint32_t& password);
379 
386  bool isRunning()
387  {
388  return isRunning_;
389  }
390 
400 
410 
418  bool runsAsync() const
419  {
420  return runsAsync_;
421  }
422 
431  {
433  }
434 
442  void resetDataFlags();
443 
451  void updateDataFlags();
452 
453 private:
464  bool configurePdo(const PdoTypeEnum pdoTypeEnum);
465 
477  bool sendCalibrationMatrixEntry(const uint8_t subId, const double entry);
478 
487  bool readFileToBuffer(const std::string& filePath);
488 
496  uint8_t getState();
497 
505 
514  std::string getSlaveStateString(uint8_t state);
515 
516  using PdoInfos = std::map<PdoTypeEnum, PdoInfo>;
517 
525  const std::string name_;
526 
534 
542  std::atomic<PdoTypeEnum> pdoTypeEnum_;
543 
551  std::atomic<PdoTypeEnum> currentPdoTypeEnum_;
552 
563 
571 
578  char* fileBuffer_;
579 
586  std::atomic<bool> isRunning_;
587 
594  std::atomic<bool> runsAsync_;
595 
604 
612  mutable std::recursive_mutex dataFlagsMutex_;
613 };
614 
615 using RokubiminiEthercatSlavePtr = std::shared_ptr<RokubiminiEthercatSlave>;
616 
617 } // namespace ethercat
618 } // namespace rokubimini
bool setAccelerationRange(const unsigned int range)
Sets an acceleration range to the device.
bool setAngularRateRange(const unsigned int range)
Sets an angular rate range to the device.
bool firmwareUpdate(const std::string &filePath, const std::string &fileName, const uint32_t &password)
Updates the firmware of the device.
Statusword currentDataFlagsDiagnostics_
The current Data Flags Diagnostics (Data Status) which is updated when a new frame is published and i...
bool getSerialNumber(unsigned int &serialNumber) override
Accessor for device serial number.
void updateRead() override
This method is called by the EthercatBusManager. Each device attached to this bus reads its data from...
bool getForceTorqueSamplingRate(int &samplingRate)
Gets the force torque sampling rate of the device.
void setRunsAsync(bool runsAsync)
Sets the runsAsync_ variable.
RokubiminiEthercatSlave()=delete
Default constructor is deleted.
PdoTypeEnum getCurrentPdoTypeEnum() const
Accessor for the current PDO type.
std::atomic< PdoTypeEnum > currentPdoTypeEnum_
Current PDO type.
uint8_t getState()
Returns the EtherCAT State of the device.
Base class for generic ethercat slaves using soem.
unsigned int fetchSerialNumber() const
Accessor for device serial number.
unsigned int serialNumber_
The serial number of the device.
void updateDataFlags()
Updates the Data Flags variable currentDataFlagsDiagnostics_.
unsigned short uint16_t
void updateWrite() override
This method is called by the EthercatBusManager. Each device attached to the bus writes its data to t...
unsigned char uint8_t
void shutdown() override
Shuts down the device.
bool setSensorConfiguration(const configuration::SensorConfiguration &sensorConfiguration)
Sets a sensor configuration to the device.
bool configurePdo(const PdoTypeEnum pdoTypeEnum)
Configures a PDO in the Ethercat device.
bool setAccelerationFilter(const unsigned int filter)
Sets an acceleration filter to the device.
The Rokubimini Ethercat Implementation (Slave) class.
void resetDataFlags()
Resets the Data Flags variable currentDataFlagsDiagnostics_.
std::recursive_mutex dataFlagsMutex_
Mutex prohibiting simultaneous access to the Data Flags structure.
bool readFileToBuffer(const std::string &filePath)
Reads the contents of a file to an internal buffer.
void getReading(rokubimini::Reading &reading) const
Gets the internal reading variable.
bool setAngularRateFilter(const unsigned int filter)
Sets an angular rate filter to the device.
EC_STATE_OPERATIONAL
bool isRunning()
Returns if the instance is running.
PdoInfos pdoInfos_
Map between PDO types and their infos.
unsigned int uint32_t
bool saveConfigParameter()
Saves the current configuration to the device.
char * fileBuffer_
The buffer to save the contents of the file.
EC_STATE_SAFE_OP
EC_STATE_PRE_OP
void setState(const uint16_t state)
Sets the desired EtherCAT state machine state of the device in the bus.
std::shared_ptr< RokubiminiEthercatSlave > RokubiminiEthercatSlavePtr
bool waitForState(const uint16_t state)
Wait for an EtherCAT state machine state to be reached.
std::string getSlaveStateString(uint8_t state)
Returns the EtherCAT State of the device in a string.
bool setForceTorqueOffset(const Eigen::Matrix< double, 6, 1 > &forceTorqueOffset)
Sets a force torque offset to the device.
bool sendCalibrationMatrixEntry(const uint8_t subId, const double entry)
Sends a calibration matrix entry to device.
void updateConnectionStatus(diagnostic_updater::DiagnosticStatusWrapper &stat)
Fills the Device Connection Status (ROS diagnostics).
bool runsAsync() const
Returns if the driver runs asynchronously.
PdoInfo getCurrentPdoInfo() const override
Accessor for the current PDO info.
void createDataFlagsDiagnostics(diagnostic_updater::DiagnosticStatusWrapper &stat)
Creates the Data Flags Diagnostics status.
static const std::map< uint8_t, std::string > STATE_TO_STRING
bool setConfigMode()
Sets the device in config mode.
Struct defining the Pdo characteristic.
Class for managing an ethercat bus containing one or multiple slaves.
std::string getName() const override
Accessor for device name.
void preSetupConfiguration()
Pre-setup configuration hook.
bool setForceTorqueFilter(const configuration::ForceTorqueFilter &filter)
Sets a force torque filter to the device.
uint16_t getALStatusCode()
Returns the AL Status Code of the slave.
bool startup() override
This method starts up and initializes the device.
bool setSensorCalibration(const calibration::SensorCalibration &sensorCalibration)
Sets a sensor calibration to the device.
Reading reading_
The internal reading variable. It&#39;s used for providing to client code the sensor readings, through the getReading () function.
std::atomic< bool > isRunning_
Internal flag to indicate if the instance is running.
EC_STATE_INIT


rokubimini_ethercat
Author(s):
autogenerated on Sat Apr 15 2023 02:51:33