mb_publisher.cpp
Go to the documentation of this file.
1 /*
2  * Copyright 2017, 2018 Simon Rasmussen (refactor)
3  *
4  * Copyright 2015, 2016 Thomas Timm Andersen (original version)
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */
18 
20 
21 inline void appendAnalog(std::vector<ur_msgs::Analog>& vec, double val, uint8_t pin)
22 {
23  ur_msgs::Analog ana;
24  ana.pin = pin;
25  ana.state = val;
26  vec.push_back(ana);
27 }
28 
29 void MBPublisher::publishIOStates(ur_msgs::IOStates& io_msg, SharedMasterBoardData& data)
30 {
31  appendAnalog(io_msg.analog_in_states, data.analog_input0, 0);
32  appendAnalog(io_msg.analog_in_states, data.analog_input1, 1);
33  appendAnalog(io_msg.analog_out_states, data.analog_output0, 0);
34  appendAnalog(io_msg.analog_out_states, data.analog_output1, 1);
35 
36  io_pub_.publish(io_msg);
37 }
38 
39 void MBPublisher::publishRobotStatus(industrial_msgs::RobotStatus& status, const SharedRobotModeData& data) const
40 {
41  // using ROS time here as the 'timestamp' in RobotModeData is not time-synced
42  // with ROS time. Publishing messages using the controller's time will
43  // complicate correlating RobotStatus messages with other messages that do
44  // use ROS time.
45  status.header.stamp = ros::Time::now();
46 
47  // note that this is true as soon as the drives are powered,
48  // even if the brakes are still closed
49  // which is in slight contrast to the comments in the
50  // message definition
51  status.drives_powered.val = data.robot_power_on;
52 
53  status.e_stopped.val = data.emergency_stopped;
54 
55  // I found no way to reliably get information if the robot is moving
56  // data.programm_running would be true when using this driver to move the robot
57  // but it would also be true when another programm is running that might not
58  // in fact contain any movement commands
59  status.in_motion.val = industrial_msgs::TriState::UNKNOWN;
60 
61  // the error code, if any, is not transmitted by this protocol
62  // it can and should be fetched seperately
63  status.error_code = 0;
64 
65  // note that e-stop is handled by a seperate variable
66  status.in_error.val = data.protective_stopped;
67 
68  status_pub_.publish(status);
69 }
70 
72 {
73  industrial_msgs::RobotStatus msg;
74 
76  msg.mode.val = industrial_msgs::RobotMode::MANUAL;
77  else
78  msg.mode.val = industrial_msgs::RobotMode::AUTO;
79 
80  // todo: verify that this correct, there is also ROBOT_READY_MODE
81  msg.motion_possible.val = (data.robot_mode == robot_mode_V1_X::ROBOT_RUNNING_MODE) ? industrial_msgs::TriState::ON :
82  industrial_msgs::TriState::OFF;
83 
84  publishRobotStatus(msg, data);
85 }
86 
88 {
89  industrial_msgs::RobotStatus msg;
90 
91  msg.motion_possible.val =
92  (data.robot_mode == robot_mode_V3_X::RUNNING) ? industrial_msgs::TriState::ON : industrial_msgs::TriState::OFF;
93 
95  msg.mode.val = industrial_msgs::RobotMode::MANUAL;
96  else
97  msg.mode.val = industrial_msgs::RobotMode::AUTO;
98 
99  publishRobotStatus(msg, data);
100 }
101 
102 void MBPublisher::publishMasterboardData(ur_msgs::MasterboardDataMsg& msg, const SharedMasterBoardData& data) const
103 {
104  // populate common fields (ie: those that exist in all versions of the protocol)
105  msg.analog_input_range0 = data.analog_input_range0;
106  msg.analog_input_range1 = data.analog_input_range1;
107  msg.analog_input0 = data.analog_input0;
108  msg.analog_input1 = data.analog_input1;
109  msg.analog_output_domain0 = data.analog_output_domain0;
110  msg.analog_output_domain1 = data.analog_output_domain1;
111  msg.analog_output0 = data.analog_output0;
112  msg.analog_output1 = data.analog_output1;
113  msg.masterboard_temperature = data.master_board_temperature;
114  msg.robot_voltage_48V = data.robot_voltage_48V;
115  msg.robot_current = data.robot_current;
116  msg.master_io_current = data.master_IO_current;
117 
119 }
120 
122 {
123  using ros_msg_dig_inp_t = ur_msgs::MasterboardDataMsg::_digital_input_bits_type;
124  using ros_msg_dig_outp_t = ur_msgs::MasterboardDataMsg::_digital_output_bits_type;
125 
126  ur_msgs::MasterboardDataMsg msg;
127 
128  // according to UR documentation, digital_*_bits fields are 4 byte integers,
129  // so this is valid (MasterBoardData ROS msg fields are sufficiently wide).
130  // in V1.x, only 10 bits are used
131  msg.digital_input_bits = static_cast<ros_msg_dig_inp_t>(data.digital_input_bits.to_ulong());
132  msg.digital_output_bits = static_cast<ros_msg_dig_outp_t>(data.digital_output_bits.to_ulong());
133 
134  // delegate remainder to common handler
135  publishMasterboardData(msg, data);
136 }
137 
139 {
140  using ros_msg_dig_inp_t = ur_msgs::MasterboardDataMsg::_digital_input_bits_type;
141  using ros_msg_dig_outp_t = ur_msgs::MasterboardDataMsg::_digital_output_bits_type;
142 
143  ur_msgs::MasterboardDataMsg msg;
144 
145  // according to UR documentation, digital_*_bits fields are 4 byte integers,
146  // so this is valid (MasterBoardData ROS msg fields are sufficiently wide)
147  // in V3.0, only 18 bits are used
148  msg.digital_input_bits = static_cast<ros_msg_dig_inp_t>(data.digital_input_bits.to_ulong());
149  msg.digital_output_bits = static_cast<ros_msg_dig_outp_t>(data.digital_output_bits.to_ulong());
150 
151  // delegate remainder to common handler
152  publishMasterboardData(msg, data);
153 }
154 
155 void MBPublisher::publishRobotModeData(ur_msgs::RobotModeDataMsg& msg, const SharedRobotModeData& data) const
156 {
157  // populate common fields (note: ROS msg structure only contains the common
158  // fields right now, so we populate all fields here).
159  msg.timestamp = data.timestamp;
160  msg.is_robot_connected = data.physical_robot_connected;
161  msg.is_real_robot_enabled = data.real_robot_enabled;
162  msg.is_power_on_robot = data.robot_power_on;
163  msg.is_emergency_stopped = data.emergency_stopped;
164  msg.is_protective_stopped = data.protective_stopped;
165  msg.is_program_running = data.program_running;
166  msg.is_program_paused = data.program_paused;
167 
169 }
170 
172 {
173  ur_msgs::RobotModeDataMsg msg;
174  publishRobotModeData(msg, data);
175 }
176 
178 {
179  // TODO: add V3 specific fields to RobotModeDataMsg and populate here
180  // for now: delegate to common handler.
181  ur_msgs::RobotModeDataMsg msg;
182  publishRobotModeData(msg, data);
183 }
184 
186 {
187  ur_msgs::IOStates io_msg;
188  appendDigital(io_msg.digital_in_states, data.digital_input_bits);
189  appendDigital(io_msg.digital_out_states, data.digital_output_bits);
190  publishIOStates(io_msg, data);
191 
193 
194  return true;
195 }
196 
198 {
199  ur_msgs::IOStates io_msg;
200  appendDigital(io_msg.digital_in_states, data.digital_input_bits);
201  appendDigital(io_msg.digital_out_states, data.digital_output_bits);
202  publishIOStates(io_msg, data);
203 
205 
206  return true;
207 }
208 
210 {
211  consume(static_cast<MasterBoardData_V3_0__1&>(data));
212  return true;
213 }
214 
216 {
217  publishRobotStatus(data);
218  publishRobotModeData(data);
219  return true;
220 }
221 
223 {
224  publishRobotStatus(data);
225  publishRobotModeData(data);
226  return true;
227 }
228 
230 {
231  publishRobotStatus(data);
232  // use 3.0 handler for now (as we don't parse version-specific fields
233  // for this type of packet yet: would require changes to the ROS msg
234  // structure)
235  publishRobotModeData(static_cast<RobotModeData_V3_0__1&>(data));
236  return true;
237 }
uint64_t timestamp
Definition: robot_mode.h:32
std::bitset< 10 > digital_output_bits
Definition: master_board.h:64
void publish(const boost::shared_ptr< M > &message) const
robot_mode_V3_X robot_mode
Definition: robot_mode.h:100
Publisher masterboard_state_pub_
Definition: mb_publisher.h:39
std::bitset< 10 > digital_input_bits
Definition: master_board.h:63
Publisher io_pub_
Definition: mb_publisher.h:37
void publishRobotStatus(industrial_msgs::RobotStatus &status, const SharedRobotModeData &data) const
Publisher robot_mode_state_pub_
Definition: mb_publisher.h:40
void publishIOStates(ur_msgs::IOStates &io_msg, SharedMasterBoardData &data)
robot_control_mode_V3_X control_mode
Definition: robot_mode.h:101
robot_mode_V1_X robot_mode
Definition: robot_mode.h:65
void appendDigital(std::vector< ur_msgs::Digital > &vec, std::bitset< N > bits)
Definition: mb_publisher.h:43
std::bitset< 18 > digital_output_bits
Definition: master_board.h:85
Publisher status_pub_
Definition: mb_publisher.h:38
virtual bool consume(MasterBoardData_V1_X &data)
void appendAnalog(std::vector< ur_msgs::Analog > &vec, double val, uint8_t pin)
static Time now()
void publishMasterboardData(ur_msgs::MasterboardDataMsg &msg, const SharedMasterBoardData &data) const
bool physical_robot_connected
Definition: robot_mode.h:33
std::bitset< 18 > digital_input_bits
Definition: master_board.h:84
void publishRobotModeData(ur_msgs::RobotModeDataMsg &msg, const SharedRobotModeData &data) const


ur_modern_driver
Author(s): Thomas Timm Andersen, Simon Rasmussen
autogenerated on Fri Jun 26 2020 03:37:00