rt_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 
22 {
23  sensor_msgs::JointState joint_msg;
24  joint_msg.header.stamp = t;
25 
26  joint_msg.name.assign(joint_names_.begin(), joint_names_.end());
27  joint_msg.position.assign(packet.q_actual.begin(), packet.q_actual.end());
28  joint_msg.velocity.assign(packet.qd_actual.begin(), packet.qd_actual.end());
29  joint_msg.effort.assign(packet.i_actual.begin(), packet.i_actual.end());
30 
31  joint_pub_.publish(joint_msg);
32 
33  return true;
34 }
35 
37 {
38  geometry_msgs::WrenchStamped wrench_msg;
39  wrench_msg.header.stamp = t;
40  // Setting this to what is configured as the "base frame" through ROS parameters.
41  // Refer to ros-industrial/ur_modern_driver#318 for the rationale.
42  wrench_msg.header.frame_id = base_frame_;
43  wrench_msg.wrench.force.x = packet.tcp_force[0];
44  wrench_msg.wrench.force.y = packet.tcp_force[1];
45  wrench_msg.wrench.force.z = packet.tcp_force[2];
46  wrench_msg.wrench.torque.x = packet.tcp_force[3];
47  wrench_msg.wrench.torque.y = packet.tcp_force[4];
48  wrench_msg.wrench.torque.z = packet.tcp_force[5];
49 
50  wrench_pub_.publish(wrench_msg);
51  return true;
52 }
53 
55 {
56  geometry_msgs::TwistStamped tool_twist;
57  tool_twist.header.stamp = t;
58  tool_twist.header.frame_id = base_frame_;
59  tool_twist.twist.linear.x = packet.tcp_speed_actual.position.x;
60  tool_twist.twist.linear.y = packet.tcp_speed_actual.position.y;
61  tool_twist.twist.linear.z = packet.tcp_speed_actual.position.z;
62  tool_twist.twist.angular.x = packet.tcp_speed_actual.rotation.x;
63  tool_twist.twist.angular.y = packet.tcp_speed_actual.rotation.y;
64  tool_twist.twist.angular.z = packet.tcp_speed_actual.rotation.z;
65 
66  tool_vel_pub_.publish(tool_twist);
67  return true;
68 }
69 
71 {
72  auto tv = packet.tool_vector_actual;
73 
74  Transform transform;
75  transform.setOrigin(Vector3(tv.position.x, tv.position.y, tv.position.z));
76 
77  // Create quaternion
78  Quaternion quat;
79 
80  double angle = std::sqrt(std::pow(tv.rotation.x, 2) + std::pow(tv.rotation.y, 2) + std::pow(tv.rotation.z, 2));
81  if (angle < 1e-16)
82  {
83  quat.setValue(0, 0, 0, 1);
84  }
85  else
86  {
87  quat.setRotation(Vector3(tv.rotation.x / angle, tv.rotation.y / angle, tv.rotation.z / angle), angle);
88  }
89 
90  transform.setRotation(quat);
91 
93 
94  return true;
95 }
96 
98 {
99  size_t len = joint_names_.size();
100  for (size_t i = 0; i < len; i++)
101  {
102  sensor_msgs::Temperature msg;
103  msg.header.stamp = t;
104  // assumption: origins of the link frames are coincident with the origins
105  // of the joints. As the temperature sensors are assumed to be located in
106  // the joints, using the names of the link frames here should be acceptable.
107  msg.header.frame_id = link_names_[i];
108  msg.temperature = packet.motor_temperatures[i];
109 
111  }
112  return true;
113 }
114 
116 {
117  Time time = Time::now();
118  bool res = true;
119  if (!temp_only_)
120  {
121  res = publishJoints(packet, time) && publishWrench(packet, time);
122  }
123 
124  return res && publishTool(packet, time) && publishTransform(packet, time) && publishTemperature(packet, time);
125 }
126 
128 {
129  return publish(state);
130 }
132 {
133  return publish(state);
134 }
136 {
137  return publish(state);
138 }
140 {
141  return publish(state);
142 }
TFSIMD_FORCE_INLINE void setRotation(const Quaternion &q)
bool publishWrench(RTShared &packet, Time &t)
void publish(const boost::shared_ptr< M > &message) const
std::array< double, 6 > i_actual
Definition: rt_state.h:51
std::array< double, 6 > motor_temperatures
Definition: rt_state.h:65
virtual bool consume(RTState_V1_6__7 &state)
double3_t rotation
Definition: types.h:31
cartesian_coord_t tcp_speed_actual
Definition: rt_state.h:60
double y
Definition: types.h:25
double3_t position
Definition: types.h:30
std::string tool_frame_
Definition: rt_publisher.h:55
bool publishTool(RTShared &packet, Time &t)
Publisher joint_temperature_pub_
Definition: rt_publisher.h:50
std::array< double, 6 > qd_actual
Definition: rt_state.h:50
TFSIMD_FORCE_INLINE tfScalar angle(const Quaternion &q1, const Quaternion &q2)
std::array< double, 6 > tcp_force
Definition: rt_state.h:55
double x
Definition: types.h:25
double z
Definition: types.h:25
std::array< double, 6 > q_actual
Definition: rt_state.h:49
Publisher tool_vel_pub_
Definition: rt_publisher.h:49
void sendTransform(const StampedTransform &transform)
Publisher wrench_pub_
Definition: rt_publisher.h:48
bool publish(RTShared &packet)
std::vector< std::string > link_names_
Definition: rt_publisher.h:53
cartesian_coord_t tool_vector_actual
Definition: rt_state.h:59
TransformBroadcaster transform_broadcaster_
Definition: rt_publisher.h:51
bool publishTemperature(RTShared &packet, Time &t)
std::string base_frame_
Definition: rt_publisher.h:54
bool publishTransform(RTShared &packet, Time &t)
bool temp_only_
Definition: rt_publisher.h:56
Publisher joint_pub_
Definition: rt_publisher.h:47
bool publishJoints(RTShared &packet, Time &t)
void setRotation(const Vector3 &axis, const tfScalar &angle)
std::vector< std::string > joint_names_
Definition: rt_publisher.h:52
TFSIMD_FORCE_INLINE void setOrigin(const Vector3 &origin)


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