BotNavSim  v0.4.3
Mobile Robot Simulation
ParamSensor Class Reference

Parameter sensor is a 2D FOV sensor model, loosely based on real ultrasonic sensor behaviour More...

Inheritance diagram for ParamSensor:
Collaboration diagram for ParamSensor:

Public Member Functions

override void Enable (Robot.SensorData callback)
 Enable this instance and pass the reference to the Robot.SensorData callback function to be called when the sensor has new information to share. More...
 
override void Disable ()
 Disable this instance. More...
 

Public Attributes

bool drawDebug = true
 If true the sensor will use Draw to draw raycast lines in the simulation More...
 
float FOV = 20f
 The field of view angle in degrees. More...
 
float maxRange = 20f
 The maximum distance for each raycast. More...
 
float updateDt = 0.2f
 The sensor update delta time in seconds. More...
 

Properties

bool scanning [get, private set]
 Gets a value indicating whether this ParamSensor is scanning. More...
 

Private Member Functions

IEnumerator UpdateData ()
 Update data coroutine. Once started, executes until disabled. Calls _callback on Robot every update. Update rate defined by updateDt More...
 
float Cast (Vector3 direction)
 Wrapper function for a single raycast. Returns the proximity distance in the specified direction. More...
 

Private Attributes

Robot.SensorData _callback
 The Robot.SensorData callback to pass ProximityData to More...
 
ProximityData _data
 Cached ProximityData from the last UpdateData() scan More...
 

Detailed Description

Parameter sensor is a 2D FOV sensor model, loosely based on real ultrasonic sensor behaviour

Definition at line 11 of file ParamSensor.cs.

Member Function Documentation

float ParamSensor.Cast ( Vector3  direction)
private

Wrapper function for a single raycast. Returns the proximity distance in the specified direction.

Parameters
directionDirection.

Definition at line 110 of file ParamSensor.cs.

110  {
111  Ray ray = new Ray(transform.position, direction);
112  RaycastHit hit;
113  if (Physics.Raycast(ray, out hit, maxRange)) {
115  transform.position,
116  hit.point,
117  Color.red);
118  return hit.distance;
119  }
120  else {
122  transform.position,
123  transform.position + direction * maxRange,
124  Color.green);
125  return maxRange;
126  }
127  }
Draws stuff, useful for displaying debug data in the simulation. Note that GL implementations require...
Definition: Draw.cs:10
float maxRange
The maximum distance for each raycast.
Definition: ParamSensor.cs:30
bool drawDebug
If true the sensor will use Draw to draw raycast lines in the simulation
Definition: ParamSensor.cs:20
void Line(Vector3 start, Vector3 end, Color color, Space relativeTo=Space.World)
Draw a line between two positions, start and end, in a specified color.
Definition: Draw.cs:76
static Draw Instance
Reference to the MonoBehaviour instance.
Definition: Draw.cs:39

Here is the call graph for this function:

Here is the caller graph for this function:

override void ParamSensor.Disable ( )
virtual

Disable this instance.

Implements Sensor.

Definition at line 74 of file ParamSensor.cs.

74  {
75  scanning = false;
76  }
bool scanning
Gets a value indicating whether this ParamSensor is scanning.
Definition: ParamSensor.cs:45
override void ParamSensor.Enable ( Robot.SensorData  callback)
virtual

Enable this instance and pass the reference to the Robot.SensorData callback function to be called when the sensor has new information to share.

Parameters
callbackCallback.

Implements Sensor.

Definition at line 67 of file ParamSensor.cs.

67  {
68  scanning = true;
69  _callback = callback;
70  StartCoroutine(UpdateData());
71  }
Robot.SensorData _callback
The Robot.SensorData callback to pass ProximityData to
Definition: ParamSensor.cs:55
IEnumerator UpdateData()
Update data coroutine. Once started, executes until disabled. Calls _callback on Robot every update...
Definition: ParamSensor.cs:86
bool scanning
Gets a value indicating whether this ParamSensor is scanning.
Definition: ParamSensor.cs:45

Here is the call graph for this function:

IEnumerator ParamSensor.UpdateData ( )
private

Update data coroutine. Once started, executes until disabled. Calls _callback on Robot every update. Update rate defined by updateDt

Definition at line 86 of file ParamSensor.cs.

86  {
87 
88  while(scanning) {
89  float proximity = maxRange;
90  for (float a = -FOV; a < FOV; a += 2f) {
91  Quaternion rotation = Quaternion.Euler(new Vector3(0,a,0));
92  Vector3 direction = rotation * transform.forward;
93  float check = Cast (direction);
94  if (check < proximity) proximity = check;
95  }
96  _data.direction = transform.forward * proximity;
97  if (proximity < maxRange * 0.75f) _data.obstructed = true;
98  else _data.obstructed = false;
100  yield return new WaitForSeconds(updateDt);
101  }
102 
103  }
bool obstructed
Indicates whether or not the location at the end of the direction is obstructed.
Robot.SensorData _callback
The Robot.SensorData callback to pass ProximityData to
Definition: ParamSensor.cs:55
float FOV
The field of view angle in degrees.
Definition: ParamSensor.cs:25
float Cast(Vector3 direction)
Wrapper function for a single raycast. Returns the proximity distance in the specified direction...
Definition: ParamSensor.cs:110
ProximityData _data
Cached ProximityData from the last UpdateData() scan
Definition: ParamSensor.cs:60
float maxRange
The maximum distance for each raycast.
Definition: ParamSensor.cs:30
bool scanning
Gets a value indicating whether this ParamSensor is scanning.
Definition: ParamSensor.cs:45
float updateDt
The sensor update delta time in seconds.
Definition: ParamSensor.cs:35
Vector3 direction
The direction of the proximity

Here is the call graph for this function:

Here is the caller graph for this function:

Member Data Documentation

Robot.SensorData ParamSensor._callback
private

The Robot.SensorData callback to pass ProximityData to

Definition at line 55 of file ParamSensor.cs.

ProximityData ParamSensor._data
private

Cached ProximityData from the last UpdateData() scan

Definition at line 60 of file ParamSensor.cs.

bool ParamSensor.drawDebug = true

If true the sensor will use Draw to draw raycast lines in the simulation

Definition at line 20 of file ParamSensor.cs.

float ParamSensor.FOV = 20f

The field of view angle in degrees.

Definition at line 25 of file ParamSensor.cs.

float ParamSensor.maxRange = 20f

The maximum distance for each raycast.

Definition at line 30 of file ParamSensor.cs.

float ParamSensor.updateDt = 0.2f

The sensor update delta time in seconds.

Definition at line 35 of file ParamSensor.cs.

Property Documentation

bool ParamSensor.scanning
getprivate set

Gets a value indicating whether this ParamSensor is scanning.

true if scanning; otherwise, false.

Definition at line 45 of file ParamSensor.cs.


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