SMACC2
Public Member Functions | Public Attributes | List of all members
sm_dance_bot_warehouse_2::cl_lidar::CpForwardObstacleDetector Class Reference

#include <cp_forward_obstacle_detector.hpp>

Inheritance diagram for sm_dance_bot_warehouse_2::cl_lidar::CpForwardObstacleDetector:
Inheritance graph
Collaboration diagram for sm_dance_bot_warehouse_2::cl_lidar::CpForwardObstacleDetector:
Collaboration graph

Public Member Functions

void onInitialize () override
 
int modulo_Euclidean (int a, int b)
 
float getForwardDistance (int raysWidthCount=0)
 
void MessageCallbackStoreDistanceToWall (const sensor_msgs::msg::LaserScan &scanmsg)
 
- Public Member Functions inherited from smacc2::ISmaccComponent
 ISmaccComponent ()
 
virtual ~ISmaccComponent ()
 
virtual std::string getName () const
 

Public Attributes

sensor_msgs::msg::LaserScan lastScanMessage_
 
const float SECURITY_DISTANCE = 0.4
 

Additional Inherited Members

- Protected Member Functions inherited from smacc2::ISmaccComponent
virtual void onInitialize ()
 
template<typename EventType >
void postEvent (const EventType &ev)
 
template<typename EventType >
void postEvent ()
 
template<typename TOrthogonal , typename TSourceObject >
void onOrthogonalAllocation ()
 
template<typename TComponent >
void requiresComponent (TComponent *&requiredComponentStorage)
 
template<typename TClient >
void requiresClient (TClient *&requiredClientStorage)
 
template<typename SmaccComponentType , typename TOrthogonal , typename TClient , typename... TArgs>
SmaccComponentType * createSiblingComponent (TArgs... targs)
 
template<typename SmaccComponentType , typename TOrthogonal , typename TClient , typename... TArgs>
SmaccComponentType * createSiblingNamedComponent (std::string name, TArgs... targs)
 
rclcpp::Node::SharedPtr getNode ()
 
rclcpp::Logger getLogger ()
 
ISmaccStateMachinegetStateMachine ()
 
- Protected Attributes inherited from smacc2::ISmaccComponent
ISmaccStateMachinestateMachine_
 
ISmaccClientowner_
 

Detailed Description

Definition at line 30 of file cp_forward_obstacle_detector.hpp.

Member Function Documentation

◆ getForwardDistance()

float sm_dance_bot_warehouse_2::cl_lidar::CpForwardObstacleDetector::getForwardDistance ( int  raysWidthCount = 0)
inline

Definition at line 56 of file cp_forward_obstacle_detector.hpp.

57 {
58 //auto fwdist = scanmsg.ranges[scanmsg.ranges.size() / 2] /*meter*/;
59 auto fwdist = lastScanMessage_.ranges[0] /*meter*/;
60
61// RCLCPP_INFO_STREAM(getLogger(), "[" << getName() << "] ranges[0]" << ss.str());
62
63 std::stringstream ss;
64 //check rays around main ray
65 for (int i = 0; i < raysWidthCount; i++)
66 {
67 // int baseindex = 0;
68 int scanindex = (- raysWidthCount / 2 + i) % raysWidthCount;
69
70 if(scanindex < 0)
71 {
72 scanindex = lastScanMessage_.ranges.size() + scanindex;
73 }
74
75 float fwdist2 = lastScanMessage_.ranges[scanindex];
76
77 RCLCPP_INFO_STREAM(
78 getLogger(), "[" << getName() << "]"
79 << "range[" << scanindex << "] = " << fwdist2);
80
81 if (fwdist2 > 0.01 && fwdist2 < fwdist)
82 {
83 RCLCPP_INFO_STREAM(
84 getLogger(), "[" << getName() << "]"
85 << "updated range[0] = " << fwdist2);
86
87 fwdist = fwdist2;
88 }
89 }
90
91 RCLCPP_INFO_STREAM(getLogger(), "[" << getName() << "]" << ss.str());
92
93 /*if the distance is infinity or nan, use max range distance*/
94 if (fwdist == std::numeric_limits<float>::infinity() || fwdist != fwdist)
95 {
96 fwdist = lastScanMessage_.range_max - SECURITY_DISTANCE /*meters*/;
97 RCLCPP_INFO_THROTTLE(
98 getLogger(), *(getNode()->get_clock()), 1000,
99 "[CpForwardObstacleDetector] Distance to forward obstacle is not a number, setting default value "
100 "to: %lf",
101 lastScanMessage_.range_max);
102 }
103 else
104 {
105 RCLCPP_INFO_STREAM(getLogger(), "[" << getName() << "] fwdist: " << fwdist);
106 fwdist = std::max(fwdist - SECURITY_DISTANCE, 0.0F);
107 RCLCPP_INFO_STREAM(getLogger(), "[" << getName() << "] fwdist: " << fwdist);
108 }
109
110 return fwdist;
111 }
rclcpp::Logger getLogger()
virtual std::string getName() const
rclcpp::Node::SharedPtr getNode()

References smacc2::ISmaccComponent::getLogger(), smacc2::ISmaccComponent::getName(), smacc2::ISmaccComponent::getNode(), lastScanMessage_, and SECURITY_DISTANCE.

Referenced by sm_dance_bot_warehouse_2::s_pattern_states::StiSPatternForward1::runtimeConfigure(), sm_dance_bot_warehouse_2::s_pattern_states::StiSPatternForward2::runtimeConfigure(), sm_dance_bot_warehouse_2::s_pattern_states::StiSPatternForward3::runtimeConfigure(), and sm_dance_bot_warehouse_2::s_pattern_states::StiSPatternForward4::runtimeConfigure().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ MessageCallbackStoreDistanceToWall()

void sm_dance_bot_warehouse_2::cl_lidar::CpForwardObstacleDetector::MessageCallbackStoreDistanceToWall ( const sensor_msgs::msg::LaserScan &  scanmsg)
inline

Definition at line 113 of file cp_forward_obstacle_detector.hpp.

114 {
115 this->lastScanMessage_ = scanmsg;
116 }

Referenced by onInitialize().

Here is the caller graph for this function:

◆ modulo_Euclidean()

int sm_dance_bot_warehouse_2::cl_lidar::CpForwardObstacleDetector::modulo_Euclidean ( int  a,
int  b 
)
inline

Definition at line 45 of file cp_forward_obstacle_detector.hpp.

46 {
47 int m = a % b;
48 if (m < 0)
49 {
50 // m += (b < 0) ? -b : b; // avoid this form: -b is UB when b == INT_MIN
51 m = (b < 0) ? m - b : m + b;
52 }
53 return m;
54 }

◆ onInitialize()

void sm_dance_bot_warehouse_2::cl_lidar::CpForwardObstacleDetector::onInitialize ( )
inlineoverridevirtual

Member Data Documentation

◆ lastScanMessage_

sensor_msgs::msg::LaserScan sm_dance_bot_warehouse_2::cl_lidar::CpForwardObstacleDetector::lastScanMessage_

Definition at line 33 of file cp_forward_obstacle_detector.hpp.

Referenced by getForwardDistance().

◆ SECURITY_DISTANCE

const float sm_dance_bot_warehouse_2::cl_lidar::CpForwardObstacleDetector::SECURITY_DISTANCE = 0.4

Definition at line 35 of file cp_forward_obstacle_detector.hpp.

Referenced by getForwardDistance().


The documentation for this class was generated from the following file: