Archive for the ‘Robotics’ Category

A line follower is just like a hello world in robotics. Many have been made and nowadays are based on arduino boards, this time I want to go old school and build this simple line follower from parts on my bin. The DS89C430 is a fast 8051 core variant from Maxim, before the era of arduino these are the microcontrollers that only requires UART connection and do not require a external programmer to load the bootloader because it is loaded with bootloader already from the factory and only a terminal program is required to load the hex file generated from the assembler or compiler.

This line follower consist of 3 TCRT5000 reflective IR sensors that goest to a LM339 quad comparator that gives the microcontroller a high or low signal when a black line is detected or not. A L9110S motor driver module was used to drive the two DC motors in differential drive mode. The whole project is powered by a single 3.7V 18650 battery from an old laptop battery pack. The output is fed to a boost converter based on the classic MC34063 to boost the battery voltage to 5V. The complete schematic is show below.

follower

Schematic Diagram

The whole project is built on a strip board with mixed thru hole and surface mount components depending on what I have on my bin.

P_20161231_111255.jpg

P_20161231_111512.jpg

And now the code! Basically a logic based on its position on the track. One motor is stopped to make a turn. The code is compiled with SDCC.

code.PNG

Voila! a nice line follower that can navigate even a complicated track! See the video demo below

This is my first post for the year, been busy for a while. The Pbot is an entry level mobile robot learning platform locally available in e-gizmo here in the Philippines. It contains three channel IR collision sensor, 3 Channel line sensor and a dual motor driver. Any arduino compatible platform can be used as the controller. It is a fun mobot platform to play with, can be configured as a line follower, a mazer or a sumobot or even a soccer bot.
Pbot

A quick weekend project to play with this mobot platform is to control it with VB.net thru Bluetooth Serial Port. When playing with these toys, it is important to know whether your battery still have the juice so you can enjoy playing, but the old board (that I have) don’t have a connection for battery feedback. My quick solution is to put a voltage divider (two 100K resistors) between the battery terminals and feed it to the Analog Input 0 of the controller.

Remote

The Arduino program transmits data every second to the computer then waits for a character from the Computer, When a correct character is received, then it tells the motors what to do.

Voila! Vb.net Controlled Pbot with Battery Status Feedback

The code listing for the Arduino

/*
'Pbot Remote Control with VB.net 2010
'Copyright (C) 2014 Richard Myrick T. Arellaga
'
'This program is free software: you can redistribute it and/or modify
'it under the terms of the GNU General Public License as published by
'the Free Software Foundation, either version 3 of the License, or
'(at your option) any later version.
'
'This program is distributed in the hope that it will be useful,
'but WITHOUT ANY WARRANTY; without even the implied warranty of
'MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
'GNU General Public License for more details.
'
' You should have received a copy of the GNU General Public License
' along with this program. If not, see .
*/

int batt = 0;
float voltage = 0;

long prevMillis = 0;
long interval = 1000;
int rx = 0;

const int M1DIR = 8;
const int M1RUN = 9;
const int M2RUN = 10;
const int M2DIR = 11;

void setup()
{
pinMode(M1DIR,OUTPUT);
pinMode(M1RUN,OUTPUT);
pinMode(M2RUN,OUTPUT);
pinMode(M2DIR,OUTPUT);

Serial.begin(9600);

}

void loop()
{
//Run RTC and send battery update every second
unsigned long currentMillis = millis();
if(currentMillis - prevMillis > interval)
{

prevMillis = currentMillis;
batt = analogRead(0);
voltage = (batt/1023.0)* (2 * readVcc());
Serial.println(voltage);

}

//check serial port character receive
if(Serial.available()){
rx=Serial.read();

if(rx == 'W')
{
digitalWrite(M1DIR,HIGH);
analogWrite(M1RUN,250);
analogWrite(M2RUN,250);
digitalWrite(M2DIR,HIGH);
rx = 0;
}else if(rx == 'Q')
{
digitalWrite(M1DIR,LOW);
analogWrite(M1RUN,0);
analogWrite(M2RUN,0);
digitalWrite(M2DIR,LOW);
rx = 0;
}else if(rx == 'S')
{
digitalWrite(M1DIR,LOW);
analogWrite(M1RUN,250);
analogWrite(M2RUN,250);
digitalWrite(M2DIR,LOW);
rx = 0;
} else if(rx == 'D')
{
digitalWrite(M1DIR,HIGH);
analogWrite(M1RUN,250);
analogWrite(M2RUN,0);
digitalWrite(M2DIR,LOW);
rx = 0;
}
else if(rx == 'A')
{
digitalWrite(M1DIR,LOW);
analogWrite(M1RUN,0);
analogWrite(M2RUN,250);
digitalWrite(M2DIR,HIGH);
rx = 0;
}
}
}

//read actual VCC of arduino for a more accurate adc reading
long readVcc() {
long result;
// Read 1.1V reference against AVcc
ADMUX = _BV(REFS0) | _BV(MUX3) | _BV(MUX2) | _BV(MUX1);
delay(2); // Wait for Vref to settle
ADCSRA |= _BV(ADSC); // Convert
while (bit_is_set(ADCSRA,ADSC));
result = ADCL;
result |= ADCH<<8;
result = 1126400L / result; // Back-calculate AVcc in mV

return result/1000;
}

VB.net Code Listing


'Pbot Remote Control with VB.net 2010
'Copyright (C) 2014 Richard Myrick T. Arellaga
'
'This program is free software: you can redistribute it and/or modify
'it under the terms of the GNU General Public License as published by
'the Free Software Foundation, either version 3 of the License, or
'(at your option) any later version.
'
'This program is distributed in the hope that it will be useful,
'but WITHOUT ANY WARRANTY; without even the implied warranty of
'MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
'GNU General Public License for more details.
'
' You should have received a copy of the GNU General Public License
' along with this program. If not, see .

Imports System.IO.Ports
Imports System.Text

Public Class Form1

Private pendingMsg As New StringBuilder()

Private Sub GetCOMPortList()
Dim i As Integer
Dim foundDifference = False

If cboCOMPorts.Items.Count = SerialPort.GetPortNames().Length Then
For Each s As String In SerialPort.GetPortNames()
If cboCOMPorts.Items(System.Math.Max(System.Threading.Interlocked.Increment(i), i - 1)).Equals(s) = False Then
foundDifference = True
End If
Next
Else
foundDifference = True
End If

If foundDifference = False Then
Return
End If

cboCOMPorts.Items.Clear()

For Each s As String In SerialPort.GetPortNames()
cboCOMPorts.Items.Add(s)
Next
cboCOMPorts.SelectedIndex = 0

End Sub

Private Sub serialPort1_DataReceived(ByVal sender As Object, ByVal e As SerialDataReceivedEventArgs) Handles SerialPort1.DataReceived

Dim completeMsg As String
completeMsg = String.Empty

pendingMsg.Append(SerialPort1.ReadExisting())

If pendingMsg.Length >= 6 Then
completeMsg = pendingMsg.ToString(0, 6)
pendingMsg.Remove(0, 6)
Me.Invoke(New Action(
Sub()
txtRxData.Text = completeMsg
End Sub))
End If

End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
btnDisconnect.Enabled = False
GetCOMPortList()
End Sub

Private Sub btnConnect_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnConnect.Click

Try
SerialPort1.PortName = cboCOMPorts.Items(cboCOMPorts.SelectedIndex).ToString()
SerialPort1.BaudRate = 9600
SerialPort1.ReadTimeout = 1000
SerialPort1.Open()
btnDisconnect.Enabled = True
btnConnect.Enabled = False
Catch ex As Exception
btnDisconnect.PerformClick()
End Try
End Sub

Private Sub btnDisconnect_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDisconnect.Click
Try
SerialPort1.DiscardInBuffer()
SerialPort1.DiscardOutBuffer()
SerialPort1.Close()
btnConnect.Enabled = True
btnDisconnect.Enabled = False
Catch ex As Exception

End Try
End Sub

Private Sub btnFW_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnFW.Click
If (SerialPort1.IsOpen()) Then
SerialPort1.Write("W")

End If
End Sub

Private Sub btnBack_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnBack.Click
If (SerialPort1.IsOpen()) Then
SerialPort1.Write("S")

End If
End Sub

Private Sub btnLeft_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLeft.Click
If (SerialPort1.IsOpen()) Then
SerialPort1.Write("A")

End If
End Sub

Private Sub btnRight_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRight.Click
If (SerialPort1.IsOpen()) Then
SerialPort1.Write("D")

End If
End Sub

Private Sub btnStop_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnStop.Click
If (SerialPort1.IsOpen()) Then
SerialPort1.Write("Q")

End If
End Sub
End Class

This is my new mobot board for testing newer mobots specifically using the Anito Board based on PIC16F877a. This board is an arduino compatible that can also be used with standard arduino board. It includes a motor driver, a port  for Bluetooth, and a 5 channel Line Tracking Sensor.

PCB Files can be downloaded here:

The Microchip Pickit2 is one of the most hobby friendly PIC programmer in the market. It lets you program the chip within MPLAB and the most important feature is its USB connectivity. I used a JDM based programmer which confines me of programming with my desktop until I had my PIKIT2, electronicslab.ph version of the original pickit2. At work I am using a PICSTART plus programmer which annoys me because I cannot do on the fly update on the development board because I always have to remove the IC from the board then put it in the programmer back to the board so I made this quick simplified pickit2 from the parts I have.

Prototype

The original pickit2 requires a  680uH inductor and a 20Mhz clock, but I only have a 220uH inductor and a 12Mhz crystal so i gave it a try. I programmed the PIC18F2550 with the PICSTART within MPLAB, to use the 12Mhz crystal the PLL prescaler selection bit must be modified to divide by 3. This version of the pickit2 is a strip down version intended for hobbyist and students that do not require the progammer to go feautres, also DO NOT use this pickit2 version on 3.3V PICs since the part for adjusting target VDD is also taken out.

I tested it with another PIC18F2550 and voila! this programmer works like a charm even with a 12Mhz crystal and a 220uH inductor on the VPP circuit. This programmer was also tested with PIC16F628A, PIC12F609 and PIC10F202 without problems.

Schematic

The firmware of the PIC used in the programmer can be found on Program Files\Microchip\MPLAB IDE\PICKit2\PK2V023200.hex. The JDM programmer can also be used to program the PIC18F2550 for the first time, just dont forget to change the PLLDIV to divide by 3 when using a 12Mhz crystal, but when a 20Mhz crystal is used no need to changed anything on the PICkit2 firmware.

Getting started with mobile robots, we definitely need a platform where we can fit the electronics of our robot and make it move. In this tutorial we will be making a cheap mobile robot platform from a toy commonly called as tumbling car here in the Philippines. It can be bought almost anywhere specially on Chinese discount stores at 40-50 pesos.

The Materials:

2 – Tumbling car

1 – Small screwdriver

1 – Side Cutter or small saw

1 – Super glue

 

Let’s get started:

First, unscrew the top cover by removing the two screws at the bottom side of the toy

Toys with top cover removed

Next, remove the wheels opposite the motor and the gearbox as shown

Trim down the shaft for proper alignment

Put super glue all around on one of the cars

 

Align and put them together

You may add a plastic or metal link for more strength and ruggedness against bumps like the one shown below

Wait for the superglue to dry and voila!, you now have a less than 200 Pesos robot platform in less than 30 minutes

A few months ago, members of electronicslab.ph conceptualize a Filipino Version of Robot Wars the D-Wars –>> Filipino Version of Robot Wars, open to students, enthusiast hobbyist and everyone else who is interested. Thus, I came up building my own autonomous sumo bot later I named Nemesis.

Specifications:

Processor: PIC16F628 at 8Mhz

Sensors: 2 E-gizmo IR Proximity Sensor Kit for enemy detection

2 IR reflective  Sensors for line detection

Powersource: 4x AA for Motors

1x9V for processor and sensors

Motors: Tamiya TwinGearbox Motors 204:1 Gear Ratio

Motor Driver: L293D

Front IR  Sensor Testing

Bottom IR Sensor Testing

The software is still in the infant stage and still many things to add specially on how it will attack its enemy.

I rebuilt my differential line follower, basically the same circuit with the first version, the only difference is PIC16F628 was used and a provision for Sumo Bot is implement