3 #include <std_msgs/Float32.h> 9 DiagnosticNodelet::onInit();
36 pnh_->param(
"period", d_period, 1.0);
93 pnh_->param(
"vital_rate", vital_rate, 1.0);
99 std::string
img =
nh_->resolveName(
"image");
100 std::string cam =
nh_->resolveName(
"camera");
101 if (img.at(0) ==
'/') {
116 #ifdef USE_2_0_9_ADVERTISE_CAMERA 129 boost::mutex::scoped_lock lock(
mutex_);
134 std_srvs::Empty::Response &res) {
135 boost::mutex::scoped_lock lock(
mutex_);
142 boost::mutex::scoped_lock lock(
mutex_);
149 boost::mutex::scoped_lock lock(
mutex_);
161 boost::mutex::scoped_lock lock(
mutex_);
171 stat.
add(
"input image",
pnh_->resolveName(
"input/image"));
172 stat.
add(
"output image",
pnh_->resolveName(
"output/image"));
175 stat.
summary(diagnostic_error_level_,
176 "no image input. Is " +
pnh_->resolveName(
"input/image") +
" active?");
181 stat.
summary(diagnostic_error_level_,
185 stat.
summary(diagnostic_msgs::DiagnosticStatus::OK,
189 stat.
add(
"info_last_received_time",
info_vital_->lastAliveTimeRelative());
192 stat.
summary(diagnostic_msgs::DiagnosticStatus::OK,
196 stat.
add(
"image_last_received_time",
image_vital_->lastAliveTimeRelative());
201 double in_time_mean = 0, in_time_rate = 1.0, in_time_std_dev = 0.0, in_time_max_delta, in_time_min_delta;
202 double out_time_mean = 0, out_time_rate = 1.0, out_time_std_dev = 0.0, out_time_max_delta, out_time_min_delta;
204 std::for_each(
in_times.begin(),
in_times.end(), (in_time_mean += boost::lambda::_1) );
205 in_time_mean /= in_time_n;
206 in_time_rate /= in_time_mean;
207 std::for_each(
in_times.begin(),
in_times.end(), (in_time_std_dev += (boost::lambda::_1 - in_time_mean)*(boost::lambda::_1 - in_time_mean) ) );
208 in_time_std_dev =
sqrt(in_time_std_dev/in_time_n);
214 std::for_each(
out_times.begin(),
out_times.end(), (out_time_mean += boost::lambda::_1) );
215 out_time_mean /= out_time_n;
216 out_time_rate /= out_time_mean;
217 std::for_each(
out_times.begin(),
out_times.end(), (out_time_std_dev += (boost::lambda::_1 - out_time_mean)*(boost::lambda::_1 - out_time_mean) ) );
218 out_time_std_dev =
sqrt(out_time_std_dev/out_time_n);
219 if (out_time_n > 1) {
224 double in_byte_mean = 0, out_byte_mean = 0;
225 std::for_each(
in_bytes.begin(),
in_bytes.end(), (in_byte_mean += boost::lambda::_1) );
226 std::for_each(
out_bytes.begin(),
out_bytes.end(), (out_byte_mean += boost::lambda::_1) );
227 in_byte_mean /= duration;
228 out_byte_mean /= duration;
229 stat.
add(
"compressed rate", in_byte_mean / out_byte_mean);
230 stat.
add(
"input bandwidth (Kbps)", in_byte_mean / 1000 * 8);
231 stat.
add(
"input bandwidth (Mbps)", in_byte_mean / 1000 / 1000 * 8);
232 stat.
add(
"input rate (hz)", in_time_rate);
233 stat.
add(
"input min delta (s)", in_time_min_delta);
234 stat.
add(
"input max delta (s)", in_time_max_delta);
235 stat.
add(
"input std_dev delta (s)", in_time_std_dev);
236 stat.
add(
"input times (n)", in_time_n);
237 stat.
add(
"output bandwidth (Kbps)", out_byte_mean / 1000 * 8);
238 stat.
add(
"output bandwidth (Mbps)", out_byte_mean / 1000 / 1000 * 8);
239 stat.
add(
"output rate (hz)", out_time_rate);
240 stat.
add(
"output min delta (s)", out_time_min_delta);
241 stat.
add(
"output max delta (s)", out_time_max_delta);
242 stat.
add(
"output std_dev delta (s)", out_time_std_dev);
243 stat.
add(
"output times (n)", out_time_n);
254 callback(img, sensor_msgs::CameraInfo::ConstPtr());
258 const sensor_msgs::CameraInfoConstPtr &info) {
259 boost::mutex::scoped_lock lock(
mutex_);
263 ROS_DEBUG(
"number of subscribers is 0, ignoring image");
267 ROS_DEBUG(
"to reduce load, ignoring image");
271 in_bytes.push_front(img->data.size());
274 sensor_msgs::ImagePtr dst_img;
275 sensor_msgs::CameraInfo dst_info;
276 process(img, info, dst_img, dst_info);
281 boost::make_shared<sensor_msgs::CameraInfo> (dst_info));
288 std_msgs::Float32 width_scale;
290 std_msgs::Float32 height_scale;
296 out_bytes.push_front(dst_img->step * dst_img->height);
300 catch (cv::Exception& e) {
sensor_msgs::CameraInfoConstPtr info_msg_
ros::Subscriber image_sub_
Subscriber subscribe(const std::string &base_topic, uint32_t queue_size, const boost::function< void(const sensor_msgs::ImageConstPtr &)> &callback, const ros::VoidPtr &tracked_object=ros::VoidPtr(), const TransportHints &transport_hints=TransportHints())
bool use_camera_subscriber_
void publish(const sensor_msgs::Image &image, const sensor_msgs::CameraInfo &info) const
void callback(const sensor_msgs::ImageConstPtr &img, const sensor_msgs::CameraInfoConstPtr &info)
jsk_topic_tools::VitalChecker::Ptr info_vital_
void publish(const boost::shared_ptr< M > &message) const
boost::circular_buffer< double > in_times
virtual void unsubscribe()
bool snapshot_srv_cb(std_srvs::Empty::Request &req, std_srvs::Empty::Response &res)
virtual void process(const sensor_msgs::ImageConstPtr &src_img, const sensor_msgs::CameraInfoConstPtr &src_info, sensor_msgs::ImagePtr &dst_img, sensor_msgs::CameraInfo &dst_info)=0
void summary(unsigned char lvl, const std::string s)
CameraSubscriber subscribeCamera(const std::string &base_topic, uint32_t queue_size, const CameraSubscriber::Callback &callback, const ros::VoidPtr &tracked_object=ros::VoidPtr(), const TransportHints &transport_hints=TransportHints())
void initPublishersAndSubscribers()
uint32_t getNumSubscribers() const
void image_nonsync_cb(const sensor_msgs::ImageConstPtr &img)
ros::Publisher height_scale_pub_
ros::Time last_publish_time_
void info_cb(const sensor_msgs::CameraInfoConstPtr &info)
ros::Time last_subscribe_time_
boost::circular_buffer< double > out_times
boost::circular_buffer< double > in_bytes
jsk_topic_tools::VitalChecker::Ptr image_vital_
void image_cb(const sensor_msgs::ImageConstPtr &img)
image_transport::Subscriber image_nonsync_sub_
virtual void updateDiagnostic(diagnostic_updater::DiagnosticStatusWrapper &stat)
#define NODELET_WARN_THROTTLE(rate,...)
ros::Publisher width_scale_pub_
std::string getTopic() const
void snapshot_msg_cb(const std_msgs::EmptyConstPtr msg)
boost::circular_buffer< double > out_bytes
INLINE Rall1d< T, V, S > sqrt(const Rall1d< T, V, S > &arg)
IMAGE_TRANSPORT_DECL std::string getCameraInfoTopic(const std::string &base_topic)
ros::Time last_rosinfo_time_
#define NODELET_INFO(...)
uint32_t getNumSubscribers() const
void add(const std::string &key, const T &val)
ros::Subscriber camera_info_sub_
image_transport::CameraPublisher cp_
image_transport::ImageTransport * it_
ros::Publisher image_pub_
image_transport::CameraSubscriber cs_