Line 4: Line 4:
 
To give a brief the Robo Controller board has a CP2102 USB to UART(Serial) convertor. We give commands to the robot from the terminal and move it. This is a very simple type and you can easily hack it. The controller board also has a atmega8 MCU with Arduino bootloader, hence we can code it from the Arduino IDE
 
To give a brief the Robo Controller board has a CP2102 USB to UART(Serial) convertor. We give commands to the robot from the terminal and move it. This is a very simple type and you can easily hack it. The controller board also has a atmega8 MCU with Arduino bootloader, hence we can code it from the Arduino IDE
 
<br />
 
<br />
 +
{{scroll box|width=600px|height=400px|text=<br />
 +
<html>
 +
<pre>
 +
#include&nbsp;&lt;<span style="color: #CC6600;">Firmata</span>.h&gt;
 +
<span style="color: #CC6600;">int</span> MotorLeft[2] = {A0,A1};
 +
<span style="color: #CC6600;">int</span> MotorRight[2] = {A2,A3};
 +
<span style="color: #CC6600;">void</span> <span style="color: #CC6600;"><b>setup</b></span>()
 +
{
 +
<span style="color: #CC6600;"><b>Serial</b></span>.<span style="color: #CC6600;">begin</span>(9600);
 +
MotorInit();
 +
<span style="color: #CC6600;"><b>Serial</b></span>.<span style="color: #CC6600;">print</span>(<span style="color: #006699;">"********Explore Robo Mode Computer: Controlled************\n\r"</span>);
 +
<span style="color: #CC6600;"><b>Serial</b></span>.<span style="color: #CC6600;">print</span>(<span style="color: #006699;">"Commands:\n W---&gt;Forward \n S---&gt;Backwards \n A---&gt;Left \n D---&gt;Right\n\r"</span>);
 +
}
 +
<span style="color: #CC6600;">void</span> <span style="color: #CC6600;"><b>loop</b></span>()
 +
{
 +
<span style="color: #CC6600;">int</span> command;
 +
command&nbsp;=&nbsp;<span style="color: #CC6600;"><b>Serial</b></span>.<span style="color: #CC6600;">read</span>();
 +
&nbsp;&nbsp;<span style="color: #CC6600;">switch</span>(command)
 +
&nbsp;{
 +
&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #CC6600;">case</span> <span style="color: #006699;">'w'</span>: Robot_Forward(); <span style="color: #CC6600;">delay</span>(100); <span style="color: #CC6600;">break</span>;
 +
&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #CC6600;">case</span> <span style="color: #006699;">'s'</span>: Robot_Backward(); <span style="color: #CC6600;">delay</span>(100); <span style="color: #CC6600;">break</span>; 
 +
&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #CC6600;">case</span> <span style="color: #006699;">'a'</span>: Robot_Left(); <span style="color: #CC6600;">delay</span>(100); <span style="color: #CC6600;">break</span>;
 +
&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #CC6600;">case</span> <span style="color: #006699;">'d'</span>: Robot_Right(); <span style="color: #CC6600;">delay</span>(100); <span style="color: #CC6600;">break</span>;
 +
&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #7E7E7E;">//in case the caps lock is ON</span>
 +
&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #CC6600;">case</span> <span style="color: #006699;">'W'</span>: Robot_Forward(); <span style="color: #CC6600;">delay</span>(100); <span style="color: #CC6600;">break</span>;
 +
&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #CC6600;">case</span> <span style="color: #006699;">'S'</span>: Robot_Backward(); <span style="color: #CC6600;">delay</span>(100); <span style="color: #CC6600;">break</span>; 
 +
&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #CC6600;">case</span> <span style="color: #006699;">'A'</span>: Robot_Left(); <span style="color: #CC6600;">delay</span>(100); <span style="color: #CC6600;">break</span>;
 +
&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #CC6600;">case</span> <span style="color: #006699;">'D'</span>: Robot_Right(); <span style="color: #CC6600;">delay</span>(100); <span style="color: #CC6600;">break</span>;     
 +
&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #CC6600;">default</span>: <span style="color: #CC6600;">break</span>;
 +
&nbsp;}&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
 +
}
 +
<span style="color: #7E7E7E;">//Intialize&nbsp;the&nbsp;motor</span>
 +
<span style="color: #CC6600;">void</span> MotorInit()
 +
{
 +
&nbsp;&nbsp;<span style="color: #CC6600;">int</span> i;
 +
&nbsp;&nbsp;<span style="color: #CC6600;">for</span>(i=0 ; i&lt;2; i++)
 +
&nbsp;&nbsp;{
 +
&nbsp;&nbsp;<span style="color: #CC6600;">pinMode</span>(MotorLeft[i],<span style="color: #006699;">OUTPUT</span>);
 +
&nbsp;&nbsp;<span style="color: #CC6600;">pinMode</span>(MotorRight[i],<span style="color: #006699;">OUTPUT</span>);
 +
&nbsp;&nbsp;}
 +
}
 +
<span style="color: #7E7E7E;">//Robot&nbsp;Driving&nbsp;Functions</span>
 +
<span style="color: #CC6600;">void</span> Robot_Forward()
 +
{
 +
&nbsp;&nbsp;&nbsp;<span style="color: #CC6600;">digitalWrite</span>(MotorLeft[0],0);
 +
&nbsp;&nbsp;&nbsp;<span style="color: #CC6600;">digitalWrite</span>(MotorLeft[1],1);
 +
&nbsp;&nbsp;&nbsp;<span style="color: #CC6600;">digitalWrite</span>(MotorRight[0],1);
 +
&nbsp;&nbsp;&nbsp;<span style="color: #CC6600;">digitalWrite</span>(MotorRight[1],0); 
 +
}
 +
<span style="color: #CC6600;">void</span> Robot_Backward()
 +
{
 +
&nbsp;&nbsp;&nbsp;<span style="color: #CC6600;">digitalWrite</span>(MotorLeft[0],1);
 +
&nbsp;&nbsp;&nbsp;<span style="color: #CC6600;">digitalWrite</span>(MotorLeft[1],0);
 +
&nbsp;&nbsp;&nbsp;<span style="color: #CC6600;">digitalWrite</span>(MotorRight[0],0);
 +
&nbsp;&nbsp;&nbsp;<span style="color: #CC6600;">digitalWrite</span>(MotorRight[1],1); 
 +
}
 +
<span style="color: #CC6600;">void</span> Robot_Left()
 +
{
 +
&nbsp;&nbsp;<span style="color: #CC6600;">digitalWrite</span>(MotorLeft[0],1);
 +
&nbsp;&nbsp;<span style="color: #CC6600;">digitalWrite</span>(MotorLeft[1],0);
 +
&nbsp;&nbsp;<span style="color: #CC6600;">digitalWrite</span>(MotorRight[0],1);
 +
&nbsp;&nbsp;<span style="color: #CC6600;">digitalWrite</span>(MotorRight[1],0);   
 +
}
 +
<span style="color: #CC6600;">void</span> Robot_Right()
 +
{
 +
&nbsp;&nbsp;<span style="color: #CC6600;">digitalWrite</span>(MotorLeft[0],0);
 +
&nbsp;&nbsp;<span style="color: #CC6600;">digitalWrite</span>(MotorLeft[1],1);
 +
&nbsp;&nbsp;<span style="color: #CC6600;">digitalWrite</span>(MotorRight[0],0);
 +
&nbsp;&nbsp;<span style="color: #CC6600;">digitalWrite</span>(MotorRight[1],1);   
 +
}
 +
</pre>
 +
</html>
 +
 +
}}

Revision as of 13:55, 27 August 2014

Intro

For this tutorial we will be using the Explore Robo kit. You may go ahead and download the schematics and other details from the link. To give a brief the Robo Controller board has a CP2102 USB to UART(Serial) convertor. We give commands to the robot from the terminal and move it. This is a very simple type and you can easily hack it. The controller board also has a atmega8 MCU with Arduino bootloader, hence we can code it from the Arduino IDE


#include <Firmata.h>
int MotorLeft[2] = {A0,A1};
int MotorRight[2] = {A2,A3};
void setup()
{
Serial.begin(9600);
MotorInit();
Serial.print("********Explore Robo Mode Computer: Controlled************\n\r");
Serial.print("Commands:\n W--->Forward \n S--->Backwards \n A--->Left \n D--->Right\n\r");
}
void loop()
{
int command; 
command = Serial.read();
  switch(command)
 {
    case 'w': Robot_Forward(); delay(100); break; 
    case 's': Robot_Backward(); delay(100); break;  
    case 'a': Robot_Left(); delay(100); break;
    case 'd': Robot_Right(); delay(100); break; 
    //in case the caps lock is ON
    case 'W': Robot_Forward(); delay(100); break; 
    case 'S': Robot_Backward(); delay(100); break;  
    case 'A': Robot_Left(); delay(100); break;
    case 'D': Robot_Right(); delay(100); break;      
    default: break; 
 }     
}
//Intialize the motor
void MotorInit()
{
  int i;
  for(i=0 ; i<2; i++)
  {
  pinMode(MotorLeft[i],OUTPUT);
  pinMode(MotorRight[i],OUTPUT);
  }
}
//Robot Driving Functions
void Robot_Forward()
{
   digitalWrite(MotorLeft[0],0);
   digitalWrite(MotorLeft[1],1);
   digitalWrite(MotorRight[0],1);
   digitalWrite(MotorRight[1],0);   
}
void Robot_Backward()
{
   digitalWrite(MotorLeft[0],1);
   digitalWrite(MotorLeft[1],0);
   digitalWrite(MotorRight[0],0);
   digitalWrite(MotorRight[1],1);  
}
void Robot_Left()
{
  digitalWrite(MotorLeft[0],1);
  digitalWrite(MotorLeft[1],0);
  digitalWrite(MotorRight[0],1);
  digitalWrite(MotorRight[1],0);    
}
void Robot_Right()
{
  digitalWrite(MotorLeft[0],0);
  digitalWrite(MotorLeft[1],1);
  digitalWrite(MotorRight[0],0);
  digitalWrite(MotorRight[1],1);    
}