EEROS  1.0.0.0
API for the EEROS Real-Time Robotics Framework
RosPublisherLaserScan.hpp
Go to the documentation of this file.
1 #ifndef ORG_EEROS_CONTROL_ROSPUBLISHER_LASERSCAN_HPP
2 #define ORG_EEROS_CONTROL_ROSPUBLISHER_LASERSCAN_HPP
3 
5 #include <eeros/math/Matrix.hpp>
6 
7 // A-1 Include the header file of the ROS message
8 #include <sensor_msgs/LaserScan.h>
9 
10 
11 
12 namespace eeros {
13  namespace control {
14  // C-1 Create the template definition. Each EEROS matrix input needs its own type
15  template < typename TRangesInput, typename TIntensitiesInput >
16  // A-3 Name your block and create the constructor. Copy the type definition
17  class RosPublisherLaserScan : public RosPublisher<sensor_msgs::LaserScan::Type, double> {
18  // A-2 Define the type of the ROS message
19  typedef sensor_msgs::LaserScan::Type TRosMsg;
20  public:
21  RosPublisherLaserScan(const std::string& topic, const uint32_t queueSize=1000) :
22  RosPublisher<TRosMsg, double>(topic, queueSize) { }
23 
24  void setRosMsg(TRosMsg& msg) {
25  // B-3 If available, set time in msg header
26  msg.header.stamp = eeros::control::rosTools::convertToRosTime(eeros::System::getTimeNs());
27 
28  // B-4 Check if EEROS input is connected. Cast the data. Assign casted data to ROS message field
30  msg.angle_min = static_cast<float>( angle_minInput.getSignal().getValue() );
32  msg.angle_max = static_cast<float>( angle_maxInput.getSignal().getValue() );
34  msg.angle_increment = static_cast<float>( angle_incrementInput.getSignal().getValue() );
36  msg.time_increment = static_cast<float>( time_incrementInput.getSignal().getValue() );
38  msg.scan_time = static_cast<float>( scan_timeInput.getSignal().getValue() );
40  msg.range_min = static_cast<float>( range_minInput.getSignal().getValue() );
42  msg.range_max = static_cast<float>( range_maxInput.getSignal().getValue() );
43  // C-4 Check if EEROS input is connected
44  if (rangesInput.isConnected() ) {
45  // C-5 Get the vector from the EEROS input
47  auto rangesTmpDouble = rangesValue.getColVector(0);
48  // C-6 Cast the vector and assign it to the appropriate ROS data field
49  std::vector<float> rangesTmpFloat( rangesTmpDouble.begin(), rangesTmpDouble.end() ); // cast to float vector
50  msg.ranges = rangesTmpFloat;
51  }
54  auto intensitiesTmpDouble = rangesValue.getColVector(0);
55  std::vector<float> intensitiesTmpFloat( intensitiesTmpDouble.begin(), intensitiesTmpDouble.end() ); // cast to float vector
56  msg.intensities = intensitiesTmpFloat;
57  }
58  }
59 
60  // B-2 Add a 'getInput()' function for each input
68  // C-3 Add a 'getInput()' function for each EEROS matrix Input
71 
72  protected:
73  // B-1 Create EEROS inputs
81  // C-2 Create a 'value' and an 'input' variable for each EEROS matrix input
82  TRangesInput rangesValue;
84  TIntensitiesInput intensitiesValue;
86  };
87 
88  };
89 };
90 
91 #endif // ORG_EEROS_CONTROL_ROSPUBLISHER_LASERSCAN_HPP
Definition: RosPublisherLaserScan.hpp:17
Input< double > time_incrementInput
Definition: RosPublisherLaserScan.hpp:77
Input< double > angle_incrementInput
Definition: RosPublisherLaserScan.hpp:76
Input< TRangesInput > rangesInput
Definition: RosPublisherLaserScan.hpp:83
Input< double > scan_timeInput
Definition: RosPublisherLaserScan.hpp:78
virtual T getValue() const
Definition: Signal.hpp:49
virtual bool isConnected() const
Definition: Input.hpp:34
Input< TRangesInput > & getRangesInput()
Definition: RosPublisherLaserScan.hpp:69
TIntensitiesInput intensitiesValue
Definition: RosPublisherLaserScan.hpp:84
Input< TIntensitiesInput > & getIntensitiessInput()
Definition: RosPublisherLaserScan.hpp:70
Definition: Config.hpp:14
static uint64_t getTimeNs()
Definition: System_POSIX.cpp:41
Type
Definition: HALFeatures.hpp:14
void setRosMsg(TRosMsg &msg)
Definition: RosPublisherLaserScan.hpp:24
Input< double > angle_minInput
Definition: RosPublisherLaserScan.hpp:70
Input< double > & getRange_minInput()
Definition: RosPublisherLaserScan.hpp:66
RosPublisherLaserScan(const std::string &topic, const uint32_t queueSize=1000)
Definition: RosPublisherLaserScan.hpp:21
Input< double > & getTime_incrementInput()
Definition: RosPublisherLaserScan.hpp:64
Input< double > angle_maxInput
Definition: RosPublisherLaserScan.hpp:75
TRangesInput rangesValue
Definition: RosPublisherLaserScan.hpp:82
Input< double > & getScan_timeInput()
Definition: RosPublisherLaserScan.hpp:65
Definition: RosPublisher.hpp:13
virtual Signal< T > & getSignal()
Definition: Input.hpp:38
Input< TIntensitiesInput > intensitiesInput
Definition: RosPublisherLaserScan.hpp:85
sensor_msgs::LaserScan::Type msg
Definition: RosPublisher.hpp:37
Input< double > & getRange_maxInput()
Definition: RosPublisherLaserScan.hpp:67
const std::string & topic
Definition: RosPublisher.hpp:35
Input< double > & getAngle_maxInput()
Definition: RosPublisherLaserScan.hpp:62
Input< double > & getAngle_minInput()
Definition: RosPublisherLaserScan.hpp:61
Input< double > range_minInput
Definition: RosPublisherLaserScan.hpp:79
Input< double > range_maxInput
Definition: RosPublisherLaserScan.hpp:80
Input< double > & getAngle_incrementInput()
Definition: RosPublisherLaserScan.hpp:63