Class: AnalogLightSensor

Robot.AnalogLightSensor(sensorRadius, position, bufferLength)

Class containing the analog light sensor features. A digital light sensor has also been implemented.

Constructor

new AnalogLightSensor(sensorRadius, position, bufferLength)

Constructor function for AnalogLightSensor
Parameters:
Name Type Default Description
sensorRadius number The value of the sensor detection circle radius.
position p5.Vector The current position of the sensor in the global coordinate frame.
bufferLength number 1 An integer showing the length of the internal circular buffer that stores the previous sensor values.
Source:
See:

Methods

calcSegmentVal(h) → {number}

Calculates the area of a segment given the height of the segment.
Area = 0.5 * r^2 * (a - sin(a)); where a is the segment angle.
a = 2 * arcos(h / r)
Parameters:
Name Type Description
h number Height of the segment
Source:
Returns:
- Area of the segment
Type
number

findClosestLinePoint(tile) → {p5.Vector}

Looks at all the lines on a tile and finds the closest point to the current global position of the light sensor. This takes into account the global position of the tile. This only returns one closest point for all the lines and does not account for regions where lines crossover.
Parameters:
Name Type Description
tile World.Tile The tile to check against
Source:
Returns:
- The vector location of the closest point.
Type
p5.Vector

getLastRead() → {number}

A function to return the last reading that the sensor made. This is done by returning the last value in the buffer.
Source:
Returns:
- between 0 (black) and 1 (white)
Type
number

isOutsideofTile(tile) → {boolean}

A function to check if the sensor is within the boundaries of a tile.
Parameters:
Name Type Description
tile World.Tile The tile to check against
Source:
Returns:
- true if outside the tile false if inside the tile.
Type
boolean

read(tile) → {number}

Calculates the an averaged sensor reading over the raw sensor readings stored within the circular buffer. This function will call Robot.AnalogLightSensor.readRaw(tile) internally and update the buffer automatically.
Parameters:
Name Type Description
tile World.Tile The tile to read.
Source:
See:
  • Robot.AnalogLightSensor.readRaw
Returns:
- Number between 0 and 1. 0 is black and 1 is white.
Type
number

readRaw(tile) → {number}

Calculates a raw sensor value based on how close the sensor is to the closest line point. Reading raw values will not add values to the sensor buffer.
Parameters:
Name Type Description
tile World.Tile The tile to read
Source:
Returns:
- Number between 0 and 1. 0 is black and 1 is white.
Type
number

setPos(position)

A function to change the current light sensor position in the global coordinate frame.
Parameters:
Name Type Description
position p5.Vector The new position value.
Source:

setRadius(sensorRadius)

A function to set the sensor radius of the light sensor
Parameters:
Name Type Description
sensorRadius number The new sensor radius.
Source:

setupBuffer()

A function to set up the internal circular buffer.
Source:

Documentation generated by JSDoc 4.0.2 on Fri Aug 30 2024 16:12:54 GMT-0600 (Mountain Daylight Time)