34 transmission_(transmission),
35 actuators_(actuators),
48 qb_device_srvs::Trigger srv;
51 services_.at(
"activate_motors").call(srv);
52 if (!srv.response.success) {
59 ROS_WARN_STREAM_NAMED(
"device_hw",
"[DeviceHW] service [activate_motors] seems no longer advertised. Trying to reconnect...");
65 std::vector<std::string> namespaced_vector(vector);
67 for (
auto &elem : namespaced_vector) {
68 if (!std::regex_match(elem, std::regex(
"^" + prefix +
".*"))) {
72 return namespaced_vector;
77 qb_device_srvs::Trigger srv;
80 services_.at(
"deactivate_motors").call(srv);
81 if (!srv.response.success) {
88 ROS_WARN_STREAM_NAMED(
"device_hw",
"[DeviceHW] service [deactivate_motors] seems no longer advertised. Trying to reconnect...");
95 qb_device_srvs::Trigger srv;
99 if (!srv.response.success) {
103 return srv.response.message;
105 ROS_WARN_STREAM_NAMED(
"device_hw",
"[DeviceHW] service [get_info] seems no longer advertised. Trying to reconnect...");
112 qb_device_srvs::GetMeasurements srv;
118 services_.at(
"get_measurements").call(srv);
119 if (!srv.response.success) {
121 return srv.response.failures;
125 for (
int i=0; i<positions.size() && i<srv.response.positions.size(); i++) {
128 for (
int i=0; i<currents.size() && i<srv.response.currents.size(); i++) {
129 currents.at(i) = srv.response.currents.at(i);
131 stamp = srv.response.stamp;
132 return srv.response.failures;
134 ROS_WARN_STREAM_NAMED(
"device_hw",
"[DeviceHW] service [get_measurements] seems no longer advertised. Trying to reconnect...");
173 qb_device_srvs::InitializeDevice srv;
176 srv.request.rescan =
node_handle_.
param<
bool>(
"rescan_on_initialization",
false);
178 srv.request.max_repeats = max_repeats;
179 services_.at(
"initialize_device").call(srv);
180 if (!srv.response.success) {
208 ROS_WARN_STREAM_NAMED(
"device_hw",
"[DeviceHW] service [initialize_device] is no longer advertised.");
217 services_[
"get_measurements"] =
node_handle_.
serviceClient<qb_device_srvs::GetMeasurements>(
"/communication_handler/get_measurements",
true);
218 services_[
"initialize_device"] =
node_handle_.
serviceClient<qb_device_srvs::InitializeDevice>(
"/communication_handler/initialize_device",
true);
219 services_[
"set_commands"] =
node_handle_.
serviceClient<qb_device_srvs::SetCommands>(
"/communication_handler/set_commands",
true);
224 qb_device_msgs::StateStamped msg;
233 qb_device_msgs::ResourceData msg_actuator_data;
239 msg.device_data.actuators.push_back(msg_actuator_data);
243 qb_device_msgs::ResourceData msg_joint_data;
249 msg.device_data.joints.push_back(msg_joint_data);
284 if (reinitialize_device) {
291 qb_device_srvs::SetCommands srv;
297 for (
auto const &
command : commands) {
302 if (!srv.response.success) {
308 ROS_WARN_STREAM_NAMED(
"device_hw",
"[DeviceHW] service [set_commands] seems no longer advertised. Trying to reconnect...");
321 service.second.waitForExistence();
323 ROS_INFO_STREAM_NAMED(
"device_hw",
"[DeviceHW] is connected to all the services advertise by [CommunicationHandler].");
ServiceClient serviceClient(const std::string &service_name, bool persistent=false, const M_string &header_values=M_string())
void resetServicesAndWait(const bool &reinitialize_device=true)
Re-subscribe to all the services advertised by the Communication Handler and wait until all the servi...
qb_device_hardware_interface::qbDeviceHWResources joints_
std::shared_ptr< transmission_interface::Transmission > TransmissionPtr
std::vector< double > efforts
void initialize(ros::NodeHandle &robot_hw_nh, qb_device_hardware_interface::qbDeviceHWResources &joints, const urdf::Model &urdf_model, hardware_interface::PositionJointInterface &joint_position)
Retrieve the joint limits for each given joint.
void setReliability(const int &max_repeats, const int &consecutive_failures)
Compare the given consecutive failures w.r.t.
void publish(const boost::shared_ptr< M > &message) const
#define ROS_ERROR_STREAM_NAMED(name, args)
virtual int getMeasurements(std::vector< double > &positions, std::vector< double > ¤ts, ros::Time &stamp)
Call the service to retrieve device measurements (both positions and currents) and wait for the respo...
std::vector< int > encoder_resolutions
void publish()
Construct a qb_device_msgs::StateStamped message of the whole device state with the data retrieved du...
std::vector< int > position_limits
std::vector< double > positions
void initialize(const std::string &transmission_name, qb_device_hardware_interface::qbDeviceHWResources &actuators, qb_device_hardware_interface::qbDeviceHWResources &joints)
Initialize the Device Transmission Resources interfaces.
qb_device_joint_limits_interface::qbDeviceJointLimitsResources joint_limits_
std::vector< double > commands
URDF_EXPORT bool initParamWithNodeHandle(const std::string ¶m, const ros::NodeHandle &nh=ros::NodeHandle())
qb_device_msgs::Info device_info_
#define ROS_INFO_STREAM_NAMED(name, args)
virtual std::string getInfo()
Call the service to retrieve the printable configuration setup of the device and wait for the respons...
bool init(ros::NodeHandle &root_nh, ros::NodeHandle &robot_hw_nh) override
The init function is called to initialize the RobotHW from a non-realtime thread. ...
~qbDeviceHW() override
Deactivate motors and stop the async spinner.
ROSLIB_DECL std::string command(const std::string &cmd)
hardware_interface::PositionJointInterface joint_position
qb_device_hardware_interface::qbDeviceResources device_
transmission_interface::JointToActuatorPositionInterface joint_to_actuator_position
bool param(const std::string ¶m_name, T ¶m_val, const T &default_val) const
void enforceLimits(const ros::Duration &period)
Enforce limits for all managed interfaces.
qb_device_hardware_interface::qbDeviceHWResources actuators_
void write(const ros::Time &time, const ros::Duration &period) override
Enforce joint limits for all registered joint limit interfaces, propagate joint commands to actuators...
ros::AsyncSpinner spinner_
const std::string & getNamespace() const
virtual int deactivateMotors()
Call the service to deactivate the device motors and wait for the response.
ros::NodeHandle node_handle_
std::vector< std::string > names
Publisher advertise(const std::string &topic, uint32_t queue_size, bool latch=false)
qb_device_transmission_interface::qbDeviceTransmissionResources transmission_
bool get_distinct_packages
virtual int activateMotors()
Call the service to activate the device motors and wait for the response.
void waitForServices()
Wait until all the services advertised by the Communication Handler are active, then reinitialize the...
void initializeServicesAndWait()
Subscribe to all the services advertised by the Communication Handler and wait until all the services...
std::vector< std::string > addNamespacePrefix(const std::vector< std::string > &vector)
Add the namespace prefix stored in the private namespace_ to all the elements of the given vector...
std::vector< double > velocities
#define ROS_INFO_STREAM(args)
qbDeviceHW(qb_device_transmission_interface::TransmissionPtr transmission, const std::vector< std::string > &actuators, const std::vector< std::string > &joints)
Initialize HW resources and interfaces, and wait until it is initialized from the Communication Handl...
transmission_interface::ActuatorToJointStateInterface actuator_to_joint_state
bool getParam(const std::string &key, std::string &s) const
virtual int initializeDevice()
Call the service to initialize the device with parameters from the Communication Handler and wait for...
void waitForInitialization()
Wait until the device is initialized.
virtual int setCommands(const std::vector< double > &commands)
Call the service to send reference commands to the device and wait for the response.
std::map< std::string, ros::ServiceClient > services_
void setJoints(const std::vector< std::string > &joints)
Initialize the joint names of the Resource with the given vector.
ros::Publisher state_publisher_
qb_device_hardware_interface::qbDeviceHWInterfaces interfaces_
void read(const ros::Time &time, const ros::Duration &period) override
Read actuator state from the hardware, propagate it to joint states and publish the whole device stat...
void initialize(hardware_interface::RobotHW *robot, qbDeviceHWResources &joints)
Initialize the joint_state and joint_position HW interfaces with the given device Resource...
#define ROS_WARN_STREAM_NAMED(name, args)