SMACC2
cp_lidar_data.cpp
Go to the documentation of this file.
1// Copyright 2021 RobosoftAI Inc.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15#include <smacc2/smacc.hpp>
16
18{
19namespace cl_lidar
20{
21using namespace std::chrono_literals;
22
24{
25 auto client_ =
27 owner_);
29}
30
32 const sensor_msgs::msg::LaserScan & scanmsg)
33{
34 this->lastMessage_ = scanmsg;
35 //auto fwdist = scanmsg.ranges[scanmsg.ranges.size() / 2] /*meter*/;
36 auto fwdist = scanmsg.ranges[0] /*meter*/;
37
38 /*if the distance is infinity or nan, use max range distance*/
39 if (fwdist == std::numeric_limits<float>::infinity() || fwdist != fwdist)
40 {
41 this->forwardObstacleDistance = scanmsg.range_max - SECURITY_DISTANCE /*meters*/;
42 RCLCPP_INFO_THROTTLE(
43 getLogger(), *(getNode()->get_clock()), 1000,
44 "[CpLidarSensorData] Distance to forward obstacle is not a number, setting default value "
45 "to: %lf",
46 scanmsg.range_max);
47 }
48 else
49 {
50 this->forwardObstacleDistance = std::max(fwdist - SECURITY_DISTANCE, 0.0F);
51 }
52}
53
54} // namespace cl_lidar
55} // namespace sm_dance_bot_strikes_back
void MessageCallbackStoreDistanceToWall(const sensor_msgs::msg::LaserScan &scanmsg)
ISmaccClient * owner_
Definition: component.hpp:77
rclcpp::Logger getLogger()
rclcpp::Node::SharedPtr getNode()
boost::signals2::connection onMessageReceived(void(T::*callback)(const MessageType &), T *object)