(Created page with "Category:Robotics")
 
 
(11 intermediate revisions by the same user not shown)
Line 1: Line 1:
[[Category:Robotics]]
+
[[Category:Robotics Tutorials]]
 +
{{#ev:youtube|aFyaYK5OJYU|680}}
 +
Skip to 0.42 sec for computer controlled.
 +
=Intro=
 +
{{Box|type=l_green_light|text=
 +
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
 +
<br />
 +
}}
 +
=Circuit=
 +
{{Box|type=l_green_light|text=
 +
The schematic for this can be downloaded from [[Explore Robo]] page. However what we need to know to make a computer controlled robot is where the motors are connected to the MCU. Note that these first go to a L293D bridge and then to the actual motors.
 +
You can see the Arduino pin numbers from the image below:
 +
Hence the motors would rotate if the combination is sent as per table below:
 +
}}
 +
{| class="wikitable"
 +
|-
 +
|
 +
Input
 +
| colspan="4" |
 +
<center>Arduino Pins</center>
 +
|
 +
Robot
 +
|-
 +
|
 +
 
 +
|
 +
<center>A0</center>
 +
|
 +
A1
 +
|
 +
A2
 +
|
 +
A3
 +
|
 +
 
 +
|-
 +
|
 +
W
 +
|
 +
<center>0</center>
 +
|
 +
1
 +
|
 +
1
 +
|
 +
0
 +
|
 +
Forward
 +
|-
 +
|
 +
S
 +
|
 +
<center>1</center>
 +
|
 +
0
 +
|
 +
0
 +
|
 +
1
 +
|
 +
Backward
 +
|-
 +
|
 +
A
 +
|
 +
<center>0</center>
 +
|
 +
1
 +
|
 +
0
 +
|
 +
1
 +
|
 +
Left
 +
|-
 +
|
 +
D
 +
|
 +
<center>1</center>
 +
|
 +
0
 +
|
 +
1
 +
|
 +
0
 +
|
 +
Right
 +
|}
 +
 
 +
[[File:Explore Robo Pinout.jpg|x430px]]
 +
 
 +
=Code=
 +
<syntaxhighlight>
 +
#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.println("Commands:\n W->Forward \n S->Backwards \n A->Left \n D->Right");
 +
}
 +
 
 +
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);   
 +
}
 +
</syntaxhighlight>
 +
{{DISQUS}}

Latest revision as of 14:47, 27 August 2014

Skip to 0.42 sec for computer controlled.

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

Circuit

The schematic for this can be downloaded from Explore Robo page. However what we need to know to make a computer controlled robot is where the motors are connected to the MCU. Note that these first go to a L293D bridge and then to the actual motors. You can see the Arduino pin numbers from the image below: Hence the motors would rotate if the combination is sent as per table below:

Input

Arduino Pins

Robot

A0

A1

A2

A3

W

0

1

1

0

Forward

S

1

0

0

1

Backward

A

0

1

0

1

Left

D

1

0

1

0

Right

Explore Robo Pinout.jpg

Code

#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.println("Commands:\n W->Forward \n S->Backwards \n A->Left \n D->Right");
}
 
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);    
}