-
Notifications
You must be signed in to change notification settings - Fork 4
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
sync_read
and bulk_read
return vec of results
#20
base: main
Are you sure you want to change the base?
sync_read
and bulk_read
return vec of results
#20
Conversation
Hey! I've been thinking a bit about this type of multi-motor response functions. The current approach is not ideal: the simple function hides some error details from you, and the callback version takes away flexibility in how you write your code. But I also don't really like returning a We could do something slightly more complicated to implement, but hopefully a lot easier to use: return an object to represent the whole transaction, with functions to get the next response. We can also implement let mut response = client.sync_read(.....)?;
while let Some((motor_id, response)) = response.next() {
let response = response?;
// Do something with the response.
}
// Or with a for loop:
for (motor_id, response) in client.sync_read(...)? {
let response = response?;
// Do something with the response.
}
// Or collecting directly into a vector:
let responses: Vec<_> = client.sync_read(...)?.collect(); What do you think? I'm thinking we can remove the other functions then: no callback or Vec version, only this. Added advantage is that is maps better to async code (having an sync version is a future goal I want to tackle somehow, some time). |
Yea cool, not something I had thought about but returning the I've also been thinking about an async version and would love to spend some time developing it. I have been given some time over the next few months to contribute to oss projects :) Also I've implemented a fast sync/bulk read but haven't tested it yet. This is my favorite crate to contribute to btw. I've learnt so much over the past year and can't really thank you enough! |
I'm thinking the iterator will do the actual calls. It can finish reading any remaining responses in the This will not be so easy in a future async version (because we have no async drop), but that's a worry for then.
Right, I would recommend not to start on this without quite some discussion first. I want to find a way to not duplicate the whole codebase. But I think all solutions to that also have serious drawbracks. So it's best not to spend a lot of effort before we have a nice (or good enough) solution for this.
Sounds good! Always happy to get contributions. Just let me know when it's ready :)
That's great to hear :D I'm always happy when other people get involved with projects I maintain. It's nice to know people are actually using it. |
Understood!
So I have started implementing a method that does this but can't return the type EDIT: Nevermind I figure out a way, changing the From impl to use the data directly. impl<'a> From<StatusPacket<'a>> for Response<&'a [u8]> {
fn from(status_packet: StatusPacket<'a>) -> Self {
Self {
motor_id: status_packet.packet_id(),
alert: status_packet.alert(),
data: &status_packet.data[STATUS_HEADER_SIZE..],
}
}
} I also discovered we can't impl Something related to this that I have been thinking about: I wonder if you would be open to the idea of letting the user define the type at call time and have traits two traits for Reading and Writing that data type. The trait impl would have a const One major draw back is that users have to specify a type when calling ( |
…` into packet module
6edaa7d
to
81a8d5e
Compare
Hello, I've created a prototype for the SyncRead iterator and the I also moved the Somethings i'm not sure about:
Todo:
|
The current behavior only captures one Err per call and returns that error even if other Dynamixels respond to the sync/bulk read.
The implementation that I have been using returns the much more verbose Vec of Results, one result for each Dynamixel responding, allowing for proper handling of each unresponsive Dynamixel in the sync/bulk.
Clippy is warning about very complex return types. Depending on what you think I could add some types to make the response types easier to read.