Octapas

From Curuxa Community

Jump to: navigation, search
Application:
Octapas
Type Robotics
Author Jorge Aparicio Roqueiro
Status Development
Date October 2009 - March, 2010


This is my testing robot built using Curuxa electronic circuits. It's still in development, but I pretend to use it for testing purposes and participate on some robotics championships.

Contents

Hardware

Used Main Boards and Modules

MBP18 Main Board: MBP18
  • Based on a PIC16F88
  • Up to 4096 instructions
  • RAM: 360 bytes
  • EEPROM: 256 bytes
  • 31kHz-8MHz internal oscillator
  • 10-bit, 7-channel Analog-to-Digital Converter
  • Up to 16 data input/outputs


MC2A 1x MC2A

Bidirectional, two-motor controller. Max 1A.

Controls the motos connected to the wheels.

Connect the data pins as defined in the source code.


SISW-SPST 3x SISW-SPST

Simple push button or on-off switch. Two positions. Microcontroller can receive either 0 or 1.

One push-button switches the robot on or off. The other two are used to make it move forward, backwards or rotate. They are only used in one sample program.

Connect them to RA2, RA3 and RA4


LTIND-A 2x LTIND-A

Indicator LED.

They indicate the direction in which the robot is moving.

Connect it to RA0 and RA1.


AO-SPK 1x AO-SPK

Simple, low-power speaker.

Generates a beep when the robot is off.

Connect it to RA7.


SIBW-1Y 2x SIBW-1Y

Reflectivity or black/white sensor.

Detects a black line over a white background

Connect them to RA2 and RA3


Pictures

Octapas Octapas Octapas Octapas Octapas Octapas Octapas Octapas Octapas

Videos

Source Code

Modules Check

/*==================================================================
* Octapas
*
* This program checks the correct behavior of the robot.
* One button turns the robot on, and the other two make it move
* forward, backwards, to the left or to the right.
*
* Connections:
* SISW-SPST: RA2, RA3, RA4
* AO-SPK: RA1 (pin 18)
* MC2A: see below
*
* Jorge Aparicio Roqueiro
*
* http://community.curuxa.org
*
*=================================================================*/
 
#define OSC_8MHz
#include <pic16f88.h>
#include "MBP18.h"
#include "Delays.h"
#include <time.h>
 
typedef unsigned int config;
config at _CONFIG1 __CONFIG = _CP_OFF & _DEBUG_OFF & _WRT_PROTECT_OFF & _CPD_OFF & _LVP_OFF & _BODEN_OFF & _MCLR_OFF & _PWRTE_ON & _WDT_OFF & _INTRC_IO;
 
#define Pressed 0
#define Released 1
#define LedON 1
#define LedOFF 0
 
// Entrada
#define ButtonDch RA2
#define ButtonIzd RA3
#define Pulsador RA4
 
// Salida
#define Spk RA7
 
#define LED1 RA1
#define LED2 RA0
 
#define M1Enable RB1
#define M1In1 RB2
#define M1In2 RB3
 
#define M2Enable RB6
#define M2In1 RB5
#define M2In2 RB4
 
//move motor 1 forward
void M1Fwd();
 
//move motor 1 backwards
void M1Bck();
 
//brake motor 1 electrically
void M1Brake();
 
//motor 1 spins free
void M1Free();
 
//move motor 2 forward
void M2Fwd();
 
//move motor 2 backwards
void M2Bck();
 
//brake motor 2 electrically
void M2Brake();
 
//motor 2 spins free
void M2Free();
 
//simple delay for an unspecified amount of time
void DelayB(int retraso);
 
//the robot moves forward
void forward();
 
//the robot moves backward
void backward();
 
//the robot stops
void stop();
 
//an object has been found, go backwards (a while)
void obejectFound();
 
// the robot tries to turn right
void turnRight();
 
// the robot tries to turn left
void turnLeft();
 
// the  setup of inputs and output of the robots
void Setup()
{
 
    ANSEL = 0;
    //set RA2, RA3, RA4 as a digital input, this is our button
	TRISA2 = TRISA3 = TRISA4 = DigitalInput;
	//set RA0, RA1, RA4, RA7 as a digital output, this is our button
	TRISA0 = TRISA1 = TRISA7 = TRISB1 = TRISB2 = TRISB3 = TRISB4 = TRISB5 = TRISB6 = DigitalOutput;
    }
 
void main(){
 
    // encendidoCon0 is the state of the robot. It is actived if the value is 0 and deactived if the value is 1
    int encendidoCon0 = 1;
    int cambio = 0;
 
    // it setups the outputs and inputs of the robot
    Setup();
 
    // the robot starts in a stop state
    stop();
 
	while(1){
        // while the button (turn on/off) is pressed, the state of the robot doesn't change
        while(Pulsador == Pressed){
            // there is a change in the state of the robot
            cambio = 1;
        }
        // there is a change of state
        if (cambio == 1){
            cambio = 0;
            encendidoCon0 = !encendidoCon0;
        }
        // if the state of the robot is actived
        if(encendidoCon0==0){
            // if no button has been pressed the robot goes forward
            if(ButtonIzd == Released && ButtonDch == Released){
                forward();
                LED1=LedOFF;
                LED2=LedOFF;
            }
            // if the botton left is pressed it turns to the right and turn on LED1
            else if(ButtonIzd == Pressed && ButtonDch == Released){
                LED1=LedON;
                LED2=LedOFF;
                obejectFound();
                turnRight();
 
            }
            // if the botton right is pressed it turns to the left and turn on LED2
            else if(ButtonIzd == Released && ButtonDch == Pressed){
                LED1=LedOFF;
                LED2=LedON;
                obejectFound();
                turnLeft();
            }
            // if both buttons have been pressed then it goes backwards and turn on both LEDs
            else{
                backward();
                LED1=LedON;
                LED2=LedON;
            }
        }
        //if the state is deactived
        else{
            stop();
            // a change of the output for the speak so it makes a beep
            Spk=!Spk;
            // blinking lights
            LED1=!LED1;
            LED2=!LED1;
            Delay(1);
        }
 
    }
}
//the robot moves forward
void forward(){
        M1Fwd();
        M2Fwd();
        LED1=LedON;
        LED2=LedOFF;
    }
 
//the robot moves backward
void backward(){
        M1Bck();
        M2Bck();
        LED1=LedOFF;
        LED2=LedON;
    }
 
//the robot stops
void stop(){
    M1Brake();
    M2Brake();
}
 
//move motor1 forward
void M1Fwd(){
	M1Enable=1;
	M1In1=1;
	M1In2=0;
}
 
//move motor2 forward
void M2Fwd(){
	M2Enable=1;
	M2In1=1;
	M2In2=0;
}
 
//move motor1 backwards
void M1Bck(){
	M1Enable=1;
	M1In1=0;
	M1In2=1;
}
 
//move motor2 backwards
void M2Bck(){
	M2Enable=1;
	M2In1=0;
	M2In2=1;
}
 
//brake motor 1 electrically
void M1Brake(){
	M1Enable=1;
	M1In1=0;
	M1In2=0;
}
 
//motor 1 spins free
void M1Free(){
	M1Enable=0;
}
 
//brake motor 2 electrically
void M2Brake(){
	M2Enable=1;
	M2In1=0;
	M2In2=0;
}
 
//motor 2 spins free
void M2Free(){
	M2Enable=0;
}
 
//simple delay for a specified amount of time
void DelayB(int retraso){
    long i;
    for (i=0; i<retraso; i++) {
        //do nothing
    }
}
 
//an object has been found, go backwards (a while)
void obejectFound(){
    int comienzo;
    for (comienzo = 0; comienzo < 250; comienzo++){
        backward();
        }
}
 
// the robot tries to turn left
void turnLeft(){
    int i;
    for(i = 0; i < 90 ; i++)    {
        M2Fwd();
        M1Bck();
        LED1=!LED1;
        LED2=!LED1;
    }
}
 
// the robot tries to turn right
void turnRight(){
    int i;
    for(i = 0; i < 90 ; i++)    {
        M1Fwd();
        M2Bck();
        LED1=!LED1;
        LED2=!LED1;
    }
}


Line Follower

/*==================================================================
* Octapas
*
* Follow a black line on top of a black background
*
* Connections:
* SISW-SPST: RA2, RA3, RA4
* AO-SPK: RA1 (pin 18)
* MC2A: see below
*
* Jorge Aparicio Roqueiro
*
* http://community.curuxa.org
*
*=================================================================*/
 
#define OSC_8MHz
#include "MBP18.h"
#include "Delays.h"
#include <time.h>
 
typedef unsigned int config;
config at _CONFIG1 __CONFIG = _CP_OFF & _DEBUG_OFF & _WRT_PROTECT_OFF & _CPD_OFF & _LVP_OFF & _BODEN_OFF & _MCLR_OFF & _PWRTE_ON & _WDT_OFF & _INTRC_IO;
 
#define Pressed 0
#define Released 1
#define LedON 1
#define LedOFF 0
#define Blanco 0
#define Negro 1
 
// Entrada
#define Sensor_D0 RA2
#define Sensor_I0 RA3
#define Pulsador RA5
 
// Salida
#define LED1 RA6
#define LED2 RA1
 
#define M1Enable RB1
#define M1In1 RB2
#define M1In2 RB3
 
#define M2Enable RB6
#define M2In1 RB5
#define M2In2 RB4
 
//move motor 1 forward
void M1Fwd();
 
//move motor 1 backwards
void M1Bck();
 
//brake motor 1 electrically
void M1Brake();
 
//motor 1 spins free
void M1Free();
 
//move motor 2 forward
void M2Fwd();
 
//move motor 2 backwards
void M2Bck();
 
//brake motor 2 electrically
void M2Brake();
 
//motor 2 spins free
void M2Free();
 
//simple delay for an unspecified amount of time
void DelayB(int retraso);
 
//the robot moves forward
void forward();
 
//the robot moves backward
void backward();
 
//the robot stops
void stop();
 
//an object has been found, go backwards (a while)
void obejectFound();
 
// the robot tries to turn right
void turnRight();
 
// the robot tries to turn left
void turnLeft();
 
// the  setup of inputs and output of the robots
void Setup()
{
    ANSEL = 0;
    //set R... as a digital input, this is our button
	TRISA2 = TRISA3 = TRISA5 = DigitalInput;
	//set R... as a digital output, this is our button
	TRISA1 = TRISA6 = TRISB1 = TRISB2 = TRISB3 = TRISB4 = TRISB5 = TRISB6 = DigitalOutput;
    }
 
void main(){
    // encendidoCon0 is the state of the robot. It is actived if the value is 0 and deactived if the value is 1
    int encendidoCon0 = 1;
    int cambio = 0;
 
    // it setups the outputs and inputs of the robot
    Setup();
 
    LED1 = 0;
    LED2 = 0;
 
	while(1){
	    if(Sensor_I0 == Negro && Sensor_D0 == Negro)    {
            M1Fwd();
            M2Fwd();
	    }
        else if(Sensor_I0 == Blanco && Sensor_D0 == Negro)   {
            M1Free();
            M2Fwd();
            }
        else if(Sensor_I0 == Negro && Sensor_D0 == Blanco)   {
            M2Free();
            M1Fwd();
            }
        else{
            //M1Free();
            //M2Free();
            LED1 = !LED1;
            LED2 = !LED2;
            }
    }
}
//the robot moves forward
void forward(){
        M1Fwd();
        M2Fwd();
    }
 
//the robot moves backward
void backward(){
        M1Bck();
        M2Bck();
    }
 
//the robot stops
void stop(){
    M1Brake();
    M2Brake();
}
 
//move motor1 forward
void M1Fwd(){
	M1Enable=1;
	M1In1=1;
	M1In2=0;
}
 
//move motor2 forward
void M2Fwd(){
	M2Enable=1;
	M2In1=1;
	M2In2=0;
}
 
//move motor1 backwards
void M1Bck(){
	M1Enable=1;
	M1In1=0;
	M1In2=1;
}
 
//move motor2 backwards
void M2Bck(){
	M2Enable=1;
	M2In1=0;
	M2In2=1;
}
 
//brake motor 1 electrically
void M1Brake(){
	M1Enable=1;
	M1In1=0;
	M1In2=0;
}
 
//motor 1 spins free
void M1Free(){
	M1Enable=0;
}
 
//brake motor 2 electrically
void M2Brake(){
	M2Enable=1;
	M2In1=0;
	M2In2=0;
}
 
//motor 2 spins free
void M2Free(){
	M2Enable=0;
}
 
//simple delay for a specified amount of time
void DelayB(int retraso){
    long i;
    for (i=0; i<retraso; i++) {
        //do nothing
    }
}
 
//an object has been found, go backwards (a while)
void obejectFound(){
    int comienzo;
    for (comienzo = 0; comienzo < 250; comienzo++){
        backward();
        }
}
 
// the robot tries to turn left
void turnLeft(){
    int i;
    for(i = 0; i < 90 ; i++)    {
        M2Fwd();
        M1Bck();
    }
}
 
// the robot tries to turn right
void turnRight(){
    int i;
    for(i = 0; i < 90 ; i++)    {
        M1Fwd();
        M2Bck();
    }
}
Personal tools