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> 55 ModbusClientUniquePtr modbus_client,
unsigned int response_timeout_ms,
56 const std::string& modbus_read_topic_name,
const std::string& modbus_write_service_name,
66 bool init(
const char* ip,
unsigned int port);
76 bool init(
const char* ip,
unsigned int port,
int retries,
const ros::Duration& timeout_ms);
103 std::vector<std::vector<unsigned short>>
static splitIntoBlocks(std::vector<unsigned short>& in);
139 std::atomic<State>
state_{ State::not_initialized };
157 return state_.load() == State::running;
161 WriteModbusRegister::Response& res)
171 #endif // PRBT_HARDWARE_SUPPORT_CLIENT_NODE_H std::vector< unsigned short > registers_to_read_
Registers which have to be read.
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.
static std::vector< std::vector< unsigned short > > splitIntoBlocks(std::vector< unsigned short > &in)
Splits a vector of integers into a vector of vectors with consecutive groups.
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::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.