<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://rsewiki.electro.dtu.dk/index.php?action=history&amp;feed=atom&amp;title=Smr_read</id>
	<title>Smr read - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://rsewiki.electro.dtu.dk/index.php?action=history&amp;feed=atom&amp;title=Smr_read"/>
	<link rel="alternate" type="text/html" href="https://rsewiki.electro.dtu.dk/index.php?title=Smr_read&amp;action=history"/>
	<updated>2026-04-28T08:46:24Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.41.1</generator>
	<entry>
		<id>https://rsewiki.electro.dtu.dk/index.php?title=Smr_read&amp;diff=227&amp;oldid=prev</id>
		<title>Lvm: New page:  int smr_read(struct smr *robot); Smr_read communcates with the smr daemon [smrd], updating fields in the [struct smr] pointed to by &#039;&#039;robot&#039;&#039; with values from the next sample period.   Sm...</title>
		<link rel="alternate" type="text/html" href="https://rsewiki.electro.dtu.dk/index.php?title=Smr_read&amp;diff=227&amp;oldid=prev"/>
		<updated>2008-09-29T12:23:56Z</updated>

		<summary type="html">&lt;p&gt;New page:  int smr_read(struct smr *robot); Smr_read communcates with the smr daemon [smrd], updating fields in the [struct smr] pointed to by &amp;#039;&amp;#039;robot&amp;#039;&amp;#039; with values from the next sample period.   Sm...&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt; int smr_read(struct smr *robot);&lt;br /&gt;
Smr_read communcates with the smr daemon [smrd], updating fields in the [struct smr] pointed to by &amp;#039;&amp;#039;robot&amp;#039;&amp;#039; with values&lt;br /&gt;
from the next sample period.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Smr_read uses some of the fields in &amp;#039;&amp;#039;*robot&amp;#039;&amp;#039; as input parameters, others for return values.&lt;br /&gt;
&lt;br /&gt;
Ordinarily, zero is returned. If case of error, for example if communication is not possible, a non-zero value is returned.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Input parameters&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
The following fields are read by smr_read:&lt;br /&gt;
   robot-&amp;gt;wait_flags:   An ORed combination of sensor flags, indicating which data smr_read should wait for.&lt;br /&gt;
   robot-&amp;gt;recv_hook:   A pointer to an asynchronous message receive function. If not NULL, smr_read calls this function for each message received from smrd. Such a function can be used to process messages which would otherwise be ignored.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Return values&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
The following fields can be written by smr_read:&lt;br /&gt;
   robot-&amp;gt;read_flags:   An ORed combination of sensor flags, indicating which data were received.&lt;br /&gt;
   robot-&amp;gt;left.encoder, robot-&amp;gt;right.encoder, robot-&amp;gt;left.pwm, robot-&amp;gt;right.pwm, robot-&amp;gt;left.status, robot-&amp;gt;right.status, robot-&amp;gt;ls, robot-&amp;gt;ir, robot-&amp;gt;ad, robot-&amp;gt;status:   Data read from server.&lt;br /&gt;
   robot-&amp;gt;ticks:   Sample number read from server.&lt;br /&gt;
   robot-&amp;gt;ts:   Time stamp read from server.&lt;br /&gt;
&lt;br /&gt;
The valid flags are:&lt;br /&gt;
   SMR_FLAG_LE:   Left encoder&lt;br /&gt;
   SMR_FLAG_RE:   Right encoder&lt;br /&gt;
   SMR_FLAG_IR:   Proximity sensors&lt;br /&gt;
   SMR_FLAG_LS:   Line sensor&lt;br /&gt;
   SMR_FLAG_LV:   Left speed&lt;br /&gt;
   SMR_FLAG_PW:   Power module data&lt;br /&gt;
   SMR_FLAG_LPS:   Left motor pwm and status&lt;br /&gt;
   SMR_FLAG_RPS:   Right motor pwm and status&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The operation of smr_read is as follows:&lt;br /&gt;
   1. Receive messages until &amp;#039;start of sample&amp;#039;.&lt;br /&gt;
   1. Copy timing fields from &amp;#039;start of sample&amp;#039; to &amp;#039;&amp;#039;*robot&amp;#039;&amp;#039;.&lt;br /&gt;
   1. Receive messages until &amp;#039;end of sample&amp;#039;, or until all data has been read as indicated in &amp;#039;&amp;#039;wait_flags&amp;#039;&amp;#039;. Copy sensor data to &amp;#039;&amp;#039;*robot&amp;#039;&amp;#039; and update &amp;#039;&amp;#039;robot-&amp;gt;read_flags&amp;#039;&amp;#039; for each message.&lt;br /&gt;
   1. Done.&lt;br /&gt;
&lt;br /&gt;
Not all data indicated in &amp;#039;&amp;#039;wait_flags&amp;#039;&amp;#039; is necessarily received: smr_read waits at most one sample.&lt;br /&gt;
Test &amp;#039;&amp;#039;read_flags&amp;#039;&amp;#039; to see which data was received: if a flag is not set in &amp;#039;&amp;#039;read_flags&amp;#039;&amp;#039; the corresponding data will be old.&lt;br /&gt;
&lt;br /&gt;
Data other than those indicated in &amp;#039;&amp;#039;wait_flags&amp;#039;&amp;#039; may be received: read_flags reflects whatever data was read.&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Reading asychronous messages&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
Smr_read calls the user specified function &amp;#039;&amp;#039;robot-&amp;gt;recv_hook&amp;#039;&amp;#039;, if specified, for each message received.&lt;br /&gt;
&lt;br /&gt;
Such a function should have the type:&lt;br /&gt;
 void recv_hook_function(struct smr *);&lt;/div&gt;</summary>
		<author><name>Lvm</name></author>
	</entry>
</feed>