bank.h
Go to the documentation of this file.
1 /*********************************************************************
2 * Software License Agreement (BSD License)
3 *
4 * Copyright (c) 2018, Andreas Gustavsson.
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 *
11 * * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * * Redistributions in binary form must reproduce the above
14 * copyright notice, this list of conditions and the following
15 * disclaimer in the documentation and/or other materials provided
16 * with the distribution.
17 * * Neither the name of the Willow Garage nor the names of its
18 * contributors may be used to endorse or promote products derived
19 * from this software without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32 * POSSIBILITY OF SUCH DAMAGE.
33 *
34 * Author: Andreas Gustavsson
35 *********************************************************************/
36 
37 #ifndef BANK_H
38 #define BANK_H
39 #include <ros/ros.h>
41 #include <visualization_msgs/Marker.h>
42 #include <visualization_msgs/MarkerArray.h>
43 #include <sensor_msgs/LaserScan.h>
44 #include <sensor_msgs/PointCloud2.h>
45 #include <find_moving_objects/MovingObject.h>
46 #include <find_moving_objects/MovingObjectArray.h>
47 
48 
50 {
51 
60 {
61 public:
63  double ema_alpha;
77  double angle_min;
86  double angle_max;
143  bool publish_ema;
189  std::string velocity_arrow_ns;
197  std::string width_line_ns;
201  std::string topic_objects;
205  std::string topic_ema;
229  std::string map_frame;
233  std::string fixed_frame;
237  std::string base_frame;
242 // // TODO: dox
243 // float merge_threshold_max_angle_gap;
244 // float merge_threshold_max_end_points_distance_delta;
245 // float merge_threshold_max_velocity_direction_delta;
246 // float merge_threshold_max_speed_delta;
247 
248 
249  /*
250  * PointCloud2 message-specific (none of these apply to LaserScan)
251  */
281  std::string node_name_suffix;
290  BankArgument();
291 
296  friend class Bank;
297 
298 private:
299  friend std::ostream& operator<<(std::ostream& os, const BankArgument& ba);
300  std::string sensor_frame;
315  float scan_time;
320  float range_min;
325  float range_max;
334  void check();
337  void check_PC2();
340 };
341 
342 
356 class Bank
357 {
358 private:
359  /* BANK ARGUMENTS */
361 
362  /* BANK */
363  float ** bank_ranges_ema;
364  double * bank_stamp;
365  unsigned int bank_ranges_bytes;
368  double resolution;
369 
370  /* INDICES FOR THE BANK */
372  int bank_index_put; // nr_scans_in_bank is/should be greater than 1!
373 
374  /* HANDLE TO THIS NODE */
376 
377  /* TRANSFORM BUFFER PTR */
379 
380  /* PUBLISHERS */
387 
388  /* SEQUENCE NR */
389  unsigned int moa_seq;
390 
391  /* Additional messages to publish (not the actual moving objects message!) */
392  sensor_msgs::LaserScan msg_ema; // EMA-adapted LaserScan with marked moving objects
393  sensor_msgs::LaserScan msg_objects_closest_point_markers; // For visualizing objects as squares
394  visualization_msgs::MarkerArray msg_objects_velocity_arrows; // For visualizing velocity using arrows...
395  visualization_msgs::Marker msg_objects_velocity_arrow; // ... one per object
396  visualization_msgs::MarkerArray msg_objects_delta_position_lines; // For visualizing delta positions using lines...
397  visualization_msgs::Marker msg_objects_delta_position_line; // ... one per object
398  visualization_msgs::MarkerArray msg_objects_width_lines; // For visualizing width using lines...
399  visualization_msgs::Marker msg_objects_width_line; // ... one per object
400 
401  /* Basic functionality used by the functions below*/
402  void initBank(BankArgument bank_argument);
403 // virtual long addFirstMessage(const sensor_msgs::LaserScan::ConstPtr &);
404 // virtual long addFirstMessage(const sensor_msgs::PointCloud2::ConstPtr &,
405 // const bool discard_message_if_no_points_added);
406  virtual long addFirstMessage(const sensor_msgs::LaserScan *);
407  virtual long addFirstMessage(const sensor_msgs::PointCloud2 *,
408  const bool discard_message_if_no_points_added);
409  inline void initIndex();
410  inline void advanceIndex();
411 // void mergeFoundObjects(MovingObjectArray * moa);
412 
413  /*
414  * Recursive tracking of an object through history to get the indices of its middle,
415  * left and right points in the oldest scans, along with the sum of all ranges etc.
416  */
417  void getOldIndices(const float range_min,
418  const float range_max,
419  const unsigned int object_width_in_points,
420  const int current_level,
421  const unsigned int levels_searched,
422  const unsigned int index_mean,
423  const unsigned int consecutive_failures_to_find_object,
424  const unsigned int threshold_consecutive_failures_to_find_object,
425  int * index_min_old,
426  int * index_mean_old,
427  int * index_max_old,
428  float * range_sum_old,
429  float * range_at_min_index_old,
430  float * range_at_max_index_old);
431 
432  /* PointCloud2 specifics */
433  typedef uint8_t byte_t;
440  int getOffsetsAndBytes(BankArgument bank_argument, const sensor_msgs::PointCloud2::ConstPtr msg);
441  int getOffsetsAndBytes(BankArgument bank_argument, const sensor_msgs::PointCloud2 * msg);
442  bool machine_is_little_endian; // set in constructor
443  void reverseBytes(byte_t * bytes, unsigned int nr_bytes);
444  void readPoint(const byte_t * start_of_point,
445  const bool must_reverse_bytes,
446  double * x,
447  double * y,
448  double * z);
449  void resetPutPoints();
450  unsigned int putPoints(const sensor_msgs::PointCloud2::ConstPtr msg);
451  unsigned int putPoints(const sensor_msgs::PointCloud2 * msg);
452  void emaPutMessage();
453  std::string getStringPutPoints();
454 
455 
456 
457 
458 public:
459 // /**
460 // * Creates an instance of Bank and starts a <code>tf::TransformListener</code>.
461 // */
462 // Bank();
463 
467  Bank(tf2_ros::Buffer * buffer);
468 
472  ~Bank();
473 
474 
475 
476 // /**
477 // * Initiate bank with received data, if possible.
478 // *
479 // * This function should be called repeatedly until it succeeds (i.e. returns 0), after this,
480 // * it should not be called again (doing so would compromise the stored data)!
481 // * @param bank_argument An instance of <code>BankArgument</code>, specifying the behavior of the bank.
482 // * @param msg Pointer to the first received message to be added to the bank.
483 // * @return 0 on success, -1 if this function must be called again.
484 // */
485 // virtual long init(BankArgument bank_argument, const sensor_msgs::LaserScan::ConstPtr & msg);
486 
496  virtual long init(BankArgument bank_argument, const sensor_msgs::LaserScan * msg);
497 
498 // /**
499 // * Initiate bank with received data, if possible.
500 // *
501 // * This function should be called repeatedly until it succeeds (i.e. returns 0), after this,
502 // * it should not be called again (doing so would compromise the stored data)!
503 // * @param bank_argument An instance of <code>BankArgument</code>, specifying the behavior of the bank.
504 // * @param msg Pointer to the first received message to be added to the bank.
505 // * @return 0 on success, -1 if this function must be called again.
506 // */
507 // virtual long init(BankArgument bank_argument, const sensor_msgs::PointCloud2::ConstPtr & msg,
508 // const bool discard_message_if_no_points_added = true);
509 
521  virtual long init(BankArgument bank_argument, const sensor_msgs::PointCloud2 * msg,
522  const bool discard_message_if_no_points_added = true);
523 
524 
525 
526 // /**
527 // * Add a <code>sensor_msgs::LaserScan</code> message to the bank (replace the oldest scan message).
528 // *
529 // * @param msg Pointer to the received message to be added to the bank.
530 // * @return 0.
531 // */
532 // virtual long addMessage(const sensor_msgs::LaserScan::ConstPtr & msg);
533 
540  virtual long addMessage(const sensor_msgs::LaserScan * msg);
541 
542 // /**
543 // * Add a <code>sensor_msgs::PointCloud2</code> message to the bank (replace the oldest scan message).
544 // *
545 // * @param msg Pointer to the received message to be added to the bank.
546 // * @return 0 on success, -1 if adding this message failed.
547 // */
548 //
549 // virtual long addMessage(const sensor_msgs::PointCloud2::ConstPtr & msg,
550 // const bool discard_message_if_no_points_added = true);
551 
560  virtual long addMessage(const sensor_msgs::PointCloud2 * msg,
561  const bool discard_message_if_no_points_added = true);
562 
563 
564 
568  void findAndReportMovingObjects();
569 
580  virtual double calculateConfidence(const find_moving_objects::MovingObject & mo,
582  const double delta_time,
583  const double mo_old_width);
584 };
585 
586 // template<typename BaseClass, typename T>
587 // inline bool instanceof(const T *ptr)
588 // {
589 // return dynamic_cast<const BaseClass*>(ptr) != nullptr;
590 // }
591 
592 } // namespace find_moving_objects
593 
594 #endif // BANK_H
sensor_msgs::LaserScan msg_ema
Definition: bank.h:392
std::string PC2_message_y_coordinate_field_name
Definition: bank.h:256
unsigned int moa_seq
Definition: bank.h:389
std::string topic_objects_closest_point_markers
Definition: bank.h:209
int32_t PC2_message_z_offset
Definition: bank.h:436
std::string delta_position_line_ns
Definition: bank.h:193
double object_threshold_bank_tracking_max_delta_distance
Definition: bank.h:129
ros::Publisher pub_objects
Definition: bank.h:386
BankArgument bank_argument
Definition: bank.h:360
int32_t PC2_message_x_bytes
Definition: bank.h:437
float ** bank_ranges_ema
Definition: bank.h:363
ros::NodeHandle * node
Definition: bank.h:375
ros::Publisher pub_objects_delta_position_lines
Definition: bank.h:384
ros::Publisher pub_objects_velocity_arrows
Definition: bank.h:383
unsigned int bank_ranges_bytes
Definition: bank.h:365
friend std::ostream & operator<<(std::ostream &os, const BankArgument &ba)
Definition: bank.cpp:167
double object_threshold_edge_max_delta_range
Definition: bank.h:104
std::string topic_objects_width_lines
Definition: bank.h:221
int32_t PC2_message_x_offset
Definition: bank.h:434
std::string PC2_message_x_coordinate_field_name
Definition: bank.h:252
visualization_msgs::MarkerArray msg_objects_velocity_arrows
Definition: bank.h:394
visualization_msgs::MarkerArray msg_objects_delta_position_lines
Definition: bank.h:396
ros::Publisher pub_ema
Definition: bank.h:381
visualization_msgs::MarkerArray msg_objects_width_lines
Definition: bank.h:398
std::string topic_objects_velocity_arrows
Definition: bank.h:213
std::string topic_objects_delta_position_lines
Definition: bank.h:217
tf2_ros::Buffer * tf_buffer
Definition: bank.h:378
std::string PC2_message_z_coordinate_field_name
Definition: bank.h:260
int32_t PC2_message_z_bytes
Definition: bank.h:439
int32_t PC2_message_y_offset
Definition: bank.h:435
ros::Publisher pub_objects_closest_point_markers
Definition: bank.h:382
int32_t PC2_message_y_bytes
Definition: bank.h:438
visualization_msgs::Marker msg_objects_width_line
Definition: bank.h:399
int object_threshold_max_delta_width_in_points
Definition: bank.h:120
bool machine_is_little_endian
Definition: bank.h:442
visualization_msgs::Marker msg_objects_delta_position_line
Definition: bank.h:397
friend class Bank
Allow Bank to access private members of this class.
Definition: bank.h:296
ros::Publisher pub_objects_width_lines
Definition: bank.h:385
sensor_msgs::LaserScan msg_objects_closest_point_markers
Definition: bank.h:393
visualization_msgs::Marker msg_objects_velocity_arrow
Definition: bank.h:395


find_moving_objects
Author(s): Andreas Gustavsson
autogenerated on Mon Jun 10 2019 13:13:19