-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
circle buffer rough fix #785
Changes from all commits
ba748cc
9e964a4
fd4f309
54d4f0d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -70,6 +70,7 @@ class MMR920 { | |
echoing = should_echo; | ||
if (should_echo) { | ||
sensor_buffer_index = 0; // reset buffer index | ||
pressure_transations = 0; | ||
} | ||
} | ||
|
||
|
@@ -290,25 +291,48 @@ class MMR920 { | |
} | ||
|
||
void send_accumulated_sensor_data(uint32_t message_index) { | ||
for (int i = 0; i < static_cast<int>(SENSOR_BUFFER_SIZE); i++) { | ||
// send over buffer and then clear buffer values | ||
// NOLINTNEXTLINE(div-by-zero) | ||
int current_index = (i + sensor_buffer_index) % | ||
static_cast<int>(SENSOR_BUFFER_SIZE); | ||
if (pressure_transations >= 500) { | ||
for (int i = 0; i < static_cast<int>(SENSOR_BUFFER_SIZE); i++) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: things used as indices should be |
||
// send over buffer and then clear buffer values | ||
// NOLINTNEXTLINE(div-by-zero) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is this warning because |
||
int current_index = (i + sensor_buffer_index) % | ||
static_cast<int>(SENSOR_BUFFER_SIZE); | ||
|
||
can_client.send_can_message( | ||
can::ids::NodeId::host, | ||
can::messages::ReadFromSensorResponse{ | ||
.message_index = message_index, | ||
.sensor = can::ids::SensorType::pressure, | ||
.sensor_id = sensor_id, | ||
.sensor_data = mmr920::reading_to_fixed_point( | ||
(*sensor_buffer).at(current_index))}); | ||
if (i % 10 == 0) { | ||
// slow it down so the can buffer doesn't choke | ||
vtask_hardware_delay(50); | ||
can_client.send_can_message( | ||
can::ids::NodeId::host, | ||
can::messages::ReadFromSensorResponse{ | ||
.message_index = message_index, | ||
.sensor = can::ids::SensorType::pressure, | ||
.sensor_id = sensor_id, | ||
.sensor_data = mmr920::reading_to_fixed_point( | ||
(*sensor_buffer).at(current_index))}); | ||
if (i % 10 == 0) { | ||
// slow it down so the can buffer doesn't choke | ||
vtask_hardware_delay(50); | ||
} | ||
(*sensor_buffer).at(current_index) = 0; | ||
} | ||
} | ||
// I think counting the transactions here might | ||
// be preferable to having to ignore a bunch | ||
// of 0's at the end in Python, because we might end up accidentally | ||
// ignoring valid data that way | ||
else { | ||
for (int i = 0; i < pressure_transations; i++) { | ||
can_client.send_can_message( | ||
can::ids::NodeId::host, | ||
can::messages::ReadFromSensorResponse{ | ||
.message_index = message_index, | ||
.sensor = can::ids::SensorType::pressure, | ||
.sensor_id = sensor_id, | ||
.sensor_data = mmr920::reading_to_fixed_point( | ||
(*sensor_buffer).at(i))}); | ||
if (i % 10 == 0) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. let's add a todo here or something - |
||
// slow it down so the can buffer doesn't choke | ||
vtask_hardware_delay(50); | ||
} | ||
} | ||
(*sensor_buffer).at(current_index) = 0; | ||
(*sensor_buffer).at(i) = 0; | ||
} | ||
} | ||
|
||
|
@@ -371,6 +395,8 @@ class MMR920 { | |
if (echo_this_time) { | ||
auto response_pressure = pressure - current_pressure_baseline_pa; | ||
// do we want pressure or response pressure | ||
if (pressure_transations < 500) { pressure_transactions++; } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 500 should be SENSOR_BUFFER_SIZE instead |
||
|
||
sensor_buffer_log(pressure); | ||
can_client.send_can_message( | ||
can::ids::NodeId::host, | ||
|
@@ -532,6 +558,7 @@ class MMR920 { | |
float pressure_running_total = 0; | ||
float temperature_running_total = 0; | ||
uint16_t total_baseline_reads = 1; | ||
uint16_t pressure_transactions = 0; | ||
|
||
float current_pressure_baseline_pa = 0; | ||
float current_temperature_baseline = 0; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
500 should be SENSOR_BUFFER_SIZE