Robowflex  v0.1
Making MoveIt Easy
robowflex::IO::RobotBroadcaster Class Reference

Helper class to broadcast transform information on TF and joint states. More...

#include <broadcaster.h>

Classes

struct  StaticTransform
 Information for a static transform. More...
 

Public Member Functions

 RobotBroadcaster (const RobotConstPtr &robot, const std::string &base_frame="world", const std::string &name="robowflex")
 Constructor. Sets up TF2 broadcaster. More...
 
 ~RobotBroadcaster ()
 Destructor. More...
 
void start ()
 Begin publishing TF and joint information. More...
 
void stop ()
 Stop publishing TF and joint information. More...
 
void addStaticTransform (const std::string &name, const std::string &base, const std::string &target, const RobotPose &tf=RobotPose::Identity())
 Add a new static transform to the broadcaster. More...
 
void removeStaticTransform (const std::string &name)
 Remove a named static transform. More...
 

Private Member Functions

void update ()
 Send out the TF and joint information. More...
 

Private Attributes

RobotConstPtr robot_
 Robot being published. More...
 
const std::string base_
 Base frame to use. More...
 
bool active_ {false}
 Is thread active? More...
 
bool done_ {false}
 Is thread done? More...
 
unsigned int rate_ {10}
 Times per second to send out. More...
 
std::unique_ptr< std::threadthread_
 Worker thread. More...
 
ros::NodeHandle nh_
 Handle for publishing. More...
 
tf2_ros::TransformBroadcaster tf2br_
 TF2 broadcaster. More...
 
ros::Publisher state_pub_
 State publisher. More...
 
std::map< std::string, StaticTransformstatic_
 Static transforms. More...
 

Detailed Description

Helper class to broadcast transform information on TF and joint states.

Definition at line 23 of file broadcaster.h.

Constructor & Destructor Documentation

◆ RobotBroadcaster()

IO::RobotBroadcaster::RobotBroadcaster ( const RobotConstPtr robot,
const std::string base_frame = "world",
const std::string name = "robowflex" 
)

Constructor. Sets up TF2 broadcaster.

Parameters
[in]robotRobot to broadcast.
[in]base_frameBase frame to use for robot transforms.
[in]nameNamespace to use.

Definition at line 20 of file broadcaster.cpp.

22  : robot_(robot), base_(base_frame), nh_("/" + name)
23 {
24  state_pub_ = nh_.advertise<sensor_msgs::JointState>("/joint_states", 1);
25 }
RobotConstPtr robot_
Robot being published.
Definition: broadcaster.h:65
ros::NodeHandle nh_
Handle for publishing.
Definition: broadcaster.h:71
ros::Publisher state_pub_
State publisher.
Definition: broadcaster.h:73
const std::string base_
Base frame to use.
Definition: broadcaster.h:66
Functions for loading and animating robots in Blender.

◆ ~RobotBroadcaster()

IO::RobotBroadcaster::~RobotBroadcaster ( )

Destructor.

Definition at line 27 of file broadcaster.cpp.

28 {
29  active_ = false;
30  while (not done_)
31  {
32  ros::WallDuration pause(1. / rate_);
33  pause.sleep();
34  }
35 }
bool active_
Is thread active?
Definition: broadcaster.h:67
unsigned int rate_
Times per second to send out.
Definition: broadcaster.h:69
bool done_
Is thread done?
Definition: broadcaster.h:68

Member Function Documentation

◆ addStaticTransform()

void IO::RobotBroadcaster::addStaticTransform ( const std::string name,
const std::string base,
const std::string target,
const RobotPose tf = RobotPose::Identity() 
)

Add a new static transform to the broadcaster.

Parameters
[in]nameName of transform (used for removal)
[in]baseBase frame of transform.
[in]targetTarget frame of transform.
[in]tfThe transform from base to target.

Definition at line 60 of file broadcaster.cpp.

62 {
63  if (static_.find(name) == static_.end())
64  {
65  StaticTransform stf;
66  stf.base = base;
67  stf.target = target;
68  stf.tf = tf;
69 
70  static_.emplace(name, stf);
71  }
72  else
73  RBX_ERROR("Static transform %s already in map!", name);
74 }
std::map< std::string, StaticTransform > static_
Static transforms.
Definition: broadcaster.h:84
#define RBX_ERROR(fmt,...)
Output a error logging message.
Definition: log.h:102

◆ removeStaticTransform()

void IO::RobotBroadcaster::removeStaticTransform ( const std::string name)

Remove a named static transform.

Parameters
[in]nameName of transform to remove.

Definition at line 76 of file broadcaster.cpp.

77 {
78  auto it = static_.find(name);
79  if (it != static_.end())
80  static_.erase(it);
81  else
82  RBX_ERROR("Static transform %s does not exist in map!", name);
83 }

◆ start()

void IO::RobotBroadcaster::start ( void  )

Begin publishing TF and joint information.

Definition at line 37 of file broadcaster.cpp.

38 {
39  active_ = true;
40  thread_.reset(new std::thread([&]() {
41  done_ = false;
42 
43  while (active_)
44  {
45  update();
46 
47  ros::WallDuration pause(1. / rate_);
48  pause.sleep();
49  }
50 
51  done_ = true;
52  }));
53 }
std::unique_ptr< std::thread > thread_
Worker thread.
Definition: broadcaster.h:70
void update()
Send out the TF and joint information.
Definition: broadcaster.cpp:85
T reset(T... args)

◆ stop()

void IO::RobotBroadcaster::stop ( void  )

Stop publishing TF and joint information.

Definition at line 55 of file broadcaster.cpp.

56 {
57  active_ = false;
58 }

◆ update()

void IO::RobotBroadcaster::update ( void  )
private

Send out the TF and joint information.

Definition at line 85 of file broadcaster.cpp.

86 {
87  const auto &state = robot_->getScratchStateConst();
88  const auto &model = robot_->getModelConst();
89 
90  for (const auto &link : model->getLinkModels())
91  {
92  const auto &parent = link->getParentLinkModel();
93 
94  RobotPose tf =
95  link->getJointOriginTransform() * state->getJointTransform(link->getParentJointModel());
96 
97  std::string source = (parent) ? parent->getName() : base_;
98  const std::string &target = link->getName();
99 
100  auto msg = TF::transformEigenToMsg(source, target, tf);
101 
102  tf2br_.sendTransform(msg);
103  }
104 
105  for (const auto &pair : static_)
106  {
107  const auto &stf = pair.second;
108  auto static_msg = TF::transformEigenToMsg(stf.base, stf.target, stf.tf);
109  tf2br_.sendTransform(static_msg);
110  }
111 
112  unsigned int n = state->getVariableCount();
113 
114  sensor_msgs::JointState msg;
115  msg.header.stamp = ros::Time::now();
116  msg.name = state->getVariableNames();
117 
118  arrayToVector(state->getVariablePositions(), n, msg.position);
119  arrayToVector(state->getVariableVelocities(), n, msg.velocity);
120  arrayToVector(state->getVariableEffort(), n, msg.effort);
121 
122  state_pub_.publish(msg);
123 }
tf2_ros::TransformBroadcaster tf2br_
TF2 broadcaster.
Definition: broadcaster.h:72
geometry_msgs::TransformStamped transformEigenToMsg(const std::string &source, const std::string &target, const RobotPose &tf)
Encode a transform as a message.
Definition: tf.cpp:262
std::decay< decltype(std::declval< moveit::core::Transforms >().getTransform("")) >::type RobotPose
A pose (point in SE(3)) used in various functions. Defined from what MoveIt! uses.
Definition: adapter.h:24

Member Data Documentation

◆ active_

bool robowflex::IO::RobotBroadcaster::active_ {false}
private

Is thread active?

Definition at line 67 of file broadcaster.h.

◆ base_

const std::string robowflex::IO::RobotBroadcaster::base_
private

Base frame to use.

Definition at line 66 of file broadcaster.h.

◆ done_

bool robowflex::IO::RobotBroadcaster::done_ {false}
private

Is thread done?

Definition at line 68 of file broadcaster.h.

◆ nh_

ros::NodeHandle robowflex::IO::RobotBroadcaster::nh_
private

Handle for publishing.

Definition at line 71 of file broadcaster.h.

◆ rate_

unsigned int robowflex::IO::RobotBroadcaster::rate_ {10}
private

Times per second to send out.

Definition at line 69 of file broadcaster.h.

◆ robot_

RobotConstPtr robowflex::IO::RobotBroadcaster::robot_
private

Robot being published.

Definition at line 65 of file broadcaster.h.

◆ state_pub_

ros::Publisher robowflex::IO::RobotBroadcaster::state_pub_
private

State publisher.

Definition at line 73 of file broadcaster.h.

◆ static_

std::map<std::string, StaticTransform> robowflex::IO::RobotBroadcaster::static_
private

Static transforms.

Definition at line 84 of file broadcaster.h.

◆ tf2br_

tf2_ros::TransformBroadcaster robowflex::IO::RobotBroadcaster::tf2br_
private

TF2 broadcaster.

Definition at line 72 of file broadcaster.h.

◆ thread_

std::unique_ptr<std::thread> robowflex::IO::RobotBroadcaster::thread_
private

Worker thread.

Definition at line 70 of file broadcaster.h.


The documentation for this class was generated from the following files: