18 #ifndef PRBT_HARDWARE_SUPPORT_CLIENT_NODE_H 19 #define PRBT_HARDWARE_SUPPORT_CLIENT_NODE_H 25 #include <boost/optional.hpp> 28 #include <std_msgs/UInt16MultiArray.h> 32 #include <prbt_hardware_support/WriteModbusRegister.h> 57 ModbusClientUniquePtr modbus_client,
58 unsigned int response_timeout_ms,
59 const std::string& modbus_read_topic_name,
60 const std::string& modbus_write_service_name,
69 bool init(
const char* ip,
unsigned int port);
79 bool init(
const char* ip,
unsigned int port,
unsigned int retries,
ros::Duration timeout_ms);
106 std::vector<std::vector<unsigned short>>
static split_into_blocks(std::vector<unsigned short> &in);
116 WriteModbusRegister::Response& res);
143 std::atomic<State>
state_ {State::not_initialized};
161 return state_.load() == State::running;
165 WriteModbusRegister::Response& res)
175 #endif // PRBT_HARDWARE_SUPPORT_CLIENT_NODE_H
void run()
Publishes the register values as messages.
bool init(const char *ip, unsigned int port)
Tries to connect to a modbus server.
State
States of the Modbus-client.
const unsigned int RESPONSE_TIMEOUT_MS
Defines how long we wait for a response from the Modbus-server.
bool isRunning()
True if 'run()' method is active, false if 'run()' method is not active or, currently, finishing.
bool modbus_write_service_cb(WriteModbusRegister::Request &req, WriteModbusRegister::Response &res)
Stores the register which have to be send to the modbus server in a local buffer for further processi...
ros::ServiceServer modbus_write_service_
ros::Publisher modbus_read_pub_
std::atomic_bool stop_run_
PilzModbusClient(ros::NodeHandle &nh, const std::vector< unsigned short > ®isters_to_read, ModbusClientUniquePtr modbus_client, unsigned int response_timeout_ms, const std::string &modbus_read_topic_name, const std::string &modbus_write_service_name, double read_frequency_hz=DEFAULT_MODBUS_READ_FREQUENCY_HZ)
Sets up publisher. To open the modbus connection call PilzModbusClient::init.
std::atomic< State > state_
Connects to a modbus server and publishes the received data into ROS.
static constexpr double DEFAULT_MODBUS_READ_FREQUENCY_HZ
static constexpr int DEFAULT_QUEUE_SIZE_MODBUS
ros::Subscriber modbus_write_sub_
std::mutex write_reg_blocks_mutex_
ModbusClientUniquePtr modbus_client_
std::vector< unsigned short > registers_to_read
Registers which have to be read.
static std::vector< std::vector< unsigned short > > split_into_blocks(std::vector< unsigned short > &in)
Splits a vector of integers into a vector of vectors with consecutive groups.
std::unique_ptr< ModbusClient > ModbusClientUniquePtr
std::queue< ModbusRegisterBlock > write_reg_blocks_
void terminate()
Ends the infinite loop started in method 'run()'.
const double READ_FREQUENCY_HZ
Defines how often the Modbus registers are read in.