TinyRobotics
Loading...
Searching...
No Matches
Public Member Functions | Protected Attributes | List of all members
RangeSensor< T > Class Template Reference

Generic range sensor abstraction for LIDAR, ultrasonic, or similar sensors. More...

#include <RangeSensor.h>

Inheritance diagram for RangeSensor< T >:
Inheritance graph
[legend]
Collaboration diagram for RangeSensor< T >:
Collaboration graph
[legend]

Public Member Functions

 RangeSensor (const Transform2D &tf, float obstacleDegree=0)
 
 RangeSensor (float obstacleDegree=0)
 
bool begin ()
 Start the sensor (e.g., initialize hardware)
 
void update (float angleDeg, float distanceM)
 Update the sensor with angle (deg) and distance (m)
 
void update (Angle angle, Distance distance)
 Update the sensor with angle and distance objects.
 
void end ()
 Stop the sensor.
 
void setObstacleDirectionDegree (float deg)
 Defines the angle to the obstacle in degrees: 0 means forward.
 
void setObstacleDirection (Angle angle)
 Set the obstacle direction using an Angle object.
 
float getObstacleDirectionDegree () const
 
bool setObstacleDistance (Distance dist)
 
bool setObstacleDistance (float distanceM)
 
void setObstacleAlertAngle (Angle deg)
 Set the alert angle threshold for obstacle detection.
 
void setObstacleAlertDistance (Distance dist)
 Set the alert distance threshold for obstacle detection.
 
float getObstacleDistance () const
 
void setObstacle (float degree, float distance)
 Convenience method to set both the obstacle bearing and distance at once.
 
void setTransform (const Transform2D &tf)
 Set the sensor-to-world transform.
 
bool getObstacleCoordinate (Coordinate< T > &result)
 
 operator bool () const
 Check if the sensor reading is valid (distance > 0)
 
bool hasObstacle () const
 Return true if there is an obstacle detected (distance > 0)
 
float getSpeedFactor (Distance breakingDistance) const
 Compute a speed factor (0.0 to 1.0) based on the distance to the obstacle.
 
- Public Member Functions inherited from MessageSource
void subscribe (MessageHandler &handler, MessageOrigin origin=MessageOrigin::Undefined, MessageContent content=MessageContent::Undefined)
 Subscribe a message handler to this source, with optional filtering.
 
void unsubscribeAll ()
 Remove all registered message handlers.
 
void sendMessage (Message< float > &msg)
 Publish a message to all registered handlers.
 
void sendMessage (const Message< Coordinate< float > > &msg)
 Publish a message to all registered handlers.
 
void sendMessage (const Message< GPSCoordinate > &msg)
 Publish a message to all registered handlers.
 
void sendMessage (const Message< MotionState3D > &msg)
 Overload for MotionState3D messages.
 

Protected Attributes

float obstacle_deg_ = 0
 
float distanceM = 0
 
Transform2D lidar_to_world_tf
 
bool has_transform_ = false
 
bool is_active_ = false
 
float alertAngleDeg_ = 5
 
float alertDistanceM_ = 1.0f
 
- Protected Attributes inherited from MessageSource
std::vector< MessageHandlerEntrymessageHandlers_
 

Detailed Description

template<typename T = DistanceM>
class tinyrobotics::RangeSensor< T >

Generic range sensor abstraction for LIDAR, ultrasonic, or similar sensors.

This template class models a simple range sensor, such as a LIDAR or ultrasonic sensor, for robotics applications. It tracks the measured distance to an obstacle, the angle (bearing) of the obstacle relative to the sensor, and the transform from the sensor's local frame to the world frame. The class provides methods to set and retrieve the measured distance and bearing, update the sensor-to-world transform, and compute the world-frame coordinates of detected obstacles.

Features

Usage Example

Transform2D tf = ...; // Sensor-to-world transform
RangeSensor<> sensor(tf, 0.0f); // 0 degrees = forward
sensor.begin();
sensor.setObstacleDistance(1.5f); // Set measured distance
if (sensor) {
if (sensor.getObstacleCoordinate(obs)) {
// Use obs for navigation
}
}
A generic 3D coordinate class for robotics, navigation, and spatial calculations.
Definition: Coordinate.h:57
Generic range sensor abstraction for LIDAR, ultrasonic, or similar sensors.
Definition: RangeSensor.h:69
Represents a 2D rigid body transform (SE(2)): translation and rotation.
Definition: FrameMgr2D.h:42

Template Parameters

Template Parameters
TDistance type (default: DistanceM)

Methods

Applications

Author
Phil Schatzmann

Member Function Documentation

◆ getObstacleCoordinate()

bool getObstacleCoordinate ( Coordinate< T > &  result)
inline

Get the obstacle coordinate in world frame based on the current distance and transform.

◆ getObstacleDirectionDegree()

float getObstacleDirectionDegree ( ) const
inline

Get the angle of the obstacle relative to the sensor's forward direction in degrees.

◆ getObstacleDistance()

float getObstacleDistance ( ) const
inline

Provide the distance measured by the sensor. In a real implementation, this would

◆ setObstacleDistance() [1/2]

bool setObstacleDistance ( Distance  dist)
inline

Set the distance measured by the sensor. Make sure that the ObstacleDegree is defined

◆ setObstacleDistance() [2/2]

bool setObstacleDistance ( float  distanceM)
inline

Set the distance measured by the sensor. Make sure that the ObstacleDegree is defined


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