<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Robottini</title>
	<atom:link href="http://robottini.altervista.org/feed" rel="self" type="application/rss+xml" />
	<link>http://robottini.altervista.org</link>
	<description>Little robots with Arduino</description>
	<lastBuildDate>Sat, 18 May 2013 11:27:36 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.5.1</generator>
		<item>
		<title>Dadaist poetry box</title>
		<link>http://robottini.altervista.org/dadaist-poetry-box</link>
		<comments>http://robottini.altervista.org/dadaist-poetry-box#comments</comments>
		<pubDate>Sat, 18 May 2013 11:26:21 +0000</pubDate>
		<dc:creator>robottini</dc:creator>
				<category><![CDATA[Senza categoria]]></category>

		<guid isPermaLink="false">http://robottini.altervista.org/?p=804</guid>
		<description><![CDATA[My second experiment (first is here ) to make Art o something similar with Arduino, is the Dadaist Poetry Box. &#160; &#160; It&#8217;s made ​​with an Arduino  using a printer for receipts to write poem.  The box composes the poems in autonomy, thanks to an algorithm that has been implemented on the Arduino. Push the [...]]]></description>
				<content:encoded><![CDATA[<p>My second experiment (first is <a href="http://robottini.altervista.org/polar-robot-arm-sketching-skyline">here</a> ) to make Art o something similar with Arduino, is the Dadaist Poetry Box.</p>
<p>&nbsp;</p>
<p><a href="http://robottini.altervista.org/wp-content/uploads/2013/05/macchina-poesie.png"><img class="aligncenter size-full wp-image-801" alt="macchina poesie" src="http://robottini.altervista.org/wp-content/uploads/2013/05/macchina-poesie.png" width="600" height="400" /></a></p>
<p>&nbsp;</p>
<p>It&#8217;s made ​​with an Arduino  using a printer for receipts to write poem.  The box composes the poems in autonomy, thanks to an algorithm that has been implemented on the Arduino. Push the button and here your dadaist poem. Each poem is different from the previous. It is original, new. Just press a button, and comes out a poem. Simple, immediate, trivial.</p>
<p>Normally, the poem is a valuable asset, is the result of an intimate moment, when the poet transposes on paper the emotions of his soul. It &#8216;an act inspired, an act of concentration and transport. It&#8217;s not immediate. The poem box instead is trivial, it seems almost anti-poem. But not, it&#8217;s Dadaist poem.  In one of his writings, the famous poet Tristan Tzara, one of the major poets Dadaists, describes how to produce a Dadaist poem.  The pass following explains their way to proceed:</p>
<ul>
<li>Take a newspaper.</li>
<li>Take some scissors.</li>
<li>Choose from this paper an article the length you want to make your poem.</li>
<li>Cut out the article.</li>
<li>Next carefully cut out each of the words that make up this article and put them all in a bag.</li>
<li>Shake gently.</li>
<li>Next take out each cutting one after the other.</li>
<li>Copy conscientiously in the order in which they left the bag.</li>
<li>The poem will resemble you.</li>
<li>And there you are—an infinitely original author of charming sensibility, even though unappreciated by the vulgar herd.</li>
</ul>
<p>&nbsp;</p>
<p>The Dadaist poetry box is based on Arduino Uno. These are the components:</p>
<p>- Arduino Uno</p>
<p>- Sparkfun thermal printer</p>
<p>- A big button</p>
<p>&nbsp;</p>
<p>The program is based on pre-defined verses, that Arduino choices with an random alghoritm. The thermal printer is drove by the Arduino, using the SoftwareSerial library. The verses are stored in the program memory of Arduino (almost 7 kb).</p>
<p>The verses are in italian, so if you want the English language, you have to rewrite all the verses!</p>
<p>Some pictures:</p>
<p style="text-align: center;"><a href="http://robottini.altervista.org/wp-content/uploads/2013/05/DSCF1285.jpg"><img class="aligncenter  wp-image-799" alt="DSCF1285" src="http://robottini.altervista.org/wp-content/uploads/2013/05/DSCF1285.jpg" width="800" height="640" /></a></p>
<p style="text-align: center;"><a href="http://robottini.altervista.org/wp-content/uploads/2013/05/DSCF1248.jpg"><img class="aligncenter  wp-image-798" alt="DSCF1248" src="http://robottini.altervista.org/wp-content/uploads/2013/05/DSCF1248.jpg" width="800" height="640" /></a></p>
<p style="text-align: center;"><a href="http://robottini.altervista.org/wp-content/uploads/2013/05/DSCF1066.jpg"><img class="aligncenter  wp-image-802" alt="DSCF1066" src="http://robottini.altervista.org/wp-content/uploads/2013/05/DSCF1066.jpg" width="800" height="640" /></a></p>
<p style="text-align: center;"><a href="http://robottini.altervista.org/wp-content/uploads/2013/05/DSCF10661.jpg"><img class="aligncenter  wp-image-803" alt="DSCF1066" src="http://robottini.altervista.org/wp-content/uploads/2013/05/DSCF10661.jpg" width="800" height="640" /></a></p>
<p style="text-align: center;"><a href="http://robottini.altervista.org/wp-content/uploads/2013/05/DSCF1068.jpg"><img class="aligncenter  wp-image-805" alt="DSCF1068" src="http://robottini.altervista.org/wp-content/uploads/2013/05/DSCF1068-640x480.jpg" width="800" height="640" /></a></p>
<p>&nbsp;</p>
<p>This is a little video of the box:</p>
<p>&nbsp;</p>
<p align="center">
<p><a href="http://www.youtube.com/watch?v=GzF8SV2IIYI">http://www.youtube.com/watch?v=GzF8SV2IIYI</a></p>
</p>
<p style="text-align: left;" align="center">
<p style="text-align: left;" align="center">This is the source code: <a href="http://robottini.altervista.org/wp-content/uploads/2013/05/Generatore_di_poesie_V4.zip">Generatore_di_poesie_V4</a></p>
<p style="text-align: left;" align="center">
]]></content:encoded>
			<wfw:commentRss>http://robottini.altervista.org/dadaist-poetry-box/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Polar robot arm &#8211; sketching a city skyline</title>
		<link>http://robottini.altervista.org/polar-robot-arm-sketching-skyline</link>
		<comments>http://robottini.altervista.org/polar-robot-arm-sketching-skyline#comments</comments>
		<pubDate>Sat, 18 May 2013 10:44:25 +0000</pubDate>
		<dc:creator>robottini</dc:creator>
				<category><![CDATA[Senza categoria]]></category>

		<guid isPermaLink="false">http://robottini.altervista.org/?p=783</guid>
		<description><![CDATA[&#160; I&#8217;m often thinking if it is possible to make Art with Arduino. Arduino is a machine, a little computer made with electronic circuits. It hasn&#8217;t a soul. Can an Arduino make Art? This is my question. I&#8217;m trying to do something with Arduino that could be Art, or similar to Art. The Arts are [...]]]></description>
				<content:encoded><![CDATA[<p style="text-align: center;"><a href="http://robottini.altervista.org/wp-content/uploads/2013/05/schizzo-citta.png"><img alt="schizzo citta" src="http://robottini.altervista.org/wp-content/uploads/2013/05/schizzo-citta.png" width="600" height="403" /></a></p>
<p>&nbsp;</p>
<p>I&#8217;m often thinking if it is possible to make Art with Arduino. Arduino is a machine, a little computer made with electronic circuits. It hasn&#8217;t a soul. Can an Arduino make Art? This is my question.</p>
<p>I&#8217;m trying to do something with Arduino that could be Art, or similar to Art. The Arts are painting, poetry, music, sculpture and so on. I&#8217;m trying to do something in different Arts. The road is long but I began to travel it. This is my first experiment with painting. Indeed, a easy form of painting, the sketching in Black and White. Arduino drives a robot arm, that with only a pen sketches a city skyline. The skyline is every time different, the buildings are always different. The arm tries to imitate the human sketching, with errors, shaking  lines not parallel and so on. The arm tries to be human, to make a little form of Art. This is the goal, I don&#8217;t know if the goal is reached. The judgment is yours.</p>
<p>The robotic arms are among the most fascinating robot that you can build. There are many commercial robotic arms with 4-5-6 axes, while, at amateur level, there are no polar arms.</p>
<p>The arms using polar, instead of Cartesian coordinates (x and y),  the polar coordinates (angle and radius).</p>
<p align="center"><a href="http://robottini.altervista.org/wp-content/uploads/2013/05/Polar-coord.png"><img class="aligncenter size-full wp-image-784" alt="Polar coord" src="http://robottini.altervista.org/wp-content/uploads/2013/05/Polar-coord.png" width="407" height="310" /></a></p>
<p align="center"><a href="http://robottini.altervista.org/wp-content/uploads/2013/05/schizzo-citta.png"> </a></p>
<p>So, the point P(x,y) in polar coordinates became P(r,phi). This means a line, which in polar coordinates is described by a very simple equation, in polar coordinates becomes a complex and more difficult, because the radius can increase and decrease while describing the line.</p>
<p>So, which is the advantage using the polar coordinates? The advantage is the robot is very simple to build. I used also an awesome aluminum infrastructure based on Makerbeam (www.makerbeam.eu) , that allows to build the robot similar to the Lego, with the advantage that all is in metal and not in plastic.  Makerbeam is an open-sourced extruded beam construction kit. I got a kit, and this is my first project using it.</p>
<p align="center"> <a href="http://robottini.altervista.org/wp-content/uploads/2013/05/MakerBeam.png"><img class="aligncenter size-full wp-image-785" alt="MakerBeam" src="http://robottini.altervista.org/wp-content/uploads/2013/05/MakerBeam.png" width="317" height="238" /></a></p>
<p>&nbsp;</p>
<p>The hardware is:</p>
<p>- 1 arduino (2009/uno or Mega)</p>
<p>- a kit of makerbeam for the chassis and 16 ball bearings (www.makerbeam.eu)</p>
<p>- 2 stepper nema 17 400 steps, 0.9° (www.robot-italy.com)</p>
<p>- 2 big easy stepper driver (www.robot-italy.com)</p>
<p>- 2 pignons and 1 gear rack (www.conrad.com)</p>
<p>- 1 little servo motor (www.robot-italy.com)</p>
<p>- 1 pen</p>
<p>&nbsp;</p>
<p>This is the robot:</p>
<p>&nbsp;</p>
<p style="text-align: center;"><a href="http://robottini.altervista.org/wp-content/uploads/2013/05/Polare-1.jpg"><img class="aligncenter  wp-image-775" alt="Polare 1" src="http://robottini.altervista.org/wp-content/uploads/2013/05/Polare-1.jpg" width="800" height="640" /></a></p>
<p style="text-align: center;"><a href="http://robottini.altervista.org/wp-content/uploads/2013/05/Polare-7.jpg"><img class="aligncenter  wp-image-781" alt="Polare 7" src="http://robottini.altervista.org/wp-content/uploads/2013/05/Polare-7.jpg" width="800" height="640" /></a></p>
<p style="text-align: center;"><a href="http://robottini.altervista.org/wp-content/uploads/2013/05/Polare-6.jpg"><img class="aligncenter  wp-image-780" alt="Polare 6" src="http://robottini.altervista.org/wp-content/uploads/2013/05/Polare-6.jpg" width="800" height="640" /></a></p>
<p style="text-align: center;"><a href="http://robottini.altervista.org/wp-content/uploads/2013/05/Polare-5.jpg"><img class="aligncenter  wp-image-779" alt="Polare 5" src="http://robottini.altervista.org/wp-content/uploads/2013/05/Polare-5.jpg" width="800" height="640" /></a></p>
<p style="text-align: center;"><a href="http://robottini.altervista.org/wp-content/uploads/2013/05/Polare-4.jpg"><img class="aligncenter  wp-image-778" alt="Polare 4" src="http://robottini.altervista.org/wp-content/uploads/2013/05/Polare-4.jpg" width="800" height="640" /></a></p>
<p style="text-align: center;"><a href="http://robottini.altervista.org/wp-content/uploads/2013/05/Polare-3.jpg"><img class="aligncenter  wp-image-777" alt="Polare 3" src="http://robottini.altervista.org/wp-content/uploads/2013/05/Polare-3.jpg" width="800" height="640" /></a></p>
<p style="text-align: center;"><a href="http://robottini.altervista.org/wp-content/uploads/2013/05/Polare-2.jpg"><img class="aligncenter  wp-image-776" alt="Polare 2" src="http://robottini.altervista.org/wp-content/uploads/2013/05/Polare-2.jpg" width="800" height="640" /></a></p>
<p style="text-align: center;"><a href="http://robottini.altervista.org/wp-content/uploads/2013/05/città.jpg"><img class="aligncenter  wp-image-786" alt="città" src="http://robottini.altervista.org/wp-content/uploads/2013/05/città.jpg" width="800" height="640" /></a></p>
<p><span style="font-size: 13px; line-height: 19px;">The robot has 2 dof: radius and angle. The forward and inverse kinematics are simple.</span></p>
<p>The only two shapes that are possible to draw when running one motor at a time is a radial line or a circle segment. The Arduino program implements sort of the Bresenham&#8217;s line drawing algorithm to draw segments. Each segment is  divided into small segments (steps). Then, for each step we translate this movement to its corresponding changes in the polar coordinate system, angle and radius. This is finally translated to the number of steps to run each motor.</p>
<p>The robot can have a good precision: the balance is between good speed and good precision. If the robot has a low speed it can be very very precise. When the speed grow the precision goes down. But in this work the precision is not very important. The goal is to imitate a human sketch, and the human when are sketching are not precise.</p>
<p>For the sketch algorithm I&#8217;m inspired by this processing sketch: <a href="http://www.openprocessing.org/sketch/12095">http://www.openprocessing.org/sketch/12095</a> semplified for Arduino. The robot can work alone, without a computer, all the logic is inside the Arduino.</p>
<p>The main inspiration for the polar arm robot building and for the motor driving software comes from this awesome robot: <a href="http://roxen.github.io/polar-plotter/">http://roxen.github.io/polar-plotter/</a></p>
<p>&nbsp;</p>
<p>You can see the robot in action here:</p>
<p style="text-align: center;">
<p><a href="http://www.youtube.com/watch?v=gHZ8i3iptas">http://www.youtube.com/watch?v=gHZ8i3iptas</a></p>
<p><a href="http://www.youtube.com/watch?v=gHZ8i3iptas"><br />
</a></p>
<p>&nbsp;</p>
<p>The code used for the robot is available here: <a href="http://robottini.altervista.org/wp-content/uploads/2013/05/citta_disegna.zip">citta_disegna</a></p>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://robottini.altervista.org/polar-robot-arm-sketching-skyline/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Dongbu Herkulex Arduino Library</title>
		<link>http://robottini.altervista.org/dongbu-herkulex-arduino-library-2</link>
		<comments>http://robottini.altervista.org/dongbu-herkulex-arduino-library-2#comments</comments>
		<pubDate>Sat, 15 Dec 2012 06:01:24 +0000</pubDate>
		<dc:creator>robottini</dc:creator>
				<category><![CDATA[Dongbu Herkulex]]></category>
		<category><![CDATA[Dynamixel]]></category>
		<category><![CDATA[Robottini]]></category>
		<category><![CDATA[Arduino]]></category>
		<category><![CDATA[Dongbu]]></category>
		<category><![CDATA[Herkulex]]></category>

		<guid isPermaLink="false">http://robottini.altervista.org/?p=730</guid>
		<description><![CDATA[I bought some time ago a couple of motors from Dongbu: the Herkulex DRS-0101. These motors are &#8216;smart&#8217; because they have inside a microprocessor that allow to manage many parameters and the behavior of the motors. &#160; &#160; &#160; The Herkulex are an alternative to more famous motors like the Dynamixel. They have 4 wires [...]]]></description>
				<content:encoded><![CDATA[<p>I bought some time ago a couple of motors from Dongbu: the Herkulex DRS-0101. These motors are &#8216;smart&#8217; because they have inside a microprocessor that allow to manage many parameters and the behavior of the motors.</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p><a href="http://robottini.altervista.org/dongbu-herkulex-arduino-library-2/herculex-drs-0101_specs" rel="attachment wp-att-746"><img class="aligncenter size-full wp-image-746" title="HerculeX-DRS-0101_specs" src="http://robottini.altervista.org/wp-content/uploads/2012/12/HerculeX-DRS-0101_specs.jpg" alt="" width="600" height="234" /></a></p>
<p>&nbsp;</p>
<p>The Herkulex are an alternative to more famous motors like the Dynamixel. They have 4 wires and can be drove by a simple microprocessor with a UART (serial) port. My choice is to control them with an Arduino, so I wrote a simple library supporting all the most common Herkulex functionalities.</p>
<p>For the wiring of Herkulex to Arduino, it is important to consider that it is necessary to dedicate a serial port to the communication Arduino-Herkulex.It is not possible (or is not advisable) to use the standard  Arduino port because it is dedicated to communication between PC and Arduino to see the values in the serial monitor. So it is important to use another serial port.</p>
<p>&nbsp;</p>
<p><a href="http://robottini.altervista.org/dongbu-herkulex-arduino-library-2/pinout" rel="attachment wp-att-747"><img class="aligncenter size-full wp-image-747" title="pinout" src="http://robottini.altervista.org/wp-content/uploads/2012/12/pinout.png" alt="" width="202" height="400" /></a></p>
<p>&nbsp;</p>
<p>For the Arduino Mega it is easy, because the Mega has 4 serial ports, for the Arduino Uno/2009 that has only one serial port, it is mandatory to use a software serial port. So a library called <em>SoftwareSerial</em> has to be included if we want to use the Arduino Uno/2009.</p>
<p>To do this the last version of SoftwareSerial is not useful, so I included in the library also the right SoftwareSerial version in order to work well with Arduino Uno/2009.</p>
<p>For general knowledge about the Herkulex Dongbu motors, please see the manual: <a href="http://www.hovis.co.kr/guide/herkulexeng.pdf">here</a></p>
<h2></h2>
<h2>Download the library: <a href="http://robottini.altervista.org/wp-content/uploads/2012/12/Herkulex.zip" rel="attachment wp-att-753">Herkulex Library for Arduino</a></h2>
<p>&nbsp;</p>
<p>These are the commands supported by the library:</p>
<table border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td valign="top" width="291"><strong>begin(long baud, int rx, int tx)</strong></td>
<td valign="top" width="361">start the communication between Arduino Uno/2009 and Herkulex</td>
</tr>
<tr>
<td valign="top" width="291"><strong>beginSerial1(long baud)</strong></td>
<td valign="top" width="361">start the communication between Arduino Mega and Herkulex using the Serial Port 1</td>
</tr>
<tr>
<td valign="top" width="291"><strong>beginSerial2(long baud)</strong></td>
<td valign="top" width="361">start the communication between Arduino Mega and Herkulex using the Serial Port 2</td>
</tr>
<tr>
<td valign="top" width="291"><strong>beginSerial3(long baud)</strong></td>
<td valign="top" width="361">start the communication between Arduino Mega and Herkulex using the Serial Port 3</td>
</tr>
<tr>
<td valign="top" width="291"><strong>end()</strong></td>
<td valign="top" width="361">stop the communication between Arduino and Herkulex</td>
</tr>
<tr>
<td valign="top" width="291"><strong>initialize()</strong></td>
<td valign="top" width="361">initialize all the motors</td>
</tr>
<tr>
<td valign="top" width="291"><strong>stat(int servoID)</strong></td>
<td valign="top" width="361">ask for the motor status to control the errors</td>
</tr>
<tr>
<td valign="top" width="291"><strong>ACK(int valueACK)</strong></td>
<td valign="top" width="361">set the answer of the motors to a request (verbose or not verbose)</td>
</tr>
<tr>
<td valign="top" width="291"><strong>set_ID(int ID_Old, int ID_New)</strong></td>
<td valign="top" width="361">change the ID of the motor</td>
</tr>
<tr>
<td valign="top" width="291"><strong>clearError(int servoID)</strong></td>
<td valign="top" width="361">clear the motor error</td>
</tr>
<tr>
<td valign="top" width="291"><strong>torqueON(int servoID)</strong></td>
<td valign="top" width="361">set the motor torque to ON</td>
</tr>
<tr>
<td valign="top" width="291"><strong>torqueOFF(int servoID)</strong></td>
<td valign="top" width="361">set the motor torque to OFF</td>
</tr>
<tr>
<td valign="top" width="291"><strong>moveAll(int servoID, int Goal, int iLed)</strong></td>
<td valign="top" width="361">prepare the motors to execute the movement in the same time to position (same start time &#8211; end time) – unison movement</td>
</tr>
<tr>
<td valign="top" width="291"><strong>moveAllAngle(int servoID, float angle, int iLed)</strong></td>
<td valign="top" width="361">prepare the motors to execute the movement in the same time to angle (same start time &#8211; end time) – unison movement</td>
</tr>
<tr>
<td valign="top" width="291"><strong>moveSpeedAll(int servoID, int Goal, int iLed)</strong></td>
<td valign="top" width="361">prepare the motors to execute the movement in continuous rotation with same start time and end time – unison movement</td>
</tr>
<tr>
<td valign="top" width="291"><strong>actionAll(int pTime)</strong></td>
<td valign="top" width="361">execute the unison movement</td>
</tr>
<tr>
<td valign="top" width="291"><strong>moveSpeedOne(int servoID, int Goal, int pTime, int iLed)</strong></td>
<td valign="top" width="361">motor continuous rotation with a specified speed</td>
</tr>
<tr>
<td valign="top" width="291"><strong>moveOne(int servoID, int Goal, int pTime, int iLed)</strong></td>
<td valign="top" width="361">move one motor to an absolute position</td>
</tr>
<tr>
<td valign="top" width="291"><strong>moveOneAngle(int servoID, float angle, int pTime, int iLed)</strong></td>
<td valign="top" width="361">move one motor to an angle</td>
</tr>
<tr>
<td valign="top" width="291"><strong>getPosition(int servoID)</strong></td>
<td valign="top" width="361">get the motor position</td>
</tr>
<tr>
<td valign="top" width="291"><strong>getAngle(int servoID)</strong></td>
<td valign="top" width="361">get the position in degrees</td>
</tr>
<tr>
<td valign="top" width="291"><strong>getSpeed(int servoID)</strong></td>
<td valign="top" width="361">get the motor speed (continuous rotation)</td>
</tr>
<tr>
<td valign="top" width="291"><strong>reboot(int servoID)</strong></td>
<td valign="top" width="361">reboot the motor</td>
</tr>
<tr>
<td valign="top" width="291"><strong>setLed(int servoID, int valueLed)</strong></td>
<td valign="top" width="361">set the led color</td>
</tr>
<tr>
<td valign="top" width="291"><strong>writeRegistryRAM(int servoID, int address, int writeByte)</strong></td>
<td valign="top" width="361">write a value in a register in the RAM memory</td>
</tr>
<tr>
<td valign="top" width="291"><strong>writeRegistryEEP(int servoID, int address, int writeByte)</strong></td>
<td valign="top" width="361">write a value in a register in the ROM memory</td>
</tr>
</tbody>
</table>
<p>&nbsp;</p>
<p>I think the Herkulex are a good motors. My tests are not very deep and I don&#8217;t stressed the motors, but in general, compared to Dynamixel, I think they are good. The big difference is the possibility to set a large variety of parameters and the possibility to start and stop the movement for all the motors at the same time leaving to motors the definition of acceleration and speed needed to cover the distance assigned in the same time frame. Some time I experimented problems with the Serial port, receiving the data, I tried to limit them in the library, but sometimes these problems are present yet. This depends by the Herkulex motors, not by my library.</p>
<p>&nbsp;</p>
<p>These are the details of each command.</p>
<p><span style="color: #ff0000;"><strong>begin</strong></span></p>
<table border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td valign="top" width="121">Command</td>
<td valign="top" width="531"><strong>void  begin(long baud, int rx, int tx)</strong></td>
</tr>
<tr>
<td valign="top" width="121">Description</td>
<td valign="top" width="531">start the communication between Arduino Uno/2009 and Herkulex</td>
</tr>
<tr>
<td valign="top" width="121">Arduino Type</td>
<td valign="top" width="531">Arduino Uno/2009</td>
</tr>
<tr>
<td valign="top" width="121">Input</td>
<td valign="top" width="531">
<ul>
<li>Baud: speed of the Serial Port: it is mandatory to use this value: 57600. Other values supported are: 115200 but in my experience it doesn&#8217;t work well with the Arduino Uno/2009</li>
<li>rx, tx: receive and transmit pins. The receiving pin on Arduino has to be wired with the transmission pin on the Herkulex. The same for the receiving pin.</li>
</ul>
</td>
</tr>
<tr>
<td valign="top" width="121">Output</td>
<td valign="top" width="531">None</td>
</tr>
<tr>
<td valign="top" width="121">Example</td>
<td valign="top" width="531">begin(57600,10,11)</td>
</tr>
</tbody>
</table>
<p><strong> </strong></p>
<p><strong> </strong></p>
<p><span style="color: #ff0000;"><strong>beginSerial1</strong></span></p>
<table border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td valign="top" width="121">Command</td>
<td valign="top" width="531"><strong>void  </strong><strong>beginSerial1(long baud)</strong></td>
</tr>
<tr>
<td valign="top" width="121">Description</td>
<td valign="top" width="531">start the communication between Arduino Mega and Herkulex using the Serial Port 1 (pins Rx1 &#8211; 19 and Tx1 &#8211; 18)</td>
</tr>
<tr>
<td valign="top" width="121">Arduino Type</td>
<td valign="top" width="531">Arduino Mega</td>
</tr>
<tr>
<td valign="top" width="121">Input</td>
<td valign="top" width="531">
<ul>
<li>Baud: speed of the Serial Port: my experience is that using the Arduino Mega, the best speed is 115200. Other value supported is 57600</li>
</ul>
</td>
</tr>
<tr>
<td valign="top" width="121">Output</td>
<td valign="top" width="531">None</td>
</tr>
<tr>
<td valign="top" width="121">Example</td>
<td valign="top" width="531">beginSerial1(115200)</td>
</tr>
</tbody>
</table>
<p><strong> </strong></p>
<p><strong> </strong></p>
<p><span style="color: #ff0000;"><strong>beginSerial2</strong></span></p>
<table border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td valign="top" width="121">Command</td>
<td valign="top" width="531"><strong>void  </strong><strong>beginSerial2(long baud)</strong></td>
</tr>
<tr>
<td valign="top" width="121">Description</td>
<td valign="top" width="531">start the communication between Arduino Mega and Herkulex using the Serial Port 2 (pins Rx1 &#8211; 17 and Tx1 &#8211; 16)</td>
</tr>
<tr>
<td valign="top" width="121">Arduino Type</td>
<td valign="top" width="531">Arduino Mega</td>
</tr>
<tr>
<td valign="top" width="121">Input</td>
<td valign="top" width="531">
<ul>
<li>Baud: speed of the Serial Port: my experience is that using the Arduino Mega, the best speed is 115200. Other value supported is 57600</li>
</ul>
</td>
</tr>
<tr>
<td valign="top" width="121">Output</td>
<td valign="top" width="531">None</td>
</tr>
<tr>
<td valign="top" width="121">Example</td>
<td valign="top" width="531">beginSerial2(115200)</td>
</tr>
</tbody>
</table>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p><span style="color: #ff0000;"><strong>beginSerial3</strong></span></p>
<table border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td valign="top" width="121">Command</td>
<td valign="top" width="531"><strong>void  </strong><strong>beginSerial3(long baud)</strong></td>
</tr>
<tr>
<td valign="top" width="121">Description</td>
<td valign="top" width="531">start the communication between Arduino Mega and Herkulex using the Serial Port 3 (pins Rx1 &#8211; 15 and Tx1 &#8211; 13)</td>
</tr>
<tr>
<td valign="top" width="121">Arduino Type</td>
<td valign="top" width="531">Arduino Mega</td>
</tr>
<tr>
<td valign="top" width="121">Input</td>
<td valign="top" width="531">
<ul>
<li>Baud: speed of the Serial Port: my experience is that using the Arduino Mega, the best speed is 115200. Other value supported is 57600</li>
</ul>
</td>
</tr>
<tr>
<td valign="top" width="121">Output</td>
<td valign="top" width="531">None</td>
</tr>
<tr>
<td valign="top" width="121">Example</td>
<td valign="top" width="531">beginSerial3(115200)</td>
</tr>
</tbody>
</table>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p><span style="color: #ff0000;"><strong>End</strong></span></p>
<table border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td valign="top" width="121">Command</td>
<td valign="top" width="531"><strong>void  </strong><strong>end()</strong></td>
</tr>
<tr>
<td valign="top" width="121">Description</td>
<td valign="top" width="531">stop the communication between Arduino  and Herkulex</td>
</tr>
<tr>
<td valign="top" width="121">Arduino Type</td>
<td valign="top" width="531">Arduino Mega- Arduino Uno/2009</td>
</tr>
<tr>
<td valign="top" width="121">Input</td>
<td valign="top" width="531">None</td>
</tr>
<tr>
<td valign="top" width="121">Output</td>
<td valign="top" width="531">None</td>
</tr>
<tr>
<td valign="top" width="121">Example</td>
<td valign="top" width="531">end()</td>
</tr>
</tbody>
</table>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p><span style="color: #ff0000;"><strong>Initialize</strong></span></p>
<table border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td valign="top" width="121">Command</td>
<td valign="top" width="531"><strong>void  </strong><strong>initialize ()</strong></td>
</tr>
<tr>
<td valign="top" width="121">Description</td>
<td valign="top" width="531">initialize the motors. Correspond to commands: clearError(BROADCAST_ID) + ACK (1) + torqueON(BROADCAST_ID).   Works  for all the motors</td>
</tr>
<tr>
<td valign="top" width="121">Arduino Type</td>
<td valign="top" width="531">Arduino Mega- Arduino Uno/2009</td>
</tr>
<tr>
<td valign="top" width="121">Input</td>
<td valign="top" width="531">None</td>
</tr>
<tr>
<td valign="top" width="121">Output</td>
<td valign="top" width="531">None</td>
</tr>
<tr>
<td valign="top" width="121">Example</td>
<td valign="top" width="531">initialize()</td>
</tr>
</tbody>
</table>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p><span style="color: #ff0000;"><strong>Stat</strong></span></p>
<table border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td valign="top" width="121">Command</td>
<td valign="top" width="531"><strong>byte stat(int servoID)</strong></td>
</tr>
<tr>
<td valign="top" width="121">Description</td>
<td valign="top" width="531">return the status of the motor. Please note that the value of BROADCAST_ID (253) often doesn&#8217;t work well</td>
</tr>
<tr>
<td valign="top" width="121">Arduino Type</td>
<td valign="top" width="531">Arduino Mega- Arduino Uno/2009</td>
</tr>
<tr>
<td valign="top" width="121">Input</td>
<td valign="top" width="531">servoID=servo ID value, value between 1-253</td>
</tr>
<tr>
<td valign="top" width="121">Output</td>
<td valign="top" width="531">
<ul>
<li>-1: error checksum 1</li>
<li>-2: error checksum 2</li>
<li>0: OK</li>
<li>for other values please see the manual, page 39</li>
</ul>
</td>
</tr>
<tr>
<td valign="top" width="121">Example</td>
<td valign="top" width="531">int status = stat(1)</td>
</tr>
</tbody>
</table>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p><span style="color: #ff0000;"><strong>ACK</strong></span></p>
<table border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td valign="top" width="121">Command</td>
<td valign="top" width="531"><strong>void ACK(int valueACK)</strong></td>
</tr>
<tr>
<td valign="top" width="121">Description</td>
<td valign="top" width="531">set the verbose answer from Herkulex. the value is valid for all the motors wired in the chain</td>
</tr>
<tr>
<td valign="top" width="121">Arduino Type</td>
<td valign="top" width="531">Arduino Mega- Arduino Uno/2009</td>
</tr>
<tr>
<td valign="top" width="121">Input</td>
<td valign="top" width="531">valueACK</p>
<ul>
<li>0: no reply</li>
<li>1: only reply to CMD command</li>
<li>2: reply always</li>
</ul>
</td>
</tr>
<tr>
<td valign="top" width="121">Output</td>
<td valign="top" width="531">None</td>
</tr>
<tr>
<td valign="top" width="121">Example</td>
<td valign="top" width="531">ACK(1)</td>
</tr>
</tbody>
</table>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p><span style="color: #ff0000;"><strong>set_ID</strong></span></p>
<table border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td valign="top" width="121">Command</td>
<td valign="top" width="531"><strong>void set_ID(int ID_Old, int ID_New)</strong></td>
</tr>
<tr>
<td valign="top" width="121">Description</td>
<td valign="top" width="531">Assign a  new ID to a motor</td>
</tr>
<tr>
<td valign="top" width="121">Arduino Type</td>
<td valign="top" width="531">Arduino Mega- Arduino Uno/2009</td>
</tr>
<tr>
<td valign="top" width="121">Input</td>
<td valign="top" width="531">Int ID_Old: the old ID motor. Values between 1-253Int ID_New: the new ID motor. Values between 1-253</td>
</tr>
<tr>
<td valign="top" width="121">Output</td>
<td valign="top" width="531">None</td>
</tr>
<tr>
<td valign="top" width="121">Example</td>
<td valign="top" width="531">set_ID(253, 1)</td>
</tr>
</tbody>
</table>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p><span style="color: #ff0000;"><strong>clearError</strong></span></p>
<table border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td valign="top" width="121">Command</td>
<td valign="top" width="531"><strong>void clearError(int servoID)</strong></td>
</tr>
<tr>
<td valign="top" width="121">Description</td>
<td valign="top" width="531">Clear the error code for a servo. Works also with BROADCAST_ID=253. Do not switch off the red led lightning</td>
</tr>
<tr>
<td valign="top" width="121">Arduino Type</td>
<td valign="top" width="531">Arduino Mega- Arduino Uno/2009</td>
</tr>
<tr>
<td valign="top" width="121">Input</td>
<td valign="top" width="531">servoID: the servo ID. Values between 1-253</td>
</tr>
<tr>
<td valign="top" width="121">Output</td>
<td valign="top" width="531">None</td>
</tr>
<tr>
<td valign="top" width="121">Example</td>
<td valign="top" width="531">clearError(BROADCAST_ID)</td>
</tr>
</tbody>
</table>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p><span style="color: #ff0000;"><strong>torqueON</strong></span></p>
<table border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td valign="top" width="121">Command</td>
<td valign="top" width="531"><strong>void torqueON(int servoID)</strong></td>
</tr>
<tr>
<td valign="top" width="121">Description</td>
<td valign="top" width="531">Set the torque on for a motor. Works also with BROADCAST_ID=253 for all motors</td>
</tr>
<tr>
<td valign="top" width="121">Arduino Type</td>
<td valign="top" width="531">Arduino Mega- Arduino Uno/2009</td>
</tr>
<tr>
<td valign="top" width="121">Input</td>
<td valign="top" width="531">Servo_ID: servo ID. Values between 1-253</td>
</tr>
<tr>
<td valign="top" width="121">Output</td>
<td valign="top" width="531">None</td>
</tr>
<tr>
<td valign="top" width="121">Example</td>
<td valign="top" width="531">torqueON(BROADCAST_ID)</td>
</tr>
</tbody>
</table>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p><span style="color: #ff0000;"><strong>torqueOFF</strong></span></p>
<table border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td valign="top" width="121">Command</td>
<td valign="top" width="531"><strong>void torqueOFF(int servoID)</strong></td>
</tr>
<tr>
<td valign="top" width="121">Description</td>
<td valign="top" width="531">Set the torque off for a motor. Works also with BROADCAST_ID=253 for all motors. The torque is Free, not Break</td>
</tr>
<tr>
<td valign="top" width="121">Arduino Type</td>
<td valign="top" width="531">Arduino Mega- Arduino Uno/2009</td>
</tr>
<tr>
<td valign="top" width="121">Input</td>
<td valign="top" width="531">Servo_ID: servo ID. Values between 1-253</td>
</tr>
<tr>
<td valign="top" width="121">Output</td>
<td valign="top" width="531">None</td>
</tr>
<tr>
<td valign="top" width="121">Example</td>
<td valign="top" width="531">torqueOFF(BROADCAST_ID)</td>
</tr>
</tbody>
</table>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p><span style="color: #ff0000;"><strong>moveAll</strong></span></p>
<table border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td valign="top" width="121">Command</td>
<td valign="top" width="531"><strong>void moveAll(int servoID, int Goal, int iLed)</strong></td>
</tr>
<tr>
<td valign="top" width="121">Description</td>
<td valign="top" width="531">prepare the motors to execute the movement in the same time to position (same start time &#8211; end time) – unison movement. Start the movement with <em>actionAll </em>command</td>
</tr>
<tr>
<td valign="top" width="121">Arduino Type</td>
<td valign="top" width="531">Arduino Mega- Arduino Uno/2009</td>
</tr>
<tr>
<td valign="top" width="121">Input</td>
<td valign="top" width="531">
<ul>
<li>Servo_ID: servo ID. Values between 1-253. Not working with BROADCAST_ID</li>
<li>Goal: values between  0 &#8211; 1023. Absolute position</li>
<li>iLed=Led color. Values are:
<ul>
<li>LED_GREEN</li>
<li>LED_BLUE</li>
<li>LED_CYAN</li>
<li>LED_RED</li>
<li>LED_GREEN2</li>
<li>LED_PINK</li>
<li>LED_WHITE</li>
</ul>
</li>
</ul>
</td>
</tr>
<tr>
<td valign="top" width="121">Output</td>
<td valign="top" width="531">None</td>
</tr>
<tr>
<td valign="top" width="121">Example</td>
<td valign="top" width="531">moveAll(1, 300, LED_GREEN)</td>
</tr>
</tbody>
</table>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p><span style="color: #ff0000;"><strong>moveAllAngle</strong></span></p>
<table border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td valign="top" width="121">Command</td>
<td valign="top" width="531"><strong>void moveAllAngle(int servoID, float angle, int iLed)</strong></td>
</tr>
<tr>
<td valign="top" width="121">Description</td>
<td valign="top" width="531">prepare the motors to execute the movement in the same time to angle (same start time &#8211; end time) – unison movement. Start the movement with <em>actionAll </em>command</td>
</tr>
<tr>
<td valign="top" width="121">Arduino Type</td>
<td valign="top" width="531">Arduino Mega- Arduino Uno/2009</td>
</tr>
<tr>
<td valign="top" width="121">Input</td>
<td valign="top" width="531">
<ul>
<li>Servo_ID: servo ID. Values between 1-253. Not working with BROADCAST_ID</li>
<li>Angle: angle of the motor. Values between -160.0 degrees … 160.0 degrees</li>
<li>iLed=Led color. Values are:
<ul>
<li>LED_GREEN</li>
<li>LED_BLUE</li>
<li>LED_CYAN</li>
<li>LED_RED</li>
<li>LED_GREEN2</li>
<li>LED_PINK</li>
<li>LED_WHITE</li>
</ul>
</li>
</ul>
</td>
</tr>
<tr>
<td valign="top" width="121">Output</td>
<td valign="top" width="531">None</td>
</tr>
<tr>
<td valign="top" width="121">Example</td>
<td valign="top" width="531">moveAllAngle(1,-120.5, LED_GREEN)</td>
</tr>
</tbody>
</table>
<p>&nbsp;</p>
<p><strong> </strong></p>
<p><span style="color: #ff0000;"><strong>moveSpeedAll</strong></span></p>
<table border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td valign="top" width="121">Command</td>
<td valign="top" width="531"><strong>void moveSpeedAll(int servoID, int Goal, int iLed)</strong></td>
</tr>
<tr>
<td valign="top" width="121">Description</td>
<td valign="top" width="531">prepare the motors to execute the movement in the same time in continuous rotation (same start time &#8211; end time) with different speeds – unison movement. Start the movement with <em>actionAll </em>command</td>
</tr>
<tr>
<td valign="top" width="121">Arduino Type</td>
<td valign="top" width="531">Arduino Mega- Arduino Uno/2009</td>
</tr>
<tr>
<td valign="top" width="121">Input</td>
<td valign="top" width="531">
<ul>
<li>Servo_ID: servo ID. Values between 1-253. Not working with BROADCAST_ID</li>
<li>Goal: values between  -1023…. 1023. Absolute speed</li>
<li>iLed=Led color. Values are:
<ul>
<li>LED_GREEN</li>
<li>LED_BLUE</li>
<li>LED_CYAN</li>
<li>LED_RED</li>
<li>LED_GREEN2</li>
<li>LED_PINK</li>
<li>LED_WHITE</li>
</ul>
</li>
</ul>
</td>
</tr>
<tr>
<td valign="top" width="121">Output</td>
<td valign="top" width="531">None</td>
</tr>
<tr>
<td valign="top" width="121">Example</td>
<td valign="top" width="531">moveAll(1, 300, LED_GREEN)</td>
</tr>
</tbody>
</table>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p><span style="color: #ff0000;"><strong>actionAll</strong></span></p>
<table border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td valign="top" width="121">Command</td>
<td valign="top" width="531"><strong>void actionAll(int pTime)</strong></td>
</tr>
<tr>
<td valign="top" width="121">Description</td>
<td valign="top" width="531">Start the unison movement prepared with moveAll, moveAllAngle, moveSpeedAll</td>
</tr>
<tr>
<td valign="top" width="121">Arduino Type</td>
<td valign="top" width="531">Arduino Mega- Arduino Uno/2009</td>
</tr>
<tr>
<td valign="top" width="121">Input</td>
<td valign="top" width="531">pTime: execution time in milliseconds. Values between 0- 2856 ms. The execution time values are in step of 11.2 ms, so if your input is 1000, the real execution time is int(1000/11.2)*11,2=996,8 ms</td>
</tr>
<tr>
<td valign="top" width="121">Output</td>
<td valign="top" width="531">None</td>
</tr>
<tr>
<td valign="top" width="121">Example</td>
<td valign="top" width="531">actionAll(1000)</td>
</tr>
</tbody>
</table>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p><span style="color: #ff0000;"><strong>moveSpeedOne</strong></span></p>
<table border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td valign="top" width="121">Command</td>
<td valign="top" width="531"><strong>void moveSpeedOne(int servoID, int Goal, int pTime, int iLed)</strong></td>
</tr>
<tr>
<td valign="top" width="121">Description</td>
<td valign="top" width="531">Move continuously a motor with a specific speed</td>
</tr>
<tr>
<td valign="top" width="121">Arduino Type</td>
<td valign="top" width="531">Arduino Mega- Arduino Uno/2009</td>
</tr>
<tr>
<td valign="top" width="121">Input</td>
<td valign="top" width="531">
<ul>
<li>servoID: servo ID. Values between 1-253. BROADCAST_ID doesn’t work</li>
<li>Goal: speed value between -1023, 1023</li>
<li>pTime=execution time in milliseconds. Values between 0- 2856 ms. The execution time values are in step of 11.2 ms, so if your input is 1000, the real execution time is int(1000/11.2)*11,2=996,8 ms</li>
<li>iLed: =Led color. Values are:
<ul>
<li>LED_GREEN</li>
<li>LED_BLUE</li>
<li>LED_CYAN</li>
<li>LED_RED</li>
<li>LED_GREEN2</li>
<li>LED_PINK</li>
<li>LED_WHITE</li>
</ul>
</li>
</ul>
</td>
</tr>
<tr>
<td valign="top" width="121">Output</td>
<td valign="top" width="531">None</td>
</tr>
<tr>
<td valign="top" width="121">Example</td>
<td valign="top" width="531">moveSpeedOne(1,-300, 1500, LED_GREEN)</td>
</tr>
</tbody>
</table>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p><span style="color: #ff0000;"><strong>moveOne</strong></span></p>
<table border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td valign="top" width="121">Command</td>
<td valign="top" width="531"><strong>void moveOne(int servoID, int Goal, int pTime, int iLed)</strong></td>
</tr>
<tr>
<td valign="top" width="121">Description</td>
<td valign="top" width="531">Move one motor to an absolute position</td>
</tr>
<tr>
<td valign="top" width="121">Arduino Type</td>
<td valign="top" width="531">Arduino Mega- Arduino Uno/2009</td>
</tr>
<tr>
<td valign="top" width="121">Input</td>
<td valign="top" width="531">
<ul>
<li>servoID: servo ID. Values between 1-253. BROADCAST_ID doesn’t work</li>
<li>Goal: position between 0 &#8211; 1023</li>
<li>pTime=execution time in milliseconds. Values between 0- 2856 ms. The execution time values are in step of 11.2 ms, so if your input is 1000, the real execution time is int(1000/11.2)*11,2=996,8 ms</li>
<li>iLed: =Led color. Values are:
<ul>
<li>LED_GREEN</li>
<li>LED_BLUE</li>
<li>LED_CYAN</li>
<li>LED_RED</li>
<li>LED_GREEN2</li>
<li>LED_PINK</li>
<li>LED_WHITE</li>
</ul>
</li>
</ul>
</td>
</tr>
<tr>
<td valign="top" width="121">Output</td>
<td valign="top" width="531">None</td>
</tr>
<tr>
<td valign="top" width="121">Example</td>
<td valign="top" width="531">moveOne(1,-300, 1500, LED_GREEN)</td>
</tr>
</tbody>
</table>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p><span style="color: #ff0000;"><strong>moveOneAngle</strong></span></p>
<table border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td valign="top" width="121">Command</td>
<td valign="top" width="531"><strong>void moveOneAngle(int servoID, floiat angle, int pTime, int iLed)</strong></td>
</tr>
<tr>
<td valign="top" width="121">Description</td>
<td valign="top" width="531">Move one motor to a position in degrees</td>
</tr>
<tr>
<td valign="top" width="121">Arduino Type</td>
<td valign="top" width="531">Arduino Mega- Arduino Uno/2009</td>
</tr>
<tr>
<td valign="top" width="121">Input</td>
<td valign="top" width="531">
<ul>
<li>servoID: servo ID. Values between 1-253. BROADCAST_ID doesn’t work</li>
<li>angle: target angle between -160°, 160°</li>
<li>pTime=execution time in milliseconds. Values between 0- 2856 ms. The execution time values are in step of 11.2 ms, so if your input is 1000, the real execution time is int(1000/11.2)*11,2=996,8 ms</li>
<li>iLed: =Led color. Values are:
<ul>
<li>LED_GREEN</li>
<li>LED_BLUE</li>
<li>LED_CYAN</li>
<li>LED_RED</li>
<li>LED_GREEN2</li>
<li>LED_PINK</li>
<li>LED_WHITE</li>
</ul>
</li>
</ul>
</td>
</tr>
<tr>
<td valign="top" width="121">Output</td>
<td valign="top" width="531">None</td>
</tr>
<tr>
<td valign="top" width="121">Example</td>
<td valign="top" width="531">moveOneAngle(1,120, 1500, LED_GREEN)</td>
</tr>
</tbody>
</table>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p><span style="color: #ff0000;"><strong>getPosition</strong></span></p>
<table border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td valign="top" width="121">Command</td>
<td valign="top" width="531"><strong>int getPosition(int servoID)</strong></td>
</tr>
<tr>
<td valign="top" width="121">Description</td>
<td valign="top" width="531">Get absolute position</td>
</tr>
<tr>
<td valign="top" width="121">Arduino Type</td>
<td valign="top" width="531">Arduino Mega- Arduino Uno/2009</td>
</tr>
<tr>
<td valign="top" width="121">Input</td>
<td valign="top" width="531">servoID: servo ID, values between 1-253. BROADCAST_ID doesn’t work</td>
</tr>
<tr>
<td valign="top" width="121">Output</td>
<td valign="top" width="531">Position. Values between 0-1024</td>
</tr>
<tr>
<td valign="top" width="121">Example</td>
<td valign="top" width="531">int pos=getPosition(253)</td>
</tr>
</tbody>
</table>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p><span style="color: #ff0000;"><strong>getAngle</strong></span></p>
<table border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td valign="top" width="121">Command</td>
<td valign="top" width="531"><strong>float getAngle(int servoID)</strong></td>
</tr>
<tr>
<td valign="top" width="121">Description</td>
<td valign="top" width="531">Get position in degrees</td>
</tr>
<tr>
<td valign="top" width="121">Arduino Type</td>
<td valign="top" width="531">Arduino Mega- Arduino Uno/2009</td>
</tr>
<tr>
<td valign="top" width="121">Input</td>
<td valign="top" width="531">servoID: servo ID, values between 1-253. BROADCAST_ID doesn’t work</td>
</tr>
<tr>
<td valign="top" width="121">Output</td>
<td valign="top" width="531">angle. Values between -160.0 … 160.0</td>
</tr>
<tr>
<td valign="top" width="121">Example</td>
<td valign="top" width="531">float angleMotor=getAngle(253)</td>
</tr>
</tbody>
</table>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p><span style="color: #ff0000;"><strong>getSpeed</strong></span></p>
<table border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td valign="top" width="121">Command</td>
<td valign="top" width="531"><strong>int getSpeed(int servoID)</strong></td>
</tr>
<tr>
<td valign="top" width="121">Description</td>
<td valign="top" width="531">Get speed in continuous rotation mode</td>
</tr>
<tr>
<td valign="top" width="121">Arduino Type</td>
<td valign="top" width="531">Arduino Mega- Arduino Uno/2009</td>
</tr>
<tr>
<td valign="top" width="121">Input</td>
<td valign="top" width="531">servoID: servo ID, values between 1-253. BROADCAST_ID doesn’t work</td>
</tr>
<tr>
<td valign="top" width="121">Output</td>
<td valign="top" width="531">Position. Values between 0-1024</td>
</tr>
<tr>
<td valign="top" width="121">Example</td>
<td valign="top" width="531">int pos=getSpeed(253)</td>
</tr>
</tbody>
</table>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p><span style="color: #ff0000;"><strong>reboot</strong></span></p>
<table border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td valign="top" width="121">Command</td>
<td valign="top" width="531"><strong>void reboot(int servoID)</strong></td>
</tr>
<tr>
<td valign="top" width="121">Description</td>
<td valign="top" width="531">servo hardware reboot</td>
</tr>
<tr>
<td valign="top" width="121">Arduino Type</td>
<td valign="top" width="531">Arduino Mega- Arduino Uno/2009</td>
</tr>
<tr>
<td valign="top" width="121">Input</td>
<td valign="top" width="531">servoID: servo ID, values between 1-253. BROADCAST_ID doesn’t work</td>
</tr>
<tr>
<td valign="top" width="121">Output</td>
<td valign="top" width="531">None</td>
</tr>
<tr>
<td valign="top" width="121">Example</td>
<td valign="top" width="531">reboot(253)</td>
</tr>
</tbody>
</table>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p><span style="color: #ff0000;"><strong>setLed</strong></span></p>
<table border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td valign="top" width="121">Command</td>
<td valign="top" width="531"><strong>void setLed(int servoID, int valueLed)</strong></td>
</tr>
<tr>
<td valign="top" width="121">Description</td>
<td valign="top" width="531">Set the led color</td>
</tr>
<tr>
<td valign="top" width="121">Arduino Type</td>
<td valign="top" width="531">Arduino Mega- Arduino Uno/2009</td>
</tr>
<tr>
<td valign="top" width="121">Input</td>
<td valign="top" width="531">
<ul>
<li>servoID: servo ID, values between 1-253. BROADCAST_ID doesn’t work</li>
<li>valueLed: Led color. Values are:
<ul>
<li>LED_GREEN</li>
<li>LED_BLUE</li>
<li>LED_CYAN</li>
<li>LED_RED</li>
<li>LED_GREEN2</li>
<li>LED_PINK</li>
<li>LED_WHITE</li>
</ul>
</li>
</ul>
</td>
</tr>
<tr>
<td valign="top" width="121">Output</td>
<td valign="top" width="531">None</td>
</tr>
<tr>
<td valign="top" width="121">Example</td>
<td valign="top" width="531">setLed(253, LED_PINK)</td>
</tr>
</tbody>
</table>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p><span style="color: #ff0000;"><strong>writeRegistryRAM</strong></span></p>
<table border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td valign="top" width="121">Command</td>
<td valign="top" width="531"><strong>void writeRegistryRAM(int servoID, int address, int writeByte)</strong></td>
</tr>
<tr>
<td valign="top" width="121">Description</td>
<td valign="top" width="531">Write a byte in the RAM registry</td>
</tr>
<tr>
<td valign="top" width="121">Arduino Type</td>
<td valign="top" width="531">Arduino Mega- Arduino Uno/2009</td>
</tr>
<tr>
<td valign="top" width="121">Input</td>
<td valign="top" width="531">
<ul>
<li>servoID: servo ID. Values between 1-253. BROADCAST_ID couldn’t work, depends on the registry value</li>
<li>address: the address value in memory. Please see manual pag.26</li>
<li>writeByte: byte value. Please see manual pag.26</li>
</ul>
</td>
</tr>
<tr>
<td valign="top" width="121">Output</td>
<td valign="top" width="531">None</td>
</tr>
<tr>
<td valign="top" width="121">Example</td>
<td valign="top" width="531">writeRegistryRAM(BROADCAST_ID, 1,1) is equivalent to ACK(1)</td>
</tr>
</tbody>
</table>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p><span style="color: #ff0000;"><strong>writeRegistryEEP</strong></span></p>
<table border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td valign="top" width="121">Command</td>
<td valign="top" width="531"><strong>void writeRegistryRAM(int servoID, int address, int writeByte)</strong></td>
</tr>
<tr>
<td valign="top" width="121">Description</td>
<td valign="top" width="531">Write a byte in the RAM registry</td>
</tr>
<tr>
<td valign="top" width="121">Arduino Type</td>
<td valign="top" width="531">Arduino Mega- Arduino Uno/2009</td>
</tr>
<tr>
<td valign="top" width="121">Input</td>
<td valign="top" width="531">
<ul>
<li>servoID: servo ID. Values between 1-253. BROADCAST_ID couldn’t work, depends on the registry value</li>
<li>address: the address value in memory. Please see manual pag.26</li>
<li>writeByte: byte value. Please see manual pag.26</li>
</ul>
</td>
</tr>
<tr>
<td valign="top" width="121">Output</td>
<td valign="top" width="531">None</td>
</tr>
<tr>
<td valign="top" width="121">Example</td>
<td valign="top" width="531">writeRegistryEEP(BROADCAST_ID, 1,1) is equivalent to ACK(1) in ROM memory</td>
</tr>
</tbody>
</table>
<p>&nbsp;</p>
<p>&nbsp;</p>
<div></div>
<div></div>
]]></content:encoded>
			<wfw:commentRss>http://robottini.altervista.org/dongbu-herkulex-arduino-library-2/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Microbo(t) &#8211; Advanced line follower</title>
		<link>http://robottini.altervista.org/microbot-advanced-line-follower</link>
		<comments>http://robottini.altervista.org/microbot-advanced-line-follower#comments</comments>
		<pubDate>Tue, 22 May 2012 05:07:10 +0000</pubDate>
		<dc:creator>robottini</dc:creator>
				<category><![CDATA[Robottini]]></category>
		<category><![CDATA[Arduino]]></category>
		<category><![CDATA[Line follower]]></category>
		<category><![CDATA[robottini]]></category>

		<guid isPermaLink="false">http://robottini.altervista.org/?p=678</guid>
		<description><![CDATA[Although it is one of the classics of robotics for beginners, the line follower robot, made ​​at high level, is quite complex. On Youtube you can see line follower running at 3 m / s and more, with optimization and maximum performance research that achieves discrete levels. Usually a line follower competition is based on pure speed and the path is quite linear and simple, with large curves and wide straights. In this case the [...]]]></description>
				<content:encoded><![CDATA[<p>Although it is one of the classics of robotics for beginners, the line follower robot, made ​​at high level, is quite complex. On Youtube you can see line follower running at 3 m / s and more, with optimization and maximum performance research that achieves discrete levels.</p>
<p>Usually a line follower competition is based on pure speed and the path is quite linear and simple, with large curves and wide straights. In this case the hardware part is the most important, because the sw part is quite simple to build. it is important to find the right compromise between the mechanical parts and the engine, to make it running as fast as possible. Unfortunately requires a lot of money, because the engine performance search or the wheels with special tires can be very expensive.The alternative is based on paths that are rather difficult or very twisted, with right angles, intersecting lines, lines breaks, obstacles and so on. In this case the HW is much less important. More important is the algorithm and then the sw. The ability of the robot builder is to build a powerful algorithm that allows the robot to drive fast in every situation.</p>
<p>In this tutorial I would describe the robot that I have realized, that is able to face a tortuous path made ​​of curves at 180 ° rather than tight coils, trying to  have a good speed.<br />
The robot ,according to tradition, was home built. It is also already equipped with an infrared sensor front in case you wish to use it in a path with obstacles.</p>
<p>Questo è Microbo(t) – line follower robot:</p>
<p><a href="http://robottini.altervista.org/microbot-advanced-line-follower/img_20120514_225025" rel="attachment wp-att-661"><img class="aligncenter size-thumbnail wp-image-661" title="IMG_20120514_225025" src="http://robottini.altervista.org/wp-content/uploads/2012/05/IMG_20120514_225025-640x480.jpg" alt="" width="640" height="480" /></a></p>
<p>It &#8216;s built with the following elements:<br />
- Chassis 5 mm PVC foam (few cents)<br />
- Arduino Nano (about 40 euros)<br />
- Drive Pololu 50:1 HP (about 30 euros both)<br />
- Pololu motor bracket (both about 6 euros)<br />
- Caster wheel  Pololu 3.8 &#8220;plastic (about 3 euros)<br />
- Pololu Wheels 42&#215;19 (both about 10 euros)<br />
- Motor driver SparkFun TB6612FNG (about 9 euros)<br />
- Sharp IR Distance sensor 4-30 cm (about 15 euros)<br />
- Sensor line Pololu QT-8RC (about 12 euros)<br />
- 7.4V 900mAh Battery Li-Po (about 9 euros)<br />
- some screws and wires<br />
As you can see the components expensive are Arduino Nano and the motors. Nothing forbids to use a traditional Arduino with an obvious saving of money. In my configuration it weighs about 160 grams. You can do much better, in fact on the internet there are line follower with Arduino that weigh 100 grams.</p>
<p><a href="http://robottini.altervista.org/microbot-advanced-line-follower/img_20120514_225003" rel="attachment wp-att-660"><img class="aligncenter size-thumbnail wp-image-660" title="IMG_20120514_225003" src="http://robottini.altervista.org/wp-content/uploads/2012/05/IMG_20120514_225003-640x480.jpg" alt="" width="640" height="480" /></a></p>
<p>&nbsp;</p>
<p><a href="http://robottini.altervista.org/microbot-advanced-line-follower/img_20120514_225110" rel="attachment wp-att-658"><img class="aligncenter size-thumbnail wp-image-658" title="IMG_20120514_225110" src="http://robottini.altervista.org/wp-content/uploads/2012/05/IMG_20120514_225110-640x480.jpg" alt="" width="640" height="480" /></a></p>
<p>&nbsp;</p>
<p><a href="http://robottini.altervista.org/microbot-advanced-line-follower/img_20120514_225127" rel="attachment wp-att-659"><img class="aligncenter size-thumbnail wp-image-659" title="IMG_20120514_225127" src="http://robottini.altervista.org/wp-content/uploads/2012/05/IMG_20120514_225127-640x480.jpg" alt="" width="640" height="480" /></a></p>
<p>Some comments on hw components used. The driving system, formed by Pololu wheels and  motors is almost good. I think that even better is using HP 100:1 Pololu motors which provide even more traction and fluidity in the changes of direction, even if it has a lower number of revolutions/minute. I tested also the 30:1 motors, but they were too nervous. Absolutely bad is the plastic wheel caster form Pololu. Unfortunately I had no other small than this, so I kept it. Not recommend its use. Terrible.</p>
<p>The motor driver SparkFun TB6612FNG is a little undersized. In fact it provides 1.2A at full speed, when the Pololu HP motors  may require up to 1.6A. But I had no problem with these drivers and they still work, so I can only advise them. Unfortunately they have a lot of wires, 7 for driving, 2 for the Vcc voltage (+5 V), one (or two with the ground) for the motor voltage and 4 wires for motors. In total 14 wires that are several. They are simple to program and manage. The full brake function is not good. In fact, if you need to brake, however, takes a little bit to stop, victim of inertia. I think that the engines 100:1 can help on this.</p>
<p>The line sensor Pololu QT-8RC is good. It provides out-of-the-box a digital output and can be connected directly to the Arduino digital ports. After a stage of self-learning during the first few seconds (see the video), it is able to calibrate with the best values ​​taking into account the reflectivity of the surface and the ambient light conditions. It can follow the black lines on white background or white on black background. For this sensor there is an Arduino  library written by Pololu that provides a value between 0 and 8000 depending on the sensor (from left to right) which is above the black line. I modified the library to get a response that goes from -800 to +800 with zero when the line is well below the IR sensor in the middle. This from my point of view makes easier the control. The only real problem I had was in the presence of right angles. In this case the robot has not always stopped in time and managed to turn. Unfortunately I have no videos on this particular problem.</p>
<p>Once built the robot, the biggest difficulty is the control parameters determination, that allow the robot to come back to the line when goes away. In this case I have put in place the usual PID control, although in my version was reduced only in PD, proportional and derivative. The integral control, with the frequent changes of direction, is extremely difficult to detect.<br />
I also wrote  some simple routines for the detection of right angles. In this case the robot tries to stop and turns 90°. This technique has worked quite, but you can sure do better.</p>
<p>For the  IR front sensor I didn&#8217;t have any important test for obstacle avoidance. The main problem is due to the need to rotate the robot for the obstacle avoidance operating in open-chain, ie, without feedback.  The robot should pass the obstacle, but that succeeded a few times because the motors battery voltage varies over time, with a variation of path. I did not do further tests, but there are two possibilities:</p>
<ul>
<li>a dc-dc converter boost 4-25v ​​for example like in the Pololu 3pi robot that maintains a constant input voltage to the motors and that have a good precision even in the absence of encoder</li>
<li>the encoders in the wheels with angles measurement</li>
</ul>
<p>The dc-dc converter costs less than 10 euros, while the cost for the Pololu encoder  is about 25 euros. Maybe in the next version of the Microbo(t) I will decide which solution to adopt. Clearly the solution encoder is more sophisticated but requires more programming effort (and verify that there are still pins available on the Arduino!).</p>
<p>This is the code for Arduino, commented but not very clean. <a href="http://robottini.altervista.org/wp-content/uploads/2012/05/Line_Follower_micorbot.zip">Link</a></p>
<p>This is the Microbo(t) in action:</p>
<p><a href="http://www.youtube.com/watch?v=2-6_wZ0Lcro&#038;fmt=18">http://www.youtube.com/watch?v=2-6_wZ0Lcro</a></p>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://robottini.altervista.org/microbot-advanced-line-follower/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Processing and Opencv 2.3.1 &#8211; Contours detection and polynomial approximation</title>
		<link>http://robottini.altervista.org/processing-and-opencv-2-3-1-contour-detection-and-polynomial-approximation</link>
		<comments>http://robottini.altervista.org/processing-and-opencv-2-3-1-contour-detection-and-polynomial-approximation#comments</comments>
		<pubDate>Mon, 14 May 2012 15:28:54 +0000</pubDate>
		<dc:creator>robottini</dc:creator>
				<category><![CDATA[OpenCv]]></category>

		<guid isPermaLink="false">http://robottini.altervista.org/?p=655</guid>
		<description><![CDATA[In the last episode of this short introduction to Opencv and Processing I want to show an algorithm that allows  to appreciate how with the libraries JavaCvPro you can use the OpenCV to implement an algorithm more sophisticated than the basic ones that I have proposed till now. In this example I make the image edge detection. Then the contours detection is obtained and hence the contours are approximated by polynomial curve. In particular, the polynomial is a set of points that can be represented for example with the segments. The code is organized as [...]]]></description>
				<content:encoded><![CDATA[<p>In the last episode of this short introduction to Opencv and Processing I want to show an algorithm that allows  to appreciate how with the libraries JavaCvPro you can use the OpenCV to implement an algorithm more sophisticated than the basic ones that I have proposed till now.</p>
<p>In this example I make the image edge detection. Then the contours detection is obtained and hence the contours are approximated by polynomial curve. In particular, the polynomial is a set of points that can be represented for example with the segments.<br />
The code is organized as a function java but it is simple to adapt for different uses.</p>
<p style="text-align: center;"> <a href="http://robottini.altervista.org/?attachment_id=673"><img class="aligncenter  wp-image-673" title="contours" src="http://robottini.altervista.org/wp-content/uploads/2012/05/contours.png" alt="" width="675" height="329" /></a></p>
<p>&nbsp;</p>
<div style="background: white; overflow: auto; width: auto; color: black; border: solid gray; border-width: .1em .1em .1em .8em; padding: .2em .6em;">
<pre><span style="color: #808080;">// -- opencv linearization variables</span>
<span style="color: #303090; font-weight: bold;">int</span> iterazione<span style="color: #303030;">=</span><span style="color: #0000d0; font-weight: bold;">0</span><span style="color: #303030;">;</span>
<span style="color: #303090; font-weight: bold;">int</span> cc<span style="color: #303030;">=-</span><span style="color: #0000d0; font-weight: bold;">1</span><span style="color: #303030;">;</span>
<span style="color: #303090; font-weight: bold;">int</span> <span style="color: #303030;">[][]</span> E<span style="color: #303030;">;</span></pre>
<pre><span style="color: #808080;">// ********************************************************</span>
<span style="color: #808080;">// OpenCV - Processing with JavaCvPro</span>
<span style="color: #808080;">// Edge detection - contour detection - polynomial approximation</span>
<span style="color: #808080;">// ********************************************************</span>
Pimage <span style="color: #0060b0; font-weight: bold;">goFilterCV</span><span style="color: #303030;">(PImage draft)</span> <span style="color: #303030;">{</span>

  E <span style="color: #303030;">=</span> <span style="color: #008000; font-weight: bold;">new</span> <span style="color: #303090; font-weight: bold;">int</span><span style="color: #303030;">[</span>ow<span style="color: #303030;">*</span>oh<span style="color: #303030;">][</span><span style="color: #0000d0; font-weight: bold;">3</span><span style="color: #303030;">];</span> <span style="color: #808080;">// matrix for vertex list - weigth * height</span>

  opencv<span style="color: #303030;">.</span><span style="color: #0000c0;">allocate</span><span style="color: #303030;">(</span>ow<span style="color: #303030;">,</span> oh<span style="color: #303030;">);</span> <span style="color: #808080;">//allocate space for image in opencv</span>

  <span style="color: #808080;">//-- copy draft image to opencv IplImage with javacvpro library</span>
  opencv_core<span style="color: #303030;">.</span><span style="color: #0000c0;">IplImage</span> opencvImgSrc<span style="color: #303030;">=</span>opencv<span style="color: #303030;">.</span><span style="color: #0000c0;">fromPImage</span><span style="color: #303030;">(</span>draft<span style="color: #303030;">);</span>  <span style="color: #808080;">// copy draft --&gt; IplImage</span>
  opencv_core<span style="color: #303030;">.</span><span style="color: #0000c0;">CvSize</span> mySize<span style="color: #303030;">=</span>opencvImgSrc<span style="color: #303030;">.</span><span style="color: #0000c0;">cvSize</span><span style="color: #303030;">();</span>             <span style="color: #808080;">// take the size of IplImage</span>

  opencv_core<span style="color: #303030;">.</span><span style="color: #0000c0;">IplImage</span> opencvImgDest<span style="color: #303030;">=</span> opencv_core<span style="color: #303030;">.</span><span style="color: #0000c0;">cvCreateImage</span><span style="color: #303030;">(</span>mySize<span style="color: #303030;">,</span> opencv_core<span style="color: #303030;">.</span><span style="color: #0000c0;">IPL_DEPTH_8U</span><span style="color: #303030;">,</span> <span style="color: #0000d0; font-weight: bold;">3</span><span style="color: #303030;">);</span> <span style="color: #808080;">// build an image IplImage , 3 channels</span>

  <span style="color: #808080;">//--- bilateral filter effect</span>
  <span style="color: #008000; font-weight: bold;">for</span> <span style="color: #303030;">(</span><span style="color: #303090; font-weight: bold;">int</span> i<span style="color: #303030;">=</span><span style="color: #0000d0; font-weight: bold;">0</span><span style="color: #303030;">;</span> i<span style="color: #303030;">&lt;</span><span style="color: #0000d0; font-weight: bold;">10</span><span style="color: #303030;">;</span> i<span style="color: #303030;">++)</span> <span style="color: #303030;">{</span>
    opencv_imgproc<span style="color: #303030;">.</span><span style="color: #0000c0;">bilateralFilter</span><span style="color: #303030;">(</span>opencvImgSrc<span style="color: #303030;">,</span> opencvImgDest<span style="color: #303030;">,</span> <span style="color: #0000d0; font-weight: bold;">3</span><span style="color: #303030;">,</span> <span style="color: #6000e0; font-weight: bold;">20.0</span><span style="color: #303030;">,</span> <span style="color: #6000e0; font-weight: bold;">50.0</span><span style="color: #303030;">,</span> <span style="color: #0000d0; font-weight: bold;">0</span> <span style="color: #303030;">);</span> <span style="color: #808080;">// applique un effet Flou gaussien </span>
    opencv_core<span style="color: #303030;">.</span><span style="color: #0000c0;">cvCopy</span><span style="color: #303030;">(</span>opencvImgDest<span style="color: #303030;">,</span> opencvImgSrc<span style="color: #303030;">);</span>
  <span style="color: #303030;">}</span>
  filter1 <span style="color: #303030;">=</span> createImage<span style="color: #303030;">(</span>ow<span style="color: #303030;">,</span>oh<span style="color: #303030;">,</span>RGB<span style="color: #303030;">);</span>
  filter1<span style="color: #303030;">=</span>toPImage<span style="color: #303030;">(</span>opencvImgDest<span style="color: #303030;">);</span>

  <span style="color: #808080;">//-- define IplImage</span>
  opencv_core<span style="color: #303030;">.</span><span style="color: #0000c0;">IplImage</span> iplImgGray<span style="color: #303030;">;</span>
  opencv_core<span style="color: #303030;">.</span><span style="color: #0000c0;">IplImage</span> iplImgGray1<span style="color: #303030;">;</span>
  iplImgGray <span style="color: #303030;">=</span> opencv_core<span style="color: #303030;">.</span><span style="color: #0000c0;">cvCreateImage</span><span style="color: #303030;">(</span>mySize<span style="color: #303030;">,</span> opencv_core<span style="color: #303030;">.</span><span style="color: #0000c0;">IPL_DEPTH_8U</span><span style="color: #303030;">,</span> <span style="color: #0000d0; font-weight: bold;">1</span><span style="color: #303030;">);</span>   <span style="color: #808080;">// build an image IplImage , 1 channels - only gray</span>
  iplImgGray1<span style="color: #303030;">=</span> opencv_core<span style="color: #303030;">.</span><span style="color: #0000c0;">cvCreateImage</span><span style="color: #303030;">(</span>mySize<span style="color: #303030;">,</span> opencv_core<span style="color: #303030;">.</span><span style="color: #0000c0;">IPL_DEPTH_8U</span><span style="color: #303030;">,</span> <span style="color: #0000d0; font-weight: bold;">1</span><span style="color: #303030;">);</span>   <span style="color: #808080;">// build an image IplImage , 1 channels - only gray</span>

  <span style="color: #808080;">//-- transform colors in gray levels</span>
  opencv_imgproc<span style="color: #303030;">.</span><span style="color: #0000c0;">cvCvtColor</span><span style="color: #303030;">(</span>opencvImgSrc<span style="color: #303030;">,</span> iplImgGray<span style="color: #303030;">,</span> opencv_imgproc<span style="color: #303030;">.</span><span style="color: #0000c0;">CV_RGB2GRAY</span><span style="color: #303030;">);</span>

  <span style="color: #808080;">//-- edge detection - canny algo</span>
  opencv_imgproc<span style="color: #303030;">.</span><span style="color: #0000c0;">cvCanny</span><span style="color: #303030;">(</span>iplImgGray<span style="color: #303030;">,</span> iplImgGray1<span style="color: #303030;">,</span> <span style="color: #6000e0; font-weight: bold;">100.0</span><span style="color: #303030;">,</span> <span style="color: #6000e0; font-weight: bold;">130.0</span><span style="color: #303030;">,</span> <span style="color: #0000d0; font-weight: bold;">3</span> <span style="color: #303030;">);</span>
  <span style="color: #808080;">//opencv_imgproc.cvDilate(iplImgGray1, iplImgGray1, null , 1); // in alternative you can use the dilate function to better find the edges</span>

  <span style="color: #808080;">//-- contour detection</span>
  opencv_core<span style="color: #303030;">.</span><span style="color: #0000c0;">CvMemStorage</span> mem <span style="color: #303030;">=</span> opencv_core<span style="color: #303030;">.</span><span style="color: #0000c0;">CvMemStorage</span><span style="color: #303030;">.</span><span style="color: #0000c0;">create</span><span style="color: #303030;">();</span>
  opencv_core<span style="color: #303030;">.</span><span style="color: #0000c0;">CvSeq</span> contour <span style="color: #303030;">=</span> <span style="color: #008000; font-weight: bold;">new</span> opencv_core<span style="color: #303030;">.</span><span style="color: #0000c0;">CvSeq</span><span style="color: #303030;">(</span><span style="color: #008000; font-weight: bold;">null</span><span style="color: #303030;">);</span>
  <span style="color: #303090; font-weight: bold;">int</span> total<span style="color: #303030;">=</span>opencv_imgproc<span style="color: #303030;">.</span><span style="color: #0000c0;">cvFindContours</span><span style="color: #303030;">(</span>iplImgGray1<span style="color: #303030;">,</span> mem<span style="color: #303030;">,</span> contour<span style="color: #303030;">,</span> Loader<span style="color: #303030;">.</span><span style="color: #0000c0;">sizeof</span><span style="color: #303030;">(</span>opencv_core<span style="color: #303030;">.</span><span style="color: #0000c0;">CvContour</span><span style="color: #303030;">.</span><span style="color: #0000c0;">class</span><span style="color: #303030;">),</span> opencv_imgproc<span style="color: #303030;">.</span><span style="color: #0000c0;">CV_RETR_LIST</span><span style="color: #303030;">,</span> opencv_imgproc<span style="color: #303030;">.</span><span style="color: #0000c0;">CV_CHAIN_APPROX_NONE</span><span style="color: #303030;">);</span>
  println<span style="color: #303030;">(</span><span style="background-color: #fff0f0;">"total point cvFindContours:"</span><span style="color: #303030;">+</span>total<span style="color: #303030;">);</span>

  <span style="color: #808080;">//-- polynomial approximation</span>
  <span style="color: #008000; font-weight: bold;">while</span> <span style="color: #303030;">(</span>contour <span style="color: #303030;">!=</span> <span style="color: #008000; font-weight: bold;">null</span> <span style="color: #303030;">&amp;&amp;</span> <span style="color: #303030;">!</span>contour<span style="color: #303030;">.</span><span style="color: #0000c0;">isNull</span> <span style="color: #303030;">())</span> <span style="color: #303030;">{</span>
    iterazione<span style="color: #303030;">++;</span> <span style="color: #808080;">//number of interactions</span>
    opencv_core<span style="color: #303030;">.</span><span style="color: #0000c0;">CvSeq</span> poly <span style="color: #303030;">=</span> <span style="color: #008000; font-weight: bold;">null</span><span style="color: #303030;">;</span>
    <span style="color: #008000; font-weight: bold;">if</span> <span style="color: #303030;">(</span>contour<span style="color: #303030;">.</span><span style="color: #0000c0;">elem_size</span><span style="color: #303030;">()</span> <span style="color: #303030;">&gt;</span> <span style="color: #0000d0; font-weight: bold;">0</span><span style="color: #303030;">)</span> <span style="color: #303030;">{</span>
      poly <span style="color: #303030;">=</span> opencv_imgproc<span style="color: #303030;">.</span><span style="color: #0000c0;">cvApproxPoly</span><span style="color: #303030;">(</span>contour<span style="color: #303030;">,</span> Loader<span style="color: #303030;">.</span><span style="color: #0000c0;">sizeof</span><span style="color: #303030;">(</span>opencv_core<span style="color: #303030;">.</span><span style="color: #0000c0;">CvContour</span><span style="color: #303030;">.</span><span style="color: #0000c0;">class</span><span style="color: #303030;">),</span> mem<span style="color: #303030;">,</span> opencv_imgproc<span style="color: #303030;">.</span><span style="color: #0000c0;">CV_POLY_APPROX_DP</span><span style="color: #303030;">,</span> <span style="color: #0000d0; font-weight: bold;">3</span><span style="color: #303030;">,</span> <span style="color: #303030;">-</span><span style="color: #0000d0; font-weight: bold;">1</span><span style="color: #303030;">);</span>

      <span style="color: #808080;">//transfer to matrix</span>
      <span style="color: #303090; font-weight: bold;">int</span> n <span style="color: #303030;">=</span> poly<span style="color: #303030;">.</span><span style="color: #0000c0;">total</span><span style="color: #303030;">();</span>
      opencv_core<span style="color: #303030;">.</span><span style="color: #0000c0;">CvPoint</span> points <span style="color: #303030;">=</span> <span style="color: #008000; font-weight: bold;">new</span> opencv_core<span style="color: #303030;">.</span><span style="color: #0000c0;">CvPoint</span><span style="color: #303030;">(</span>n<span style="color: #303030;">);</span>
      opencv_core<span style="color: #303030;">.</span><span style="color: #0000c0;">cvCvtSeqToArray</span><span style="color: #303030;">(</span>poly<span style="color: #303030;">,</span> points<span style="color: #303030;">.</span><span style="color: #0000c0;">position</span><span style="color: #303030;">(</span><span style="color: #0000d0; font-weight: bold;">0</span><span style="color: #303030;">),</span> opencv_core<span style="color: #303030;">.</span><span style="color: #0000c0;">CV_WHOLE_SEQ</span><span style="color: #303030;">);</span>
      <span style="color: #008000; font-weight: bold;">for</span> <span style="color: #303030;">(</span><span style="color: #303090; font-weight: bold;">int</span> i <span style="color: #303030;">=</span> <span style="color: #0000d0; font-weight: bold;">0</span><span style="color: #303030;">;</span> i <span style="color: #303030;">&lt;</span> n<span style="color: #303030;">;</span> i<span style="color: #303030;">++)</span> <span style="color: #303030;">{</span>
        cc<span style="color: #303030;">++;</span>
        opencv_core<span style="color: #303030;">.</span><span style="color: #0000c0;">CvPoint</span> pt <span style="color: #303030;">=</span> points<span style="color: #303030;">.</span><span style="color: #0000c0;">position</span><span style="color: #303030;">(</span>i<span style="color: #303030;">);</span>
        <span style="color: #303090; font-weight: bold;">int</span> x <span style="color: #303030;">=</span> pt<span style="color: #303030;">.</span><span style="color: #0000c0;">x</span><span style="color: #303030;">();</span>
        <span style="color: #303090; font-weight: bold;">int</span> y <span style="color: #303030;">=</span> pt<span style="color: #303030;">.</span><span style="color: #0000c0;">y</span><span style="color: #303030;">();</span>
        E<span style="color: #303030;">[</span>cc<span style="color: #303030;">][</span><span style="color: #0000d0; font-weight: bold;">0</span><span style="color: #303030;">]=</span>x<span style="color: #303030;">;</span>
        E<span style="color: #303030;">[</span>cc<span style="color: #303030;">][</span><span style="color: #0000d0; font-weight: bold;">1</span><span style="color: #303030;">]=</span>y<span style="color: #303030;">;</span>
        E<span style="color: #303030;">[</span>cc<span style="color: #303030;">][</span><span style="color: #0000d0; font-weight: bold;">2</span><span style="color: #303030;">]=</span>iterazione<span style="color: #303030;">;</span>
        <span style="color: #808080;">// println("pts:"+i+" x:"+x+" y:"+y);</span>
      <span style="color: #303030;">}</span>
    <span style="color: #303030;">}</span>
    contour <span style="color: #303030;">=</span> contour<span style="color: #303030;">.</span><span style="color: #0000c0;">h_next</span><span style="color: #303030;">();</span>
  <span style="color: #303030;">}</span> <span style="color: #808080;">//end polynomial approx</span>

 <span style="color: #808080;">// -- print some values for debugging purposes</span>
 <span style="color: #808080;">// for (int i = 0; i &lt; 100; i++) //contatore to have all the points</span>
 <span style="color: #808080;">// println(E[i][0]+" "+E[i][1]+" "+E[i][2]);</span>

  draft<span style="color: #303030;">=</span>toPImage<span style="color: #303030;">(</span>iplImgGray1<span style="color: #303030;">);</span> <span style="color: #808080;">// return draft - PImage</span>
  <span style="color: #008000; font-weight: bold;">return</span> (draft)<span style="color: #303030;">;</span>

<span style="color: #303030;">}</span>

<span style="color: #808080;">// ********************************************************</span>
<span style="color: #808080;">// take an IplImage and give a PImage</span>
<span style="color: #808080;">// ********************************************************</span>
PImage <span style="color: #0060b0; font-weight: bold;">toPImage</span> <span style="color: #303030;">(</span>opencv_core<span style="color: #303030;">.</span><span style="color: #0000c0;">IplImage</span> iplImgIn<span style="color: #303030;">)</span> <span style="color: #303030;">{</span> <span style="color: #808080;">// take an IplImage and give a PImage</span>
  <span style="color: #808080;">//--- put the IplImage in a bufferedImage</span>
  BufferedImage bufImg<span style="color: #303030;">=</span>iplImgIn<span style="color: #303030;">.</span><span style="color: #0000c0;">getBufferedImage</span><span style="color: #303030;">();</span> 

  <span style="color: #808080;">//---- build a PImage with the same size of IplImage--- </span>
  PImage imgOut <span style="color: #303030;">=</span> createImage<span style="color: #303030;">(</span>iplImgIn<span style="color: #303030;">.</span><span style="color: #0000c0;">width</span><span style="color: #303030;">(),</span> iplImgIn<span style="color: #303030;">.</span><span style="color: #0000c0;">height</span><span style="color: #303030;">(),</span> RGB<span style="color: #303030;">);</span>

  <span style="color: #808080;">// put the pixel of IplImage to imgOut.pixels of PImage</span>
  bufImg<span style="color: #303030;">.</span><span style="color: #0000c0;">getRGB</span><span style="color: #303030;">(</span><span style="color: #0000d0; font-weight: bold;">0</span><span style="color: #303030;">,</span> <span style="color: #0000d0; font-weight: bold;">0</span><span style="color: #303030;">,</span> iplImgIn<span style="color: #303030;">.</span><span style="color: #0000c0;">width</span><span style="color: #303030;">(),</span> iplImgIn<span style="color: #303030;">.</span><span style="color: #0000c0;">height</span><span style="color: #303030;">(),</span> imgOut<span style="color: #303030;">.</span><span style="color: #0000c0;">pixels</span><span style="color: #303030;">,</span> <span style="color: #0000d0; font-weight: bold;">0</span><span style="color: #303030;">,</span> iplImgIn<span style="color: #303030;">.</span><span style="color: #0000c0;">width</span><span style="color: #303030;">());</span> 

  imgOut<span style="color: #303030;">.</span><span style="color: #0000c0;">updatePixels</span><span style="color: #303030;">();</span> <span style="color: #808080;">// PImage update</span>

  <span style="color: #008000; font-weight: bold;">return</span><span style="color: #303030;">(</span>imgOut<span style="color: #303030;">);</span> <span style="color: #808080;">// return the PImage</span>
<span style="color: #303030;">}</span></pre>
</div>
]]></content:encoded>
			<wfw:commentRss>http://robottini.altervista.org/processing-and-opencv-2-3-1-contour-detection-and-polynomial-approximation/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Processing and Opencv 2.3.1 &#8211; Using JavaCvPro</title>
		<link>http://robottini.altervista.org/processing-and-opencv-2-3-1-using-javacvpro</link>
		<comments>http://robottini.altervista.org/processing-and-opencv-2-3-1-using-javacvpro#comments</comments>
		<pubDate>Thu, 10 May 2012 21:04:05 +0000</pubDate>
		<dc:creator>robottini</dc:creator>
				<category><![CDATA[OpenCv]]></category>

		<guid isPermaLink="false">http://robottini.altervista.org/?p=619</guid>
		<description><![CDATA[To use the OpenCV 2.3.1 in Processing  the shortest and easiest way is to use the JavaCvPro by X.Hinault. The library JavaCVPro allows to use the OpenCV primitives in a very simple and immediate. To use the webcam, it requires the library GSVideo  that can be installed in Processing / modes / java / libraries (for Processing 1.5). Here&#8217;s an example of JavaCVPro usage: // Programme d'exemple de la librairie javacvPro // par X. [...]]]></description>
				<content:encoded><![CDATA[<p>To use the OpenCV 2.3.1 in Processing  the shortest and easiest way is to use the JavaCvPro by X.Hinault.<br />
The library JavaCVPro allows to use the OpenCV primitives in a very simple and immediate.<br />
To use the webcam, it requires the library <a href=" http://gsvideo.sourceforge.net/">GSVideo</a>  that can be installed in Processing / modes / java / libraries (for Processing 1.5).</p>
<p>Here&#8217;s an example of JavaCVPro usage:</p>
<pre><span style="color: #696969;">// Programme d'exemple de la librairie javacvPro</span>
<span style="color: #696969;">// par X. HINAULT - octobre 2011</span>
<span style="color: #696969;">// Tous droits réservés - Licence GPLv3</span>

<span style="color: #696969;">// Exemple fonction contrast()</span>

<span style="color: #800000; font-weight: bold;">import</span> monclubelec<span style="color: #808030;">.</span>javacvPro<span style="color: #808030;">.</span><span style="color: #808030;">*</span><span style="color: #800080;">;</span> <span style="color: #696969;">// importe la librairie javacvPro</span>

PImage img<span style="color: #800080;">;</span>

<span style="color: #603000;">String</span> url<span style="color: #808030;">=</span><span style="color: #800000;">"</span><span style="color: #0000e6;">http://www.mon-club-elec.fr/mes_images/online/lena.jpg</span><span style="color: #800000;">"</span><span style="color: #800080;">;</span> <span style="color: #696969;">// String contenant l'adresse internet de l'image à utiliser</span>

OpenCV opencv<span style="color: #800080;">;</span> <span style="color: #696969;">// déclare un objet OpenCV principal</span>

<span style="color: #800000; font-weight: bold;">void</span> setup<span style="color: #808030;">(</span><span style="color: #808030;">)</span><span style="color: #800080;">{</span> <span style="color: #696969;">// fonction d'initialisation exécutée 1 fois au démarrage</span>

        <span style="color: #696969;">//-- charge image utilisée --- </span>
        img<span style="color: #808030;">=</span>loadImage<span style="color: #808030;">(</span>url<span style="color: #808030;">,</span><span style="color: #800000;">"</span><span style="color: #0000e6;">jpg</span><span style="color: #800000;">"</span><span style="color: #808030;">)</span><span style="color: #800080;">;</span> <span style="color: #696969;">// crée un PImage contenant le fichier à partir adresse web</span>

        <span style="color: #696969;">//--- initialise OpenCV ---</span>
        opencv <span style="color: #808030;">=</span> <span style="color: #800000; font-weight: bold;">new</span> OpenCV<span style="color: #808030;">(</span><span style="color: #800000; font-weight: bold;">this</span><span style="color: #808030;">)</span><span style="color: #800080;">;</span> <span style="color: #696969;">// initialise objet OpenCV à partir du parent This</span>
        opencv<span style="color: #808030;">.</span>allocate<span style="color: #808030;">(</span>img<span style="color: #808030;">.</span>width<span style="color: #808030;">,</span> img<span style="color: #808030;">.</span>height<span style="color: #808030;">)</span><span style="color: #800080;">;</span> <span style="color: #696969;">// initialise les buffers OpenCv à la taille de l'image</span>

        opencv<span style="color: #808030;">.</span><span style="color: #603000;">copy</span><span style="color: #808030;">(</span>img<span style="color: #808030;">)</span><span style="color: #800080;">;</span> <span style="color: #696969;">// charge le PImage dans le buffer OpenCV</span>

        <span style="color: #696969;">//--- initialise fenêtre Processing </span>
        size <span style="color: #808030;">(</span>opencv<span style="color: #808030;">.</span>width<span style="color: #808030;">(</span><span style="color: #808030;">)</span><span style="color: #808030;">*</span><span style="color: #008c00;">2</span><span style="color: #808030;">,</span> opencv<span style="color: #808030;">.</span>height<span style="color: #808030;">(</span><span style="color: #808030;">)</span><span style="color: #808030;">)</span><span style="color: #800080;">;</span> <span style="color: #696969;">// crée une fenêtre Processing de la 2xtaille du buffer principal OpenCV</span>
        <span style="color: #696969;">//size (img.width, img.height); // aalternative en se basant sur l'image d'origine</span>

        <span style="color: #696969;">//--- affiche image de départ --- </span>
        image<span style="color: #808030;">(</span>opencv<span style="color: #808030;">.</span>getBuffer<span style="color: #808030;">(</span><span style="color: #808030;">)</span><span style="color: #808030;">,</span><span style="color: #008c00;">0</span><span style="color: #808030;">,</span><span style="color: #008c00;">0</span><span style="color: #808030;">)</span><span style="color: #800080;">;</span> <span style="color: #696969;">// affiche le buffer principal OpenCV dans la fenêtre Processing</span>

        <span style="color: #696969;">//--- opérations sur image ---</span>
        opencv<span style="color: #808030;">.</span>contrast<span style="color: #808030;">(</span><span style="color: #808030;">+</span><span style="color: #008c00;">50</span><span style="color: #808030;">)</span><span style="color: #800080;">;</span> <span style="color: #696969;">// applique réglage contraste sur le buffer principal OpenCV</span>

        <span style="color: #696969;">//--- affiche image finale --- </span>
        image<span style="color: #808030;">(</span>opencv<span style="color: #808030;">.</span>getBuffer<span style="color: #808030;">(</span><span style="color: #808030;">)</span><span style="color: #808030;">,</span>opencv<span style="color: #808030;">.</span>width<span style="color: #808030;">(</span><span style="color: #808030;">)</span><span style="color: #808030;">,</span><span style="color: #008c00;">0</span><span style="color: #808030;">)</span><span style="color: #800080;">;</span> <span style="color: #696969;">// affiche le buffer principal OpenCV dans la fenêtre Processing</span>

       noLoop<span style="color: #808030;">(</span><span style="color: #808030;">)</span><span style="color: #800080;">;</span> <span style="color: #696969;">// stop programme </span>
<span style="color: #800080;">}</span>

<span style="color: #800000; font-weight: bold;">void</span>  draw<span style="color: #808030;">(</span><span style="color: #808030;">)</span> <span style="color: #800080;">{</span> <span style="color: #696969;">// fonction exécutée en boucle</span>

<span style="color: #800080;">}</span></pre>
<p><span style="color: #800080;"><img class="aligncenter size-thumbnail wp-image-629" title="llena" src="http://robottini.altervista.org/wp-content/uploads/2012/05/llena-640x358.png" alt="" width="640" height="358" /></span><br />
The code is very simple. All the opencv instructions are called simply using &#8216;opencv.&#8217; before the real instruction. You can use the opencv instructions translated in Processing by X. Hinault in the JavaCvPro libraries.</p>
<p>But it is very interesting to mix OpenCv instruction supported by JavaCvPro libraries and native OpenCv instructions. The JavaCvPro allow to use also the native OpenCV instruction. This is a powerful tool!!!</p>
<p>In the example below, only native<a href="http://robottini.altervista.org/processing-and-opencv-2-3-1-using-javacvpro/bilinear-2" rel="attachment wp-att-632"><br />
</a> OpenCV instructions are used.</p>
<pre><span style="color: #696969;">// Example of using native OpenCVPro instruction in Processing</span>
<span style="color: #696969;">// Robottini.altervista.org</span>
<span style="color: #696969;">// example by X.Hinault modified</span>
<span style="color: #696969;">// Licence GPLv3</span>

<span style="color: #696969;">// Bilinear filter example</span>

<span style="color: #800000; font-weight: bold;">import</span> com<span style="color: #808030;">.</span>googlecode<span style="color: #808030;">.</span>javacv<span style="color: #808030;">.</span><span style="color: #808030;">*</span><span style="color: #800080;">;</span>
<span style="color: #800000; font-weight: bold;">import</span> com<span style="color: #808030;">.</span>googlecode<span style="color: #808030;">.</span>javacv<span style="color: #808030;">.</span>cpp<span style="color: #808030;">.</span><span style="color: #808030;">*</span><span style="color: #800080;">;</span>
<span style="color: #800000; font-weight: bold;">import</span> monclubelec<span style="color: #808030;">.</span>javacvPro<span style="color: #808030;">.</span><span style="color: #808030;">*</span><span style="color: #800080;">;</span>
<span style="color: #800000; font-weight: bold;">import</span> java<span style="color: #808030;">.</span>awt<span style="color: #808030;">.</span>image<span style="color: #808030;">.</span>BufferedImage<span style="color: #800080;">;</span>
PImage imgDest<span style="color: #808030;">,</span> OrigImg<span style="color: #800080;">;</span>
<span style="color: #800000; font-weight: bold;">void</span> setup<span style="color: #808030;">(</span><span style="color: #808030;">)</span> <span style="color: #800080;">{</span>
  size<span style="color: #808030;">(</span><span style="color: #008c00;">640</span><span style="color: #808030;">,</span> <span style="color: #008c00;">240</span><span style="color: #808030;">)</span><span style="color: #800080;">;</span>
  <span style="color: #603000;">String</span> cheminFichier<span style="color: #808030;">=</span><span style="color: #800000;">"</span><span style="color: #0000e6;">C:/Users/Nane/Dropbox/Sorgenti Arduino/Jarkman/Foto/gioconda1.jpg</span><span style="color: #800000;">"</span><span style="color: #800080;">;</span><span style="color: #800080;">;</span> 
  OrigImg<span style="color: #808030;">=</span>loadImage<span style="color: #808030;">(</span>cheminFichier<span style="color: #808030;">,</span><span style="color: #800000;">"</span><span style="color: #0000e6;">jpg</span><span style="color: #800000;">"</span><span style="color: #808030;">)</span><span style="color: #800080;">;</span> 
  <span style="color: #696969;">//---- appel direct des fonctions de la librairie javacv ---- </span>
  <span style="color: #696969;">//--- chargement d'un fichier image </span>
  opencv_core<span style="color: #808030;">.</span>IplImage opencvImgSrc<span style="color: #808030;">=</span> opencv_highgui<span style="color: #808030;">.</span>cvLoadImage<span style="color: #808030;">(</span>cheminFichier<span style="color: #808030;">)</span><span style="color: #800080;">;</span>

  opencv_core<span style="color: #808030;">.</span>CvSize mySize<span style="color: #808030;">=</span>opencvImgSrc<span style="color: #808030;">.</span>cvSize<span style="color: #808030;">(</span><span style="color: #808030;">)</span><span style="color: #800080;">;</span> <span style="color: #696969;">// récupère la taille de l'image </span>

  opencv_core<span style="color: #808030;">.</span>IplImage opencvImgDest<span style="color: #808030;">=</span> opencv_core<span style="color: #808030;">.</span>cvCreateImage<span style="color: #808030;">(</span>mySize<span style="color: #808030;">,</span> opencv_core<span style="color: #808030;">.</span>IPL_DEPTH_8U<span style="color: #808030;">,</span> <span style="color: #008c00;">3</span><span style="color: #808030;">)</span><span style="color: #800080;">;</span> <span style="color: #696969;">// crée une image IplImage , 3 canaux</span>

  <span style="color: #696969;">//--- application d'effet opencv ---</span>
 <span style="color: #800000; font-weight: bold;">for</span> <span style="color: #808030;">(</span><span style="color: #800000; font-weight: bold;">int</span> i<span style="color: #808030;">=</span><span style="color: #008c00;">0</span><span style="color: #800080;">;</span> i<span style="color: #808030;">&lt;</span><span style="color: #008c00;">20</span><span style="color: #800080;">;</span> i<span style="color: #808030;">+</span><span style="color: #808030;">+</span><span style="color: #808030;">)</span>
    opencv_imgproc<span style="color: #808030;">.</span>bilateralFilter<span style="color: #808030;">(</span>opencvImgSrc<span style="color: #808030;">,</span> opencvImgDest<span style="color: #808030;">,</span> <span style="color: #008c00;">3</span><span style="color: #808030;">,</span><span style="color: #008000;">120.0</span><span style="color: #808030;">,</span> <span style="color: #008000;">190.00</span><span style="color: #808030;">,</span><span style="color: #008c00;">1</span> <span style="color: #808030;">)</span><span style="color: #800080;">;</span> <span style="color: #696969;">// applique un effet Flou gaussien </span>

<span style="color: #696969;">//============ récupérer une image openCV dans Processing ===== </span>
  <span style="color: #696969;">//--- récupérer l'objet IplImage dans un BufferedImage </span>
  BufferedImage bufImg<span style="color: #808030;">=</span>opencvImgDest<span style="color: #808030;">.</span>getBufferedImage<span style="color: #808030;">(</span><span style="color: #808030;">)</span><span style="color: #800080;">;</span> <span style="color: #696969;">// récupère l'image</span>

  <span style="color: #696969;">//---- créer un PImage --- </span>
  PImage img <span style="color: #808030;">=</span> createImage<span style="color: #808030;">(</span><span style="color: #008c00;">320</span><span style="color: #808030;">,</span><span style="color: #008c00;">240</span><span style="color: #808030;">,</span> PConstants<span style="color: #808030;">.</span><span style="color: #603000;">RGB</span><span style="color: #808030;">)</span><span style="color: #800080;">;</span> 

  <span style="color: #696969;">// charge les pixels de l'image buffer dans img.pixels</span>
  bufImg<span style="color: #808030;">.</span>getRGB<span style="color: #808030;">(</span><span style="color: #008c00;">0</span><span style="color: #808030;">,</span> <span style="color: #008c00;">0</span><span style="color: #808030;">,</span> <span style="color: #008c00;">320</span><span style="color: #808030;">,</span> <span style="color: #008c00;">240</span><span style="color: #808030;">,</span> img<span style="color: #808030;">.</span>pixels<span style="color: #808030;">,</span> <span style="color: #008c00;">0</span><span style="color: #808030;">,</span> <span style="color: #008c00;">320</span><span style="color: #808030;">)</span><span style="color: #800080;">;</span> 
  img<span style="color: #808030;">.</span>updatePixels<span style="color: #808030;">(</span><span style="color: #808030;">)</span><span style="color: #800080;">;</span>
  image<span style="color: #808030;">(</span>OrigImg<span style="color: #808030;">,</span><span style="color: #008c00;">0</span><span style="color: #808030;">,</span><span style="color: #008c00;">0</span><span style="color: #808030;">)</span><span style="color: #800080;">;</span> 
  image<span style="color: #808030;">(</span>img<span style="color: #808030;">,</span><span style="color: #008c00;">320</span><span style="color: #808030;">,</span><span style="color: #008c00;">0</span><span style="color: #808030;">)</span><span style="color: #800080;">;</span> <span style="color: #696969;">// affiche l'image</span>
<span style="color: #800080;">}</span>
<span style="color: #800000; font-weight: bold;">void</span> draw<span style="color: #808030;">(</span><span style="color: #808030;">)</span> <span style="color: #800080;">{</span>

<span style="color: #800080;">}</span></pre>
<p><a href="http://robottini.altervista.org/processing-and-opencv-2-3-1-using-javacvpro/bilinear-2" rel="attachment wp-att-632"><img class="aligncenter" title="bilinear" src="http://robottini.altervista.org/wp-content/uploads/2012/05/bilinear1-640x279.png" alt="" width="640" height="279" /></a><br />
In this case the OpenCv instructions for Processing are used only in the last part of the code, in order to show the images. The coding of the native OpenCV instructions is more difficult, but very very powerful. It is possible to use almost the whole set of instructions offered by the OpenCv 2.3.1.</p>
]]></content:encoded>
			<wfw:commentRss>http://robottini.altervista.org/processing-and-opencv-2-3-1-using-javacvpro/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Processing and Opencv 2.3.1 – How to install in win 7</title>
		<link>http://robottini.altervista.org/processing-and-opencv-2-3-1-how-to-install-in-win-7</link>
		<comments>http://robottini.altervista.org/processing-and-opencv-2-3-1-how-to-install-in-win-7#comments</comments>
		<pubDate>Tue, 03 Apr 2012 01:37:39 +0000</pubDate>
		<dc:creator>robottini</dc:creator>
				<category><![CDATA[OpenCv]]></category>
		<category><![CDATA[javacv]]></category>
		<category><![CDATA[JavaCvPro]]></category>
		<category><![CDATA[OpenCV]]></category>
		<category><![CDATA[Processing]]></category>

		<guid isPermaLink="false">http://robottini.altervista.org/?p=578</guid>
		<description><![CDATA[THIS HOW-TO WORKS ONLY WITH PROCESSING 1.5.1, NOT WITH THE LAST 2.03b &#160; The procedures to install opencv 2.3.1 libraries and JavaCvPro are explained in several sites. But I had many difficulties doing an installation in Windows 7, even following the step-by-step guides. Then I would write a step-by-step procedure that is as simple as possible. The information sources that I used are : http://code.google.com/p/javacv/wiki/Windows7AndOpenCV http://www.mon-club-elec.fr/pmwiki_reference_lib_javacvPro/pmwiki.php &#160; This installation is working in windows 7 (32 and 64 bit) with Processing [...]]]></description>
				<content:encoded><![CDATA[<h2>THIS HOW-TO WORKS ONLY WITH PROCESSING 1.5.1, NOT WITH THE LAST 2.03b</h2>
<p>&nbsp;</p>
<p>The procedures to install opencv 2.3.1 libraries and JavaCvPro are explained in several sites. But I had many difficulties doing an installation in Windows 7, even following the step-by-step guides.</p>
<p>Then I would write a step-by-step procedure that is as simple as possible. The information sources that I used are :</p>
<p><a href="http://code.google.com/p/javacv/wiki/Windows7AndOpenCV">http://code.google.com/p/javacv/wiki/Windows7AndOpenCV</a></p>
<p><a href="http://www.mon-club-elec.fr/pmwiki_reference_lib_javacvPro/pmwiki.php">http://www.mon-club-elec.fr/pmwiki_reference_lib_javacvPro/pmwiki.php</a></p>
<p>&nbsp;</p>
<p>This installation is working in windows 7 (32 and 64 bit) with Processing 1.5.  It was tested by me in 4 different pc. These are the steps:</p>
<p>&nbsp;</p>
<p>1. Install the runtime components for Microsoft Visual C++ 2010:</p>
<ol start="1">
<ul>
<li><a href="http://www.microsoft.com/download/en/details.aspx?id=5555">Microsoft Visual C++ 2010 Redistributable Package (x86)</a></li>
<li><a href="http://www.microsoft.com/download/en/details.aspx?id=14632">Microsoft Visual C++ 2010 Redistributable Package (x64)</a></li>
</ul>
</ol>
<p>&nbsp;</p>
<p>2. Extract <a href="http://sourceforge.net/projects/opencvlibrary/files/opencv-win/2.3.1/OpenCV-2.3.1-win-superpack.exe/download">OpenCV-2.3.1-win-superpack.exe</a> inside the root directory <strong>C:\</strong>. At the end, the opencv are in  <strong>C:\OpenCV\</strong></p>
<p>&nbsp;</p>
<p>3. Add the ddl path generated by opencv to windows 7 path. This can be made easily with a free program:  <em>RapidEE</em>. Download it from <a href="http://www.rapidee.com/en/download">here</a> and launch it.</p>
<p>&nbsp;</p>
<p>4. Find the registry key PATH and click on it.</p>
<p>&nbsp;</p>
<p style="text-align: center;"><a href="http://robottini.altervista.org/processing-and-opencv-2-3-1-how-to-install-in-win-7/path" rel="attachment wp-att-586"><img class=" wp-image-586 aligncenter" title="path" src="http://robottini.altervista.org/wp-content/uploads/2012/04/path-1024x550.jpg" alt="" width="640" height="480" /></a></p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>5. Click the right mouse button and <span style="white-space: nowrap;">choose </span><em>add value</em> in the menu. Add these values:</p>
<ul>
<li><strong>C:\opencv\build\x64\vc10\bin\</strong></li>
<li><strong>C:\opencv\build\x64\vc10\lib\</strong></li>
<li><strong>C:\opencv\build\common\tbb\intel64\vc10\</strong></li>
</ul>
<p>If the win7 32bit version the directory are with <em>x86</em> instead of <em>x64</em>. For 32bit version add also <strong>C:\opencv\build\common\tbb\ia32\vc10\</strong></p>
<p>&nbsp;</p>
<p style="text-align: center;"><a href="http://robottini.altervista.org/processing-and-opencv-2-3-1-how-to-install-in-win-7/path-detail" rel="attachment wp-att-584"><img class="aligncenter  wp-image-584" title="path detail" src="http://robottini.altervista.org/wp-content/uploads/2012/04/path-detail.jpg" alt="" width="640" height="480" /></a></p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>6. Download the JavaCvPro library (version 0.3) <a href="http://www.mon-club-elec.fr/mes_downloads/javacvPro-0.3.zip">here</a>.</p>
<p>&nbsp;</p>
<p>7. Extract and copy all in the Processing library directory: <strong>Processing /Mode/java/libraries</strong></p>
<p>&nbsp;</p>
<p>8. Download the last version of binary JavaCV  library <a href="http://code.google.com/p/javacv/downloads/list">here</a> (today is  <a href="http://javacv.googlecode.com/files/javacv-bin-20120329.zip">javacv-bin-20120329.zip</a>).</p>
<p>&nbsp;</p>
<p>9. Extract and copy all in the Processing library directory: <strong>Processing /Mode/java/libraries</strong></p>
<p>&nbsp;</p>
<p>10. Create a directory called <strong>library</strong><strong> </strong>inside the<strong> javacv-bin</strong> directory and put all the file (not the sample directory) inside this new <strong>library</strong> directory</p>
<p>&nbsp;</p>
<p>11. Rename the library<strong> javacv-bin</strong> extracted with this name:<strong> javacv</strong></p>
<p>&nbsp;</p>
<p>12. Download the last version of the binary Javacpp library <a href="http://code.google.com/p/javacpp/downloads/list">here</a>  ( today is<a href="http://code.google.com/p/javacpp/downloads/detail?name=javacpp-0.1-bin.zip&amp;can=2&amp;q="> javacpp-0.1-bin.zip</a>)</p>
<p>&nbsp;</p>
<p>13. Extract and copy all in the Processing library directory: <strong>Processing /Mode/java/libraries</strong></p>
<p>&nbsp;</p>
<p>10. Create a directory called <strong>library </strong>inside the<strong> javacpp-bin</strong> directory and put all the file (not the sample directory) inside this new <strong>library</strong> directory</p>
<p>&nbsp;</p>
<p>11. Rename the library<strong> javacpp-bin</strong> with this name:<strong> javacpp</strong></p>
<p><strong> </strong></p>
<p>&nbsp;</p>
<p>If all the steps are succeeded, it is done. Now you can start Processing and test this simple program (take from <a href="http://www.mon-club-elec.fr/pmwiki_reference_lib_javacvPro/pmwiki.php?n=Main.HomePage">here</a>):<a href="http://robottini.altervista.org/?attachment_id=585" rel="attachment wp-att-585"><br />
</a></p>
<pre><span style="color: #800000; font-weight: bold;">import</span> com<span style="color: #808030;">.</span>googlecode<span style="color: #808030;">.</span>javacv<span style="color: #808030;">.</span><span style="color: #808030;">*</span><span style="color: #800080;">;</span>
<span style="color: #800000; font-weight: bold;">import</span> com<span style="color: #808030;">.</span>googlecode<span style="color: #808030;">.</span>javacv<span style="color: #808030;">.</span>cpp<span style="color: #808030;">.</span><span style="color: #808030;">*</span><span style="color: #800080;">;</span>

<span style="color: #800000; font-weight: bold;">import</span> monclubelec<span style="color: #808030;">.</span>javacvPro<span style="color: #808030;">.</span><span style="color: #808030;">*</span><span style="color: #800080;">;</span>

OpenCV opencv<span style="color: #800080;">;</span> <span style="color: #696969;">// déclare un objet OpenCV principal</span>

<span style="color: #800000; font-weight: bold;">void</span> setup<span style="color: #808030;">(</span><span style="color: #808030;">)</span><span style="color: #800080;">{</span> <span style="color: #696969;">// fonction d'initialisation exécutée 1 fois au démarrage</span>

        opencv <span style="color: #808030;">=</span> new OpenCV<span style="color: #808030;">(</span><span style="color: #800000; font-weight: bold;">this</span><span style="color: #808030;">)</span><span style="color: #800080;">;</span> <span style="color: #696969;">// initialise objet OpenCV à partir du parent This</span>
        opencv<span style="color: #808030;">.</span>allocate<span style="color: #808030;">(</span><span style="color: #008c00;">320</span><span style="color: #808030;">,</span><span style="color: #008c00;">240</span><span style="color: #808030;">)</span><span style="color: #800080;">;</span> <span style="color: #696969;">// crée le buffer image de la taille voulue</span>

<span style="color: #800080;">}</span>

<span style="color: #800000; font-weight: bold;">void</span>  draw<span style="color: #808030;">(</span><span style="color: #808030;">)</span> <span style="color: #800080;">{</span> <span style="color: #696969;">// fonction exécutée en boucle</span>

<span style="color: #800080;">}</span></pre>
<p>&nbsp;</p>
<p>It is very important to include also the javacv and javacpp libraries. In the <a href="http://www.mon-club-elec.fr/">http://www.mon-club-elec.fr</a> documentation this is not required, but in my experience, without these libraries, the program doesn&#8217;t work.</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://robottini.altervista.org/processing-and-opencv-2-3-1-how-to-install-in-win-7/feed</wfw:commentRss>
		<slash:comments>32</slash:comments>
		</item>
		<item>
		<title>Processing and Opencv 2.3.1 &#8211; Introduction</title>
		<link>http://robottini.altervista.org/processing-and-opencv-2-3-1-introduction</link>
		<comments>http://robottini.altervista.org/processing-and-opencv-2-3-1-introduction#comments</comments>
		<pubDate>Sat, 24 Mar 2012 09:39:21 +0000</pubDate>
		<dc:creator>robottini</dc:creator>
				<category><![CDATA[OpenCv]]></category>
		<category><![CDATA[JavaCvPro]]></category>
		<category><![CDATA[OpenCV]]></category>
		<category><![CDATA[Processing]]></category>

		<guid isPermaLink="false">http://robottini.altervista.org/?p=522</guid>
		<description><![CDATA[To build a robot that draws portraits I need to have a good supply of tools for image processing. The best open source libraries available are the opencv that I would use with Processing. Unfortunately opencv are available in C + + and python, but not in Java that is the language used in Processing. [...]]]></description>
				<content:encoded><![CDATA[<div id="gt-res-wrap">
<div id="gt-res-content">
<div dir="ltr"><a href="http://robottini.altervista.org/processing-and-opencv-2-3-1-introduction/opencveprocessing" rel="attachment wp-att-528"><img class="aligncenter size-full wp-image-528" title="opencveprocessing" src="http://robottini.altervista.org/wp-content/uploads/2012/03/opencveprocessing-e1332576045471.png" alt="" width="640" height="254" /></a></div>
<div dir="ltr"></div>
<div dir="ltr"></div>
<div style="text-align: justify;" dir="ltr">
<p>To build a robot that draws portraits I need to have a good supply of tools for image processing. The best open source libraries available are the opencv that I would use with Processing.</p>
<p>Unfortunately opencv are available in C + + and python, but not in Java that is the language used in Processing. Luckily some guys  have built some wrappers that allow to use opencv with Processing.</p>
<p><strong> </strong></p>
<p><span style="color: #ff0000;"><strong>Opencv processing library</strong></span></p>
</div>
<p style="text-align: justify;" dir="ltr">The most famous library is this: <a href="http://ubaa.net/shared/processing/opencv/ ">http://ubaa.net/shared/processing/opencv/ </a>which is very well documented. Its installation is simple and works well. But this library  supports only a few commands opencv and doesn&#8217;t provide access to thousands of opencv functions.It use QuickTime to perform functions that use the webcam. The commands supported are the most important, however, it is not enough.It allows to write code using opencv in a very simple way, making the primitives opencv a part of Processing language.</p>
<div style="text-align: justify;" dir="ltr">For example this is the <em>capture()</em>  function that allocates and initializes resources for reading a video stream from a camera.</div>
</div>
<div dir="ltr"><img class="aligncenter" src="http://ubaa.net/shared/processing/opencv/images/capture.png" alt="" width="320" height="240" /></div>
<pre><span style="color: #800000; font-weight: bold;">import</span> hypermedia<span style="color: #808030;">.</span>video<span style="color: #808030;">.</span><span style="color: #808030;">*</span><span style="color: #800080;">;</span>
OpenCV opencv<span style="color: #800080;">;</span> <span style="color: #696969;">//opecv object</span>

<span style="color: #800000; font-weight: bold;">void</span> setup<span style="color: #808030;">(</span><span style="color: #808030;">)</span> <span style="color: #800080;">{</span>
size<span style="color: #808030;">(</span> <span style="color: #008c00;">320</span><span style="color: #808030;">,</span> <span style="color: #008c00;">240</span> <span style="color: #808030;">)</span><span style="color: #800080;">;</span> <span style="color: #696969;">//window size</span>
opencv <span style="color: #808030;">=</span> new OpenCV<span style="color: #808030;">(</span> <span style="color: #800000; font-weight: bold;">this</span> <span style="color: #808030;">)</span><span style="color: #800080;">;</span> <span style="color: #696969;">// opencv object</span>
opencv<span style="color: #808030;">.</span>capture<span style="color: #808030;">(</span> width<span style="color: #808030;">,</span> height <span style="color: #808030;">)</span><span style="color: #800080;">;</span> <span style="color: #696969;">// open video stream</span>
<span style="color: #800080;">}</span>

<span style="color: #800000; font-weight: bold;">void</span> draw<span style="color: #808030;">(</span><span style="color: #808030;">)</span> <span style="color: #800080;">{</span>
opencv<span style="color: #808030;">.</span>read<span style="color: #808030;">(</span><span style="color: #808030;">)</span><span style="color: #800080;">;</span> <span style="color: #696969;">// grab frame from camera</span>
image<span style="color: #808030;">(</span> opencv<span style="color: #808030;">.</span>image<span style="color: #808030;">(</span><span style="color: #808030;">)</span><span style="color: #808030;">,</span> <span style="color: #008c00;">0</span><span style="color: #808030;">,</span> <span style="color: #008c00;">0</span> <span style="color: #808030;">)</span><span style="color: #800080;">;</span> <span style="color: #800080;">}</span> <span style="color: #696969;">// and display image</span></pre>
<div style="text-align: justify;" dir="ltr">
<p>not bad! only 10 rows to display the webcam image. The opencv functions are very easy with this library, but the opencv supported is only the 1.0 and the number of the function is very low.</p>
<p>&nbsp;</p>
<p><span style="color: #ff0000;"><strong>JavaCVPro</strong></span></p>
</div>
<div style="text-align: justify;" dir="ltr">Luckily there is another library that allows to use the last version of the opencv, the 2.3.1: <a href=" http://www.mon-club-elec.fr/pmwiki_reference_lib_javacvPro/pmwiki.php?n=Main.Presentation">JavacvPro</a>.</div>
<div style="text-align: justify;" dir="ltr">The documentation for this library is only in French.I understandFrench well, so I have no problems! <img src='http://robottini.altervista.org/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </div>
<div dir="ltr">
<p style="text-align: justify;">This library implements natively over 100 opencv functions, making them part of the language Processing. In addition it use the library GSVideo which is the official video library for the version 2.0 of Processing.</p>
<p style="text-align: justify;">The use of the library is very simple. This is an example of syntax of the function of edge detection of the original opencv:</p>
<h5><span style="font-size: 12px;"><em>cvCanny (opencv_core.CvArr image, opencv_core.CvArr edges, double threshold1, double threshold2, int aperture_size)</em></span></h5>
<p style="text-align: justify;">this is the corresponding on JacaCvPro in Processing:</p>
<h5><span style="font-size: 12px;"><em>canny (PImage image)</em></span></h5>
<p style="text-align: justify;">The library takes care of the rest! not bad right?  But how does work the processing wrapping in opencv? Opencv is a library written in C + +, Processing works in Java.<br />
JavaCvPro uses another library ,<a href="http://code.google.com/p/javacv/"> javacv</a>, which implements almost all the OpenCV functions directly in Java. Moreover, there is another library, <a href="http://code.google.com/p/javacpp/">javacpp</a>, which implemets the real link between Java and C++.</p>
<p style="text-align: justify;">So, the chain among libraries is:</p>
<p style="text-align: justify;">Processing &#8212;&gt; JavaCvPro &#8212;&gt; javacv &#8212;&gt; javacpp- &#8211;&gt; OpenCV</p>
<p style="text-align: justify;">Difficult? No, easy!</p>
<p style="text-align: justify;">In the next post I show how install opencv and JavaCvPro in windows 7 environment.</p>
</div>
</div>
]]></content:encoded>
			<wfw:commentRss>http://robottini.altervista.org/processing-and-opencv-2-3-1-introduction/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Dynamixel AX-12A and Arduino: how to use the Serial Port</title>
		<link>http://robottini.altervista.org/dynamixel-ax-12a-and-arduino-how-to-use-the-serial-port</link>
		<comments>http://robottini.altervista.org/dynamixel-ax-12a-and-arduino-how-to-use-the-serial-port#comments</comments>
		<pubDate>Sat, 24 Dec 2011 18:47:15 +0000</pubDate>
		<dc:creator>robottini</dc:creator>
				<category><![CDATA[Auduino]]></category>
		<category><![CDATA[Dynamixel]]></category>

		<guid isPermaLink="false">http://robottini.altervista.org/?p=469</guid>
		<description><![CDATA[I bought two servos Dynamixel, the AX-12A, which are the basic servos version of the Korean company Robotis inc. Dynamixel servomotors are like Ferrari in the world of the  cars : the best servomotors on the market. Some characteristics of these servos:   Operational Torque: 144 oz-in (10.4 kg.cm)   1 / 2 duplex multi-drop serial bus   1M bps serial communication   Reports position, speed, load, voltage, and temperature   Full rotation mode   300 ° angular position in 1024 increments   Speed ​​and torque control in 1024 increments   [...]]]></description>
				<content:encoded><![CDATA[<p style="text-align: justify;">I bought two servos <a href="http://www.robotis.com/xe/dynamixel_en">Dynamixel</a>, the AX-12A, which are the basic servos version of the Korean company Robotis inc.<br />
Dynamixel servomotors are like Ferrari in the world of the  cars : the best servomotors on the market.<br />
Some characteristics of these servos:</p>
<ul>
<li>  Operational Torque: 144 oz-in (10.4 kg.cm)</li>
<li>  1 / 2 duplex multi-drop serial bus</li>
<li>  1M bps serial communication</li>
<li>  Reports position, speed, load, voltage, and temperature</li>
<li>  Full rotation mode</li>
<li>  300 ° angular position in 1024 increments</li>
<li>  Speed ​​and torque control in 1024 increments</li>
<li>  Built in LED status indicator / alarm</li>
<li>  Shutdown on max / min voltage, load or temperature</li>
<li>  Single cable network connection</li>
</ul>
<p style="text-align: justify;">They are not particularly expensive: about $ 45 U.S., in Europe about 45-50 euros.</p>
<p style="text-align: justify;"><img class="aligncenter" src="http://robosavvy.com/store/images/AX-12A.jpg" alt="" width="500" height="500" /></p>
<p style="text-align: justify;">These servomotors have difficulty connecting to the Arduino. In fact, the half-duplex communication to 1Mbps requires additional circuitry to make connections to Arduino if there are several servos to be connected. A single servo can be connected directly to the Arduino, in the case of several actuators it is necessary to use a tri-state buffer, which is placed between the Arduino and AX-12A. A simple tri-state buffer is the <a href="http://html.alldatasheet.com/html-pdf/28082/TI/SN74LS241N3/25/1/SN74LS241N3.html">74LS241N</a>.</p>
<div class="wp-caption aligncenter" style="width: 310px"><img src="http://www.circuitspecialists.com/content/image/6503/300/74LS241" alt="" width="300" height="266" /><p class="wp-caption-text">74LS241</p></div>
<p style="text-align: justify;">The Dynamixel protocol is a serial protocol, so, Arduino side, the buffer 74LS241 must be connected to the serial port and then on pins 0 and 1. This is a problem: if the serial port is used byDynamixel, how to display information through the Arduino IDE Serial monitor?</p>
<p style="text-align: justify;">We need another serial port. The Arduino library NewSoftSerial  can help us, but we also need a USB-serial converter. I chose the converter<a href="http://store.arduino.cc/ww/index.php?main_page=product_info&amp;cPath=11_12&amp;products_id=143"> USB2Seria</a>l built from Arduino team.</p>
<p style="text-align: justify;">This is a picture of all the components needed to use the Dynamixel Servos.</p>
<p style="text-align: justify;"><a href="http://robottini.altervista.org/dynamixel-ax-12a-and-arduino-how-to-use-the-serial-port/dynamixel-ax-12a-arduino" rel="attachment wp-att-466"><img class="aligncenter size-large wp-image-466" title="Dynamixel AX-12A Arduino" src="http://robottini.altervista.org/wp-content/uploads/2011/12/Dynamixel-AX-12A-Arduino-1024x768.jpg" alt="" width="600" height="450" /></a></p>
<p style="text-align: justify;">The 2 &#8216;strange&#8217; components: the 74LS241 and the USB2Serial converter:</p>
<p style="text-align: justify;"><a href="http://robottini.altervista.org/dynamixel-ax-12a-and-arduino-how-to-use-the-serial-port/dynamixel-chips-needed" rel="attachment wp-att-468"><img class="aligncenter size-large wp-image-468" title="Dynamixel chips needed" src="http://robottini.altervista.org/wp-content/uploads/2011/12/Dynamixel-chips-needed-1024x768.jpg" alt="" width="600" height="450" /></a></p>
<p style="text-align: justify;">These are all the components wired:</p>
<p style="text-align: justify;"><a href="http://robottini.altervista.org/dynamixel-ax-12a-and-arduino-how-to-use-the-serial-port/dinamixel-arduino" rel="attachment wp-att-465"><img class="aligncenter size-large wp-image-465" title="Dinamixel Arduino" src="http://robottini.altervista.org/wp-content/uploads/2011/12/Dinamixel-Arduino-1024x768.jpg" alt="" width="600" height="450" /></a></p>
<p style="text-align: justify;">This is the wiring schema (sorry for the manual drawing):</p>
<p style="text-align: justify;"><a href="http://robottini.altervista.org/dynamixel-ax-12a-and-arduino-how-to-use-the-serial-port/dynamixel-arduino-electric-schema" rel="attachment wp-att-464"><img class="aligncenter size-large wp-image-464" title="Dynamixel Arduino wiring schema" src="http://robottini.altervista.org/wp-content/uploads/2011/12/Dynamixel-Arduino-electric-schema-1024x768.jpg" alt="" width="600" height="450" /></a></p>
<p style="text-align: justify;">Dynamixel servos require a software library to work with Arduino. An awesome library, realized by Savage Electronics, can be found <a href="http://savageelectronics.blogspot.com/2011/08/actualizacion-biblioteca-dynamixel.html">here</a>. Instructions can be found <a href="http://savageelectronics.blogspot.com/2011/01/arduino-y-dynamixel-ax-12.html">here</a>.</p>
<p style="text-align: justify;">This is a short video showing the Dynamixel servos in action. It is possible also to see the values printed in the Serial monitor with the NewSoftSerial throw the Serial port between the pins 8 and 9.</p>
<p style="text-align: justify;">
<p><a href="http://www.youtube.com/watch?v=svD-m-NUD3I&#038;fmt=18">http://www.youtube.com/watch?v=svD-m-NUD3I</a></p>
</p>
<p style="text-align: justify;">This is the code used:</p>
<pre style="color: #000000; background: #ffffff;"><span style="color: #004a43;">#</span><span style="color: #004a43;">include </span><span style="color: #800000;">&lt;</span><span style="color: #40015a;">Dynamixel_Serial.h</span><span style="color: #800000;">&gt;</span>
<span style="color: #004a43;">#</span><span style="color: #004a43;">include </span><span style="color: #800000;">&lt;</span><span style="color: #40015a;">NewSoftSerial.h</span><span style="color: #800000;">&gt;</span>

NewSoftSerial mySerial<span style="color: #808030;">(</span><span style="color: #008c00;">9</span><span style="color: #808030;">,</span><span style="color: #008c00;">8</span><span style="color: #808030;">)</span><span style="color: #800080;">;</span> <span style="color: #696969;">//9=tx, 8=rx</span>
<span style="color: #800000; font-weight: bold;">int</span> k<span style="color: #808030;">=</span><span style="color: #008c00;">0</span><span style="color: #800080;">;</span>

<span style="color: #800000; font-weight: bold;">void</span> setup<span style="color: #808030;">(</span><span style="color: #808030;">)</span><span style="color: #800080;">{</span> <span style="color: #696969;">// Configuration</span>

Ax12<span style="color: #808030;">.</span>begin<span style="color: #808030;">(</span><span style="color: #008c00;">1000000</span><span style="color: #808030;">,</span><span style="color: #008c00;">2</span><span style="color: #808030;">)</span><span style="color: #800080;">;</span> <span style="color: #696969;">//2=data control</span>
mySerial<span style="color: #808030;">.</span>begin<span style="color: #808030;">(</span><span style="color: #008c00;">9600</span><span style="color: #808030;">)</span><span style="color: #800080;">;</span>  <span style="color: #696969;">//speed of serial port used by NewSoftSerial</span>
<span style="color: #800080;">}</span>

<span style="color: #800000; font-weight: bold;">void</span> loop<span style="color: #808030;">(</span><span style="color: #808030;">)</span><span style="color: #800080;">{</span>

<span style="color: #696969;">// move servo 1 and 2 randomly</span>
Ax12<span style="color: #808030;">.</span>move<span style="color: #808030;">(</span><span style="color: #008c00;">1</span><span style="color: #808030;">,</span>random<span style="color: #808030;">(</span><span style="color: #008c00;">200</span><span style="color: #808030;">,</span><span style="color: #008c00;">600</span><span style="color: #808030;">)</span><span style="color: #808030;">)</span><span style="color: #800080;">;</span>
Ax12<span style="color: #808030;">.</span>move<span style="color: #808030;">(</span><span style="color: #008c00;">2</span><span style="color: #808030;">,</span>random<span style="color: #808030;">(</span><span style="color: #008c00;">200</span><span style="color: #808030;">,</span><span style="color: #008c00;">600</span><span style="color: #808030;">)</span><span style="color: #808030;">)</span><span style="color: #800080;">;</span>
mySerial<span style="color: #808030;">.</span>print<span style="color: #808030;">(</span><span style="color: #800000;">"</span><span style="color: #0000e6;">Number:</span><span style="color: #800000;">"</span><span style="color: #808030;">)</span><span style="color: #800080;">;</span>
mySerial<span style="color: #808030;">.</span>println<span style="color: #808030;">(</span>k<span style="color: #808030;">+</span><span style="color: #808030;">+</span><span style="color: #808030;">)</span><span style="color: #800080;">;</span>

delay<span style="color: #808030;">(</span><span style="color: #008c00;">1000</span><span style="color: #808030;">)</span><span style="color: #800080;">;</span>

mySerial<span style="color: #808030;">.</span>print<span style="color: #808030;">(</span><span style="color: #800000;">"</span><span style="color: #0000e6;">Number2:</span><span style="color: #800000;">"</span><span style="color: #808030;">)</span><span style="color: #800080;">;</span>
mySerial<span style="color: #808030;">.</span>println<span style="color: #808030;">(</span>random<span style="color: #808030;">(</span><span style="color: #008c00;">100</span><span style="color: #808030;">)</span><span style="color: #808030;">)</span><span style="color: #800080;">;</span>

<span style="color: #800080;">}</span></pre>
<pre style="color: #000000; background: #ffffff;"></pre>
]]></content:encoded>
			<wfw:commentRss>http://robottini.altervista.org/dynamixel-ax-12a-and-arduino-how-to-use-the-serial-port/feed</wfw:commentRss>
		<slash:comments>16</slash:comments>
		</item>
		<item>
		<title>Delta robot with Arduino</title>
		<link>http://robottini.altervista.org/delta-robot-with-arduino</link>
		<comments>http://robottini.altervista.org/delta-robot-with-arduino#comments</comments>
		<pubDate>Tue, 18 Oct 2011 11:51:04 +0000</pubDate>
		<dc:creator>robottini</dc:creator>
				<category><![CDATA[delta robot]]></category>
		<category><![CDATA[Robottini]]></category>
		<category><![CDATA[vacuum gripper]]></category>
		<category><![CDATA[Arduino]]></category>
		<category><![CDATA[Delta Robot]]></category>

		<guid isPermaLink="false">http://robottini.altervista.org/?p=431</guid>
		<description><![CDATA[Today I present my first Delta robot made with Arduino. The Delta robot structure was designed by a professor at the Technical University of Lausanne in 1985.  It is a parallel robot, and within two decades has become the star of pick and place industrial robots . The delta robot distinctive elements are two: The robot geometry which simplifies the equations of motion (kinematics) The great idea to anchor the [...]]]></description>
				<content:encoded><![CDATA[<p>Today I present my first Delta robot made with Arduino. The Delta robot structure was designed by a professor at the Technical University of Lausanne in 1985.  It is a <a href="http://en.wikipedia.org/wiki/Parallel_robot">parallel</a> robot, and within two decades has become the star of pick and place industrial robots . The delta robot distinctive elements are two:</p>
<ul>
<li>The robot geometry which simplifies the equations of motion (kinematics)</li>
</ul>
<ul>
<li>The great idea to anchor the robot upside down so that it has the motors connected to the base. This is very important because while the robot works, the motors remain attached at the base, allowing the robot to have arms very light. Lightness means low friction, low inertia, low power motors, precision, speed, fast acceleration and deceleration.</li>
</ul>
<p>These are two examples of delta robot:</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p align="center">
<p><a href="http://www.youtube.com/watch?v=8G59zTXVHHU">http://www.youtube.com/watch?v=8G59zTXVHHU</a></p>
</p>
<p align="center">
<p><a href="http://www.youtube.com/watch?v=Gv5B63HeF1E">http://www.youtube.com/watch?v=Gv5B63HeF1E</a></p>
</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>These aren&#8217;t laboratory prototypes, but commercial robots and they cost about 50-60.000 euros. I tried to build a simple delta robot with Arduino. My Delta robot works like the commercial Delta robot, ie, in inverse kinematics. Given a point x, y, z in space, in real time Arduino calculates the angles of the servomotors that allow  to reach that point in space.</p>
<p>The Delta robot has two triangular plates. A higher which is fixed and the lower is free. The servo motors are fixed to the top plate. The gripping tool (i.e. an electromagnet, a gripper, a vacuum suction cup), is fixed to the lower plate. The two plates are triangular equilateral, that is, equal sides and equal angles of 60 °.</p>
<p>The Delta  has 3 servo motors and two arms for each servo. One is integral with the servo. The other arm is free to rotate in all directions and it is connected to the lower small triangle. In order to ensure the free turning, the second arm is linked with ball joints. To find the ball joints has not been easy. I found something about the steering of the machine model. Just search on google &#8220;joint Uniball&#8221; and you can find little cheap joints.</p>
<p>A very good explanation about the the Delta robot geometry and a very effective explanation of inverse and direct kinematics formulas can be found <a href="http://www.google.it/url?sa=t&amp;source=web&amp;cd=1&amp;ved=0CCYQFjAA&amp;url=http%3A%2F%2Fforums.trossenrobotics.com%2Ftutorials%2Fintroduction-129%2Fdelta-robot-kinematics-3276%2F&amp;ei=BGmdTqoFrsTiBLyS9LoJ&amp;usg=AFQjCNHwgQyaTSxZzS1AU2oFvopjEh-ljA&amp;sig2=3AI1zDrZDkV7LirVxSxf_w">here</a> . You can find also the code that calculates the inverse kinematic.</p>
<p>These are some Delta robot pictures (with an ATtiny85 microcontroller).</p>
<p>&nbsp;</p>
<p style="text-align: center;"><a href="http://robottini.altervista.org/deltaduino-a-delta-robot-with-arduino/deltapico1" rel="attachment wp-att-406"><img class="aligncenter size-large wp-image-406" title="deltaPico1" src="http://robottini.altervista.org/wp-content/uploads/2011/10/deltaPico1-1024x768.jpg" alt="" width="600" height="450" /></a></p>
<p style="text-align: center;"><a href="http://robottini.altervista.org/deltaduino-a-delta-robot-with-arduino/deltapico2" rel="attachment wp-att-407"><img class="aligncenter size-large wp-image-407" title="DeltaPico2" src="http://robottini.altervista.org/wp-content/uploads/2011/10/DeltaPico2-768x1024.jpg" alt="" width="600" height="800" /></a></p>
<p style="text-align: center;"><a href="http://robottini.altervista.org/deltaduino-a-delta-robot-with-arduino/deltapico3" rel="attachment wp-att-408"><img class="aligncenter size-large wp-image-408" title="DeltaPico3" src="http://robottini.altervista.org/wp-content/uploads/2011/10/DeltaPico3-1024x768.jpg" alt="" width="600" height="450" /></a></p>
<p style="text-align: center;"><a href="http://robottini.altervista.org/delta-robot-with-arduino/deltapico4" rel="attachment wp-att-409"><img class="aligncenter size-large wp-image-409" title="DeltaPico4" src="http://robottini.altervista.org/wp-content/uploads/2011/10/DeltaPico4-1024x768.jpg" alt="" width="600" height="450" /></a></p>
<p style="text-align: center;"><a href="http://robottini.altervista.org/deltaduino-a-delta-robot-with-arduino/deltapico5" rel="attachment wp-att-410"><img class="aligncenter size-large wp-image-410" title="DeltaPico5" src="http://robottini.altervista.org/wp-content/uploads/2011/10/DeltaPico5-1024x768.jpg" alt="" width="600" height="450" /></a></p>
<p>The end effector can be used with different tools. I tried a vacuum syringe and  a drawing pen.</p>
<p>These below are some videos with different tools.</p>
<p>&nbsp;</p>
<p>The first experiment with a simple trajectory (a circle).</p>
<p>&nbsp;</p>
<p align="center">
<p><a href="http://www.youtube.com/watch?v=DHdFg0ezqLw">http://www.youtube.com/watch?v=DHdFg0ezqLw</a></p>
</p>
<p>&nbsp;</p>
<p>The Delta robot drove by a mouse with Processing. The code is available <a href="http://robottini.altervista.org/wp-content/uploads/2011/10/DeltaArduProc.zip">here</a>.</p>
<p>&nbsp;</p>
<p align="center">
<p><a href="http://www.youtube.com/watch?v=3DJE0SBv3uU">http://www.youtube.com/watch?v=3DJE0SBv3uU</a></p>
</p>
<p>The Delta robot in  pick and place configuration. The code is available <a href="http://robottini.altervista.org/wp-content/uploads/2011/10/Pneumo_Arduino.zip">here</a>.</p>
<p>&nbsp;</p>
<p align="center">
<p><a href="http://www.youtube.com/watch?v=TlmcxDExwd8">http://www.youtube.com/watch?v=TlmcxDExwd8</a></p>
</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>The Delta robot drawing. This is a first draft. The code is available <a href="http://robottini.altervista.org/wp-content/uploads/2011/10/Delta_drawing.zip">here</a>.</p>
<p>&nbsp;</p>
<p style="text-align: center;">
<p><a href="http://www.youtube.com/watch?v=JEaGTsSyNfg">http://www.youtube.com/watch?v=JEaGTsSyNfg</a></p></p>
]]></content:encoded>
			<wfw:commentRss>http://robottini.altervista.org/delta-robot-with-arduino/feed</wfw:commentRss>
		<slash:comments>11</slash:comments>
		</item>
	</channel>
</rss>
