22 #include "joint_thread.h" 24 #include <ros/this_node.h> 25 #include <sensor_msgs/JointState.h> 38 :
Thread(
"RosJointThread",
Thread::OPMODE_WAITFORWAKEUP),
51 ros_pub_ =
rosnode->advertise<sensor_msgs::JointState>(
"/joints", 100);
54 for (std::list<JointInterface *>::iterator it = ifs_.begin(); it != ifs_.end(); it++) {
70 for (std::list<JointInterface *>::iterator it = ifs_.begin(); it != ifs_.end(); it++) {
79 if (strncmp(type,
"JointInterface", __INTERFACE_TYPE_SIZE) != 0)
return;
82 interface =
blackboard->open_for_reading<JointInterface>(id);
90 ifs_.push_back(interface);
100 unsigned int instance_serial)
103 conditional_close(interface);
109 unsigned int instance_serial)
112 conditional_close(interface);
116 RosJointThread::conditional_close(
Interface *interface)
throw()
120 if (! jiface)
return;
122 std::list<JointInterface *>::iterator it;
123 for (it = ifs_.begin(); it != ifs_.end(); ++it) {
124 if (*interface == **it) {
143 sensor_msgs::JointState joint_state;
145 joint_state.name.push_back(jiface->
id());
146 joint_state.position.push_back(jiface->
position());
147 joint_state.velocity.push_back(jiface->
velocity());
148 ros_pub_.publish(joint_state);
virtual void register_observer(BlackBoardInterfaceObserver *observer)
Register BB interface observer.
virtual void bb_interface_created(const char *type, const char *id)
BlackBoard interface created notification.
virtual void init()
Initialize the thread.
virtual void bb_interface_data_changed(fawkes::Interface *interface)
BlackBoard data changed notification.
float position() const
Get position value.
Fawkes library namespace.
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.
Logger * logger
This is the Logger member used to access the logger.
virtual void bb_interface_reader_removed(fawkes::Interface *interface, unsigned int instance_serial)
A reading instance has been closed for a watched interface.
virtual void register_listener(BlackBoardInterfaceListener *listener, ListenerRegisterFlag flag=BBIL_FLAG_ALL)
Register BB event listener.
virtual ~RosJointThread()
Destructor.
void bbio_add_observed_create(const char *type_pattern, const char *id_pattern="*")
Add interface creation type to watch list.
float velocity() const
Get velocity value.
Base class for exceptions in Fawkes.
void read()
Read from BlackBoard into local copy.
virtual void unregister_observer(BlackBoardInterfaceObserver *observer)
Unregister BB interface observer.
bool has_writer() const
Check if there is a writer for the interface.
const char * name() const
Get name of thread.
virtual void bb_interface_writer_removed(fawkes::Interface *interface, unsigned int instance_serial)
A writing instance has been closed for a watched interface.
RosJointThread()
Constructor.
virtual void log_warn(const char *component, const char *format,...)=0
Log warning message.
virtual std::list< Interface * > open_multiple_for_reading(const char *type_pattern, const char *id_pattern="*", const char *owner=NULL)=0
Open multiple interfaces for reading.
void bbil_remove_data_interface(Interface *interface)
Remove an interface to the data modification watch list.
LockPtr< ros::NodeHandle > rosnode
Central ROS node handle.
JointInterface Fawkes BlackBoard Interface.
unsigned int num_readers() const
Get the number of readers.
BlackBoard interface listener.
BlackBoard * blackboard
This is the BlackBoard instance you can use to interact with the BlackBoard.
virtual void finalize()
Finalize the thread.
void bbil_add_data_interface(Interface *interface)
Add an interface to the data modification watch list.
virtual void close(Interface *interface)=0
Close interface.