<?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>arvydas.co.uk &#187; R/C toy hacking</title>
	<atom:link href="http://www.arvydas.co.uk/category/rc-toy-hacking/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.arvydas.co.uk</link>
	<description>Software development and electronics</description>
	<lastBuildDate>Tue, 22 Feb 2011 22:07:14 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Robot logic</title>
		<link>http://www.arvydas.co.uk/2009/11/robot-logic/</link>
		<comments>http://www.arvydas.co.uk/2009/11/robot-logic/#comments</comments>
		<pubDate>Thu, 26 Nov 2009 16:24:53 +0000</pubDate>
		<dc:creator>Arvydas</dc:creator>
				<category><![CDATA[R/C toy hacking]]></category>

		<guid isPermaLink="false">http://www.arvydas.co.uk/?p=44</guid>
		<description><![CDATA[
Started thinking about the logic for the robot. The first one that I used in my prototype from LuckyLarry&#8217;s website seems to be too basic, so I did a quick brainstorm and came up with the flowchart above.  The logic adds the complexity of using a range finder sensor on top of the servo. Robot [...]]]></description>
			<content:encoded><![CDATA[<p><img class="alignnone size-full wp-image-43" title="robot-logic" src="http://www.arvydas.co.uk/wp-content/uploads/2009/11/robot-logic.png" alt="robot-logic" width="436" height="870" /></p>
<p>Started thinking about the logic for the robot. The first one that I used in my prototype from <a href="http://luckylarry.co.uk/" target="_blank" class="liexternal">LuckyLarry&#8217;s</a> website seems to be too basic, so I did a quick brainstorm and came up with the flowchart above.  The logic adds the complexity of using a range finder sensor on top of the servo. Robot should drive forward, unless it encounters an obstacle closer than 20cm. Then it should stop, look around and determine the next free path it should go. The most challenging bits are the ones that I colored in red: this requires some sort of sensory &#8220;knowledge&#8221; of the direction of the robot. If I had a spare accelerometer, everything should seem more simple: just get the data from the accelerometer and calculate the direction of the robot when it turns. All I have now is just SRF05 range finder so another thought came to my mind. At the point after robot scans the surrounding area, it should know the distance to the surrounding area with 10 degree resolution. For example:</p>
<ol>
<li>-90 deg | 70 cm</li>
<li>-80 deg | 60 cm</li>
<li>-70 deg | 50 cm</li>
<li>-60 deg | 50 cm</li>
<li>-50 deg | 40 cm</li>
<li>-40 deg | 40 cm</li>
<li>-30 deg | 30 cm</li>
<li>-20 deg | 20 cm</li>
<li>-10 deg | 20 cm</li>
<li>0 deg | 20 cm</li>
<li>10 deg | 20 cm</li>
<li>20 deg | 20 cm</li>
<li>30 deg | 20 cm</li>
<li>&#8230;</li>
</ol>
<p>According to the logic, robot should choose path (1) by turning -90 degrees. Considering that before the turning head is facing 0 degrees, it should continue turning, until it determines that the distance is more than 70cm to the closes object, so the range finder should read all the way from 20cm to 70cm with a threshold of +-5cm.</p>
<p>Huh, seems that hardware setup was the easiest bit. Building smart software to run the robot is a bigger challenge and that&#8217;s what makes this project so interesting. :)</p>
]]></content:encoded>
			<wfw:commentRss>http://www.arvydas.co.uk/2009/11/robot-logic/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Hacking a toy car @ fizzPOP Howduino</title>
		<link>http://www.arvydas.co.uk/2009/11/hacking-a-toy-car-fizzpop-howduino/</link>
		<comments>http://www.arvydas.co.uk/2009/11/hacking-a-toy-car-fizzpop-howduino/#comments</comments>
		<pubDate>Tue, 24 Nov 2009 14:19:07 +0000</pubDate>
		<dc:creator>Arvydas</dc:creator>
				<category><![CDATA[Arduino]]></category>
		<category><![CDATA[Arduino MEGA]]></category>
		<category><![CDATA[Hardware hacking]]></category>
		<category><![CDATA[R/C toy hacking]]></category>
		<category><![CDATA[Birmingham]]></category>
		<category><![CDATA[event]]></category>
		<category><![CDATA[fizzPOP]]></category>
		<category><![CDATA[Howduino]]></category>
		<category><![CDATA[R/C toy]]></category>
		<category><![CDATA[UK]]></category>

		<guid isPermaLink="false">http://www.arvydas.co.uk/?p=6</guid>
		<description><![CDATA[
This Saturday I had a chance to attend a fantastic Howduino event in Birmingham &#8211; a one day hackers workshop. This was my first experience in this type of event, so I came without any expectations. :) Once the the welcoming announcements were made everybody started hacking either by going to beginners workshops or working [...]]]></description>
			<content:encoded><![CDATA[<p><img class="alignnone size-full wp-image-14" title="IMG1716" src="http://www.arvydas.co.uk/wp-content/uploads/2009/11/IMG1716.jpg" alt="IMG1716" width="500" height="333" /></p>
<p>This Saturday I had a chance to attend a fantastic <a href="http://www.howduino.com" target="_blank" class="liexternal">Howduino</a> event in Birmingham &#8211; a one day hackers workshop. This was my first experience in this type of event, so I came without any expectations. :) Once the the welcoming announcements were made everybody started hacking either by going to beginners workshops or working on their own projects. Steward from <a href="http://www.kre8.com/" target="_blank" class="liexternal">Kre8</a> joined me at my desk and we had a lot of fun working together.</p>
<h3>The task</h3>
<p>My task for the day was to transform this R/C toy car from <a href="http://www.elc.co.uk" class="liexternal">ELC</a> into an obstacle avoiding robot.</p>
<p><img class="alignnone size-full wp-image-15" title="IMG1710" src="http://www.arvydas.co.uk/wp-content/uploads/2009/11/IMG1710.jpg" alt="IMG1710" width="500" height="333" /></p>
<p>I chose this cute little toy, because each side of the wheels is controlled by a separate motor. This allows the car to turn around 360 degrees in one spot. There was one big challenge involved in hacking this toy car: I had to be able to assemble it back again, because my son had already announced the ownership. :) <span id="more-6"></span></p>
<h3>Let the hacking begin!</h3>
<p><img class="alignnone size-full wp-image-16" title="IMG1711" src="http://www.arvydas.co.uk/wp-content/uploads/2009/11/IMG1711.jpg" alt="IMG1711" width="500" height="333" /></p>
<p>Above is the picture of the disassembled car. The quality of the toy is really high, because it is supposed to sustain driving in the mud and water. You can see the wires coming from the two motors on each side of the chassis. Those were cut roughly in the middle and extended with additional wires.</p>
<p><img class="alignnone size-full wp-image-17" title="IMG1712" src="http://www.arvydas.co.uk/wp-content/uploads/2009/11/IMG1712.jpg" alt="IMG1712" width="500" height="333" /></p>
<p>A quick break: above is the picture of my work desk @ Howduino. The only thing that bothered in the event was very poor lighting. Despite that it was great to have so many like-minded hackers around sharing ideas and hardware with each other.</p>
<p><img class="alignnone size-full wp-image-18" title="IMG1713" src="http://www.arvydas.co.uk/wp-content/uploads/2009/11/IMG1713.jpg" alt="IMG1713" width="500" height="333" /></p>
<p>Here you can see the prototype spread on the table: the chassis upside down so it doesn&#8217;t dive off the desk together with all electronic parts, breadboard with L293D motor driver, Arduino MEGA, SRF05 ultrasonic range finder on top of a servo. I couldn&#8217;t manage to use the servo for advanced range finding, because it would have complicated the software and I wouldn&#8217;t have finished the project on time.</p>
<h3>The code</h3>
<p>I grabbed the essential part of the code from <a href="http://luckylarry.co.uk/2009/08/obstacle-avoidance-robot-build-your-own-larrybot/" target="_blank" class="liexternal">LuckyLarry&#8217;s Obstacle avoidance robot</a> and tested it.</p>
<pre class="brush: cpp;">
const int numOfReadings = 10;           // number of readings to take/ items in the array
int readings[numOfReadings];            // stores the distance readings in an array
int arrayIndex = 0;                     // arrayIndex of the current item in the array
int total = 0;                          // stores the cumlative total
int averageDistance = 0;                // stores the average value
unsigned long distance = 0;

const int motor1Pin1 = 2;    // H-bridge leg 1
const int motor1Pin2 = 3;    // H-bridge leg 2
const int motor2Pin1 = 4;    // H-bridge leg 3
const int motor2Pin2 = 5;    // H-bridge leg 4
const int enable1Pin = 9;    // H-bridge enable pin
const int enable2Pin = 10;   // H-bridge enable pin
const int ledPin = 13;       // LED

#define echoPin 6             // the SRF04's echo pin
#define initPin 7             // the SRF04's init pin
unsigned long pulseTime = 0;  // variable for reading the pulse
long servoAngle = 90;         // variable for reading the pulse
int servoDirection = 1;

void setup() {
  pinMode(ledPin, OUTPUT);

  // set all the other pins you're using as outputs:
  pinMode(motor1Pin1, OUTPUT);
  pinMode(motor1Pin2, OUTPUT);
  pinMode(enable1Pin, OUTPUT);

  pinMode(motor2Pin1, OUTPUT);
  pinMode(motor2Pin2, OUTPUT);
  pinMode(enable2Pin, OUTPUT);

  // set enablePin high so that motor can turn on:
  digitalWrite(enable1Pin, HIGH);
  digitalWrite(enable2Pin, HIGH);

  // make the init pin an output:
  pinMode(initPin, OUTPUT);
  // make the echo pin an input:
  pinMode(echoPin, INPUT);

  for (int thisReading = 0; thisReading &lt; numOfReadings; thisReading++)
  {
    readings[thisReading] = 0;
  }

  // blink the LED 3 times. This should happen only once.
  // if you see the LED blink three times, it means that the module
  // reset itself,. probably because the motor caused a brownout
  // or a short.
  blink(ledPin, 3, 100);
}

void loop() {
  digitalWrite(initPin, HIGH);              // send 10 microsecond pulse
  delayMicroseconds(10);                    // wait 10 microseconds before turning off
  digitalWrite(initPin, LOW);               // stop sending the pulse
  pulseTime = pulseIn(echoPin, HIGH);       // Look for a return pulse, it should be high as the pulse goes low-high-low
  distance = pulseTime/58;                  // Distance = pulse time / 58 to convert to cm.
  total= total - readings[arrayIndex];      // subtract the last distance
  readings[arrayIndex] = distance;          // add distance reading to array
  total= total + readings[arrayIndex];      // add the reading to the total
  arrayIndex = arrayIndex + 1;              // go to the next item in the array                                

  // At the end of the array (10 items) then start again
  if (arrayIndex &gt;= numOfReadings)  {
    arrayIndex = 0;
  }

  averageDistance = total / numOfReadings;      // calculate the average distance
  delay(10);

  // check the average distance and move accordingly

  if (averageDistance &lt; = 20){
    // go backwards
    digitalWrite(motor1Pin1, HIGH);
    digitalWrite(motor1Pin2, LOW);
    digitalWrite(motor2Pin1, HIGH);
    digitalWrite(motor2Pin2, LOW);   

  }

  if (averageDistance &lt;= 60 &amp;&amp; averageDistance &gt; 20) {
    // turn
    digitalWrite(motor1Pin1, HIGH);
    digitalWrite(motor1Pin2, LOW);
    digitalWrite(motor2Pin1, LOW);
    digitalWrite(motor2Pin2, LOW);
  }

  if (averageDistance &gt; 60)   {
    // go forward
    digitalWrite(motor1Pin1, LOW);
    digitalWrite(motor1Pin2, HIGH);
    digitalWrite(motor2Pin1, LOW);
    digitalWrite(motor2Pin2, HIGH);    

  }

}

/*
blinks an LED
*/
void blink(int whatPin, int howManyTimes, int milliSecs) {
  int i = 0;
  for ( i = 0; i &lt; howManyTimes; i++) {
    digitalWrite(whatPin, HIGH);
    delay(milliSecs/2);
    digitalWrite(whatPin, LOW);
    delay(milliSecs/2);
  }
}
</pre>
<p>The code above keeps checking the distance to the closest object and calculates the average. If distance is more than 60cm, robot runs forward, when distance is between 20cm and 60cm robot turns left. When distance is less than 20cm, robot runs back.</p>
<h3>Mission accomplished!</h3>
<p>Tested and working! Final assembly on the desk:</p>
<p><img class="alignnone size-full wp-image-19" title="IMG1714" src="http://www.arvydas.co.uk/wp-content/uploads/2009/11/IMG1714.jpg" alt="IMG1714" width="500" height="333" /></p>
<p>You can see the little car running on the floor :)</p>
<p><a href="http://www.arvydas.co.uk/2009/11/hacking-a-toy-car-fizzpop-howduino/"><em>Click here to view the embedded video.</em></a></p>
<p>Thanks to <a href="http://twitter.com/genzaichi" target="_blank" class="liexternal">Nikki</a> for this video!</p>
<h3>What&#8217;s next?</h3>
<p>There is still a lot to do:</p>
<ul>
<li>Use the servo to move the range finder for better &#8220;view&#8221; of the objects around;</li>
<li>Resolve battery drain, because quickly switching the direction of the motor is not good;</li>
<li>Make it a bit smarter to stop and look around;</li>
<li>Investigate surrounding area and draw a map in the memory;</li>
<li>Try to find docking station to recharge all by itself;</li>
<li>Make it light loving/phobic;</li>
</ul>
<p>You can find more pictures from the event in the <a href="http://www.flickr.com/groups/howduino/" target="_blank" class="liexternal">Howduino Flickr group</a> and a <a href="http://www.fizzpop.org.uk/blog/the-howduino-happened/" target="_blank" class="liexternal">blog post</a>. Big thank you goes to fizzPOP for organizing the even and hope to see all of you next year!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.arvydas.co.uk/2009/11/hacking-a-toy-car-fizzpop-howduino/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>

