22 #include "position_3d_thread.h" 24 #include <fawkes_msgs/Position3D.h> 25 #include <ros/this_node.h> 29 #define CFG_PREFIX "/ros/position-3d/" 40 :
Thread(
"RosPosition3DThread",
Thread::OPMODE_WAITFORWAKEUP),
53 cfg_ros_topic_ =
"/objects";
59 ros_pub_ =
rosnode->advertise<fawkes_msgs::Position3D>(cfg_ros_topic_, 100);
62 for (std::list<Position3DInterface *>::iterator it = ifs_.begin(); it != ifs_.end(); ++it) {
78 for (std::list<Position3DInterface *>::iterator it = ifs_.begin(); it != ifs_.end(); ++it) {
87 if (strncmp(type,
"Position3DInterface", INTERFACE_TYPE_SIZE_) != 0)
93 logger->
log_warn(name(),
"Failed to open %s:%s: %s", type,
id, e.
what());
97 bbil_add_data_interface(interface);
99 ifs_.push_back(interface);
101 blackboard->
close(interface);
102 logger->
log_warn(name(),
"Failed to register for %s:%s: %s", type,
id, e.
what());
109 unsigned int instance_serial)
throw()
111 conditional_close(interface);
116 unsigned int instance_serial)
throw()
118 conditional_close(interface);
122 RosPosition3DThread::conditional_close(
Interface *interface)
throw()
129 std::list<Position3DInterface *>::iterator it;
130 for (it = ifs_.begin(); it != ifs_.end(); ++it) {
131 if (*interface == **it) {
132 if (!interface->has_writer() && (interface->num_readers() == 1)) {
134 bbil_remove_data_interface(*it);
136 blackboard->
close(*it);
151 fawkes_msgs::Position3D position;
152 position.header.frame_id = iface->
frame();
153 position.name = iface->
id();
154 position.pose.position.x = iface->
translation()[0];
155 position.pose.position.y = iface->
translation()[1];
156 position.pose.position.z = iface->
translation()[2];
157 position.pose.orientation.x = iface->
rotation()[0];
158 position.pose.orientation.y = iface->
rotation()[1];
159 position.pose.orientation.z = iface->
rotation()[2];
160 position.pose.orientation.w = iface->
rotation()[3];
162 ros_pub_.publish(position);
virtual void register_observer(BlackBoardInterfaceObserver *observer)
Register BB interface observer.
RosPosition3DThread()
Constructor.
double * rotation() const
Get rotation value.
char * frame() const
Get frame value.
virtual ~RosPosition3DThread()
Destructor.
Fawkes library namespace.
virtual void init()
Initialize the thread.
const char * id() const
Get identifier of interface.
virtual const char * what() const
Get primary string.
virtual void unregister_listener(BlackBoardInterfaceListener *listener)
Unregister BB interface listener.
Thread class encapsulation of pthreads.
virtual void update_listener(BlackBoardInterfaceListener *listener, ListenerRegisterFlag flag=BBIL_FLAG_ALL)
Update BB event listener.
Base class for all Fawkes BlackBoard interfaces.
virtual void register_listener(BlackBoardInterfaceListener *listener, ListenerRegisterFlag flag=BBIL_FLAG_ALL)
Register BB event listener.
virtual void bb_interface_reader_removed(fawkes::Interface *interface, unsigned int instance_serial)
A reading instance has been closed for a watched interface.
void bbio_add_observed_create(const char *type_pattern, const char *id_pattern="*")
Add interface creation type to watch list.
virtual void bb_interface_writer_removed(fawkes::Interface *interface, unsigned int instance_serial)
A writing instance has been closed for a watched interface.
Position3DInterface Fawkes BlackBoard Interface.
Base class for exceptions in Fawkes.
void read()
Read from BlackBoard into local copy.
virtual void bb_interface_data_changed(fawkes::Interface *interface)
BlackBoard data changed notification.
virtual void log_warn(const char *component, const char *format,...)
Log warning message.
virtual void unregister_observer(BlackBoardInterfaceObserver *observer)
Unregister BB interface observer.
double * translation() const
Get translation value.
LockPtr< ros::NodeHandle > rosnode
Central ROS node handle.
virtual void bb_interface_created(const char *type, const char *id)
BlackBoard interface created notification.
int32_t visibility_history() const
Get visibility_history value.
Configuration * config
This is the Configuration member used to access the configuration.
virtual void finalize()
Finalize the thread.
virtual std::string get_string(const char *path)=0
Get value from configuration which is of type string.
BlackBoard interface listener.
BlackBoard * blackboard
This is the BlackBoard instance you can use to interact with the BlackBoard.
void bbil_add_data_interface(Interface *interface)
Add an interface to the data modification watch list.
virtual void close(Interface *interface)=0
Close interface.