<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en-gb">
<link rel="self" type="application/atom+xml" href="http://forum.robosavvy.com/feed.php?f=5&amp;t=5904" />

<title>RoboSavvy Forum</title>
<subtitle>Robosavvy Forum: The largest online community of Humanoid Robot Builders</subtitle>
<link href="http://forum.robosavvy.com/index.php" />
<updated>2010-03-03T18:47:10+01:00</updated>

<author><name><![CDATA[RoboSavvy Forum]]></name></author>
<id>http://forum.robosavvy.com/feed.php?f=5&amp;t=5904</id>
<entry>
<author><name><![CDATA[pirobot]]></name></author>
<updated>2010-03-03T18:47:10+01:00</updated>
<published>2010-03-03T18:47:10+01:00</published>
<id>http://forum.robosavvy.com/viewtopic.php?t=5904&amp;p=25698#p25698</id>
<link href="http://forum.robosavvy.com/viewtopic.php?t=5904&amp;p=25698#p25698"/>
<title type="html"><![CDATA[Random timeouts using AX-12s, CM-5 and Forest Moon library]]></title>

<content type="html" xml:base="http://forum.robosavvy.com/viewtopic.php?t=5904&amp;p=25698#p25698"><![CDATA[
Just an update on how I finally solved the timeout issue I was having.  Scott Ferguson, author of the Dynamixel library I am using (<!-- m --><a class="postlink" href="http://www.forestmoon.com/Software/AX12ArmSample/">http://www.forestmoon.com/Software/AX12ArmSample/</a><!-- m -->), kindly pointed out to me that there was no need to use the CM-5's RS-232 connection since I have a USB2Dynamixel device.  Controlling the Dynamixels over the TTL connection instead of RS-232 instantly resolved all my timeout problems.  Even better, I can now run at 1 Mb/s instead of 56k and I no longer have to insert delays between queries to the Dynamixels.  So the bottom line is: don't use a Serial-USB converted and then attach it to the CM-5's serial port.  Use the TTL connection instead.  (Although I still use the CM-5 as a power hub and bus distribution point.)<br /><br />--patrick<br /><br /><!-- m --><a class="postlink" href="http://www.pirobot.org">http://www.pirobot.org</a><!-- m --><p>Statistics: Posted by <a href="http://forum.robosavvy.com/memberlist.php?mode=viewprofile&amp;u=1984">pirobot</a> — Wed Mar 03, 2010 6:47 pm</p><hr />
]]></content>
</entry>
<entry>
<author><name><![CDATA[pirobot]]></name></author>
<updated>2010-02-25T17:27:57+01:00</updated>
<published>2010-02-25T17:27:57+01:00</published>
<id>http://forum.robosavvy.com/viewtopic.php?t=5904&amp;p=25644#p25644</id>
<link href="http://forum.robosavvy.com/viewtopic.php?t=5904&amp;p=25644#p25644"/>
<title type="html"><![CDATA[Random timeouts using AX-12s, CM-5 and Forest Moon library]]></title>

<content type="html" xml:base="http://forum.robosavvy.com/viewtopic.php?t=5904&amp;p=25644#p25644"><![CDATA[
Thanks i-Bot!  This is exactly the tip I needed.  I modified the ReadData method as shown below and it works like a charm.  I can even unplug a cable, see the&quot;Time Out&quot; message, then plug the cable back in and the robot continues where it left off.<br /><br />Thanks again!<br />patrick<br /><br /><!-- m --><a class="postlink" href="http://www.pirobot.org">http://www.pirobot.org</a><!-- m --><br /><br /><dl class="codebox"><dt>Code: </dt><dd><code>protected byte&#91;&#93; ReadData&#40;int id, Register startAddress, int count&#41;<br />&#123;<br />   List&lt;byte&gt; cmd = new List&lt;byte&gt;&#40;&#41;;<br />   byte&#91;&#93; returnPacket = null;<br />   bool retry = true;<br /><br />   // the start address and count form the parameters for the command<br />   // packet<br />   cmd.Add&#40;&#40;byte&#41;startAddress&#41;;<br />   cmd.Add&#40;&#40;byte&#41;count&#41;;<br />   while &#40;retry&#41;<br />   &#123;<br />       WriteInstruction&#40;id, Instruction.ReadData, cmd&#41;;<br />       try<br />      &#123;<br />         returnPacket = ReadPacket&#40;id, count&#41;;<br />         retry = false;<br />      &#125;<br />      catch &#40;System.TimeoutException&#41;<br />      &#123;<br />          Console.WriteLine&#40;&quot;TIME OUT accessing ID: &quot; + id&#41;;<br />          Stream.Flush&#40;&#41;;<br />      &#125;<br />   &#125;<br />   return returnPacket;<br />&#125;</code></dd></dl><p>Statistics: Posted by <a href="http://forum.robosavvy.com/memberlist.php?mode=viewprofile&amp;u=1984">pirobot</a> — Thu Feb 25, 2010 5:27 pm</p><hr />
]]></content>
</entry>
<entry>
<author><name><![CDATA[i-Bot]]></name></author>
<updated>2010-02-25T12:10:37+01:00</updated>
<published>2010-02-25T12:10:37+01:00</published>
<id>http://forum.robosavvy.com/viewtopic.php?t=5904&amp;p=25640#p25640</id>
<link href="http://forum.robosavvy.com/viewtopic.php?t=5904&amp;p=25640#p25640"/>
<title type="html"><![CDATA[Random timeouts using AX-12s, CM-5 and Forest Moon library]]></title>

<content type="html" xml:base="http://forum.robosavvy.com/viewtopic.php?t=5904&amp;p=25640#p25640"><![CDATA[
If you timeout after around 100ms, simply resend the command and try again. You may need to purge the receive buffer.<p>Statistics: Posted by <a href="http://forum.robosavvy.com/memberlist.php?mode=viewprofile&amp;u=159">i-Bot</a> — Thu Feb 25, 2010 12:10 pm</p><hr />
]]></content>
</entry>
<entry>
<author><name><![CDATA[pirobot]]></name></author>
<updated>2010-02-25T01:20:15+01:00</updated>
<published>2010-02-25T01:20:15+01:00</published>
<id>http://forum.robosavvy.com/viewtopic.php?t=5904&amp;p=25631#p25631</id>
<link href="http://forum.robosavvy.com/viewtopic.php?t=5904&amp;p=25631#p25631"/>
<title type="html"><![CDATA[Random timeouts using AX-12s, CM-5 and Forest Moon library]]></title>

<content type="html" xml:base="http://forum.robosavvy.com/viewtopic.php?t=5904&amp;p=25631#p25631"><![CDATA[
Hello,<br /><br />I have read a few other posts on this forum regarding how to deal with communication errors when using AX-12s and the CM-5 over a serial connection.  I'm having a similar problem with timeouts that I have tried to debug for several weeks with no luck.<br /><br />I have a robot with 10 AX-12+ servos connected to a CM-5 which in turn is connected to my PC by way of a USB-Serial converter.  The CM-5 and servos are powered by the 12V brick that came with the Bioloid kit.  I am controlling the servos using a C# program that references the Forest Moon Dynamixel library found at:<br /><br /><!-- m --><a class="postlink" href="http://www.forestmoon.com/Software/AX12ArmSample/">http://www.forestmoon.com/Software/AX12ArmSample/</a><!-- m --><br /><br />I am running the servos in Synchronized mode and I make a call to Synchronize() in a dedicated thread that looks like this:<br /><br /><dl class="codebox"><dt>Code: </dt><dd><code>while &#40;true&#41;<br />&#123;<br />   DynaNet.Synchronize&#40;&#41;;<br />   Thread.Sleep&#40;50&#41;;<br />   sensorValues&#91;HeadPan&#93; = HeadPan.CurrentPosition;<br />   Thread.Sleep&#40;50&#41;;<br />   sensorValues&#91;HeadTilt&#93; = HeadTilt.CurrentPosition;<br />   Thread.Sleep&#40;50&#41;;<br />   etc.<br />&#125;</code></dd></dl><br /><br />As you can see, after synchronizing any outstanding writes, I query two servos for their current position.  In fact, I query several other servos also for their positions but I left them out of the code above for brevity.<br /><br />In the meantime, in a different thread, I am setting the goal positions and speeds of the servos to track a moving target.  This thread updates the position and speed settings about once every 50ms.  But I am assuming they are only written to the servos when the Synchronize() method is called in the thread shown above.<br /><br />With both threads running, the robot generally behaves nice and smoothly and the servos work as expected.  However, at random intervals after starting--any where from 10 seconds to 10 minutes--I get a timeout exception and my control program grinds to a halt and the robot freezes.  I have tried eliminating hardware problems by swapping out cables, servos, the USB-Serial cable and even the CM-5 but with no effect.  I have the timeout on the serial port set to 1000 msec which I assume should be more than enough for 10 servos.<br /><br />Fortunately, the Forest Moon library comes with source code and I was able to isolate where the timeout is occurring.  It happens always on the same line within the ReadPacket method.  I include the code block below to illustrate:<br /><br /><dl class="codebox"><dt>Code: </dt><dd><code>protected byte&#91;&#93; ReadPacket&#40;out int id&#41;<br />      &#123;<br />         // ReadPacket is only ever called immediately following a WriteInstruction &#40;sent packet&#41;<br />         // So we can use this opportunity to time the response from the Dynamixel.<br /><br />         System.Diagnostics.Stopwatch watch = System.Diagnostics.Stopwatch.StartNew&#40;&#41;;<br /><br />         // set an invalid id for error return cases<br />         id = 0xFF;<br />         //<br />         // status packet returned from Dynamixel servo:<br />         // 0      1      2    3        4       5            5 + data-length<br />         // &#91;0xFF&#93; &#91;0xFF&#93; &#91;id&#93; &#91;length&#93; &#91;error&#93; &#91;...data...&#93; &#91;checksum&#93;<br />         //<br />         // 1st header byte<br />            int b = 0;<br /><br />            try<br />            &#123;<br />                b = Stream.ReadByte&#40;&#41;;<br />            &#125;<br />            catch &#40;System.TimeoutException&#41;<br />            &#123;<br />                Console.WriteLine&#40;&quot;TIMEOUT 1&quot;&#41;;<br />            &#125;<br /><br />         // Stop the Stopwatch and record the statistics for later<br />         watch.Stop&#40;&#41;;<br />         ResponseTotalElapsed += watch.ElapsedMilliseconds;<br />         ResponseCount++;<br />         if &#40;watch.ElapsedMilliseconds &gt; ResponseMaxElapsed&#41;<br />            ResponseMaxElapsed = watch.ElapsedMilliseconds;<br /><br />         if &#40;b != 0xFF&#41;<br />         &#123;<br />            ++ErrorCnt1stHeaderByte;<br />            return null;<br />         &#125;<br />         // 2nd header byte<br />            try<br />            &#123;<br />                b = Stream.ReadByte&#40;&#41;;<br />            &#125;<br />            catch &#40;System.TimeoutException&#41;<br />            &#123;<br />                Console.WriteLine&#40;&quot;TIMEOUT 2&quot;&#41;;<br />            &#125;<br /><br />         if &#40;b != 0xFF&#41;<br />         &#123;<br />            ++ErrorCnt2ndHeaderByte;<br />            return null;<br />         &#125;<br />         // id &#40;or 3rd header byte??&#41;<br />            try<br />            &#123;<br />                b = Stream.ReadByte&#40;&#41;;<br />            &#125;<br />            catch &#40;System.TimeoutException&#41;<br />            &#123;<br />                Console.WriteLine&#40;&quot;TIMEOUT 3&quot;&#41;;<br />            &#125;<br /><br />         if &#40;b == 0xFF&#41;      // have seen a third header byte! not sure why/how<br />         &#123;<br />            ++ErrorCnt3rdHeaderByte;<br />                try<br />                &#123;<br />                    b = Stream.ReadByte&#40;&#41;;<br />                &#125;<br />                catch &#40;System.TimeoutException&#41;<br />                &#123;<br />                    Console.WriteLine&#40;&quot;TIMEOUT 4&quot;&#41;;<br />                &#125;<br />         &#125;<br />         id = b;<br />         // packet length &#40;includes data-length plus 2&#41;<br />         int len = Stream.ReadByte&#40;&#41; - 2;<br />         if &#40;len &lt;0&gt; 0&#41;<br />         &#123;<br />            // read the data, if any<br />            data = new byte&#91;len&#93;;<br />            int offset = 0;<br />            while &#40;len &gt; 0&#41;<br />            &#123;<br />               int cnt = Stream.Read&#40;data, offset, len&#41;;<br />               len -= cnt;<br />               offset += cnt;<br />            &#125;<br />         &#125;<br />         // get the CheckSum byte<br />         // CONSIDER: Could validate the checksum and reject the packet.<br />         int CheckSum = Stream.ReadByte&#40;&#41;;<br />         // let anyone listening know about any errors reported in the packet<br />         // use the 'InErrorHandler' flag to avoid recursion from the user's handler<br />         if &#40;error != 0 &amp;&amp; DynamixelError != null &amp;&amp; !InErrorHandler&#41;<br />         &#123;<br />            InErrorHandler = true;<br />            DynamixelError&#40;this, new DynamixelErrorArgs&#40;id, error&#41;&#41;;<br />            InErrorHandler = false;<br />         &#125;<br />         return data;<br />      &#125;</code></dd></dl><br /><br />The try-catch blocks were added by me to find out where the timeout is occurring and it always occurs at the point where I print out the message &quot;TIMEOUT 1&quot;.<br /><br />Ideally I would like to eliminate the timeouts altogether but I'd also settle for being able to recover gracefully from a timeout when it is caught.  Unfortunately, I don't know what I would add to the try-catch block to recover control.<br /><br />If anyone has any suggestions, I would be most grateful!<br /><br />Many thanks,<br />patrick<br /><br /><!-- m --><a class="postlink" href="http://www.pirobot.org">http://www.pirobot.org</a><!-- m --><p>Statistics: Posted by <a href="http://forum.robosavvy.com/memberlist.php?mode=viewprofile&amp;u=1984">pirobot</a> — Thu Feb 25, 2010 1:20 am</p><hr />
]]></content>
</entry>
</feed>