2#include "TinyRobotics/coordinates/Coordinate.h"
3#include "TinyRobotics/imu/IMU2D.h"
4#include "TinyRobotics/maps/GridBitMap.h"
5#include "TinyRobotics/planning/IFrontierExplorer.h"
6#include "TinyRobotics/sensors/RangeSensor.h"
8namespace tinyrobotics {
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
66 : explorer_(explorer),
72 callbackHandler_.setValueCallback(onIMUPublished,
this);
73 imu2d_.subscribe(callbackHandler_);
81 bool rcIMU = imu2d_.begin(transform);
82 bool rcSensor = rangeSensor_.begin();
83 return rcIMU && rcSensor;
99 rangeSensor_.setTransform(
100 tf_.getTransform(lidar_, world_));
101 rangeSensor_.setObstacle(distanceM, angleDeg);
103 if (rangeSensor_.getObstacleCoordinate(obs)) {
105 Transform2D tf_lidar2world = tf_.getTransform(lidar_, world_);
106 Coordinate<
float> obs_world = tf_lidar2world.apply(obs);
109 tf_lidar2world.apply(Coordinate<
float>(0, 0));
112 markRay(sensor_world, obs_world, state);
117
118
119
120
121
123 return explorer_.getNextFrontier(result);
129 rangeSensor_.subscribe(handler);
132 void unsubscribeAll() {
134 rangeSensor_.unsubscribeAll();
150 CallbackMessageHandler callbackHandler_;
158
159
160
161
162
165 auto points = sensor.interpolateTo(obstacle, map_.getResolution());
166 for (
auto& loc : points) {
167 if (map_.isValid(loc)) map_.setCell(loc, CellState::FREE);
169 if (map_.isValid(obstacle)) {
170 map_.setCell(obstacle, state);
174 static bool onIMUPublished(
const Message<
float>& msg,
void* ref) {
177 self.base_.setTransform(self.imu2d_.getTransform());
Represents an angle with unit conversion and wrap-around support.
Definition: Angle.h:42
A generic 3D coordinate class for robotics, navigation, and spatial calculations.
Definition: Coordinate.h:57
Represents a distance measurement with unit conversion support.
Definition: Distance.h:40
Manages a hierarchy of 2D coordinate frames and enables SE(2) transforms and GPS conversion.
Definition: FrameMgr2D.h:196
Interface for frontier-based exploration utilities.
Definition: IFrontierExplorer.h:18
Abstract interface for 2D grid maps and occupancy maps in TinyRobotics.
Definition: IMap.h:79
Interface for representing the navigation state of a robot in 2D space.
Definition: MotionState2D.h:35
Modular 2D Simultaneous Localization and Mapping (SLAM) system with flexible map, IMU,...
Definition: LocalizationAndMapping2D.h:61
IMotionState2D & getIMU()
Access to IMU state.
Definition: LocalizationAndMapping2D.h:141
IMap< T > & getMap()
Access to map.
Definition: LocalizationAndMapping2D.h:138
void addRangeMeasurement(float distanceM, float angleDeg, CellState state)
Register Range Measurement from Lidar.
Definition: LocalizationAndMapping2D.h:98
void addRangeMeasurement(Distance dist, Angle angle, CellState state)
Register Range Measurement from Lidar.
Definition: LocalizationAndMapping2D.h:92
void markRay(const Coordinate< float > &sensor, const Coordinate< float > &obstacle, CellState state)
Mark all cells between the sensor and the obstacle as FREE, and the obstacle cell as OCCUPIED.
Definition: LocalizationAndMapping2D.h:163
bool begin()
Initialize SLAM system (IMU and range sensor)
Definition: LocalizationAndMapping2D.h:77
void subscribe(MessageHandler &handler)
Subscribe to imu and range sensor messages.
Definition: LocalizationAndMapping2D.h:127
bool getNextFrontier(Coordinate< float > &result) const
Find the next frontier cell (boundary between known free and unknown space).
Definition: LocalizationAndMapping2D.h:122
Interface for handling messages in the TinyRobotics framework.
Definition: MessageHandler.h:18
Base class for message sources in the TinyRobotics communication framework.
Definition: MessageSource.h:35
void unsubscribeAll()
Remove all registered message handlers.
Definition: MessageSource.h:69
void subscribe(MessageHandler &handler, MessageOrigin origin=MessageOrigin::Undefined, MessageContent content=MessageContent::Undefined)
Subscribe a message handler to this source, with optional filtering.
Definition: MessageSource.h:59
Generic range sensor abstraction for LIDAR, ultrasonic, or similar sensors.
Definition: RangeSensor.h:69
DistanceUnit
Supported distance units for conversion and representation.
Definition: Distance.h:10
AngleUnit
Supported angle units for conversion and representation.
Definition: Angle.h:11
CellState
Cell state for occupancy grid mapping (e.g., UNKNOWN, FREE, OCCUPIED).
Definition: Common.h:32
Represents a 2D coordinate frame in a hierarchical frame tree.
Definition: FrameMgr2D.h:130
Generic message structure for communication, parameterized by value type.
Definition: Message.h:72