Changeset View
Changeset View
Standalone View
Standalone View
src/applications/caspian/CaspianLIDARAnalyzer.php
- This file was added.
<?php | |||||
final class CaspianLIDARAnalyzer | |||||
extends CaspianAnalyzer { | |||||
public function analyzeSensors(CaspianState $state) { | |||||
$lidars = array(); | |||||
foreach ($state->getSensorState() as $sensor_state) { | |||||
if ($sensor_state['sensor'] instanceof CaspianLIDARSensor) { | |||||
$lidars[] = $sensor_state; | |||||
} | |||||
} | |||||
$lidar_result = array(); | |||||
for ($ii = 0; $ii < 12; $ii++) { | |||||
$readings = array(); | |||||
foreach ($lidars as $lidar_reading) { | |||||
$state = $lidar_reading['state']; | |||||
if ($state[$ii] !== null) { | |||||
$readings[] = $state[$ii]; | |||||
} | |||||
} | |||||
// Combine the values and certainties. This is just a rough approximation | |||||
// that produces output in vaguely the right shape. | |||||
$values = array(); | |||||
$certainties = array(); | |||||
foreach ($readings as $reading) { | |||||
$values[] = $reading['reading']; | |||||
$certainties[] = $reading['certainty']; | |||||
} | |||||
$value = array_sum($values) / count($values); | |||||
$certainty = array_sum($certainties) / (count($certainties) + 1); | |||||
$lidar_result[] = array( | |||||
'reading' => $value, | |||||
'certainty' => $certainty, | |||||
); | |||||
} | |||||
return $lidar_result; | |||||
} | |||||
public function newView(array $state) { | |||||
return id(new CaspianLIDARView())->newView( | |||||
$this->getName(), | |||||
$state); | |||||
} | |||||
} |