Skip to content

Basic question regarding yarp::os::BufferedPort::read()! #683

Answered by pattacini
paliasgh asked this question in Q&A
Discussion options

You must be logged in to vote

Hi @paliasgh

Never mind, we're here to help.

In this case, i.e., when no new data has come, messageRsPos returns a null pointer. Is this expected?

Yep.

How can I make it read the last message regardless (repeat the last message if there is no new one)?

An easy solution consists in latching the value in a class data member for example.
Something like the following:

messageRsPos = rsPos.read(false);
if (messageRsPos != nullptr) {
  messageRsPosLatch = *messageRsPos; 
}

In your code, you'll be using messageRsPosLatch, which gets updated only when a new message is retrieved via polling. Just make sure to initialize messageRsPosLatch with a value that is sensible for your application.

This…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by paliasgh
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants