-
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
feat(sensors): add a new can message to batch read sensor data #805
base: main
Are you sure you want to change the base?
Conversation
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.
logic looks good to me!
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.
Couple small readability and robustness changes and also definitely want some tests for the index math and logic
.data_length = j, | ||
.sensor_data = data, | ||
}; | ||
can_client.send_can_message(can::ids::NodeId::host, response); |
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.
We haven't faced it before as much, but I think we can improve this a lot by changing (or adding a new version of) send_can_message
that will either (a) block (by sleeping) or (b) return false
when the local buffer is full. That will let us dynamically slow down data output when the buffer is full while not adding a delay all the time.
// slow it down so the can buffer doesn't choke | ||
vtask_hardware_delay(20); | ||
uint8_t j = 0; | ||
while (j < 14 and i < count) { |
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.
We absolutely need some tests for the fiddly index math.
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.
also can use j < data.size()
or even take this to a range-for that stops early a la
for (auto& copy_to : data) {
if (i >= count) {
break;
}
copy_to = mmr920::reading_to_fixed_point(sensor_buffer->at(current_index));
i++;
current_index = (i + start) % static_cast<int>(SENSOR_BUFFER_SIZE);
}
for (int i = 0; i < count; i++) { | ||
std::array<uint32_t, 14> data{}; | ||
int i = 0; | ||
while (i < count) { |
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.
could make this for(size_t i = 0; i < count; ) { }
if we wanted. in general, seems like we could use a size here instead of a signed value.
@@ -315,24 +315,32 @@ class MMR920 { | |||
can_client.send_can_message( | |||
can::ids::NodeId::host, | |||
can::messages::Acknowledgment{.message_index = count}); | |||
for (int i = 0; i < count; i++) { | |||
std::array<uint32_t, 14> data{}; |
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.
would love to see this 14 derived from somewhere
Marking as draft since Caila didn't get a chance to use this before her trip. I'll clean it up and make it better styled |
In a first step to streamline tool_sensors.py we want to batch read sensor data, this will speed up the process and let us stream alot better