Ultrasonic sensor model.
More...
|
IEnumerator | Scan () |
| Scan for obstructions in a cone More...
|
|
float | Cast (Vector3 direction) |
| Cast a ray and return detected obstruction if the hit angle is less than a threshold More...
|
|
void | Awake () |
| Awake this instance. More...
|
|
void | OnDrawGizmos () |
| Raises the draw gizmos event. More...
|
|
Ultrasonic sensor model.
Definition at line 7 of file UltrasonicSensor.cs.
void UltrasonicSensor.Awake |
( |
| ) |
|
|
private |
float UltrasonicSensor.Cast |
( |
Vector3 |
direction | ) |
|
|
private |
Cast a ray and return detected obstruction if the hit angle is less than a threshold
- Parameters
-
Definition at line 103 of file UltrasonicSensor.cs.
104 Ray ray =
new Ray(transform.position, direction);
109 if (Vector3.Angle(-hit.normal, direction) < 30f) {
110 proximity = hit.distance;
117 hit.point+hit.normal*0.1f,
127 hit.point+hit.normal*0.1f,
134 transform.position + direction *
maxRange,
LayerMask raycastLayer
The raycast collision layer.
Draws stuff, useful for displaying debug data in the simulation. Note that GL implementations require...
float maxRange
The max range of the sensor in metres.
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.
static Draw Instance
Reference to the MonoBehaviour instance.
override void UltrasonicSensor.Disable |
( |
| ) |
|
|
virtual |
Disable this instance.
Implements Sensor.
Definition at line 58 of file UltrasonicSensor.cs.
bool scanning
Gets a value indicating whether this UltrasonicSensor is enabled and scanning.
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
-
Implements Sensor.
Definition at line 52 of file UltrasonicSensor.cs.
55 StartCoroutine(
Scan());
Robot.SensorData _callback
The callback function to execute when the sensor has new data to share.
IEnumerator Scan()
Scan for obstructions in a cone
bool scanning
Gets a value indicating whether this UltrasonicSensor is enabled and scanning.
void UltrasonicSensor.OnDrawGizmos |
( |
| ) |
|
|
private |
Raises the draw gizmos event.
Definition at line 157 of file UltrasonicSensor.cs.
158 Gizmos.color = Color.grey;
160 for (
float r = 0; r <= 180f; r += 30f) {
162 for (
float y = -
Fov; y <=
Fov; y += 10f){
163 Quaternion rotation = Quaternion.AngleAxis(y, transform.up);
164 Vector3 direction = rotation * transform.forward;
165 rotation = Quaternion.AngleAxis(r, transform.forward);
166 direction = rotation * direction;
167 Gizmos.DrawRay(transform.position, direction *
maxRange);
float Fov
The field of view angle in degrees.
float maxRange
The max range of the sensor in metres.
IEnumerator UltrasonicSensor.Scan |
( |
| ) |
|
|
private |
Scan for obstructions in a cone
Definition at line 73 of file UltrasonicSensor.cs.
78 for (
float r = 0; r <= 180f; r += 10f) {
80 for (
float y = -
Fov; y <
Fov; y += 6f){
83 rotation = Quaternion.AngleAxis(y, transform.up);
84 direction = rotation * transform.forward;
85 rotation = Quaternion.AngleAxis(r, transform.forward);
86 direction = rotation * direction;
87 float cast =
Cast(direction);
89 if (cast < proximity) proximity = cast;
94 yield
return new WaitForSeconds(
updateDt);
Robot.SensorData _callback
The callback function to execute when the sensor has new data to share.
ProximityData _data
Cached proximity data from the last scan
float updateDt
The sensor update delta time in seconds.
Proximity data structure.
float Fov
The field of view angle in degrees.
float Cast(Vector3 direction)
Cast a ray and return detected obstruction if the hit angle is less than a threshold ...
float maxRange
The max range of the sensor in metres.
bool scanning
Gets a value indicating whether this UltrasonicSensor is enabled and scanning.
The callback function to execute when the sensor has new data to share.
Definition at line 39 of file UltrasonicSensor.cs.
Color UltrasonicSensor._hitColor |
|
private |
Color UltrasonicSensor._missColor |
|
private |
Color UltrasonicSensor._recieveColor |
|
private |
float UltrasonicSensor.Fov |
float UltrasonicSensor.maxRange |
LayerMask UltrasonicSensor.raycastLayer |
float UltrasonicSensor.updateDt |
bool UltrasonicSensor.scanning |
|
getprivate set |
The documentation for this class was generated from the following file: