mirror of
https://github.com/firestar5683/StarPilot.git
synced 2026-07-02 20:12:07 +08:00
sensord: rm light sensor (#29503)
old-commit-hash: f5071411cb460cc64474f533143f37ba3eb54ce6
This commit is contained in:
@@ -1,9 +1,7 @@
|
||||
Import('env', 'arch', 'common', 'cereal', 'messaging')
|
||||
|
||||
sensors = [
|
||||
'sensors/file_sensor.cc',
|
||||
'sensors/i2c_sensor.cc',
|
||||
'sensors/light_sensor.cc',
|
||||
'sensors/bmx055_accel.cc',
|
||||
'sensors/bmx055_gyro.cc',
|
||||
'sensors/bmx055_magn.cc',
|
||||
|
||||
@@ -1,17 +0,0 @@
|
||||
#include "file_sensor.h"
|
||||
|
||||
#include <string>
|
||||
|
||||
FileSensor::FileSensor(std::string filename) : file(filename) {}
|
||||
|
||||
int FileSensor::init() {
|
||||
return file.is_open() ? 0 : 1;
|
||||
}
|
||||
|
||||
FileSensor::~FileSensor() {
|
||||
file.close();
|
||||
}
|
||||
|
||||
bool FileSensor::has_interrupt_enabled() {
|
||||
return false;
|
||||
}
|
||||
@@ -1,19 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <fstream>
|
||||
#include <string>
|
||||
|
||||
#include "cereal/gen/cpp/log.capnp.h"
|
||||
#include "system/sensord/sensors/sensor.h"
|
||||
|
||||
class FileSensor : public Sensor {
|
||||
protected:
|
||||
std::ifstream file;
|
||||
|
||||
public:
|
||||
FileSensor(std::string filename);
|
||||
~FileSensor();
|
||||
int init();
|
||||
bool has_interrupt_enabled();
|
||||
virtual bool get_event(MessageBuilder &msg, uint64_t ts = 0) = 0;
|
||||
};
|
||||
@@ -1,27 +0,0 @@
|
||||
#include "light_sensor.h"
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "common/timing.h"
|
||||
#include "system/sensord/sensors/constants.h"
|
||||
|
||||
LightSensor::LightSensor(std::string filename) : FileSensor(filename) {}
|
||||
|
||||
bool LightSensor::get_event(MessageBuilder &msg, uint64_t ts) {
|
||||
uint64_t start_time = nanos_since_boot();
|
||||
file.clear();
|
||||
file.seekg(0);
|
||||
|
||||
int value;
|
||||
file >> value;
|
||||
|
||||
auto event = msg.initEvent().initLightSensor();
|
||||
event.setSource(cereal::SensorEventData::SensorSource::RPR0521);
|
||||
event.setVersion(1);
|
||||
event.setSensor(SENSOR_LIGHT);
|
||||
event.setType(SENSOR_TYPE_LIGHT);
|
||||
event.setTimestamp(start_time);
|
||||
event.setLight(value);
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -1,9 +0,0 @@
|
||||
#pragma once
|
||||
#include "file_sensor.h"
|
||||
|
||||
class LightSensor : public FileSensor {
|
||||
public:
|
||||
LightSensor(std::string filename);
|
||||
bool get_event(MessageBuilder &msg, uint64_t ts = 0);
|
||||
int shutdown() { return 0; }
|
||||
};
|
||||
@@ -18,7 +18,6 @@
|
||||
#include "system/sensord/sensors/bmx055_magn.h"
|
||||
#include "system/sensord/sensors/bmx055_temp.h"
|
||||
#include "system/sensord/sensors/constants.h"
|
||||
#include "system/sensord/sensors/light_sensor.h"
|
||||
#include "system/sensord/sensors/lsm6ds3_accel.h"
|
||||
#include "system/sensord/sensors/lsm6ds3_gyro.h"
|
||||
#include "system/sensord/sensors/lsm6ds3_temp.h"
|
||||
@@ -101,8 +100,6 @@ int sensor_loop(I2CBus *i2c_bus_imu) {
|
||||
|
||||
MMC5603NJ_Magn mmc5603nj_magn(i2c_bus_imu);
|
||||
|
||||
LightSensor light("/sys/class/i2c-adapter/i2c-2/2-0038/iio:device1/in_intensity_both_raw");
|
||||
|
||||
std::map<Sensor*, std::string> sensor_service = {
|
||||
{&bmx055_accel, "accelerometer2"},
|
||||
{&bmx055_gyro, "gyroscope2"},
|
||||
@@ -114,7 +111,6 @@ int sensor_loop(I2CBus *i2c_bus_imu) {
|
||||
{&lsm6ds3_temp, "temperatureSensor"},
|
||||
|
||||
{&mmc5603nj_magn, "magnetometer"},
|
||||
{&light, "lightSensor"}
|
||||
};
|
||||
|
||||
// Sensor init
|
||||
@@ -130,8 +126,6 @@ int sensor_loop(I2CBus *i2c_bus_imu) {
|
||||
|
||||
sensors_init.push_back({&mmc5603nj_magn, false});
|
||||
|
||||
sensors_init.push_back({&light, true});
|
||||
|
||||
bool has_magnetometer = false;
|
||||
|
||||
// Initialize sensors
|
||||
@@ -165,8 +159,7 @@ int sensor_loop(I2CBus *i2c_bus_imu) {
|
||||
util::set_core_affinity({1});
|
||||
std::system("sudo su -c 'echo 1 > /proc/irq/336/smp_affinity_list'");
|
||||
|
||||
PubMaster pm_non_int({"gyroscope2", "accelerometer2", "temperatureSensor",
|
||||
"lightSensor", "magnetometer"});
|
||||
PubMaster pm_non_int({"gyroscope2", "accelerometer2", "temperatureSensor", "magnetometer"});
|
||||
init_ts = nanos_since_boot();
|
||||
|
||||
// thread for reading events via interrupts
|
||||
|
||||
@@ -29,24 +29,16 @@ MMC = {
|
||||
('mmc5603nj', 'magneticUncalibrated'),
|
||||
}
|
||||
|
||||
RPR = {
|
||||
('rpr0521', 'light'),
|
||||
}
|
||||
|
||||
SENSOR_CONFIGURATIONS = (
|
||||
(BMX | LSM | RPR),
|
||||
(MMC | LSM | RPR),
|
||||
(BMX | LSM_C | RPR),
|
||||
(MMC| LSM_C | RPR),
|
||||
(BMX | LSM),
|
||||
(MMC | LSM),
|
||||
(BMX | LSM_C),
|
||||
(MMC| LSM_C),
|
||||
)
|
||||
|
||||
Sensor = log.SensorEventData.SensorSource
|
||||
SensorConfig = namedtuple('SensorConfig', ['type', 'sanity_min', 'sanity_max', 'expected_freq'])
|
||||
ALL_SENSORS = {
|
||||
Sensor.rpr0521: {
|
||||
SensorConfig("light", 0, 1023, 100),
|
||||
},
|
||||
|
||||
Sensor.lsm6ds3: {
|
||||
SensorConfig("acceleration", 5, 15, 100),
|
||||
SensorConfig("gyroUncalibrated", 0, .2, 100),
|
||||
@@ -79,7 +71,7 @@ def get_irq_count(irq: int):
|
||||
|
||||
def read_sensor_events(duration_sec):
|
||||
sensor_types = ['accelerometer', 'gyroscope', 'magnetometer', 'accelerometer2',
|
||||
'gyroscope2', 'lightSensor', 'temperatureSensor']
|
||||
'gyroscope2', 'temperatureSensor']
|
||||
esocks = {}
|
||||
events = defaultdict(list)
|
||||
for stype in sensor_types:
|
||||
|
||||
Reference in New Issue
Block a user