mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-04-14 10:07:39 +08:00
MPC9808: Run ScheduleOnInterval() at desired publishing rate and remove elapsed time check and timestamp_sample field from message as no longer needed.
MCP9808: Replaced PX4_INFO with PX4_DEBUG MCP9808: Update date in headers MCP9808: Define functions before variables MCP9808: Increase logging interval for sensor_temp MCP9808: Removed extra space MCP9808: Remove this->
This commit is contained in:
parent
ddb98abf1d
commit
5483d901f9
@ -1,6 +1,4 @@
|
||||
uint64 timestamp # time since system start (microseconds)
|
||||
uint64 timestamp_sample # Time at which measurement was taken
|
||||
|
||||
uint32 device_id # unique device ID for the sensor that does not change between power cycles
|
||||
|
||||
float32 temperature # Temperature provided by sensor (Celsius)
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
############################################################################
|
||||
#
|
||||
# Copyright (c) 2024 PX4 Development Team. All rights reserved.
|
||||
# Copyright (c) 2025 PX4 Development Team. All rights reserved.
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without
|
||||
# modification, are permitted provided that the following conditions
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
/****************************************************************************
|
||||
*
|
||||
* Copyright (c) 2024 PX4 Development Team. All rights reserved.
|
||||
* Copyright (c) 2025 PX4 Development Team. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
@ -39,7 +39,7 @@ MCP9808::MCP9808(const I2CSPIDriverConfig &config) :
|
||||
_cycle_perf(perf_alloc(PC_ELAPSED, MODULE_NAME": single-sample")),
|
||||
_comms_errors(perf_alloc(PC_COUNT, MODULE_NAME": comms errors"))
|
||||
{
|
||||
_sensor_temp.device_id = this->get_device_id();
|
||||
_sensor_temp.device_id = get_device_id();
|
||||
}
|
||||
|
||||
MCP9808::~MCP9808()
|
||||
@ -53,11 +53,7 @@ void MCP9808::RunImpl()
|
||||
{
|
||||
perf_begin(_cycle_perf);
|
||||
|
||||
// publish at around 5HZ
|
||||
if ((hrt_elapsed_time(&measurement_time)) > 200_ms) {
|
||||
|
||||
float temperature = read_temperature();
|
||||
measurement_time = hrt_absolute_time(); // get the time the measurement was taken
|
||||
|
||||
if (std::isnan(temperature)) {
|
||||
|
||||
@ -65,12 +61,10 @@ void MCP9808::RunImpl()
|
||||
|
||||
} else {
|
||||
_sensor_temp.timestamp = hrt_absolute_time();
|
||||
_sensor_temp.timestamp_sample = measurement_time;
|
||||
_sensor_temp.temperature = temperature;
|
||||
|
||||
_sensor_temp_pub.publish(_sensor_temp);
|
||||
}
|
||||
}
|
||||
|
||||
perf_end(_cycle_perf);
|
||||
}
|
||||
@ -109,7 +103,7 @@ int MCP9808::init()
|
||||
return ret;
|
||||
}
|
||||
|
||||
PX4_INFO("I2C initialized successfully");
|
||||
PX4_DEBUG("I2C initialized successfully");
|
||||
|
||||
ret = write_reg(MCP9808_REG_CONFIG, 0x0000); // Ensure default configuration
|
||||
|
||||
@ -120,7 +114,7 @@ int MCP9808::init()
|
||||
|
||||
_sensor_temp_pub.advertise();
|
||||
|
||||
ScheduleOnInterval(100_ms); // Sample at 10 Hz
|
||||
ScheduleOnInterval(200_ms); // Sample at 5 Hz
|
||||
return PX4_OK;
|
||||
}
|
||||
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
/****************************************************************************
|
||||
*
|
||||
* Copyright (c) 2024 PX4 Development Team. All rights reserved.
|
||||
* Copyright (c) 2025 PX4 Development Team. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
@ -66,11 +66,10 @@ protected:
|
||||
|
||||
private:
|
||||
uORB::PublicationMulti<sensor_temp_s> _sensor_temp_pub{ORB_ID(sensor_temp)};
|
||||
perf_counter_t _cycle_perf;
|
||||
perf_counter_t _comms_errors;
|
||||
sensor_temp_s _sensor_temp{};
|
||||
int read_reg(uint8_t address, uint16_t &data);
|
||||
int write_reg(uint8_t address, uint16_t value);
|
||||
float read_temperature();
|
||||
hrt_abstime measurement_time = 0;
|
||||
sensor_temp_s _sensor_temp{};
|
||||
perf_counter_t _cycle_perf;
|
||||
perf_counter_t _comms_errors;
|
||||
};
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
/****************************************************************************
|
||||
*
|
||||
* Copyright (c) 2024 PX4 Development Team. All rights reserved.
|
||||
* Copyright (c) 2025 PX4 Development Team. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
/****************************************************************************
|
||||
*
|
||||
* Copyright (c) 2024 PX4 Development Team. All rights reserved.
|
||||
* Copyright (c) 2025 PX4 Development Team. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
|
||||
@ -123,7 +123,7 @@ void LoggedTopics::add_default_topics()
|
||||
add_optional_topic("sensor_gyro_fft", 50);
|
||||
add_topic("sensor_selection");
|
||||
add_topic("sensors_status_imu", 200);
|
||||
add_optional_topic("sensor_temp", 10);
|
||||
add_optional_topic("sensor_temp", 100);
|
||||
add_optional_topic("spoilers_setpoint", 1000);
|
||||
add_topic("system_power", 500);
|
||||
add_optional_topic("takeoff_status", 1000);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user