<?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=17&amp;t=6695" />

<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-11-09T08:36:20+01:00</updated>

<author><name><![CDATA[RoboSavvy Forum]]></name></author>
<id>http://forum.robosavvy.com/feed.php?f=17&amp;t=6695</id>
<entry>
<author><name><![CDATA[veltrop]]></name></author>
<updated>2010-11-09T08:36:20+01:00</updated>
<published>2010-11-09T08:36:20+01:00</published>
<id>http://forum.robosavvy.com/viewtopic.php?t=6695&amp;p=28674#p28674</id>
<link href="http://forum.robosavvy.com/viewtopic.php?t=6695&amp;p=28674#p28674"/>
<title type="html"><![CDATA[How to move a Kondo serial servo on COM4]]></title>

<content type="html" xml:base="http://forum.robosavvy.com/viewtopic.php?t=6695&amp;p=28674#p28674"><![CDATA[
Here's some sample code for Kondo serial servos on COM4.  Just a simple ICS command.  The serial port code should be a useful copy and paste for someone out there  <img src="http://forum.robosavvy.com/images/smilies/icon_wink.gif" alt=":wink:" title="Wink" /> <br /><br />The servo will move back and forth a few times before the program exists.<br /><br /><dl class="codebox"><dt>Code: </dt><dd><code>#include &lt;stdio&gt;<br />#include &lt;string&gt;<br />#include &lt;fcntl&gt;<br />#include &lt;errno&gt;<br />#include &lt;termios&gt;<br />#include &lt;unistd&gt;<br /><br />int main&#40;&#41;<br />&#123;<br />  int com4 = open&#40;&quot;/dev/ttyS3&quot;, O_RDWR | O_NOCTTY | O_NDELAY&#41;;<br />  <br />  if &#40;com4 == -1 &#41;<br />    perror&#40;&quot;Unable to open port&quot;&#41;;<br />  else<br />    fcntl&#40;com4, F_SETFL,0&#41;;<br />  <br />  struct termios tio;<br />  tcgetattr&#40;com4,&amp;tio&#41;;<br />  // set 115200 baud, 8 data bits, 1 stop bit, even parity<br />  tio.c_cflag = B115200 | CS8 | CSTOPB | PARENB;<br />  tcflush&#40;com4, TCIFLUSH&#41;;<br />  tcsetattr&#40;com4,TCSANOW,&amp;tio&#41;;<br />  <br />  char cmd = 0x80;      // 0x80 is the ics position command<br />  char id = 0;          // servo id<br />  short int pos = 8193; // servo position &#40;1 ~ 16386&#41;<br />  char out&#91;3&#93;;<br />  <br />  int increase = 1;<br />  int count=0;<br />  while &#40;count LESSTHAN 10&#41;<br />  &#123;<br />    out&#91;0&#93; = &#40;cmd | &#40;id &amp; 0x1F&#41;&#41;;          // command<br />    out&#91;1&#93; = &#40;char&#41;&#40;&#40;pos GREATERTHANGREATERTHAN 7&#41; &amp; 0x007F&#41;;  // position high bit<br />    out&#91;2&#93; = &#40;char&#41;&#40;pos &amp; 0x007F&#41;;         // position low bit<br />    int wb = write&#40;com4, out, 3&#41;;<br />    <br />    increase ? pos++ : pos--;<br />    if &#40;pos GREATERTHAN 12000 || pos LESSTHAN 4000&#41;<br />    &#123;<br />      increase = !increase;<br />      count++;<br />    &#125;<br />  &#125;<br />  <br />  close&#40;com4&#41;;<br />  <br />  return 0;<br />&#125;<br /><br /></code></dd></dl><br /><br />Edit: The greater than/less than symbol bug of the forum got me on this post.  So you'll need to replace those characters in the code above.<br />I tried to upload the .c file instead... and the forum file manager tells me that .c is a forbidden extension.  c'mon...<p>Statistics: Posted by <a href="http://forum.robosavvy.com/memberlist.php?mode=viewprofile&amp;u=1573">veltrop</a> — Tue Nov 09, 2010 8:36 am</p><hr />
]]></content>
</entry>
</feed>