mirror of
https://gitlab.com/obbart/universal_robots_ros_driver.git
synced 2026-04-10 01:50:46 +02:00
Added ROS publisher of IOStates
This commit is contained in:
@@ -209,7 +209,7 @@ double RobotState::getVersion() {
|
|||||||
double ver;
|
double ver;
|
||||||
val_lock_.lock();
|
val_lock_.lock();
|
||||||
ver = version_msg_.major_version + 0.1 * version_msg_.minor_version
|
ver = version_msg_.major_version + 0.1 * version_msg_.minor_version
|
||||||
+ .0000001 * version_msg_.svn_revision;
|
+ .0000001 * version_msg_.svn_revision;
|
||||||
val_lock_.unlock();
|
val_lock_.unlock();
|
||||||
return ver;
|
return ver;
|
||||||
|
|
||||||
@@ -218,3 +218,23 @@ double RobotState::getVersion() {
|
|||||||
void RobotState::finishedReading() {
|
void RobotState::finishedReading() {
|
||||||
new_data_available_ = false;
|
new_data_available_ = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int RobotState::getDigitalInputBits() {
|
||||||
|
return mb_data_.digitalInputBits;
|
||||||
|
}
|
||||||
|
int RobotState::getDigitalOutputBits() {
|
||||||
|
return mb_data_.digitalOutputBits;
|
||||||
|
}
|
||||||
|
double RobotState::getAnalogInput0() {
|
||||||
|
return mb_data_.analogInput0;
|
||||||
|
}
|
||||||
|
double RobotState::getAnalogInput1() {
|
||||||
|
return mb_data_.analogInput1;
|
||||||
|
}
|
||||||
|
double RobotState::getAnalogOutput0() {
|
||||||
|
return mb_data_.analogOutput0;
|
||||||
|
|
||||||
|
}
|
||||||
|
double RobotState::getAnalogOutput1() {
|
||||||
|
return mb_data_.analogOutput1;
|
||||||
|
}
|
||||||
|
|||||||
@@ -31,6 +31,9 @@
|
|||||||
#include "ur_msgs/SetPayloadResponse.h"
|
#include "ur_msgs/SetPayloadResponse.h"
|
||||||
#include "ur_msgs/SetIORequest.h"
|
#include "ur_msgs/SetIORequest.h"
|
||||||
#include "ur_msgs/SetIOResponse.h"
|
#include "ur_msgs/SetIOResponse.h"
|
||||||
|
#include "ur_msgs/IOStates.h"
|
||||||
|
#include "ur_msgs/Digital.h"
|
||||||
|
#include "ur_msgs/Analog.h"
|
||||||
#include "std_msgs/String.h"
|
#include "std_msgs/String.h"
|
||||||
|
|
||||||
class RosWrapper {
|
class RosWrapper {
|
||||||
@@ -366,6 +369,51 @@ private:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void publishMsg() {
|
||||||
|
ros::Publisher io_pub = nh_.advertise<ur_msgs::IOStates>("/io_states",
|
||||||
|
1);
|
||||||
|
|
||||||
|
while (ros::ok()) {
|
||||||
|
ur_msgs::IOStates io_msg;
|
||||||
|
std::mutex msg_lock; // The values are locked for reading in the class, so just use a dummy mutex
|
||||||
|
std::unique_lock<std::mutex> locker(msg_lock);
|
||||||
|
while (!robot_.sec_interface_->robot_state_->getNewDataAvailable()) {
|
||||||
|
msg_cond_.wait(locker);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (unsigned int i = 0; i < 10; i++) {
|
||||||
|
ur_msgs::Digital digi;
|
||||||
|
digi.pin = i;
|
||||||
|
digi.state =
|
||||||
|
((robot_.sec_interface_->robot_state_->getDigitalInputBits()
|
||||||
|
& (1 << i)) >> i);
|
||||||
|
io_msg.digital_in_states.push_back(digi);
|
||||||
|
digi.state =
|
||||||
|
((robot_.sec_interface_->robot_state_->getDigitalOutputBits()
|
||||||
|
& (1 << i)) >> i);
|
||||||
|
io_msg.digital_out_states.push_back(digi);
|
||||||
|
}
|
||||||
|
ur_msgs::Analog ana;
|
||||||
|
ana.pin = 0;
|
||||||
|
ana.state = robot_.sec_interface_->robot_state_->getAnalogInput0();
|
||||||
|
io_msg.analog_in_states.push_back(ana);
|
||||||
|
ana.pin = 1;
|
||||||
|
ana.state = robot_.sec_interface_->robot_state_->getAnalogInput1();
|
||||||
|
io_msg.analog_in_states.push_back(ana);
|
||||||
|
|
||||||
|
ana.pin = 0;
|
||||||
|
ana.state = robot_.sec_interface_->robot_state_->getAnalogOutput0();
|
||||||
|
io_msg.analog_out_states.push_back(ana);
|
||||||
|
ana.pin = 1;
|
||||||
|
ana.state = robot_.sec_interface_->robot_state_->getAnalogOutput1();
|
||||||
|
io_msg.analog_out_states.push_back(ana);
|
||||||
|
io_pub.publish(io_msg);
|
||||||
|
|
||||||
|
robot_.sec_interface_->robot_state_->finishedReading();
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
int main(int argc, char **argv) {
|
int main(int argc, char **argv) {
|
||||||
|
|||||||
Reference in New Issue
Block a user